mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +00:00
getAccount returns undefined when address not found
This commit is contained in:
parent
b39a54211b
commit
d079f7673a
@ -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", () => {
|
||||
|
@ -153,14 +153,15 @@ export class CosmWasmClient {
|
||||
public async getNonce(address?: string): Promise<GetNonceResult> {
|
||||
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<CosmosSdkAccount> {
|
||||
public async getAccount(address?: string): Promise<CosmosSdkAccount | undefined> {
|
||||
const account = await this.restClient.authAccounts(address || this.senderAddress);
|
||||
return account.result.value;
|
||||
const value = account.result.value;
|
||||
return value.address === "" ? undefined : value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
2
packages/sdk/types/cosmwasmclient.d.ts
vendored
2
packages/sdk/types/cosmwasmclient.d.ts
vendored
@ -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<GetNonceResult>;
|
||||
getAccount(address?: string): Promise<CosmosSdkAccount>;
|
||||
getAccount(address?: string): Promise<CosmosSdkAccount | undefined>;
|
||||
/**
|
||||
* Gets block header and meta
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user