From 80b49841a65282425e50b529f08acc8ff0b2ab32 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Fri, 7 Feb 2020 17:10:41 +0100 Subject: [PATCH] Let getContractAddress return most recent contract --- packages/sdk/src/restclient.spec.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/sdk/src/restclient.spec.ts b/packages/sdk/src/restclient.spec.ts index 889b5424..a093c0f1 100644 --- a/packages/sdk/src/restclient.spec.ts +++ b/packages/sdk/src/restclient.spec.ts @@ -405,13 +405,17 @@ describe("RestClient", () => { const noContract = makeRandomAddress(); const expectedKey = toAscii("config"); - // find an existing contract (created above) - // we assume all contracts on this chain are the same (created by these tests) - const getContractAddress = async (): Promise => { - const contractInfos = await client.listContractAddresses(); - expect(contractInfos.length).toBeGreaterThan(0); - return contractInfos[0]; - }; + /** + * Finds the most recent contract (created above) + * + * We assume the tests above ran, all instantiate the same contract and no other process squeezed in a different contract. + */ + async function getContractAddress(): Promise { + const contracts = Array.from(await client.listContractAddresses()); + const last = contracts.reverse().find(() => true); + if (!last) throw new Error("No contract found"); + return last; + } it("can get all state", async () => { pendingWithoutCosmos();