From 03f783194fbfc8e90013e1871693a665ded9950a Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Mon, 14 Mar 2022 11:16:44 +0100 Subject: [PATCH] Fix Tests & Beautify Code --- .../src/cosmwasmclient.spec.ts | 4 ++-- .../cosmwasm-stargate/src/cosmwasmclient.ts | 22 +++++++------------ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts b/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts index 1ba4794c58..669602ddd1 100644 --- a/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts +++ b/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts @@ -275,9 +275,9 @@ describe("CosmWasmClient", () => { const expectedAddresses = deployedHackatom.instances.map((info) => info.address); // Test first 3 instances we get from scripts/wasmd/init.sh. There may me more than that in the result. - expect(result[0]).toEqual(expectedAddresses[2]); + expect(result[0]).toEqual(expectedAddresses[0]); expect(result[1]).toEqual(expectedAddresses[1]); - expect(result[2]).toEqual(expectedAddresses[0]); + expect(result[2]).toEqual(expectedAddresses[2]); }); }); diff --git a/packages/cosmwasm-stargate/src/cosmwasmclient.ts b/packages/cosmwasm-stargate/src/cosmwasmclient.ts index b1da085db0..0baa38bc3d 100644 --- a/packages/cosmwasm-stargate/src/cosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/cosmwasmclient.ts @@ -342,20 +342,14 @@ export class CosmWasmClient { */ public async getContracts(codeId: number): Promise { const allContracts = []; - - try { - let startAtKey: Uint8Array | undefined = undefined; - do { - const { contracts, pagination }: QueryContractsByCodeResponse = - await this.forceGetQueryClient().wasm.listContractsByCodeId(codeId, startAtKey); - const loadedContracts = contracts || []; - loadedContracts.reverse(); - allContracts.unshift(...loadedContracts); - startAtKey = pagination?.nextKey; - } while (startAtKey?.length !== 0); - } catch (_e: any) { - throw new Error(_e); - } + let startAtKey: Uint8Array | undefined = undefined; + do { + const { contracts, pagination }: QueryContractsByCodeResponse = + await this.forceGetQueryClient().wasm.listContractsByCodeId(codeId, startAtKey); + const loadedContracts = contracts || []; + allContracts.unshift(...loadedContracts); + startAtKey = pagination?.nextKey; + } while (startAtKey?.length !== 0 && startAtKey !== undefined); return allContracts; }