launchpad: Improve CosmosClient.getBlock tests

This commit is contained in:
willclarktech 2020-08-12 13:45:33 +02:00
parent cd7c5c2efa
commit edb84ce7de
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7

View File

@ -145,19 +145,21 @@ describe("CosmosClient", () => {
const client = new CosmosClient(wasmd.endpoint);
const response = await client.getBlock();
// id
expect(response.id).toMatch(tendermintIdMatcher);
expect(response).toEqual(
jasmine.objectContaining({
id: jasmine.stringMatching(tendermintIdMatcher),
header: jasmine.objectContaining({
chainId: await client.getChainId(),
}),
txs: [],
}),
);
// header
expect(response.header.height).toBeGreaterThanOrEqual(1);
expect(response.header.chainId).toEqual(await client.getChainId());
expect(new ReadonlyDate(response.header.time).getTime()).toBeLessThan(ReadonlyDate.now());
expect(new ReadonlyDate(response.header.time).getTime()).toBeGreaterThanOrEqual(
ReadonlyDate.now() - 5_000,
);
// txs
expect(Array.isArray(response.txs)).toEqual(true);
});
it("works for block by height", async () => {
@ -166,19 +168,21 @@ describe("CosmosClient", () => {
const height = (await client.getBlock()).header.height;
const response = await client.getBlock(height - 1);
// id
expect(response.id).toMatch(tendermintIdMatcher);
expect(response).toEqual(
jasmine.objectContaining({
id: jasmine.stringMatching(tendermintIdMatcher),
header: jasmine.objectContaining({
height: height - 1,
chainId: await client.getChainId(),
}),
txs: [],
}),
);
// header
expect(response.header.height).toEqual(height - 1);
expect(response.header.chainId).toEqual(await client.getChainId());
expect(new ReadonlyDate(response.header.time).getTime()).toBeLessThan(ReadonlyDate.now());
expect(new ReadonlyDate(response.header.time).getTime()).toBeGreaterThanOrEqual(
ReadonlyDate.now() - 5_000,
);
// txs
expect(Array.isArray(response.txs)).toEqual(true);
});
});