From 8f036778018c47dec34b970bfa9ae9ae7db0629e Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Wed, 3 Jun 2020 23:38:48 +0800 Subject: [PATCH] feat: remove getInflation in favor of getInflationGovernor --- web3.js/module.d.ts | 5 ++-- web3.js/module.flow.js | 11 ++++--- web3.js/package.json | 2 +- web3.js/src/connection.js | 27 +++++++++-------- web3.js/test/connection.test.js | 40 ++++++++++++++++---------- web3.js/test/nonce.test.js | 4 ++- web3.js/test/transaction-payer.test.js | 9 +++--- 7 files changed, 54 insertions(+), 44 deletions(-) diff --git a/web3.js/module.d.ts b/web3.js/module.d.ts index 9b65764924..de248da5e7 100644 --- a/web3.js/module.d.ts +++ b/web3.js/module.d.ts @@ -170,11 +170,10 @@ declare module '@solana/web3.js' { err: TransactionError | null; }; - export type Inflation = { + export type InflationGovernor = { foundation: number; foundationTerm: number; initial: number; - storage: number; taper: number; terminal: number; }; @@ -266,7 +265,7 @@ declare module '@solana/web3.js' { getTransactionCount(commitment?: Commitment): Promise; getTotalSupply(commitment?: Commitment): Promise; getVersion(): Promise; - getInflation(commitment?: Commitment): Promise; + getInflationGovernor(commitment?: Commitment): Promise; getEpochSchedule(): Promise; getEpochInfo(commitment?: Commitment): Promise; getRecentBlockhashAndContext( diff --git a/web3.js/module.flow.js b/web3.js/module.flow.js index c3c99d9c07..cfd47f897f 100644 --- a/web3.js/module.flow.js +++ b/web3.js/module.flow.js @@ -55,12 +55,12 @@ declare module '@solana/web3.js' { }; declare export type SendOptions = { - skipPreflight: boolean; + skipPreflight: boolean, }; declare export type ConfirmOptions = { - confirmations: number; - skipPreflight: boolean; + confirmations: number, + skipPreflight: boolean, }; declare export type RpcResponseAndContext = { @@ -183,11 +183,10 @@ declare module '@solana/web3.js' { err: TransactionError | null, |}; - declare export type Inflation = { + declare export type InflationGovernor = { foundation: number, foundationTerm: number, initial: number, - storage: number, taper: number, terminal: number, }; @@ -279,7 +278,7 @@ declare module '@solana/web3.js' { getTransactionCount(commitment: ?Commitment): Promise; getTotalSupply(commitment: ?Commitment): Promise; getVersion(): Promise; - getInflation(commitment: ?Commitment): Promise; + getInflationGovernor(commitment: ?Commitment): Promise; getEpochSchedule(): Promise; getEpochInfo(commitment: ?Commitment): Promise; getRecentBlockhashAndContext( diff --git a/web3.js/package.json b/web3.js/package.json index 23b7c2d5d1..75b485e57e 100644 --- a/web3.js/package.json +++ b/web3.js/package.json @@ -40,7 +40,7 @@ "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 {} \\;", "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": "rimraf ./coverage ./lib", "codecov": "set -ex; npm run test:cover; cat ./coverage/lcov.info | codecov", diff --git a/web3.js/src/connection.js b/web3.js/src/connection.js index e160485704..c5b40de0c2 100644 --- a/web3.js/src/connection.js +++ b/web3.js/src/connection.js @@ -212,28 +212,25 @@ type VoteAccountStatus = { * Network Inflation * (see https://docs.solana.com/implemented-proposals/ed_overview) * - * @typedef {Object} Inflation + * @typedef {Object} InflationGovernor * @property {number} foundation * @property {number} foundation_term * @property {number} initial - * @property {number} storage * @property {number} taper * @property {number} terminal */ -type Inflation = { +type InflationGovernor = { foundation: number, foundationTerm: number, initial: number, - storage: number, taper: number, terminal: number, }; -const GetInflationResult = struct({ +const GetInflationGovernorResult = struct({ foundation: 'number', foundationTerm: 'number', initial: 'number', - storage: 'number', taper: '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'), id: 'string', 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 { + async getInflationGovernor( + commitment: ?Commitment, + ): Promise { const args = this._argsWithCommitment([], commitment); - const unsafeRes = await this._rpcRequest('getInflation', args); - const res = GetInflationRpcResult(unsafeRes); + const unsafeRes = await this._rpcRequest('getInflationGovernor', args); + const res = GetInflationGovernorRpcResult(unsafeRes); if (res.error) { throw new Error('failed to get inflation: ' + res.error.message); } assert(typeof res.result !== 'undefined'); - return GetInflationResult(res.result); + return GetInflationGovernorResult(res.result); } /** diff --git a/web3.js/test/connection.test.js b/web3.js/test/connection.test.js index 141fc36b31..8a9f053578 100644 --- a/web3.js/test/connection.test.js +++ b/web3.js/test/connection.test.js @@ -324,7 +324,7 @@ test('get inflation', async () => { mockRpc.push([ url, { - method: 'getInflation', + method: 'getInflationGovernor', params: [], }, { @@ -333,14 +333,13 @@ test('get inflation', async () => { foundation: 0.05, foundationTerm: 7.0, initial: 0.15, - storage: 0.1, taper: 0.15, terminal: 0.015, }, }, ]); - const inflation = await connection.getInflation(); + const inflation = await connection.getInflationGovernor(); for (const key of [ 'initial', @@ -348,7 +347,6 @@ test('get inflation', async () => { 'taper', 'foundation', 'foundationTerm', - 'storage', ]) { expect(inflation).toHaveProperty(key); expect(inflation[key]).toBeGreaterThan(0); @@ -1529,9 +1527,14 @@ test('transaction failure', async () => { newAccountPubkey: newAccount.publicKey, lamports: 1000, 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([ url, @@ -1551,9 +1554,13 @@ test('transaction failure', async () => { newAccountPubkey: newAccount.publicKey, lamports: 10, 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}]}; mockRpc.push([ @@ -1738,9 +1745,11 @@ test('transaction', async () => { toPubkey: accountTo.publicKey, lamports: 10, }); - const signature = await connection.sendTransaction(transaction, [ - accountFrom, - ], {skipPreflight: true}); + const signature = await connection.sendTransaction( + transaction, + [accountFrom], + {skipPreflight: true}, + ); mockRpc.push([ url, @@ -1942,10 +1951,11 @@ test('multi-instruction transaction', async () => { lamports: 100, }), ); - const signature = await connection.sendTransaction(transaction, [ - accountFrom, - accountTo, - ], {skipPreflight: true}); + const signature = await connection.sendTransaction( + transaction, + [accountFrom, accountTo], + {skipPreflight: true}, + ); await connection.confirmTransaction(signature, 1); diff --git a/web3.js/test/nonce.test.js b/web3.js/test/nonce.test.js index 45ba17c2f0..842471e569 100644 --- a/web3.js/test/nonce.test.js +++ b/web3.js/test/nonce.test.js @@ -103,7 +103,9 @@ test('create and query nonce account', async () => { authorizedPubkey: from.publicKey, lamports: minimumAmount, }); - await connection.sendTransaction(transaction, [from, nonceAccount], {skipPreflight: true}); + await connection.sendTransaction(transaction, [from, nonceAccount], { + skipPreflight: true, + }); mockRpc.push([ url, diff --git a/web3.js/test/transaction-payer.test.js b/web3.js/test/transaction-payer.test.js index 60473a78e0..e7ba0201f0 100644 --- a/web3.js/test/transaction-payer.test.js +++ b/web3.js/test/transaction-payer.test.js @@ -105,10 +105,11 @@ test('transaction-payer', async () => { lamports: 10, }); - const signature = await connection.sendTransaction(transaction, [ - accountPayer, - accountFrom, - ], {skipPreflight: true}); + const signature = await connection.sendTransaction( + transaction, + [accountPayer, accountFrom], + {skipPreflight: true}, + ); mockRpc.push([ url,