From 4af419b3651c68ab4b5872292d2189338321a7f5 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Thu, 8 Oct 2020 16:04:45 +0200 Subject: [PATCH] Make many test independent of ERC20_ENABLED --- packages/cosmwasm/src/cosmwasmclient.spec.ts | 69 +++++++++----------- packages/cosmwasm/src/testutils.spec.ts | 15 ++++- scripts/wasmd/deploy_hackatom.js | 45 +++++++++---- 3 files changed, 80 insertions(+), 49 deletions(-) diff --git a/packages/cosmwasm/src/cosmwasmclient.spec.ts b/packages/cosmwasm/src/cosmwasmclient.spec.ts index 0584f26a68..60f82f5e4f 100644 --- a/packages/cosmwasm/src/cosmwasmclient.spec.ts +++ b/packages/cosmwasm/src/cosmwasmclient.spec.ts @@ -19,10 +19,9 @@ import { SigningCosmWasmClient } from "./signingcosmwasmclient"; import cosmoshub from "./testdata/cosmoshub.json"; import { alice, - deployedErc20, + deployedHackatom, getHackatom, makeRandomAddress, - pendingWithoutErc20, pendingWithoutWasmd, tendermintIdMatcher, unused, @@ -255,16 +254,15 @@ describe("CosmWasmClient", () => { describe("getCodes", () => { it("works", async () => { pendingWithoutWasmd(); - pendingWithoutErc20(); // TODO: Adapt test to use hackatom instead const client = new CosmWasmClient(wasmd.endpoint); const result = await client.getCodes(); expect(result.length).toBeGreaterThanOrEqual(1); const [first] = result; expect(first).toEqual({ - id: deployedErc20.codeId, - source: deployedErc20.source, - builder: deployedErc20.builder, - checksum: deployedErc20.checksum, + id: deployedHackatom.codeId, + source: deployedHackatom.source, + builder: deployedHackatom.builder, + checksum: deployedHackatom.checksum, creator: alice.address0, }); }); @@ -273,15 +271,14 @@ describe("CosmWasmClient", () => { describe("getCodeDetails", () => { it("works", async () => { pendingWithoutWasmd(); - pendingWithoutErc20(); // TODO: Adapt test to use hackatom instead const client = new CosmWasmClient(wasmd.endpoint); const result = await client.getCodeDetails(1); const expectedInfo: Code = { - id: deployedErc20.codeId, - source: deployedErc20.source, - builder: deployedErc20.builder, - checksum: deployedErc20.checksum, + id: deployedHackatom.codeId, + source: deployedHackatom.source, + builder: deployedHackatom.builder, + checksum: deployedHackatom.checksum, creator: alice.address0, }; @@ -293,13 +290,12 @@ describe("CosmWasmClient", () => { it("caches downloads", async () => { pendingWithoutWasmd(); - pendingWithoutErc20(); // TODO: Adapt test to use hackatom instead const client = new CosmWasmClient(wasmd.endpoint); const openedClient = (client as unknown) as PrivateCosmWasmClient; const getCodeSpy = spyOn(openedClient.lcdClient.wasm, "getCode").and.callThrough(); - const result1 = await client.getCodeDetails(deployedErc20.codeId); // from network - const result2 = await client.getCodeDetails(deployedErc20.codeId); // from cache + const result1 = await client.getCodeDetails(deployedHackatom.codeId); // from network + const result2 = await client.getCodeDetails(deployedHackatom.codeId); // from cache expect(result2).toEqual(result1); expect(getCodeSpy).toHaveBeenCalledTimes(1); @@ -309,31 +305,30 @@ describe("CosmWasmClient", () => { describe("getContracts", () => { it("works", async () => { pendingWithoutWasmd(); - pendingWithoutErc20(); // TODO: Adapt test to use hackatom instead const client = new CosmWasmClient(wasmd.endpoint); const result = await client.getContracts(1); expect(result.length).toBeGreaterThanOrEqual(3); - const [hash, isa, jade] = result; - expect(hash).toEqual({ - address: "cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5", + const [zero, one, two] = result; + expect(zero).toEqual({ + address: deployedHackatom.instances[0].address, codeId: 1, creator: alice.address0, admin: undefined, - label: "HASH", + label: deployedHackatom.instances[0].label, }); - expect(isa).toEqual({ - address: "cosmos1hqrdl6wstt8qzshwc6mrumpjk9338k0lr4dqxd", + expect(one).toEqual({ + address: deployedHackatom.instances[1].address, codeId: 1, creator: alice.address0, admin: undefined, - label: "ISA", + label: deployedHackatom.instances[1].label, }); - expect(jade).toEqual({ - address: "cosmos18r5szma8hm93pvx6lwpjwyxruw27e0k5uw835c", + expect(two).toEqual({ + address: deployedHackatom.instances[2].address, codeId: 1, creator: alice.address0, admin: alice.address1, - label: "JADE", + label: deployedHackatom.instances[2].label, }); }); }); @@ -341,27 +336,27 @@ describe("CosmWasmClient", () => { describe("getContract", () => { it("works for instance without admin", async () => { pendingWithoutWasmd(); - pendingWithoutErc20(); // TODO: Adapt test to use hackatom instead const client = new CosmWasmClient(wasmd.endpoint); - const hash = await client.getContract("cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5"); - expect(hash).toEqual({ - address: "cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5", - codeId: 1, + const zero = await client.getContract(deployedHackatom.instances[0].address); + expect(zero).toEqual({ + address: deployedHackatom.instances[0].address, + codeId: deployedHackatom.codeId, creator: alice.address0, - label: "HASH", + label: deployedHackatom.instances[0].label, admin: undefined, }); }); it("works for instance with admin", async () => { pendingWithoutWasmd(); - pendingWithoutErc20(); // TODO: Adapt test to use hackatom instead const client = new CosmWasmClient(wasmd.endpoint); - const jade = await client.getContract("cosmos18r5szma8hm93pvx6lwpjwyxruw27e0k5uw835c"); - expect(jade).toEqual( + const two = await client.getContract(deployedHackatom.instances[2].address); + expect(two).toEqual( jasmine.objectContaining({ - address: "cosmos18r5szma8hm93pvx6lwpjwyxruw27e0k5uw835c", - label: "JADE", + address: deployedHackatom.instances[2].address, + codeId: deployedHackatom.codeId, + creator: alice.address0, + label: deployedHackatom.instances[2].label, admin: alice.address1, }), ); diff --git a/packages/cosmwasm/src/testutils.spec.ts b/packages/cosmwasm/src/testutils.spec.ts index cf8c6a1b21..22fc0e89eb 100644 --- a/packages/cosmwasm/src/testutils.spec.ts +++ b/packages/cosmwasm/src/testutils.spec.ts @@ -30,8 +30,21 @@ export const base64Matcher = /^(?:[a-zA-Z0-9+/]{4})*(?:|(?:[a-zA-Z0-9+/]{3}=)|(? export const bech32AddressMatcher = /^[\x21-\x7e]{1,83}1[02-9ac-hj-np-z]{38}$/; /** Deployed as part of scripts/wasmd/init.sh */ -export const deployedErc20 = { +export const deployedHackatom = { codeId: 1, + source: "https://crates.io/api/v1/crates/hackatom/not-yet-released/download", + builder: "cosmwasm/rust-optimizer:0.9.1", + checksum: "3defc33a41f58c71d38b176d521c411d8e74d26403fde7660486930c7579a016", + instances: [ + { address: "cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5", label: "From deploy_hackatom.js (0)" }, + { address: "cosmos1hqrdl6wstt8qzshwc6mrumpjk9338k0lr4dqxd", label: "From deploy_hackatom.js (1)" }, + { address: "cosmos18r5szma8hm93pvx6lwpjwyxruw27e0k5uw835c", label: "From deploy_hackatom.js (2)" }, + ], +}; + +/** Deployed as part of scripts/wasmd/init.sh */ +export const deployedErc20 = { + codeId: 2, source: "https://crates.io/api/v1/crates/cw-erc20/not-yet-released/download", builder: "cosmwasm/rust-optimizer:0.9.0", checksum: "0f14abcc6fed08f2dd06896db974989db97dbcc6e8e30188b73fe5ab427c7785", diff --git a/scripts/wasmd/deploy_hackatom.js b/scripts/wasmd/deploy_hackatom.js index 0609e5aa18..b104086186 100755 --- a/scripts/wasmd/deploy_hackatom.js +++ b/scripts/wasmd/deploy_hackatom.js @@ -17,13 +17,35 @@ const alice = { const codeMeta = { source: "https://crates.io/api/v1/crates/hackatom/not-yet-released/download", - builder: "cosmwasm/rust-optimizer:0.9.0", + builder: "cosmwasm/rust-optimizer:0.9.1", }; -const initMsg = { - beneficiary: alice.address0, - verifier: alice.address0, -}; +const inits = [ + { + label: "From deploy_hackatom.js (0)", + msg: { + beneficiary: alice.address0, + verifier: alice.address0, + }, + admin: undefined, + }, + { + label: "From deploy_hackatom.js (1)", + msg: { + beneficiary: alice.address1, + verifier: alice.address1, + }, + admin: undefined, + }, + { + label: "From deploy_hackatom.js (2)", + msg: { + beneficiary: alice.address2, + verifier: alice.address2, + }, + admin: alice.address1, + }, +]; async function main() { const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); @@ -33,12 +55,13 @@ async function main() { const uploadReceipt = await client.upload(wasm, codeMeta, "Upload hackatom contract"); console.info(`Upload succeeded. Receipt: ${JSON.stringify(uploadReceipt)}`); - const label = "From deploy_hackatom.js"; - const { contractAddress } = await client.instantiate(uploadReceipt.codeId, initMsg, label, { - memo: `Create a hackatom instance in deploy_hackatom.js`, - admin: alice.address0, - }); - console.info(`Contract instantiated at ${contractAddress}`); + for (const { label, msg, admin } of inits) { + const { contractAddress } = await client.instantiate(uploadReceipt.codeId, msg, label, { + memo: `Create a hackatom instance in deploy_hackatom.js`, + admin: admin, + }); + console.info(`Contract instantiated at ${contractAddress}`); + } } main().then(