diff --git a/packages/bcp/src/cosmwasmconnection.spec.ts b/packages/bcp/src/cosmwasmconnection.spec.ts index d1777a4a..734cd00d 100644 --- a/packages/bcp/src/cosmwasmconnection.spec.ts +++ b/packages/bcp/src/cosmwasmconnection.spec.ts @@ -10,6 +10,7 @@ import { PubkeyBytes, SendTransaction, TokenTicker, + TransactionId, TransactionState, } from "@iov/bcp"; import { Random, Secp256k1 } from "@iov/crypto"; @@ -264,6 +265,21 @@ describe("CosmWasmConnection", () => { }); }); + describe("getTx", () => { + it("throws for non-existent transaction", async () => { + pendingWithoutCosmos(); + const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultConfig); + + const nonExistentId = "0000000000000000000000000000000000000000000000000000000000000000" as TransactionId; + await connection.getTx(nonExistentId).then( + () => fail("this must not succeed"), + error => expect(error).toMatch(/transaction does not exist/i), + ); + + connection.disconnect(); + }); + }); + describe("integration tests", () => { it("can post and get a transaction", async () => { pendingWithoutCosmos(); diff --git a/packages/bcp/src/cosmwasmconnection.ts b/packages/bcp/src/cosmwasmconnection.ts index d7c9e893..c90047ef 100644 --- a/packages/bcp/src/cosmwasmconnection.ts +++ b/packages/bcp/src/cosmwasmconnection.ts @@ -231,15 +231,14 @@ export class CosmWasmConnection implements BlockchainConnection { public async getTx( id: TransactionId, ): Promise | FailedTransaction> { - try { - // tslint:disable-next-line: deprecation - const response = await this.restClient.txsById(id); - return this.parseAndPopulateTxResponseSigned(response); - } catch (error) { - if (error.response.status === 404) { + const results = await this.cosmWasmClient.searchTx({ id: id }); + switch (results.length) { + case 0: throw new Error("Transaction does not exist"); - } - throw error; + case 1: + return this.parseAndPopulateTxResponseSigned(results[0]); + default: + throw new Error("Got unexpected amount of search results"); } }