Tests pass

This commit is contained in:
Ethan Frey 2020-02-11 09:54:15 +01:00
parent 6f35fad87c
commit 5677976463
2 changed files with 25 additions and 13 deletions

View File

@ -468,7 +468,7 @@ describe("RestClient", () => {
.catch(error => expect(error).toMatch(`No contract with address ${beneficiaryAddress}`));
});
describe("contract state", () => {
fdescribe("contract state", () => {
const client = new RestClient(httpUrl);
const noContract = makeRandomAddress();
const expectedKey = toAscii("config");
@ -497,8 +497,10 @@ describe("RestClient", () => {
expect(state.length).toEqual(1);
const data = state[0];
expect(data.key.toLowerCase()).toEqual(toHex(expectedKey));
expect((data.val as any).verifier).toBeDefined();
expect((data.val as any).beneficiary).toBeDefined();
const value = JSON.parse(fromAscii(fromBase64(data.val)));
console.log(value);
expect(value.verifier).toBeDefined();
expect(value.beneficiary).toBeDefined();
// bad address is empty array
const noContractState = await client.getAllContractState(noContract);
@ -509,10 +511,11 @@ describe("RestClient", () => {
pendingWithoutCosmos();
// query by one key
const model = await client.queryContractRaw(contractAddress!, expectedKey);
expect(model).not.toBeNull();
expect((model as any).verifier).toBeDefined();
expect((model as any).beneficiary).toBeDefined();
const raw = await client.queryContractRaw(contractAddress!, expectedKey);
expect(raw).not.toBeNull();
const model = JSON.parse(fromAscii(raw!));
expect(model.verifier).toBeDefined();
expect(model.beneficiary).toBeDefined();
// missing key is null
const missing = await client.queryContractRaw(contractAddress!, fromHex("cafe0dad"));

View File

@ -97,6 +97,11 @@ interface GetCodeResult {
readonly code: string;
}
interface SmartQueryResponse {
// base64 encoded response
readonly smart: string;
}
type RestClientResponse =
| NodeInfoResponse
| BlocksResponse
@ -309,7 +314,12 @@ export class RestClient {
public async getAllContractState(address: string): Promise<readonly WasmData[]> {
const path = `/wasm/contract/${address}/state`;
const responseData = (await this.get(path)) as WasmResponse<WasmData[]>;
return unwrapWasmResponse(responseData);
console.log("all state");
console.log(responseData);
console.log("***");
const r = unwrapWasmResponse(responseData);
console.log(r);
return r || [];
}
// Returns the data at the key if present (unknown decoded json),
@ -327,11 +337,10 @@ export class RestClient {
public async queryContractSmart(address: string, query: object): Promise<Uint8Array> {
const encoded = toHex(toUtf8(JSON.stringify(query)));
const path = `/wasm/contract/${address}/smart/${encoded}?encoding=hex`;
const responseData = (await this.get(path)) as WasmResponse;
if (isWasmError(responseData)) {
throw new Error(responseData.error);
}
const responseData = (await this.get(path)) as WasmResponse<SmartQueryResponse>;
const result = unwrapWasmResponse(responseData);
// no extra parse here for now, see https://github.com/confio/cosmwasm/issues/144
return fromBase64(responseData.result);
console.log(result);
return fromBase64(result.smart);
}
}