diff --git a/packages/sdk/src/cosmwasmclient.spec.ts b/packages/sdk/src/cosmwasmclient.spec.ts index 2994e3b9..29628d49 100644 --- a/packages/sdk/src/cosmwasmclient.spec.ts +++ b/packages/sdk/src/cosmwasmclient.spec.ts @@ -74,7 +74,15 @@ describe("CosmWasmClient", () => { }); }); - + it("returns zeros for missing accounts", async () => { + pendingWithoutCosmos(); + const client = CosmWasmClient.makeReadOnly(httpUrl); + const missing = makeRandomAddress(); + expect(await client.getNonce(missing)).toEqual({ + accountNumber: 0, + sequence: 0, + }); + }); }); describe("getAccount", () => { @@ -87,11 +95,18 @@ describe("CosmWasmClient", () => { sequence: 0, public_key: "", coins: [ - {denom: 'ucosm', amount: '1000000000'}, - {denom: 'ustake', amount: '1000000000'}, + { denom: "ucosm", amount: "1000000000" }, + { denom: "ustake", amount: "1000000000" }, ], }); }); + + it("returns undefined for missing accounts", async () => { + pendingWithoutCosmos(); + const client = CosmWasmClient.makeReadOnly(httpUrl); + const missing = makeRandomAddress(); + expect(await client.getAccount(missing)).toBeUndefined(); + }); }); describe("getBlock", () => { diff --git a/packages/sdk/src/cosmwasmclient.ts b/packages/sdk/src/cosmwasmclient.ts index 55335904..f7c58231 100644 --- a/packages/sdk/src/cosmwasmclient.ts +++ b/packages/sdk/src/cosmwasmclient.ts @@ -153,14 +153,15 @@ export class CosmWasmClient { public async getNonce(address?: string): Promise { const account = await this.getAccount(address); return { - accountNumber: account.account_number, - sequence: account.sequence, + accountNumber: account ? account.account_number : 0, + sequence: account ? account.sequence : 0, }; } - public async getAccount(address?: string): Promise { + public async getAccount(address?: string): Promise { const account = await this.restClient.authAccounts(address || this.senderAddress); - return account.result.value; + const value = account.result.value; + return value.address === "" ? undefined : value; } /** diff --git a/packages/sdk/types/cosmwasmclient.d.ts b/packages/sdk/types/cosmwasmclient.d.ts index da430498..70e07e10 100644 --- a/packages/sdk/types/cosmwasmclient.d.ts +++ b/packages/sdk/types/cosmwasmclient.d.ts @@ -46,7 +46,7 @@ export declare class CosmWasmClient { * @param address returns data for this address. When unset, the client's sender adddress is used. */ getNonce(address?: string): Promise; - getAccount(address?: string): Promise; + getAccount(address?: string): Promise; /** * Gets block header and meta *