diff --git a/src/cosmosconnection.spec.ts b/src/cosmosconnection.spec.ts index cd67dec124..e11ea319ee 100644 --- a/src/cosmosconnection.spec.ts +++ b/src/cosmosconnection.spec.ts @@ -95,9 +95,9 @@ describe("CosmosConnection", () => { const connection = await CosmosConnection.establish(httpUrl, defaultPrefix, defaultTokens); const token = await connection.getToken("COSM" as TokenTicker); expect(token).toEqual({ - fractionalDigits: 6, - tokenName: "Fee Token", - tokenTicker: "COSM" as TokenTicker, + fractionalDigits: 6, + tokenName: "Fee Token", + tokenTicker: "COSM" as TokenTicker, }); connection.disconnect(); }); @@ -150,9 +150,10 @@ describe("CosmosConnection", () => { throw new Error("Expected account not to be undefined"); } expect(account.address).toEqual(defaultAddress); - expect(account.pubkey).toEqual(defaultPubkey); - // Unsupported coins are filtered out - expect(account.balance.length).toEqual(1); + // Undefined until we sign a transaction + expect(account.pubkey).toEqual(undefined); + // Starts with two tokens + expect(account.balance.length).toEqual(2); connection.disconnect(); }); @@ -164,12 +165,10 @@ describe("CosmosConnection", () => { throw new Error("Expected account not to be undefined"); } expect(account.address).toEqual(defaultAddress); - expect(account.pubkey).toEqual({ - algo: Algorithm.Secp256k1, - data: fromBase64("A08EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQ"), - }); - // Unsupported coins are filtered out - expect(account.balance.length).toEqual(1); + // Undefined until we sign a transaction + expect(account.pubkey).toEqual(undefined); + // Starts with two tokens + expect(account.balance.length).toEqual(2); connection.disconnect(); }); }); diff --git a/src/cosmosconnection.ts b/src/cosmosconnection.ts index f4e8e6d507..aec3825b7d 100644 --- a/src/cosmosconnection.ts +++ b/src/cosmosconnection.ts @@ -145,19 +145,23 @@ export class CosmosConnection implements BlockchainConnection { const address = isPubkeyQuery(query) ? pubkeyToAddress(query.pubkey, this.prefix) : query.address; const { result } = await this.restClient.authAccounts(address); const account = result.value; + if (!account.address) { + return undefined; + } const supportedCoins = account.coins.filter(({ denom }) => this.tokenInfo.find(token => token.denom === denom), ); - return account.public_key === null + const pubkey = !account.public_key ? undefined : { - address: address, - balance: supportedCoins.map(decodeAmount(this.tokenInfo)), - pubkey: { - algo: Algorithm.Secp256k1, - data: fromBase64(account.public_key.value) as PubkeyBytes, - }, + algo: Algorithm.Secp256k1, + data: fromBase64(account.public_key.value) as PubkeyBytes, }; + return { + address: address, + balance: supportedCoins.map(decodeAmount(this.tokenInfo)), + pubkey: pubkey, + }; } public watchAccount(_account: AccountQuery): Stream {