Let CodeDetails extend Code
This commit is contained in:
parent
195057baf4
commit
3ffe5597a1
@ -4,7 +4,7 @@ import { Bech32, Encoding } from "@iov/encoding";
|
||||
import { assert, sleep } from "@iov/utils";
|
||||
import { ReadonlyDate } from "readonly-date";
|
||||
|
||||
import { CosmWasmClient } from "./cosmwasmclient";
|
||||
import { Code, CosmWasmClient } from "./cosmwasmclient";
|
||||
import { makeSignBytes } from "./encoding";
|
||||
import { findAttribute } from "./logs";
|
||||
import { Secp256k1Pen } from "./pen";
|
||||
@ -419,8 +419,19 @@ describe("CosmWasmClient", () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = new CosmWasmClient(httpUrl);
|
||||
const result = await client.getCodeDetails(1);
|
||||
const checksum = new Sha256(result.wasm).digest();
|
||||
expect(checksum).toEqual(fromHex("aff8c8873d79d2153a8b9066a0683fec3c903669267eb806ffa831dcd4b3daae"));
|
||||
|
||||
const expectedInfo: Code = {
|
||||
id: 1,
|
||||
checksum: "aff8c8873d79d2153a8b9066a0683fec3c903669267eb806ffa831dcd4b3daae",
|
||||
source: undefined,
|
||||
builder: undefined,
|
||||
creator: faucet.address,
|
||||
};
|
||||
|
||||
// check info
|
||||
expect(result).toEqual(jasmine.objectContaining(expectedInfo));
|
||||
// check data
|
||||
expect(new Sha256(result.data).digest()).toEqual(fromHex(expectedInfo.checksum));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -58,9 +58,9 @@ export interface Code {
|
||||
readonly builder?: string;
|
||||
}
|
||||
|
||||
export interface CodeDetails {
|
||||
export interface CodeDetails extends Code {
|
||||
/** The original wasm bytes */
|
||||
readonly wasm: Uint8Array;
|
||||
readonly data: Uint8Array;
|
||||
}
|
||||
|
||||
export interface Contract {
|
||||
@ -208,9 +208,15 @@ export class CosmWasmClient {
|
||||
}
|
||||
|
||||
public async getCodeDetails(codeId: number): Promise<CodeDetails> {
|
||||
const result = await this.restClient.getCode(codeId);
|
||||
// TODO: implement as one request when https://github.com/cosmwasm/wasmd/issues/90 is done
|
||||
const [codeInfos, getCodeResult] = await Promise.all([this.getCodes(), this.restClient.getCode(codeId)]);
|
||||
|
||||
const codeInfo = codeInfos.find(code => code.id === codeId);
|
||||
if (!codeInfo) throw new Error("No code info found");
|
||||
|
||||
return {
|
||||
wasm: result,
|
||||
...codeInfo,
|
||||
data: getCodeResult,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
4
packages/sdk/types/cosmwasmclient.d.ts
vendored
4
packages/sdk/types/cosmwasmclient.d.ts
vendored
@ -34,9 +34,9 @@ export interface Code {
|
||||
readonly source?: string;
|
||||
readonly builder?: string;
|
||||
}
|
||||
export interface CodeDetails {
|
||||
export interface CodeDetails extends Code {
|
||||
/** The original wasm bytes */
|
||||
readonly wasm: Uint8Array;
|
||||
readonly data: Uint8Array;
|
||||
}
|
||||
export interface Contract {
|
||||
readonly address: string;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user