Merge pull request #127 from confio/test-0.7-simon3
Set code verification data for nameservice contract
This commit is contained in:
commit
9195ae52cf
@ -32,5 +32,6 @@ export {
|
||||
SigningCallback,
|
||||
SigningCosmWasmClient,
|
||||
ExecuteResult,
|
||||
UploadMeta,
|
||||
UploadReceipt,
|
||||
} from "./signingcosmwasmclient";
|
||||
|
||||
@ -4,7 +4,7 @@ import { assert } from "@iov/utils";
|
||||
|
||||
import { Secp256k1Pen } from "./pen";
|
||||
import { RestClient } from "./restclient";
|
||||
import { SigningCosmWasmClient } from "./signingcosmwasmclient";
|
||||
import { SigningCosmWasmClient, UploadMeta } from "./signingcosmwasmclient";
|
||||
import { getRandomizedHackatom, makeRandomAddress, pendingWithoutWasmd } from "./testutils.spec";
|
||||
import { Coin } from "./types";
|
||||
|
||||
@ -50,6 +50,23 @@ describe("SigningCosmWasmClient", () => {
|
||||
expect(compressedSize).toBeLessThan(wasm.length * 0.5);
|
||||
expect(codeId).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
it("can set builder and source", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const pen = await Secp256k1Pen.fromMnemonic(faucet.mnemonic);
|
||||
const client = new SigningCosmWasmClient(httpUrl, faucet.address, signBytes => pen.sign(signBytes));
|
||||
const wasm = getRandomizedHackatom();
|
||||
|
||||
const meta: UploadMeta = {
|
||||
source: "https://crates.io/api/v1/crates/cw-nameservice/0.1.0/download",
|
||||
builder: "confio/cosmwasm-opt:0.6.2",
|
||||
};
|
||||
const { codeId } = await client.upload(wasm, meta);
|
||||
|
||||
const codeDetails = await client.getCodeDetails(codeId);
|
||||
expect(codeDetails.source).toEqual(meta.source);
|
||||
expect(codeDetails.builder).toEqual(meta.builder);
|
||||
});
|
||||
});
|
||||
|
||||
describe("instantiate", () => {
|
||||
|
||||
@ -51,6 +51,13 @@ const defaultFees: FeeTable = {
|
||||
},
|
||||
};
|
||||
|
||||
export interface UploadMeta {
|
||||
/** The source URL */
|
||||
readonly source?: string;
|
||||
/** The builder tag */
|
||||
readonly builder?: string;
|
||||
}
|
||||
|
||||
export interface UploadReceipt {
|
||||
/** Size of the original wasm code in bytes */
|
||||
readonly originalSize: number;
|
||||
@ -96,7 +103,10 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
}
|
||||
|
||||
/** Uploads code and returns a receipt, including the code ID */
|
||||
public async upload(wasmCode: Uint8Array, memo = ""): Promise<UploadReceipt> {
|
||||
public async upload(wasmCode: Uint8Array, meta: UploadMeta = {}, memo = ""): Promise<UploadReceipt> {
|
||||
const source = meta.source || "";
|
||||
const builder = meta.builder || "";
|
||||
|
||||
const compressed = pako.gzip(wasmCode, { level: 9 });
|
||||
const storeCodeMsg: MsgStoreCode = {
|
||||
type: "wasm/store-code",
|
||||
@ -104,8 +114,8 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
sender: this.senderAddress,
|
||||
// eslint-disable-next-line @typescript-eslint/camelcase
|
||||
wasm_byte_code: Encoding.toBase64(compressed),
|
||||
source: "",
|
||||
builder: "",
|
||||
source: source,
|
||||
builder: builder,
|
||||
},
|
||||
};
|
||||
const fee = this.fees.upload;
|
||||
|
||||
1
packages/sdk/types/index.d.ts
vendored
1
packages/sdk/types/index.d.ts
vendored
@ -31,5 +31,6 @@ export {
|
||||
SigningCallback,
|
||||
SigningCosmWasmClient,
|
||||
ExecuteResult,
|
||||
UploadMeta,
|
||||
UploadReceipt,
|
||||
} from "./signingcosmwasmclient";
|
||||
|
||||
@ -11,6 +11,12 @@ export interface FeeTable {
|
||||
readonly exec: StdFee;
|
||||
readonly send: StdFee;
|
||||
}
|
||||
export interface UploadMeta {
|
||||
/** The source URL */
|
||||
readonly source?: string;
|
||||
/** The builder tag */
|
||||
readonly builder?: string;
|
||||
}
|
||||
export interface UploadReceipt {
|
||||
/** Size of the original wasm code in bytes */
|
||||
readonly originalSize: number;
|
||||
@ -40,7 +46,7 @@ export declare class SigningCosmWasmClient extends CosmWasmClient {
|
||||
getNonce(address?: string): Promise<GetNonceResult>;
|
||||
getAccount(address?: string): Promise<CosmosSdkAccount | undefined>;
|
||||
/** Uploads code and returns a receipt, including the code ID */
|
||||
upload(wasmCode: Uint8Array, memo?: string): Promise<UploadReceipt>;
|
||||
upload(wasmCode: Uint8Array, meta?: UploadMeta, memo?: string): Promise<UploadReceipt>;
|
||||
instantiate(
|
||||
codeId: number,
|
||||
initMsg: object,
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
aff8c8873d79d2153a8b9066a0683fec3c903669267eb806ffa831dcd4b3daae cw-erc20.wasm
|
||||
8427fcbf9e6c15d0e0dea0afe75640d997a6854d03c3aa1c8bdf1a9787a35681 cw-nameservice.wasm
|
||||
d5dde423d321f7d3793a9b1667d06ac86c7f57dfbd2534a9c790963e1c2955ed cw-nameservice.wasm
|
||||
|
||||
Binary file not shown.
@ -72,7 +72,7 @@ async function main() {
|
||||
const client = new SigningCosmWasmClient(httpUrl, faucet.address, signBytes => pen.sign(signBytes));
|
||||
|
||||
const wasm = fs.readFileSync(__dirname + "/contracts/cw-erc20.wasm");
|
||||
const uploadReceipt = await client.upload(wasm, "Upload ERC20 contract");
|
||||
const uploadReceipt = await client.upload(wasm, {}, "Upload ERC20 contract");
|
||||
console.info(`Upload succeeded. Receipt: ${JSON.stringify(uploadReceipt)}`);
|
||||
|
||||
for (const initMsg of [initMsgHash, initMsgIsa, initMsgJade]) {
|
||||
|
||||
@ -11,18 +11,27 @@ const faucet = {
|
||||
address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
};
|
||||
|
||||
const initFree = {
|
||||
name: "Free",
|
||||
const codeMeta = {
|
||||
source: "https://crates.io/api/v1/crates/cw-nameservice/0.2.0/download",
|
||||
builder: "confio/cosmwasm-opt:0.7.0",
|
||||
};
|
||||
const initLuxury = {
|
||||
name: "Luxury",
|
||||
purchase_price: {
|
||||
denom: "ucosm",
|
||||
amount: "2000000",
|
||||
},
|
||||
transfer_price: {
|
||||
denom: "ucosm",
|
||||
amount: "1000000",
|
||||
|
||||
const free = {
|
||||
label: "Free",
|
||||
initMsg: {},
|
||||
};
|
||||
|
||||
const luxury = {
|
||||
label: "Luxury",
|
||||
initMsg: {
|
||||
purchase_price: {
|
||||
denom: "ucosm",
|
||||
amount: "2000000",
|
||||
},
|
||||
transfer_price: {
|
||||
denom: "ucosm",
|
||||
amount: "1000000",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@ -31,13 +40,13 @@ async function main() {
|
||||
const client = new SigningCosmWasmClient(httpUrl, faucet.address, signBytes => pen.sign(signBytes));
|
||||
|
||||
const wasm = fs.readFileSync(__dirname + "/contracts/cw-nameservice.wasm");
|
||||
const uploadReceipt = await client.upload(wasm, "Upload Name Service contract");
|
||||
const uploadReceipt = await client.upload(wasm, codeMeta, "Upload Name Service code");
|
||||
console.info(`Upload succeeded. Receipt: ${JSON.stringify(uploadReceipt)}`);
|
||||
|
||||
for (const initMsg of [initFree, initLuxury]) {
|
||||
const memo = `Create an nameservice instance for ${initMsg.name}`;
|
||||
const contractAddress = await client.instantiate(uploadReceipt.codeId, initMsg, initMsg.name, memo);
|
||||
console.info(`Contract instantiated for ${initMsg.name} at ${contractAddress}`);
|
||||
for (const { label, initMsg } of [free, luxury]) {
|
||||
const memo = `Create an nameservice instance "${label}"`;
|
||||
const contractAddress = await client.instantiate(uploadReceipt.codeId, initMsg, label, memo);
|
||||
console.info(`Contract "${label}" instantiated at ${contractAddress}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user