Skip to content

Commit a6e97cf

Browse files
authored
Fix decodeCommit to allow decoding height 0 commits (cosmos#1678)
1 parent 57e5da2 commit a6e97cf

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ and this project adheres to
1010

1111
- @cosmjs/faucet: `isValidAddress` now accepts addresses up to 128 bytes (e.g.
1212
for Penumbra). ([#1674])
13+
- @cosmjs/tendermint-rpc: Fix `decodeCommit` to allow decoding height 0 commits
14+
with block hash set but empty signatures. ([#1590])
1315

16+
[#1590]: https://github.com/cosmos/cosmjs/issues/1590
1417
[#1674]: https://github.com/cosmos/cosmjs/pull/1674
1518

1619
### Added

packages/tendermint-rpc/src/comet38/adaptor/responses.spec.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
/* eslint-disable @typescript-eslint/naming-convention */
22
import { fromBase64, fromHex } from "@cosmjs/encoding";
33

4-
import { decodeEvent, decodeValidatorGenesis, decodeValidatorInfo, decodeValidatorUpdate } from "./responses";
4+
import {
5+
decodeCommit,
6+
decodeEvent,
7+
decodeValidatorGenesis,
8+
decodeValidatorInfo,
9+
decodeValidatorUpdate,
10+
} from "./responses";
511

612
describe("Responses", () => {
713
describe("decodeEvent", () => {
@@ -30,6 +36,36 @@ describe("Responses", () => {
3036
});
3137
});
3238

39+
describe("decodeCommit", () => {
40+
it("works for commit at height 0", () => {
41+
// See https://github.com/cosmos/cosmjs/issues/1590
42+
const data = {
43+
height: "0",
44+
round: 0,
45+
block_id: {
46+
hash: "617E8F71CC8D555B0D30D2628C919C0DB20F9AFA07E3AA547DF3CBB999B9B33C",
47+
parts: {
48+
total: 1,
49+
hash: "617E8F71CC8D555B0D30D2628C919C0DB20F9AFA07E3AA547DF3CBB999B9B33C",
50+
},
51+
},
52+
signatures: null,
53+
};
54+
expect(decodeCommit(data)).toEqual({
55+
height: 0,
56+
round: 0,
57+
blockId: {
58+
hash: fromHex("617E8F71CC8D555B0D30D2628C919C0DB20F9AFA07E3AA547DF3CBB999B9B33C"),
59+
parts: {
60+
total: 1,
61+
hash: fromHex("617E8F71CC8D555B0D30D2628C919C0DB20F9AFA07E3AA547DF3CBB999B9B33C"),
62+
},
63+
},
64+
signatures: [],
65+
});
66+
});
67+
});
68+
3369
describe("decodeValidatorGenesis", () => {
3470
it("works for genesis format", () => {
3571
// from https://raw.githubusercontent.com/cosmos/mainnet/master/genesis.json

packages/tendermint-rpc/src/comet38/adaptor/responses.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,16 +477,16 @@ function decodeCommitSignature(data: RpcSignature): CommitSignature {
477477
interface RpcCommit {
478478
readonly block_id: RpcBlockId;
479479
readonly height: string;
480-
readonly round: string;
481-
readonly signatures: readonly RpcSignature[];
480+
readonly round: string | number; // Seems to be number now (https://github.com/cosmos/cosmjs/issues/1590)
481+
readonly signatures: readonly RpcSignature[] | null;
482482
}
483483

484-
function decodeCommit(data: RpcCommit): responses.Commit {
484+
export function decodeCommit(data: RpcCommit): responses.Commit {
485485
return {
486486
blockId: decodeBlockId(assertObject(data.block_id)),
487487
height: apiToSmallInt(assertNotEmpty(data.height)),
488488
round: apiToSmallInt(data.round),
489-
signatures: assertArray(data.signatures).map(decodeCommitSignature),
489+
signatures: data.signatures ? assertArray(data.signatures).map(decodeCommitSignature) : [],
490490
};
491491
}
492492

0 commit comments

Comments
 (0)