mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
Tests pass
This commit is contained in:
parent
6f35fad87c
commit
5677976463
@ -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"));
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user