mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 13:47:12 +00:00
fix: decoding validator update from slashing
This commit is contained in:
parent
42e39f91f4
commit
ae820763d9
@ -10,8 +10,10 @@ and this project adheres to
|
||||
|
||||
- @cosmjs/stargate: Fix valid values of `BondStatusString` for `validators`
|
||||
query ([#1170]).
|
||||
- @cosmjs/tendermint-rpc: Fix decoding validator updates due to slashing ([#1177]).
|
||||
|
||||
[#1170]: https://github.com/cosmos/cosmjs/issues/1170
|
||||
[#1177]: https://github.com/cosmos/cosmjs/issues/1177
|
||||
|
||||
### Changed
|
||||
|
||||
|
@ -49,6 +49,26 @@ describe("Adaptor Responses", () => {
|
||||
votingPower: 11418237,
|
||||
});
|
||||
});
|
||||
|
||||
it("works for block results format without voting power", () => {
|
||||
// from https://rpc.cosmos.network/block_results?height=10883046
|
||||
const update = decodeValidatorUpdate({
|
||||
pub_key: {
|
||||
Sum: {
|
||||
type: "tendermint.crypto.PublicKey_Ed25519",
|
||||
value: {
|
||||
ed25519: "HjSC7VkhKih6xMhudlqfaFE8ZZnP8RKJPv4iqR7RhcE="
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
expect(update).toEqual({
|
||||
pubkey: {
|
||||
algorithm: "ed25519",
|
||||
data: fromBase64("HjSC7VkhKih6xMhudlqfaFE8ZZnP8RKJPv4iqR7RhcE="),
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("decodeValidatorInfo", () => {
|
||||
|
@ -257,13 +257,13 @@ function decodeConsensusParams(data: RpcConsensusParams): responses.ConsensusPar
|
||||
// for block results
|
||||
interface RpcValidatorUpdate {
|
||||
readonly pub_key: RpcPubkey;
|
||||
readonly power: string;
|
||||
readonly power?: string;
|
||||
}
|
||||
|
||||
export function decodeValidatorUpdate(data: RpcValidatorUpdate): responses.ValidatorUpdate {
|
||||
return {
|
||||
pubkey: decodePubkey(assertObject(data.pub_key)),
|
||||
votingPower: Integer.parse(assertNotEmpty(data.power)),
|
||||
votingPower: data.power ? Integer.parse(data.power) : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -356,7 +356,7 @@ export interface Validator {
|
||||
|
||||
export interface ValidatorUpdate {
|
||||
readonly pubkey: ValidatorPubkey;
|
||||
readonly votingPower: number;
|
||||
readonly votingPower?: number;
|
||||
}
|
||||
|
||||
export interface ConsensusParams {
|
||||
|
@ -49,6 +49,26 @@ describe("Adaptor Responses", () => {
|
||||
votingPower: 11418237,
|
||||
});
|
||||
});
|
||||
|
||||
it("works for block results format without voting power", () => {
|
||||
// from https://rpc.cosmos.network/block_results?height=10883046
|
||||
const update = decodeValidatorUpdate({
|
||||
pub_key: {
|
||||
Sum: {
|
||||
type: "tendermint.crypto.PublicKey_Ed25519",
|
||||
value: {
|
||||
ed25519: "HjSC7VkhKih6xMhudlqfaFE8ZZnP8RKJPv4iqR7RhcE="
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
expect(update).toEqual({
|
||||
pubkey: {
|
||||
algorithm: "ed25519",
|
||||
data: fromBase64("HjSC7VkhKih6xMhudlqfaFE8ZZnP8RKJPv4iqR7RhcE="),
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("decodeValidatorInfo", () => {
|
||||
|
@ -259,13 +259,13 @@ function decodeConsensusParams(data: RpcConsensusParams): responses.ConsensusPar
|
||||
// for block results
|
||||
interface RpcValidatorUpdate {
|
||||
readonly pub_key: RpcPubkey;
|
||||
readonly power: string;
|
||||
readonly power?: string;
|
||||
}
|
||||
|
||||
export function decodeValidatorUpdate(data: RpcValidatorUpdate): responses.ValidatorUpdate {
|
||||
return {
|
||||
pubkey: decodePubkey(assertObject(data.pub_key)),
|
||||
votingPower: Integer.parse(assertNotEmpty(data.power)),
|
||||
votingPower: data.power ? Integer.parse(data.power) : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -361,7 +361,7 @@ export interface Validator {
|
||||
|
||||
export interface ValidatorUpdate {
|
||||
readonly pubkey: ValidatorPubkey;
|
||||
readonly votingPower: number;
|
||||
readonly votingPower?: number;
|
||||
}
|
||||
|
||||
export interface ConsensusParams {
|
||||
|
Loading…
x
Reference in New Issue
Block a user