From ffecf9adffc71fb8c0dcbf24e04ef769dc6abea8 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Fri, 19 Jun 2020 13:58:57 +0200 Subject: [PATCH] Streamline test tx types --- .../src/cosmwasmclient.searchtx.spec.ts | 64 +++++++++---------- .../sdk38/src/cosmosclient.searchtx.spec.ts | 28 +++----- 2 files changed, 41 insertions(+), 51 deletions(-) diff --git a/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts b/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts index e0c8f909..19d9d102 100644 --- a/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts +++ b/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts @@ -16,29 +16,27 @@ import { wasmdEnabled, } from "./testutils.spec"; -type TestSendTx = - | { - readonly sender: string; - readonly recipient: string; - readonly hash: string; - readonly height: number; - readonly tx: CosmosSdkTx; - } - | undefined; +interface TestTxSend { + readonly sender: string; + readonly recipient: string; + readonly hash: string; + readonly height: number; + readonly tx: CosmosSdkTx; +} + +interface TestTxExecute { + readonly sender: string; + readonly contract: string; + readonly hash: string; + readonly height: number; + readonly tx: CosmosSdkTx; +} describe("CosmWasmClient.searchTx", () => { - let sendSuccessful: TestSendTx; - let sendSelfSuccessful: TestSendTx; - let sendUnsuccessful: TestSendTx; - let postedExecute: - | { - readonly sender: string; - readonly contract: string; - readonly hash: string; - readonly height: number; - readonly tx: CosmosSdkTx; - } - | undefined; + let sendSuccessful: TestTxSend | undefined; + let sendSelfSuccessful: TestTxSend | undefined; + let sendUnsuccessful: TestTxSend | undefined; + let execute: TestTxExecute | undefined; beforeAll(async () => { if (wasmdEnabled()) { @@ -148,7 +146,7 @@ describe("CosmWasmClient.searchTx", () => { const result = await client.execute(hashInstance, msg); await sleep(75); // wait until tx is indexed const txDetails = await new RestClient(wasmd.endpoint).txById(result.transactionHash); - postedExecute = { + execute = { sender: alice.address0, contract: hashInstance, hash: result.transactionHash, @@ -413,10 +411,10 @@ describe("CosmWasmClient.searchTx", () => { it("can search by message.contract_address", async () => { pendingWithoutWasmd(); - assert(postedExecute, "value must be set in beforeAll()"); + assert(execute, "value must be set in beforeAll()"); const client = new CosmWasmClient(wasmd.endpoint); const results = await client.searchTx({ - tags: [{ key: "message.contract_address", value: postedExecute.contract }], + tags: [{ key: "message.contract_address", value: execute.contract }], }); expect(results.length).toBeGreaterThanOrEqual(1); @@ -446,20 +444,20 @@ describe("CosmWasmClient.searchTx", () => { // Check details of most recent result expect(results[results.length - 1]).toEqual( jasmine.objectContaining({ - height: postedExecute.height, - hash: postedExecute.hash, - tx: postedExecute.tx, + height: execute.height, + hash: execute.hash, + tx: execute.tx, }), ); }); it("can search by message.contract_address + message.action", async () => { pendingWithoutWasmd(); - assert(postedExecute, "value must be set in beforeAll()"); + assert(execute, "value must be set in beforeAll()"); const client = new CosmWasmClient(wasmd.endpoint); const results = await client.searchTx({ tags: [ - { key: "message.contract_address", value: postedExecute.contract }, + { key: "message.contract_address", value: execute.contract }, { key: "message.action", value: "execute" }, ], }); @@ -469,15 +467,15 @@ describe("CosmWasmClient.searchTx", () => { for (const result of results) { const msg = fromOneElementArray(result.tx.value.msg); assert(isMsgExecuteContract(msg), `${result.hash} (at ${result.height}) not an execute msg`); - expect(msg.value.contract).toEqual(postedExecute.contract); + expect(msg.value.contract).toEqual(execute.contract); } // Check details of most recent result expect(results[results.length - 1]).toEqual( jasmine.objectContaining({ - height: postedExecute.height, - hash: postedExecute.hash, - tx: postedExecute.tx, + height: execute.height, + hash: execute.hash, + tx: execute.tx, }), ); }); diff --git a/packages/sdk38/src/cosmosclient.searchtx.spec.ts b/packages/sdk38/src/cosmosclient.searchtx.spec.ts index b1c75d60..39eb8a30 100644 --- a/packages/sdk38/src/cosmosclient.searchtx.spec.ts +++ b/packages/sdk38/src/cosmosclient.searchtx.spec.ts @@ -17,25 +17,17 @@ import { } from "./testutils.spec"; import { CosmosSdkTx, isMsgSend, MsgSend } from "./types"; +interface TestTxSend { + readonly sender: string; + readonly recipient: string; + readonly hash: string; + readonly height: number; + readonly tx: CosmosSdkTx; +} + describe("CosmosClient.searchTx", () => { - let sendSuccessful: - | { - readonly sender: string; - readonly recipient: string; - readonly hash: string; - readonly height: number; - readonly tx: CosmosSdkTx; - } - | undefined; - let sendUnsuccessful: - | { - readonly sender: string; - readonly recipient: string; - readonly hash: string; - readonly height: number; - readonly tx: CosmosSdkTx; - } - | undefined; + let sendSuccessful: TestTxSend | undefined; + let sendUnsuccessful: TestTxSend | undefined; beforeAll(async () => { if (wasmdEnabled()) {