Merge pull request #664 from cosmos/659-fix-tendermint-validator-type
Fix Tendermint RPC Validator types
This commit is contained in:
commit
965fc20ac7
@ -166,6 +166,7 @@ interface RpcValidatorUpdate {
|
||||
readonly address: string;
|
||||
readonly pub_key: RpcPubkey;
|
||||
readonly voting_power: string;
|
||||
readonly proposer_priority: string;
|
||||
}
|
||||
|
||||
function decodeValidatorUpdate(data: RpcValidatorUpdate): responses.Validator {
|
||||
@ -173,6 +174,7 @@ function decodeValidatorUpdate(data: RpcValidatorUpdate): responses.Validator {
|
||||
pubkey: decodePubkey(assertObject(data.pub_key)),
|
||||
votingPower: Integer.parse(assertNotEmpty(data.voting_power)),
|
||||
address: fromHex(assertNotEmpty(data.address)),
|
||||
proposerPriority: Integer.parse(data.proposer_priority),
|
||||
};
|
||||
}
|
||||
|
||||
@ -453,6 +455,8 @@ function decodeCommitResponse(data: RpcCommitResponse): responses.CommitResponse
|
||||
}
|
||||
|
||||
interface RpcValidatorGenesis {
|
||||
/** hex-encoded */
|
||||
readonly address: string;
|
||||
readonly pub_key: RpcPubkey;
|
||||
readonly power: string;
|
||||
readonly name?: string;
|
||||
@ -460,9 +464,9 @@ interface RpcValidatorGenesis {
|
||||
|
||||
function decodeValidatorGenesis(data: RpcValidatorGenesis): responses.Validator {
|
||||
return {
|
||||
address: fromHex(assertNotEmpty(data.address)),
|
||||
pubkey: decodePubkey(assertObject(data.pub_key)),
|
||||
votingPower: Integer.parse(assertNotEmpty(data.power)),
|
||||
name: data.name,
|
||||
};
|
||||
}
|
||||
|
||||
@ -679,27 +683,19 @@ function decodeTxEvent(data: RpcTxEvent): responses.TxEvent {
|
||||
};
|
||||
}
|
||||
|
||||
// for validators
|
||||
interface RpcValidatorData extends RpcValidatorUpdate {
|
||||
readonly accum?: string;
|
||||
}
|
||||
|
||||
function decodeValidatorData(data: RpcValidatorData): responses.Validator {
|
||||
return {
|
||||
...decodeValidatorUpdate(data),
|
||||
accum: may(Integer.parse, data.accum),
|
||||
};
|
||||
}
|
||||
|
||||
interface RpcValidatorsResponse {
|
||||
readonly block_height: string;
|
||||
readonly validators: readonly RpcValidatorData[];
|
||||
readonly validators: readonly RpcValidatorUpdate[];
|
||||
readonly count: string;
|
||||
readonly total: string;
|
||||
}
|
||||
|
||||
function decodeValidators(data: RpcValidatorsResponse): responses.ValidatorsResponse {
|
||||
return {
|
||||
blockHeight: Integer.parse(assertNotEmpty(data.block_height)),
|
||||
results: assertArray(data.validators).map(decodeValidatorData),
|
||||
validators: assertArray(data.validators).map(decodeValidatorUpdate),
|
||||
count: Integer.parse(assertNotEmpty(data.count)),
|
||||
total: Integer.parse(assertNotEmpty(data.total)),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -130,6 +130,24 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
client.disconnect();
|
||||
});
|
||||
|
||||
it("can get validators", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const response = await client.validators();
|
||||
|
||||
expect(response).toBeTruthy();
|
||||
expect(response.blockHeight).toBeGreaterThanOrEqual(1);
|
||||
expect(response.count).toBeGreaterThanOrEqual(1);
|
||||
expect(response.total).toBeGreaterThanOrEqual(1);
|
||||
expect(response.validators.length).toBeGreaterThanOrEqual(1);
|
||||
expect(response.validators[0].address.length).toEqual(20);
|
||||
expect(response.validators[0].pubkey).toBeDefined();
|
||||
expect(response.validators[0].votingPower).toBeGreaterThanOrEqual(0);
|
||||
expect(response.validators[0].proposerPriority).toBeGreaterThanOrEqual(0);
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
|
||||
it("can call a bunch of methods", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
@ -137,7 +155,6 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
expect(await client.block()).toBeTruthy();
|
||||
expect(await client.genesis()).toBeTruthy();
|
||||
expect(await client.health()).toBeNull();
|
||||
expect(await client.validators()).toBeTruthy();
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
|
||||
@ -140,7 +140,9 @@ export interface TxSearchResponse {
|
||||
|
||||
export interface ValidatorsResponse {
|
||||
readonly blockHeight: number;
|
||||
readonly results: readonly Validator[];
|
||||
readonly validators: readonly Validator[];
|
||||
readonly count: number;
|
||||
readonly total: number;
|
||||
}
|
||||
|
||||
// Events
|
||||
@ -307,13 +309,11 @@ export interface SyncInfo {
|
||||
readonly catchingUp: boolean;
|
||||
}
|
||||
|
||||
// this is in status
|
||||
export interface Validator {
|
||||
readonly address?: Uint8Array;
|
||||
readonly pubkey: ValidatorPubkey;
|
||||
readonly address: Uint8Array;
|
||||
readonly pubkey?: ValidatorPubkey;
|
||||
readonly votingPower: number;
|
||||
readonly accum?: number;
|
||||
readonly name?: string;
|
||||
readonly proposerPriority?: number;
|
||||
}
|
||||
|
||||
export interface ConsensusParams {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user