diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b4ca7e3..bd7aca98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,8 +24,10 @@ and this project adheres to and remove dependency on @cosmjs/cosmwasm-launchpad. - @cosmjs/faucet: Add new configuration variable `FAUCET_PATH_PATTERN` to configure the HD path of the faucet accounts ([#832]). +- @cosmjs/cosmwasm-stargate: Add field `ibcPortId` to `Contract` ([#836]). [#832]: https://github.com/cosmos/cosmjs/issues/832 +[#836]: https://github.com/cosmos/cosmjs/issues/836 ### Changed diff --git a/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts b/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts index 83647705..18674f7e 100644 --- a/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts +++ b/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts @@ -22,6 +22,7 @@ import { defaultInstantiateFee, defaultUploadFee, deployedHackatom, + deployedIbcReflect, getHackatom, makeRandomAddress, pendingWithoutWasmd, @@ -291,6 +292,7 @@ describe("CosmWasmClient", () => { creator: alice.address0, label: deployedHackatom.instances[0].label, admin: undefined, + ibcPortId: undefined, }); }); @@ -298,13 +300,25 @@ describe("CosmWasmClient", () => { pendingWithoutWasmd(); const client = await CosmWasmClient.connect(wasmd.endpoint); const two = await client.getContract(deployedHackatom.instances[2].address); - expect(two).toEqual( + expect(two).toEqual({ + address: deployedHackatom.instances[2].address, + codeId: deployedHackatom.codeId, + creator: alice.address0, + label: deployedHackatom.instances[2].label, + admin: alice.address1, + ibcPortId: undefined, + }); + }); + + it("works for instance with IBC port ID", async () => { + pendingWithoutWasmd(); + const client = await CosmWasmClient.connect(wasmd.endpoint); + const contract = await client.getContract(deployedIbcReflect.instances[0]); + expect(contract).toEqual( jasmine.objectContaining({ - address: deployedHackatom.instances[2].address, - codeId: deployedHackatom.codeId, - creator: alice.address0, - label: deployedHackatom.instances[2].label, - admin: alice.address1, + address: deployedIbcReflect.instances[0], + codeId: deployedIbcReflect.codeId, + ibcPortId: "wasm.wasm1vjecguu37pmd577339wrdp208ddzymku8yy0te", }), ); }); diff --git a/packages/cosmwasm-stargate/src/cosmwasmclient.ts b/packages/cosmwasm-stargate/src/cosmwasmclient.ts index c0529b86..3a65bcfa 100644 --- a/packages/cosmwasm-stargate/src/cosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/cosmwasmclient.ts @@ -67,6 +67,12 @@ export interface Contract { /** Bech32-encoded admin address */ readonly admin: string | undefined; readonly label: string; + /** + * The IBC port ID assigned to this contract by wasmd. + * + * This is set for all IBC contracts (https://github.com/CosmWasm/wasmd/blob/v0.16.0/x/wasm/keeper/keeper.go#L299-L306). + */ + readonly ibcPortId: string | undefined; } export interface ContractCodeHistoryEntry { @@ -360,6 +366,7 @@ export class CosmWasmClient { creator: contractInfo.creator, admin: contractInfo.admin || undefined, label: contractInfo.label, + ibcPortId: contractInfo.ibcPortId || undefined, }; } diff --git a/packages/cosmwasm-stargate/src/testutils.spec.ts b/packages/cosmwasm-stargate/src/testutils.spec.ts index 7bd7307a..66aba2c3 100644 --- a/packages/cosmwasm-stargate/src/testutils.spec.ts +++ b/packages/cosmwasm-stargate/src/testutils.spec.ts @@ -137,6 +137,12 @@ export const deployedHackatom = { ], }; +/** Deployed as part of scripts/wasmd/init.sh */ +export const deployedIbcReflect = { + codeId: 2, + instances: ["wasm1vjecguu37pmd577339wrdp208ddzymku8yy0te"], +}; + /** Deployed as part of scripts/wasmd/init.sh */ export const deployedCw3 = { codeId: 3, diff --git a/scripts/wasmd/contracts/checksums.sha256 b/scripts/wasmd/contracts/checksums.sha256 index bea08863..f0e132bd 100644 --- a/scripts/wasmd/contracts/checksums.sha256 +++ b/scripts/wasmd/contracts/checksums.sha256 @@ -1,3 +1,4 @@ 775f9f8fe7d2ca1ac33ec47799e9b8fd25aa1bf3cf97961f49f091b99e62f85b cw1_subkeys.wasm 3e3ea92c4ec35d90aa0bef344bdb0a94939120fce57265d5ff81bf8e8caec7e9 cw3_fixed_multisig.wasm a32acdcfe15a2b3c8ba6963cf1e4ab63347725cc35a0f2434696dd492d63fb5f hackatom.wasm +089598e3cab468aff26233bc7363c713529124a0f7fd50320461cb58881a2da7 ibc_reflect.wasm diff --git a/scripts/wasmd/contracts/download.sh b/scripts/wasmd/contracts/download.sh index 1a5ab8fd..967be9a9 100755 --- a/scripts/wasmd/contracts/download.sh +++ b/scripts/wasmd/contracts/download.sh @@ -6,6 +6,7 @@ COSMWASM_VERSION="v0.14.0" PLUS_VERSION="v0.6.0" curl -L -O "https://github.com/CosmWasm/cosmwasm/releases/download/${COSMWASM_VERSION}/hackatom.wasm" +curl -L -O "https://github.com/CosmWasm/cosmwasm/releases/download/${COSMWASM_VERSION}/ibc_reflect.wasm" curl -L -O "https://github.com/CosmWasm/cosmwasm-plus/releases/download/${PLUS_VERSION}/cw1_subkeys.wasm" curl -L -O "https://github.com/CosmWasm/cosmwasm-plus/releases/download/${PLUS_VERSION}/cw3_fixed_multisig.wasm" diff --git a/scripts/wasmd/contracts/ibc_reflect.wasm b/scripts/wasmd/contracts/ibc_reflect.wasm new file mode 100644 index 00000000..b95ab4d0 --- /dev/null +++ b/scripts/wasmd/contracts/ibc_reflect.wasm @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:089598e3cab468aff26233bc7363c713529124a0f7fd50320461cb58881a2da7 +size 290806 diff --git a/scripts/wasmd/deploy_ibc_reflect.js b/scripts/wasmd/deploy_ibc_reflect.js new file mode 100755 index 00000000..3adc18e7 --- /dev/null +++ b/scripts/wasmd/deploy_ibc_reflect.js @@ -0,0 +1,76 @@ +#!/usr/bin/env -S yarn node + +/* eslint-disable @typescript-eslint/naming-convention */ +const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate"); +const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing"); +const { calculateFee, GasPrice } = require("@cosmjs/stargate"); +const fs = require("fs"); + +const endpoint = "http://localhost:26659"; +const alice = { + mnemonic: "enlist hip relief stomach skate base shallow young switch frequent cry park", + address0: "wasm14qemq0vw6y3gc3u3e0aty2e764u4gs5lndxgyk", + address1: "wasm1hhg2rlu9jscacku2wwckws7932qqqu8xm5ca8y", + address2: "wasm1xv9tklw7d82sezh9haa573wufgy59vmwnxhnsl", + address3: "wasm17yg9mssjenmc3jkqth6ulcwj9cxujrxxg9nmzk", + address4: "wasm1f7j7ryulwjfe9ljplvhtcaxa6wqgula3nh873j", +}; + +const codeMeta = { + source: "https://crates.io/api/v1/crates/hackatom/not-yet-released/download", + builder: "cosmwasm/rust-optimizer:0.10.8", +}; + +const inits = [ + { + label: "Instantiate IBC reflect", + msg: { + reflect_code_id: 222, // dummy value that will not work + }, + admin: undefined, + }, +]; + +async function main() { + const gasPrice = GasPrice.fromString("0.025ucosm"); + const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: "wasm" }); + const client = await SigningCosmWasmClient.connectWithSigner(endpoint, wallet); + + const wasm = fs.readFileSync(__dirname + "/contracts/ibc_reflect.wasm"); + const uploadFee = calculateFee(2_500_000, gasPrice); + const uploadReceipt = await client.upload( + alice.address0, + wasm, + uploadFee, + codeMeta, + "Upload IBC reflect contract", + ); + console.info(`Upload succeeded. Receipt: ${JSON.stringify(uploadReceipt)}`); + + const instantiateFee = calculateFee(900_000, gasPrice); + for (const { label, msg, admin } of inits) { + const { contractAddress } = await client.instantiate( + alice.address0, + uploadReceipt.codeId, + msg, + label, + instantiateFee, + { + memo: `Create a ibc_reflect instance in deploy_ibc_reflect.js`, + admin: admin, + }, + ); + console.info(`Contract instantiated at ${contractAddress}`); + } +} + +main().then( + () => { + console.info("All done, have fun with IBC."); + process.exit(0); + }, + (error) => { + console.error(error); + process.exit(1); + }, +); diff --git a/scripts/wasmd/init.sh b/scripts/wasmd/init.sh index be03d1d0..6d73b2a0 100755 --- a/scripts/wasmd/init.sh +++ b/scripts/wasmd/init.sh @@ -26,5 +26,6 @@ SCRIPT_DIR="$(realpath "$(dirname "$0")")" sha256sum --check checksums.sha256 ) "$SCRIPT_DIR/deploy_hackatom.js" +"$SCRIPT_DIR/deploy_ibc_reflect.js" # "$SCRIPT_DIR/deploy_cw3.js" # "$SCRIPT_DIR/deploy_cw1.js"