Merge pull request #759 from cosmos/387-missing-block-meta-fields

Add missing block meta fields
This commit is contained in:
Simon Warta 2021-04-08 11:35:18 +02:00 committed by GitHub
commit fcdab9d6d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 13 deletions

View File

@ -263,7 +263,7 @@ interface RpcBlockId {
/** hex encoded */
readonly hash: string;
readonly parts: {
readonly total: string;
readonly total: number;
/** hex encoded */
readonly hash: string;
};
@ -273,7 +273,7 @@ function decodeBlockId(data: RpcBlockId): responses.BlockId {
return {
hash: fromHex(assertNotEmpty(data.hash)),
parts: {
total: Integer.parse(assertNotEmpty(data.parts.total)),
total: assertNotEmpty(data.parts.total),
hash: fromHex(assertNotEmpty(data.parts.hash)),
},
};
@ -296,8 +296,6 @@ interface RpcHeader {
readonly chain_id: string;
readonly height: string;
readonly time: string;
readonly num_txs: string;
readonly total_txs: string;
readonly last_block_id: RpcBlockId;
@ -348,13 +346,17 @@ function decodeHeader(data: RpcHeader): responses.Header {
interface RpcBlockMeta {
readonly block_id: RpcBlockId;
readonly block_size: string;
readonly header: RpcHeader;
readonly num_txs: string;
}
function decodeBlockMeta(data: RpcBlockMeta): responses.BlockMeta {
return {
blockId: decodeBlockId(data.block_id),
blockSize: Integer.parse(assertNotEmpty(data.block_size)),
header: decodeHeader(data.header),
numTxs: Integer.parse(assertNotEmpty(data.num_txs)),
};
}

View File

@ -195,9 +195,9 @@ export interface TxProof {
export interface BlockMeta {
readonly blockId: BlockId;
readonly blockSize: number;
readonly header: Header;
// TODO: Add blockSize (e.g "block_size": "471")
// TODO: Add numTxs (e.g "num_txs": "0")
readonly numTxs: number;
}
export interface BlockId {

View File

@ -275,19 +275,18 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
expect(blockchain.blockMetas.length).toBeGreaterThanOrEqual(1);
const meta = blockchain.blockMetas[0];
// TODO: check all the fields
expect(meta).toEqual({
blockId: jasmine.objectContaining({}),
// block_size: jasmine.stringMatching(nonNegativeIntegerMatcher),
// num_txs: jasmine.stringMatching(nonNegativeIntegerMatcher),
header: jasmine.objectContaining({
expect(meta.blockId).toEqual(jasmine.objectContaining({}));
expect(meta.blockSize).toBeInstanceOf(Number);
expect(meta.header).toEqual(
jasmine.objectContaining({
version: {
block: expected.blockVersion,
app: expected.appVersion,
},
chainId: jasmine.stringMatching(chainIdMatcher),
}),
});
);
expect(meta.numTxs).toBeInstanceOf(Number);
client.disconnect();
});