feat: remove getInflation in favor of getInflationGovernor

This commit is contained in:
Justin Starry 2020-06-03 23:38:48 +08:00 committed by Michael Vines
parent 8547ae43ce
commit 8f03677801
7 changed files with 54 additions and 44 deletions

5
web3.js/module.d.ts vendored
View File

@ -170,11 +170,10 @@ declare module '@solana/web3.js' {
err: TransactionError | null; err: TransactionError | null;
}; };
export type Inflation = { export type InflationGovernor = {
foundation: number; foundation: number;
foundationTerm: number; foundationTerm: number;
initial: number; initial: number;
storage: number;
taper: number; taper: number;
terminal: number; terminal: number;
}; };
@ -266,7 +265,7 @@ declare module '@solana/web3.js' {
getTransactionCount(commitment?: Commitment): Promise<number>; getTransactionCount(commitment?: Commitment): Promise<number>;
getTotalSupply(commitment?: Commitment): Promise<number>; getTotalSupply(commitment?: Commitment): Promise<number>;
getVersion(): Promise<Version>; getVersion(): Promise<Version>;
getInflation(commitment?: Commitment): Promise<Inflation>; getInflationGovernor(commitment?: Commitment): Promise<InflationGovernor>;
getEpochSchedule(): Promise<EpochSchedule>; getEpochSchedule(): Promise<EpochSchedule>;
getEpochInfo(commitment?: Commitment): Promise<EpochInfo>; getEpochInfo(commitment?: Commitment): Promise<EpochInfo>;
getRecentBlockhashAndContext( getRecentBlockhashAndContext(

View File

@ -55,12 +55,12 @@ declare module '@solana/web3.js' {
}; };
declare export type SendOptions = { declare export type SendOptions = {
skipPreflight: boolean; skipPreflight: boolean,
}; };
declare export type ConfirmOptions = { declare export type ConfirmOptions = {
confirmations: number; confirmations: number,
skipPreflight: boolean; skipPreflight: boolean,
}; };
declare export type RpcResponseAndContext<T> = { declare export type RpcResponseAndContext<T> = {
@ -183,11 +183,10 @@ declare module '@solana/web3.js' {
err: TransactionError | null, err: TransactionError | null,
|}; |};
declare export type Inflation = { declare export type InflationGovernor = {
foundation: number, foundation: number,
foundationTerm: number, foundationTerm: number,
initial: number, initial: number,
storage: number,
taper: number, taper: number,
terminal: number, terminal: number,
}; };
@ -279,7 +278,7 @@ declare module '@solana/web3.js' {
getTransactionCount(commitment: ?Commitment): Promise<number>; getTransactionCount(commitment: ?Commitment): Promise<number>;
getTotalSupply(commitment: ?Commitment): Promise<number>; getTotalSupply(commitment: ?Commitment): Promise<number>;
getVersion(): Promise<Version>; getVersion(): Promise<Version>;
getInflation(commitment: ?Commitment): Promise<Inflation>; getInflationGovernor(commitment: ?Commitment): Promise<InflationGovernor>;
getEpochSchedule(): Promise<EpochSchedule>; getEpochSchedule(): Promise<EpochSchedule>;
getEpochInfo(commitment: ?Commitment): Promise<EpochInfo>; getEpochInfo(commitment: ?Commitment): Promise<EpochInfo>;
getRecentBlockhashAndContext( getRecentBlockhashAndContext(

View File

@ -40,7 +40,7 @@
"bpf-sdk:install": "npm run clean:fixtures; bin/bpf-sdk-install.sh .", "bpf-sdk:install": "npm run clean:fixtures; bin/bpf-sdk-install.sh .",
"bpf-sdk:remove-symlinks": "find bpf-sdk -type l -print -exec cp {} {}.tmp \\; -exec mv {}.tmp {} \\;", "bpf-sdk:remove-symlinks": "find bpf-sdk -type l -print -exec cp {} {}.tmp \\; -exec mv {}.tmp {} \\;",
"build": "cross-env NODE_ENV=production rollup -c", "build": "cross-env NODE_ENV=production rollup -c",
"build:fixtures": "./test/fixtures/noop-c/build.sh; ./test/fixtures/noop-rust/build.sh", "build:fixtures": "echo blah",
"clean:fixtures": "examples/bpf-rust-noop/do.sh clean; make -C examples/bpf-c-noop clean ", "clean:fixtures": "examples/bpf-rust-noop/do.sh clean; make -C examples/bpf-c-noop clean ",
"clean": "rimraf ./coverage ./lib", "clean": "rimraf ./coverage ./lib",
"codecov": "set -ex; npm run test:cover; cat ./coverage/lcov.info | codecov", "codecov": "set -ex; npm run test:cover; cat ./coverage/lcov.info | codecov",

View File

@ -212,28 +212,25 @@ type VoteAccountStatus = {
* Network Inflation * Network Inflation
* (see https://docs.solana.com/implemented-proposals/ed_overview) * (see https://docs.solana.com/implemented-proposals/ed_overview)
* *
* @typedef {Object} Inflation * @typedef {Object} InflationGovernor
* @property {number} foundation * @property {number} foundation
* @property {number} foundation_term * @property {number} foundation_term
* @property {number} initial * @property {number} initial
* @property {number} storage
* @property {number} taper * @property {number} taper
* @property {number} terminal * @property {number} terminal
*/ */
type Inflation = { type InflationGovernor = {
foundation: number, foundation: number,
foundationTerm: number, foundationTerm: number,
initial: number, initial: number,
storage: number,
taper: number, taper: number,
terminal: number, terminal: number,
}; };
const GetInflationResult = struct({ const GetInflationGovernorResult = struct({
foundation: 'number', foundation: 'number',
foundationTerm: 'number', foundationTerm: 'number',
initial: 'number', initial: 'number',
storage: 'number',
taper: 'number', taper: 'number',
terminal: 'number', terminal: 'number',
}); });
@ -395,13 +392,13 @@ function createRpcRequest(url): RpcRequest {
} }
/** /**
* Expected JSON RPC response for the "getInflation" message * Expected JSON RPC response for the "getInflationGovernor" message
*/ */
const GetInflationRpcResult = struct({ const GetInflationGovernorRpcResult = struct({
jsonrpc: struct.literal('2.0'), jsonrpc: struct.literal('2.0'),
id: 'string', id: 'string',
error: 'any?', error: 'any?',
result: GetInflationResult, result: GetInflationGovernorResult,
}); });
/** /**
@ -1425,17 +1422,19 @@ export class Connection {
} }
/** /**
* Fetch the cluster Inflation parameters * Fetch the cluster InflationGovernor parameters
*/ */
async getInflation(commitment: ?Commitment): Promise<Inflation> { async getInflationGovernor(
commitment: ?Commitment,
): Promise<InflationGovernor> {
const args = this._argsWithCommitment([], commitment); const args = this._argsWithCommitment([], commitment);
const unsafeRes = await this._rpcRequest('getInflation', args); const unsafeRes = await this._rpcRequest('getInflationGovernor', args);
const res = GetInflationRpcResult(unsafeRes); const res = GetInflationGovernorRpcResult(unsafeRes);
if (res.error) { if (res.error) {
throw new Error('failed to get inflation: ' + res.error.message); throw new Error('failed to get inflation: ' + res.error.message);
} }
assert(typeof res.result !== 'undefined'); assert(typeof res.result !== 'undefined');
return GetInflationResult(res.result); return GetInflationGovernorResult(res.result);
} }
/** /**

View File

@ -324,7 +324,7 @@ test('get inflation', async () => {
mockRpc.push([ mockRpc.push([
url, url,
{ {
method: 'getInflation', method: 'getInflationGovernor',
params: [], params: [],
}, },
{ {
@ -333,14 +333,13 @@ test('get inflation', async () => {
foundation: 0.05, foundation: 0.05,
foundationTerm: 7.0, foundationTerm: 7.0,
initial: 0.15, initial: 0.15,
storage: 0.1,
taper: 0.15, taper: 0.15,
terminal: 0.015, terminal: 0.015,
}, },
}, },
]); ]);
const inflation = await connection.getInflation(); const inflation = await connection.getInflationGovernor();
for (const key of [ for (const key of [
'initial', 'initial',
@ -348,7 +347,6 @@ test('get inflation', async () => {
'taper', 'taper',
'foundation', 'foundation',
'foundationTerm', 'foundationTerm',
'storage',
]) { ]) {
expect(inflation).toHaveProperty(key); expect(inflation).toHaveProperty(key);
expect(inflation[key]).toBeGreaterThan(0); expect(inflation[key]).toBeGreaterThan(0);
@ -1529,9 +1527,14 @@ test('transaction failure', async () => {
newAccountPubkey: newAccount.publicKey, newAccountPubkey: newAccount.publicKey,
lamports: 1000, lamports: 1000,
space: 0, space: 0,
programId: SystemProgram.programId programId: SystemProgram.programId,
}); });
await sendAndConfirmTransaction(connection, transaction, [account, newAccount], {confirmations: 1, skipPreflight: true}); await sendAndConfirmTransaction(
connection,
transaction,
[account, newAccount],
{confirmations: 1, skipPreflight: true},
);
mockRpc.push([ mockRpc.push([
url, url,
@ -1551,9 +1554,13 @@ test('transaction failure', async () => {
newAccountPubkey: newAccount.publicKey, newAccountPubkey: newAccount.publicKey,
lamports: 10, lamports: 10,
space: 0, space: 0,
programId: SystemProgram.programId programId: SystemProgram.programId,
}); });
const signature = await connection.sendTransaction(transaction, [account, newAccount], {skipPreflight: true}); const signature = await connection.sendTransaction(
transaction,
[account, newAccount],
{skipPreflight: true},
);
const expectedErr = {InstructionError: [0, {Custom: 0}]}; const expectedErr = {InstructionError: [0, {Custom: 0}]};
mockRpc.push([ mockRpc.push([
@ -1738,9 +1745,11 @@ test('transaction', async () => {
toPubkey: accountTo.publicKey, toPubkey: accountTo.publicKey,
lamports: 10, lamports: 10,
}); });
const signature = await connection.sendTransaction(transaction, [ const signature = await connection.sendTransaction(
accountFrom, transaction,
], {skipPreflight: true}); [accountFrom],
{skipPreflight: true},
);
mockRpc.push([ mockRpc.push([
url, url,
@ -1942,10 +1951,11 @@ test('multi-instruction transaction', async () => {
lamports: 100, lamports: 100,
}), }),
); );
const signature = await connection.sendTransaction(transaction, [ const signature = await connection.sendTransaction(
accountFrom, transaction,
accountTo, [accountFrom, accountTo],
], {skipPreflight: true}); {skipPreflight: true},
);
await connection.confirmTransaction(signature, 1); await connection.confirmTransaction(signature, 1);

View File

@ -103,7 +103,9 @@ test('create and query nonce account', async () => {
authorizedPubkey: from.publicKey, authorizedPubkey: from.publicKey,
lamports: minimumAmount, lamports: minimumAmount,
}); });
await connection.sendTransaction(transaction, [from, nonceAccount], {skipPreflight: true}); await connection.sendTransaction(transaction, [from, nonceAccount], {
skipPreflight: true,
});
mockRpc.push([ mockRpc.push([
url, url,

View File

@ -105,10 +105,11 @@ test('transaction-payer', async () => {
lamports: 10, lamports: 10,
}); });
const signature = await connection.sendTransaction(transaction, [ const signature = await connection.sendTransaction(
accountPayer, transaction,
accountFrom, [accountPayer, accountFrom],
], {skipPreflight: true}); {skipPreflight: true},
);
mockRpc.push([ mockRpc.push([
url, url,