From a504d1a3c66038556c9a51b7e921a64bd05f0430 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Fri, 5 Jun 2020 10:40:57 +0200 Subject: [PATCH] Get sendUnsuccessful.height from error this makes parallel testing more stable --- .../src/cosmwasmclient.searchtx.spec.ts | 19 +++++++++++-------- packages/cosmwasm/src/cosmwasmclient.ts | 2 +- .../sdk38/src/cosmosclient.searchtx.spec.ts | 19 +++++++++++-------- packages/sdk38/src/cosmosclient.ts | 2 +- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts b/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts index 03f2664a..f278f0ba 100644 --- a/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts +++ b/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/camelcase */ import { Coin, CosmosSdkTx, isMsgSend, makeSignBytes, MsgSend, Secp256k1Pen } from "@cosmjs/sdk38"; +import { Uint53 } from "@iov/encoding"; import { assert, sleep } from "@iov/utils"; import { CosmWasmClient } from "./cosmwasmclient"; @@ -112,20 +113,22 @@ describe("CosmWasmClient.searchTx", () => { }, }; const transactionId = await client.getIdentifier(tx); - const heightBeforeThis = await client.getHeight(); try { await client.postTx(tx.value); } catch (error) { // postTx() throws on execution failures, which is a questionable design. Ignore for now. // console.log(error); + const errorMessage: string = error.toString(); + const [_, heightMatch] = errorMessage.match(/at height ([0-9]+)/) || ["", ""]; + + sendUnsuccessful = { + sender: alice.address0, + recipient: recipient, + hash: transactionId, + height: Uint53.fromString(heightMatch).toNumber(), + tx: tx, + }; } - sendUnsuccessful = { - sender: alice.address0, - recipient: recipient, - hash: transactionId, - height: heightBeforeThis + 1, - tx: tx, - }; } { diff --git a/packages/cosmwasm/src/cosmwasmclient.ts b/packages/cosmwasm/src/cosmwasmclient.ts index dbbdaffb..d22be7aa 100644 --- a/packages/cosmwasm/src/cosmwasmclient.ts +++ b/packages/cosmwasm/src/cosmwasmclient.ts @@ -296,7 +296,7 @@ export class CosmWasmClient { if (result.code) { throw new Error( - `Error when posting tx ${result.txhash}. Code: ${result.code}; Raw log: ${result.raw_log}`, + `Error when posting tx ${result.txhash} at height ${result.height}. Code: ${result.code}; Raw log: ${result.raw_log}`, ); } diff --git a/packages/sdk38/src/cosmosclient.searchtx.spec.ts b/packages/sdk38/src/cosmosclient.searchtx.spec.ts index c33e9247..3cf19b05 100644 --- a/packages/sdk38/src/cosmosclient.searchtx.spec.ts +++ b/packages/sdk38/src/cosmosclient.searchtx.spec.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/camelcase */ +import { Uint53 } from "@iov/encoding"; import { assert, sleep } from "@iov/utils"; import { Coin } from "./coins"; @@ -104,20 +105,22 @@ describe("CosmosClient.searchTx", () => { }, }; const transactionId = await client.getIdentifier(tx); - const heightBeforeThis = await client.getHeight(); try { await client.postTx(tx.value); } catch (error) { // postTx() throws on execution failures, which is a questionable design. Ignore for now. // console.log(error); + const errorMessage: string = error.toString(); + const [_, heightMatch] = errorMessage.match(/at height ([0-9]+)/) || ["", ""]; + + sendUnsuccessful = { + sender: faucet.address, + recipient: recipient, + hash: transactionId, + height: Uint53.fromString(heightMatch).toNumber(), + tx: tx, + }; } - sendUnsuccessful = { - sender: faucet.address, - recipient: recipient, - hash: transactionId, - height: heightBeforeThis + 1, - tx: tx, - }; } } }); diff --git a/packages/sdk38/src/cosmosclient.ts b/packages/sdk38/src/cosmosclient.ts index d3b5d807..3a390e6a 100644 --- a/packages/sdk38/src/cosmosclient.ts +++ b/packages/sdk38/src/cosmosclient.ts @@ -278,7 +278,7 @@ export class CosmosClient { if (result.code) { throw new Error( - `Error when posting tx ${result.txhash}. Code: ${result.code}; Raw log: ${result.raw_log}`, + `Error when posting tx ${result.txhash} at height ${result.height}. Code: ${result.code}; Raw log: ${result.raw_log}`, ); }