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;
};
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<number>;
getTotalSupply(commitment?: Commitment): Promise<number>;
getVersion(): Promise<Version>;
getInflation(commitment?: Commitment): Promise<Inflation>;
getInflationGovernor(commitment?: Commitment): Promise<InflationGovernor>;
getEpochSchedule(): Promise<EpochSchedule>;
getEpochInfo(commitment?: Commitment): Promise<EpochInfo>;
getRecentBlockhashAndContext(

View File

@ -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<T> = {
@ -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<number>;
getTotalSupply(commitment: ?Commitment): Promise<number>;
getVersion(): Promise<Version>;
getInflation(commitment: ?Commitment): Promise<Inflation>;
getInflationGovernor(commitment: ?Commitment): Promise<InflationGovernor>;
getEpochSchedule(): Promise<EpochSchedule>;
getEpochInfo(commitment: ?Commitment): Promise<EpochInfo>;
getRecentBlockhashAndContext(

View File

@ -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",

View File

@ -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<Inflation> {
async getInflationGovernor(
commitment: ?Commitment,
): Promise<InflationGovernor> {
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);
}
/**

View File

@ -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);

View File

@ -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,

View File

@ -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,