Fix beginBlockEvents/endBlockEvents

This commit is contained in:
Simon Warta 2020-09-21 13:24:51 +02:00
parent c97c43fbc7
commit 318e37868e
5 changed files with 27 additions and 9 deletions

View File

@ -56,6 +56,9 @@
`Record<string, unknown> | undefined`.
- @cosmjs/tendermint-rpc: Remove obsolete `TxData.tags` and make `TxData.events`
non-optional. Rename `Tag` to `Attribute`.
- @cosmjs/tendermint-rpc: Remove obsolete `BlockResultsResponse.beginBlock` and
`.beginBlock`. The new `.beginBlockEvents` and `.endBlockEvents` now parse the
events correctly.
- @cosmjs/utils: Add `assertDefined`.
- @cosmjs/faucet: Rename binary from `cosmwasm-faucet` to `cosmos-faucet`.

View File

@ -119,7 +119,6 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor): void {
const client = new Client(rpcFactory(), adaptor);
expect(await client.block()).toBeTruthy();
expect(await client.blockResults(3)).toBeTruthy();
expect(await client.commit(4)).toBeTruthy();
expect(await client.genesis()).toBeTruthy();
expect(await client.health()).toBeNull();
@ -145,6 +144,22 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor): void {
});
});
describe("blockResults", () => {
it("works", async () => {
pendingWithoutTendermint();
const client = new Client(rpcFactory(), adaptor);
const height = 3;
const results = await client.blockResults(height);
expect(results.height).toEqual(height);
expect(results.results).toEqual([]);
expect(results.beginBlockEvents).toEqual([]);
expect(results.endBlockEvents).toEqual([]);
client.disconnect();
});
});
describe("blockchain", () => {
it("returns latest in descending order by default", async () => {
pendingWithoutTendermint();

View File

@ -55,8 +55,8 @@ export interface BlockResultsResponse {
readonly results: readonly TxData[];
readonly validatorUpdates: readonly Validator[];
readonly consensusUpdates?: ConsensusParams;
readonly beginBlock?: readonly Attribute[];
readonly endBlock?: readonly Attribute[];
readonly beginBlockEvents: readonly Event[];
readonly endBlockEvents: readonly Event[];
}
export interface BlockchainResponse {

View File

@ -234,8 +234,8 @@ function decodeConsensusParams(data: RpcConsensusParams): responses.ConsensusPar
interface RpcBlockResultsResponse {
readonly height: IntegerString;
readonly txs_results: readonly RpcTxData[] | null;
readonly begin_block_events: null;
readonly end_block_events: null;
readonly begin_block_events: readonly RpcEvent[] | null;
readonly end_block_events: readonly RpcEvent[] | null;
readonly validator_updates: null;
readonly consensus_param_updates: null;
}
@ -248,8 +248,8 @@ function decodeBlockResults(data: RpcBlockResultsResponse): responses.BlockResul
results: results.map(decodeTxData),
validatorUpdates: validatorUpdates.map(decodeValidatorUpdate),
consensusUpdates: may(decodeConsensusParams, data.consensus_param_updates),
beginBlock: may(decodeAttributes, data.begin_block_events),
endBlock: may(decodeAttributes, data.end_block_events),
beginBlockEvents: decodeEvents(data.begin_block_events || []),
endBlockEvents: decodeEvents(data.end_block_events || []),
};
}

View File

@ -47,8 +47,8 @@ export interface BlockResultsResponse {
readonly results: readonly TxData[];
readonly validatorUpdates: readonly Validator[];
readonly consensusUpdates?: ConsensusParams;
readonly beginBlock?: readonly Attribute[];
readonly endBlock?: readonly Attribute[];
readonly beginBlockEvents: readonly Event[];
readonly endBlockEvents: readonly Event[];
}
export interface BlockchainResponse {
readonly lastHeight: number;