diff --git a/packages/sdk/src/restclient.spec.ts b/packages/sdk/src/restclient.spec.ts index 5406181f..405b780e 100644 --- a/packages/sdk/src/restclient.spec.ts +++ b/packages/sdk/src/restclient.spec.ts @@ -443,7 +443,7 @@ describe("RestClient", () => { expect((myInfo.init_msg as any).beneficiary).toEqual(beneficiaryAddress); // make sure random addresses don't give useful info - client + await client .getContractInfo(beneficiaryAddress) .then(() => fail("this shouldn't succeed")) .catch(error => expect(error).toMatch(`No contract with address ${beneficiaryAddress}`)); @@ -507,22 +507,20 @@ describe("RestClient", () => { expect(verifier).toEqual(faucetAddress); // invalid query syntax throws an error - await client - .queryContractSmart(contractAddress, { nosuchkey: {} }) - .then(() => fail("shouldn't succeed")) - .catch(() => {}); - // TODO: debug rest server. Here I get: - // Expected Error: Request failed with status code 500 to match 'Parse Error:' - // .catch(error => expect(error).toMatch(`not found: contract`)); + await client.queryContractSmart(contractAddress, { nosuchkey: {} }).then( + () => fail("shouldn't succeed"), + error => expect(error).toBeTruthy(), + ); + // TODO: debug rest server. I expect a 'Parse Error', but get + // Request failed with status code 500 to match 'Parse Error:' // invalid address throws an error - await client - .queryContractSmart(noContract, { verifier: {} }) - .then(() => fail("shouldn't succeed")) - .catch(() => {}); - // TODO: debug rest server. Here I get: - // Expected Error: Request failed with status code 500 to match 'Parse Error:' - // .catch(error => expect(error).toMatch(`not found: contract`)); + await client.queryContractSmart(noContract, { verifier: {} }).then( + () => fail("shouldn't succeed"), + error => expect(error).toBeTruthy(), + ); + // TODO: debug rest server. I expect a 'not found', but get + // Request failed with status code 500 to match 'Parse Error:' }); }); }); diff --git a/packages/sdk/src/restclient.ts b/packages/sdk/src/restclient.ts index 22513647..29e17cc8 100644 --- a/packages/sdk/src/restclient.ts +++ b/packages/sdk/src/restclient.ts @@ -246,15 +246,17 @@ export class RestClient { public async listContractAddresses(): Promise { const path = `/wasm/contract`; const responseData = await this.get(path); - // answer may be null (empty array) - return parseWasmResponse(responseData as WasmResponse) || []; + // answer may be null (go's encoding of empty array) + const addresses: string[] | null = parseWasmResponse(responseData as WasmResponse); + return addresses || []; } // throws error if no contract at this address public async getContractInfo(address: string): Promise { const path = `/wasm/contract/${address}`; const responseData = await this.get(path); - const info = parseWasmResponse(responseData as WasmResponse); + // rest server returns null if no data for the address + const info: ContractInfo | null = parseWasmResponse(responseData as WasmResponse); if (!info) { throw new Error(`No contract with address ${address}`); }