diff --git a/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts b/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts index ce064371..8e4c77bd 100644 --- a/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts +++ b/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts @@ -82,24 +82,6 @@ describe("CosmWasmClient", () => { }); }); - describe("getSequence", () => { - it("works", async () => { - pendingWithoutWasmd(); - const client = await CosmWasmClient.connect(wasmd.endpoint); - expect(await client.getSequence(unused.address)).toEqual({ - accountNumber: unused.accountNumber, - sequence: unused.sequence, - }); - }); - - it("returns null for missing accounts", async () => { - pendingWithoutWasmd(); - const client = await CosmWasmClient.connect(wasmd.endpoint); - const missing = makeRandomAddress(); - expect(await client.getSequence(missing)).toBeNull(); - }); - }); - describe("getAccount", () => { it("works", async () => { pendingWithoutWasmd(); @@ -120,6 +102,26 @@ describe("CosmWasmClient", () => { }); }); + describe("getSequence", () => { + it("works", async () => { + pendingWithoutWasmd(); + const client = await CosmWasmClient.connect(wasmd.endpoint); + expect(await client.getSequence(unused.address)).toEqual({ + accountNumber: unused.accountNumber, + sequence: unused.sequence, + }); + }); + + it("rejects for missing accounts", async () => { + pendingWithoutWasmd(); + const client = await CosmWasmClient.connect(wasmd.endpoint); + const missing = makeRandomAddress(); + await expectAsync(client.getSequence(missing)).toBeRejectedWithError( + /account does not exist on chain/i, + ); + }); + }); + describe("getBlock", () => { it("works for latest block", async () => { pendingWithoutWasmd(); diff --git a/packages/cosmwasm-stargate/src/cosmwasmclient.ts b/packages/cosmwasm-stargate/src/cosmwasmclient.ts index 11644fb8..b6d57e64 100644 --- a/packages/cosmwasm-stargate/src/cosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/cosmwasmclient.ts @@ -120,14 +120,17 @@ export class CosmWasmClient { } } - public async getSequence(address: string): Promise { + public async getSequence(address: string): Promise { const account = await this.getAccount(address); - return account - ? { - accountNumber: account.accountNumber, - sequence: account.sequence, - } - : null; + if (!account) { + throw new Error( + "Account does not exist on chain. Send some tokens there before trying to query sequence.", + ); + } + return { + accountNumber: account.accountNumber, + sequence: account.sequence, + }; } public async getBlock(height?: number): Promise { diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts index 9184905a..8da3742c 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts @@ -409,11 +409,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { throw new Error("Failed to retrieve account from signer"); } const pubkey = encodePubkey(encodeSecp256k1Pubkey(accountFromSigner.pubkey)); - const accountFromChain = await this.getAccount(signerAddress); - if (!accountFromChain) { - throw new Error("Account not found"); - } - const { accountNumber, sequence } = accountFromChain; + const { accountNumber, sequence } = await this.getSequence(signerAddress); const chainId = await this.getChainId(); const txBody = { messages: messages,