Fix Tests & Beautify Code

This commit is contained in:
Milan Steiner 2022-03-14 11:16:44 +01:00
parent 6d6fe29ad0
commit 03f783194f
2 changed files with 10 additions and 16 deletions

View File

@ -275,9 +275,9 @@ describe("CosmWasmClient", () => {
const expectedAddresses = deployedHackatom.instances.map((info) => info.address); 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. // 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[1]).toEqual(expectedAddresses[1]);
expect(result[2]).toEqual(expectedAddresses[0]); expect(result[2]).toEqual(expectedAddresses[2]);
}); });
}); });

View File

@ -342,20 +342,14 @@ export class CosmWasmClient {
*/ */
public async getContracts(codeId: number): Promise<readonly string[]> { public async getContracts(codeId: number): Promise<readonly string[]> {
const allContracts = []; const allContracts = [];
let startAtKey: Uint8Array | undefined = undefined;
try { do {
let startAtKey: Uint8Array | undefined = undefined; const { contracts, pagination }: QueryContractsByCodeResponse =
do { await this.forceGetQueryClient().wasm.listContractsByCodeId(codeId, startAtKey);
const { contracts, pagination }: QueryContractsByCodeResponse = const loadedContracts = contracts || [];
await this.forceGetQueryClient().wasm.listContractsByCodeId(codeId, startAtKey); allContracts.unshift(...loadedContracts);
const loadedContracts = contracts || []; startAtKey = pagination?.nextKey;
loadedContracts.reverse(); } while (startAtKey?.length !== 0 && startAtKey !== undefined);
allContracts.unshift(...loadedContracts);
startAtKey = pagination?.nextKey;
} while (startAtKey?.length !== 0);
} catch (_e: any) {
throw new Error(_e);
}
return allContracts; return allContracts;
} }