diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts index 64e5a113..9693e350 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts @@ -1192,7 +1192,7 @@ describe("SigningCosmWasmClient", () => { client.disconnect(); }); - it("works with a custom timeout height", async () => { + it("works with a custom timeoutHeight", async () => { pendingWithoutWasmd(); const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix }); const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, { @@ -1222,6 +1222,42 @@ describe("SigningCosmWasmClient", () => { client.disconnect(); }); + + it("fails with past timeoutHeight", async () => { + pendingWithoutWasmd(); + const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix }); + const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, { + ...defaultSigningClientOptions, + }); + + const msg = MsgSend.fromPartial({ + fromAddress: alice.address0, + toAddress: alice.address0, + amount: [coin(1, "ucosm")], + }); + const msgAny: MsgSendEncodeObject = { + typeUrl: "/cosmos.bank.v1beta1.MsgSend", + value: msg, + }; + const fee = { + amount: coins(2000, "ucosm"), + gas: "222000", // 222k + }; + const memo = "Use your power wisely"; + const height = await client.getHeight(); + const signed = await client.sign(alice.address0, [msgAny], fee, memo, undefined, BigInt(height - 1)); + + try { + await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish())); + } catch (e: any) { + assert(e.code === 30); + return; + } finally { + client.disconnect(); + } + + throw new Error("tx should have failed because of past timeoutHeight"); + }); }); describe("legacy Amino mode", () => { @@ -1469,6 +1505,42 @@ describe("SigningCosmWasmClient", () => { client.disconnect(); }); + + it("fails with past timeoutHeight", async () => { + pendingWithoutWasmd(); + const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix }); + const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, { + ...defaultSigningClientOptions, + }); + + const msg = MsgSend.fromPartial({ + fromAddress: alice.address0, + toAddress: alice.address0, + amount: [coin(1, "ucosm")], + }); + const msgAny: MsgSendEncodeObject = { + typeUrl: "/cosmos.bank.v1beta1.MsgSend", + value: msg, + }; + const fee = { + amount: coins(2000, "ucosm"), + gas: "200000", + }; + const memo = "Use your tokens wisely"; + const height = await client.getHeight(); + const signed = await client.sign(alice.address0, [msgAny], fee, memo, undefined, BigInt(height - 1)); + + try { + await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish())); + } catch (e: any) { + assert(e.code === 30); + return; + } finally { + client.disconnect(); + } + + throw new Error("tx should have failed because of past timeoutHeight"); + }); }); }); }); diff --git a/packages/stargate/src/signingstargateclient.spec.ts b/packages/stargate/src/signingstargateclient.spec.ts index 22e709b0..ef26449e 100644 --- a/packages/stargate/src/signingstargateclient.spec.ts +++ b/packages/stargate/src/signingstargateclient.spec.ts @@ -942,6 +942,44 @@ describe("SigningStargateClient", () => { const result = await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish())); assertIsDeliverTxSuccess(result); }); + + it("fails with past timeoutHeight", async () => { + pendingWithoutSimapp(); + const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic); + const client = await SigningStargateClient.connectWithSigner( + simapp.tendermintUrl, + wallet, + defaultSigningClientOptions, + ); + + const msg = MsgSend.fromPartial({ + fromAddress: faucet.address0, + toAddress: faucet.address0, + amount: [coin(1, "ucosm")], + }); + const msgAny: MsgSendEncodeObject = { + typeUrl: "/cosmos.bank.v1beta1.MsgSend", + value: msg, + }; + const fee = { + amount: coins(2000, "ucosm"), + gas: "222000", // 222k + }; + const memo = "Use your power wisely"; + const height = await client.getHeight(); + const signed = await client.sign(faucet.address0, [msgAny], fee, memo, undefined, BigInt(height - 1)); + + try { + await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish())); + } catch (e: any) { + assert(e.code === 30); + return; + } finally { + client.disconnect(); + } + + throw new Error("tx should have failed because of past timeoutHeight"); + }); }); describe("legacy Amino mode", () => { @@ -1183,6 +1221,44 @@ describe("SigningStargateClient", () => { const result = await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish())); assertIsDeliverTxSuccess(result); }); + + it("fails with past timeoutHeight", async () => { + pendingWithoutSimapp(); + const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); + const client = await SigningStargateClient.connectWithSigner( + simapp.tendermintUrl, + wallet, + defaultSigningClientOptions, + ); + + const msg = MsgSend.fromPartial({ + fromAddress: faucet.address0, + toAddress: faucet.address0, + amount: [coin(1, "ucosm")], + }); + const msgAny: MsgSendEncodeObject = { + typeUrl: "/cosmos.bank.v1beta1.MsgSend", + value: msg, + }; + const fee = { + amount: coins(2000, "ucosm"), + gas: "200000", + }; + const memo = "Use your tokens wisely"; + const height = await client.getHeight(); + const signed = await client.sign(faucet.address0, [msgAny], fee, memo, undefined, BigInt(height - 1)); + + try { + await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish())); + } catch (e: any) { + assert(e.code === 30); + return; + } finally { + client.disconnect(); + } + + throw new Error("tx should have failed because of past timeoutHeight"); + }); }); }); });