diff --git a/Cargo.lock b/Cargo.lock index 2bd348a..a5abaaa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -221,6 +221,25 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cw-multi-test" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2519fd64b6b8c7c4e77c317e665bd19b438db3e8e4867241fa6a31cf060feda9" +dependencies = [ + "anyhow", + "cosmwasm-std", + "cosmwasm-storage", + "cw-storage-plus 0.15.0", + "cw-utils 0.15.0", + "derivative", + "itertools", + "prost", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "cw-storage-plus" version = "0.13.4" @@ -243,6 +262,17 @@ dependencies = [ "serde", ] +[[package]] +name = "cw-storage-plus" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39ba3fb5fad2dce94263d070848b2befc46b5c8e4929adfb9a3595267823d6ec" +dependencies = [ + "cosmwasm-std", + "schemars", + "serde", +] + [[package]] name = "cw-utils" version = "0.13.4" @@ -269,6 +299,21 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cw-utils" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a67007ff056f4cd034f361c8ed69780c0180959b9c8037c84f3caa78120faf5" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw2 0.15.0", + "schemars", + "semver", + "serde", + "thiserror", +] + [[package]] name = "cw2" version = "0.13.4" @@ -293,6 +338,19 @@ dependencies = [ "serde", ] +[[package]] +name = "cw2" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0a1924a28607bf7cb9fd6681a64feea3e5fa9a8cb71fb4d24cf33635b21065a" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 0.15.0", + "schemars", + "serde", +] + [[package]] name = "cw721" version = "0.13.4" @@ -395,6 +453,18 @@ dependencies = [ "signature", ] +[[package]] +name = "echo" +version = "0.1.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 0.15.0", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "ed25519-zebra" version = "3.0.0" @@ -510,6 +580,21 @@ dependencies = [ "digest 0.10.3", ] +[[package]] +name = "ibc-controller" +version = "0.1.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cosmwasm-storage", + "cw-storage-plus 0.15.0", + "echo", + "ibc-dispatcher", + "schemars", + "serde", + "thiserror", +] + [[package]] name = "ibc-dispatcher" version = "0.1.0" @@ -517,9 +602,9 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", - "cw-multi-test", - "cw-storage-plus 0.14.0", - "cw2 0.14.0", + "cw-multi-test 0.15.0", + "cw-storage-plus 0.15.0", + "cw2 0.15.0", "schemars", "serde", "thiserror", @@ -532,7 +617,7 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", - "cw-multi-test", + "cw-multi-test 0.14.0", "cw-storage-plus 0.14.0", "cw2 0.14.0", "schemars", diff --git a/README.md b/README.md index ebe6628..228305c 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,21 @@ Have a look at unit tests showing how to: - mint an NFT for this instantiated collection - transfer an NFT to another address +## IBC Dispatcher + +The objective of this (not yet finished) contract is the following: +- a source contract on chain A wants to execute +- a target contract on chain B, where in return +- source contract gets a response back from target contract. + +This can already be done by using IBC - hence this requires a lot of boiler plate code. Basically all IBC calls looks the same. + +IBC dispatcher to the rescue: +- a source chain can pass target message along with target contract address and IBC channel (telling on which chain it is) and +- pass this message to the dispatcher, where +- dispatcher pass it to target contract on the other channel, where in return +- source target gets a response back from the dispatcher + # Resources Ark Protocol PoC diff --git a/contracts/echo/.cargo/config b/contracts/echo/.cargo/config new file mode 100644 index 0000000..336b618 --- /dev/null +++ b/contracts/echo/.cargo/config @@ -0,0 +1,4 @@ +[alias] +wasm = "build --release --target wasm32-unknown-unknown" +unit-test = "test --lib" +schema = "run --example schema" diff --git a/contracts/echo/.circleci/config.yml b/contracts/echo/.circleci/config.yml new file mode 100644 index 0000000..9b07669 --- /dev/null +++ b/contracts/echo/.circleci/config.yml @@ -0,0 +1,61 @@ +version: 2.1 + +executors: + builder: + docker: + - image: buildpack-deps:trusty + +jobs: + docker-image: + executor: builder + steps: + - checkout + - setup_remote_docker + docker_layer_caching: true + - run: + name: Build Docker artifact + command: docker build --pull -t "cosmwasm/cw-gitpod-base:${CIRCLE_SHA1}" . + - run: + name: Push application Docker image to docker hub + command: | + if [ "${CIRCLE_BRANCH}" = "master" ]; then + docker tag "cosmwasm/cw-gitpod-base:${CIRCLE_SHA1}" cosmwasm/cw-gitpod-base:latest + docker login --password-stdin -u "$DOCKER_USER" \<<<"$DOCKER_PASS" + docker push cosmwasm/cw-gitpod-base:latest + docker logout + fi + + docker-tagged: + executor: builder + steps: + - checkout + - setup_remote_docker + docker_layer_caching: true + - run: + name: Push application Docker image to docker hub + command: | + docker tag "cosmwasm/cw-gitpod-base:${CIRCLE_SHA1}" "cosmwasm/cw-gitpod-base:${CIRCLE_TAG}" + docker login --password-stdin -u "$DOCKER_USER" \<<<"$DOCKER_PASS" + docker push + docker logout + +workflows: + version: 2 + test-suite: + jobs: + # this is now a slow process... let's only run on master + - docker-image: + filters: + branches: + only: + - master + - docker-tagged: + filters: + tags: + only: + - /^v.*/ + branches: + ignore: + - /.*/ + requires: + - docker-image diff --git a/contracts/echo/.editorconfig b/contracts/echo/.editorconfig new file mode 100644 index 0000000..3d36f20 --- /dev/null +++ b/contracts/echo/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.rs] +indent_size = 4 diff --git a/contracts/echo/.github/workflows/Basic.yml b/contracts/echo/.github/workflows/Basic.yml new file mode 100644 index 0000000..0aa4193 --- /dev/null +++ b/contracts/echo/.github/workflows/Basic.yml @@ -0,0 +1,75 @@ +# Based on https://github.com/actions-rs/example/blob/master/.github/workflows/quickstart.yml + +on: [push, pull_request] + +name: Basic + +jobs: + + test: + name: Test Suite + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: 1.58.1 + target: wasm32-unknown-unknown + override: true + + - name: Run unit tests + uses: actions-rs/cargo@v1 + with: + command: unit-test + args: --locked + env: + RUST_BACKTRACE: 1 + + - name: Compile WASM contract + uses: actions-rs/cargo@v1 + with: + command: wasm + args: --locked + env: + RUSTFLAGS: "-C link-arg=-s" + + lints: + name: Lints + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: 1.58.1 + override: true + components: rustfmt, clippy + + - name: Run cargo fmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + - name: Run cargo clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings + + - name: Generate Schema + uses: actions-rs/cargo@v1 + with: + command: schema + args: --locked + + - name: Schema Changes + # fails if any changes not committed + run: git diff --exit-code schema diff --git a/contracts/echo/.gitignore b/contracts/echo/.gitignore new file mode 100644 index 0000000..dfdaaa6 --- /dev/null +++ b/contracts/echo/.gitignore @@ -0,0 +1,15 @@ +# Build results +/target + +# Cargo+Git helper file (https://github.com/rust-lang/cargo/blob/0.44.1/src/cargo/sources/git/utils.rs#L320-L327) +.cargo-ok + +# Text file backups +**/*.rs.bk + +# macOS +.DS_Store + +# IDEs +*.iml +.idea diff --git a/contracts/echo/Cargo.lock b/contracts/echo/Cargo.lock new file mode 100644 index 0000000..91fb09f --- /dev/null +++ b/contracts/echo/Cargo.lock @@ -0,0 +1,738 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" + +[[package]] +name = "base16ct" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "base64ct" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dea908e7347a8c64e378c17e30ef880ad73e3b4498346b055c2c00ea342f3179" + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-oid" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" + +[[package]] +name = "cosmwasm-crypto" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eb0afef2325df81aadbf9be1233f522ed8f6e91df870c764bc44cca2b1415bd" +dependencies = [ + "digest", + "ed25519-zebra", + "k256", + "rand_core 0.6.3", + "thiserror", +] + +[[package]] +name = "cosmwasm-derive" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b36e527620a2a3e00e46b6e731ab6c9b68d11069c986f7d7be8eba79ef081a4" +dependencies = [ + "syn", +] + +[[package]] +name = "cosmwasm-schema" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "772e80bbad231a47a2068812b723a1ff81dd4a0d56c9391ac748177bea3a61da" +dependencies = [ + "schemars", + "serde_json", +] + +[[package]] +name = "cosmwasm-std" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "875994993c2082a6fcd406937bf0fca21c349e4a624f3810253a14fa83a3a195" +dependencies = [ + "base64", + "cosmwasm-crypto", + "cosmwasm-derive", + "forward_ref", + "schemars", + "serde", + "serde-json-wasm", + "thiserror", + "uint", +] + +[[package]] +name = "cosmwasm-storage" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d18403b07304d15d304dad11040d45bbcaf78d603b4be3fb5e2685c16f9229b5" +dependencies = [ + "cosmwasm-std", + "serde", +] + +[[package]] +name = "cpufeatures" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" +dependencies = [ + "libc", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-bigint" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03c6a1d5fa1de37e071642dfa44ec552ca5b299adb128fab16138e24b548fd21" +dependencies = [ + "generic-array", + "rand_core 0.6.3", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-mac" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +dependencies = [ + "byteorder", + "digest", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "cw-multi-test" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbea57e5be4a682268a5eca1a57efece57a54ff216bfd87603d5e864aad40e12" +dependencies = [ + "anyhow", + "cosmwasm-std", + "cosmwasm-storage", + "cw-storage-plus", + "cw-utils", + "derivative", + "itertools", + "prost", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "cw-storage-plus" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9336ecef1e19d56cf6e3e932475fc6a3dee35eec5a386e07917a1d1ba6bb0e35" +dependencies = [ + "cosmwasm-std", + "schemars", + "serde", +] + +[[package]] +name = "cw-utils" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "babd2c090f39d07ce5bf2556962305e795daa048ce20a93709eb591476e4a29e" +dependencies = [ + "cosmwasm-std", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "cw2" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "993df11574f29574dd443eb0c189484bb91bc0638b6de3e32ab7f9319c92122d" +dependencies = [ + "cosmwasm-std", + "cw-storage-plus", + "schemars", + "serde", +] + +[[package]] +name = "der" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6919815d73839e7ad218de758883aae3a257ba6759ce7a9992501efbb53d705c" +dependencies = [ + "const-oid", +] + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "dyn-clone" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21e50f3adc76d6a43f5ed73b698a87d0760ca74617f60f7c3b879003536fdd28" + +[[package]] +name = "ecdsa" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0d69ae62e0ce582d56380743515fefaf1a8c70cec685d9677636d7e30ae9dc9" +dependencies = [ + "der", + "elliptic-curve", + "rfc6979", + "signature", +] + +[[package]] +name = "ed25519-zebra" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "403ef3e961ab98f0ba902771d29f842058578bb1ce7e3c59dad5a6a93e784c69" +dependencies = [ + "curve25519-dalek", + "hex", + "rand_core 0.6.3", + "serde", + "sha2", + "thiserror", + "zeroize", +] + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + +[[package]] +name = "elliptic-curve" +version = "0.11.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25b477563c2bfed38a3b7a60964c49e058b2510ad3f12ba3483fd8f62c2306d6" +dependencies = [ + "base16ct", + "crypto-bigint", + "der", + "ff", + "generic-array", + "group", + "rand_core 0.6.3", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "ff" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "131655483be284720a17d74ff97592b8e76576dc25563148601df2d7c9080924" +dependencies = [ + "rand_core 0.6.3", + "subtle", +] + +[[package]] +name = "forward_ref" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8cbd1169bd7b4a0a20d92b9af7a7e0422888bd38a6f5ec29c1fd8c1558a272e" + +[[package]] +name = "generic-array" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.10.2+wasi-snapshot-preview1", +] + +[[package]] +name = "group" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5ac374b108929de78460075f3dc439fa66df9d8fc77e8f12caa5165fcf0c89" +dependencies = [ + "ff", + "rand_core 0.6.3", + "subtle", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hmac" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" +dependencies = [ + "crypto-mac", + "digest", +] + +[[package]] +name = "itertools" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" + +[[package]] +name = "k256" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19c3a5e0a0b8450278feda242592512e09f61c72e018b8cd5c859482802daf2d" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "sec1", + "sha2", +] + +[[package]] +name = "libc" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "pkcs8" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cabda3fb821068a9a4fab19a683eac3af12edf0f34b94a8be53c4972b8149d0" +dependencies = [ + "der", + "spki", + "zeroize", +] + +[[package]] +name = "proc-macro2" +version = "1.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "prost" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "444879275cb4fd84958b1a1d5420d15e6fcf7c235fe47f053c9c2a80aceb6001" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9cc1a3263e07e0bf68e96268f37665207b49560d98739662cdfaae215c720fe" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "quote" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom 0.2.6", +] + +[[package]] +name = "rfc6979" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96ef608575f6392792f9ecf7890c00086591d29a83910939d430753f7c050525" +dependencies = [ + "crypto-bigint", + "hmac", + "zeroize", +] + +[[package]] +name = "ryu" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" + +[[package]] +name = "schemars" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d21ecb263bf75fc69d5e74b0f2a60b6dd80cfd9fb0eba15c4b9d1104ceffc77" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "219b924f5b39f25b7d7c9203873a2698fdac8db2b396aaea6fa099b699cc40e9" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn", +] + +[[package]] +name = "sec1" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08da66b8b0965a5555b6bd6639e68ccba85e1e2506f5fbb089e93f8a04e1a2d1" +dependencies = [ + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "serde" +version = "1.0.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-json-wasm" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479b4dbc401ca13ee8ce902851b834893251404c4f3c65370a49e047a6be09a5" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_derive_internals" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer", + "cfg-if", + "cpufeatures", + "digest", + "opaque-debug", +] + +[[package]] +name = "signature" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02658e48d89f2bec991f9a78e69cfa4c316f8d6a6c4ec12fae1aeb263d486788" +dependencies = [ + "digest", + "rand_core 0.6.3", +] + +[[package]] +name = "spki" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d01ac02a6ccf3e07db148d2be087da624fea0221a16152ed01f0496a6b0a27" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + +[[package]] +name = "syn" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "testgen-local" +version = "0.1.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cosmwasm-storage", + "cw-multi-test", + "cw-storage-plus", + "cw2", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "thiserror" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "typenum" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" + +[[package]] +name = "uint" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f03af7ccf01dd611cc450a0d10dbc9b745770d096473e2faf0ca6e2d66d1e0" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + +[[package]] +name = "unicode-ident" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "zeroize" +version = "1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94693807d016b2f2d2e14420eb3bfcca689311ff775dcf113d74ea624b7cdf07" diff --git a/contracts/echo/Cargo.toml b/contracts/echo/Cargo.toml new file mode 100644 index 0000000..3fad244 --- /dev/null +++ b/contracts/echo/Cargo.toml @@ -0,0 +1,49 @@ +# (c) Ark Protocol 2022 +# - ALL rights reserved. +# - No copies, disclosure or forward of all data or any info provided here or by the Ark Protocol team is allowed! +# - In case of any doubt contact Ark Protocol on Discord or Twitter. + +[package] +name = "echo" +version = "0.1.0" +authors = ["taitruong", "art3mix", "tottruong"] +edition = "2021" + +exclude = [ + # Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. + "contract.wasm", + "hash.txt", +] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +# for more explicit tests, cargo test --features=backtraces +backtraces = ["cosmwasm-std/backtraces"] +# use library feature to disable all instantiate/execute/query exports +library = [] + +[package.metadata.scripts] +optimize = """docker run --rm -v "$(pwd)":/code \ + --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ + --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ + cosmwasm/rust-optimizer:0.12.6 +""" + +[dependencies] +cosmwasm-std = "1.1.0" +# cosmwasm-storage = "1.1.0" +cw-storage-plus = "0.15.0" +# cw2 = "0.14.0" +# cw721 = "0.13.4" +# cw721-base = "0.13.4" +schemars = "0.8.10" +serde = { version = "1.0.144", default-features = false, features = ["derive"] } +thiserror = { version = "1.0.34" } + +[dev-dependencies] +cosmwasm-schema = "1.1.0" +# cw-multi-test = "0.14.0" \ No newline at end of file diff --git a/contracts/echo/LICENSE b/contracts/echo/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/contracts/echo/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/contracts/echo/NOTICE b/contracts/echo/NOTICE new file mode 100644 index 0000000..7d47f5c --- /dev/null +++ b/contracts/echo/NOTICE @@ -0,0 +1,13 @@ +Copyright 2022 Tai 'Mr. T' Truong + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/contracts/echo/README.md b/contracts/echo/README.md new file mode 100644 index 0000000..954383a --- /dev/null +++ b/contracts/echo/README.md @@ -0,0 +1,106 @@ +# CosmWasm Starter Pack + +This is a template to build smart contracts in Rust to run inside a +[Cosmos SDK](https://github.com/cosmos/cosmos-sdk) module on all chains that enable it. +To understand the framework better, please read the overview in the +[cosmwasm repo](https://github.com/CosmWasm/cosmwasm/blob/master/README.md), +and dig into the [cosmwasm docs](https://www.cosmwasm.com). +This assumes you understand the theory and just want to get coding. + +## Creating a new repo from template + +Assuming you have a recent version of rust and cargo (v1.58.1+) installed +(via [rustup](https://rustup.rs/)), +then the following should get you a new repo to start a contract: + +Install [cargo-generate](https://github.com/ashleygwilliams/cargo-generate) and cargo-run-script. +Unless you did that before, run this line now: + +```sh +cargo install cargo-generate --features vendored-openssl +cargo install cargo-run-script +``` + +Now, use it to create your new contract. +Go to the folder in which you want to place it and run: + + +**Latest: 1.0.0-beta6** + +```sh +cargo generate --git https://github.com/CosmWasm/cw-template.git --name PROJECT_NAME +```` + +**Older Version** + +Pass version as branch flag: + +```sh +cargo generate --git https://github.com/CosmWasm/cw-template.git --branch --name PROJECT_NAME +```` + +Example: + +```sh +cargo generate --git https://github.com/CosmWasm/cw-template.git --branch 0.16 --name PROJECT_NAME +``` + +You will now have a new folder called `PROJECT_NAME` (I hope you changed that to something else) +containing a simple working contract and build system that you can customize. + +## Create a Repo + +After generating, you have a initialized local git repo, but no commits, and no remote. +Go to a server (eg. github) and create a new upstream repo (called `YOUR-GIT-URL` below). +Then run the following: + +```sh +# this is needed to create a valid Cargo.lock file (see below) +cargo check +git branch -M main +git add . +git commit -m 'Initial Commit' +git remote add origin YOUR-GIT-URL +git push -u origin main +``` + +## CI Support + +We have template configurations for both [GitHub Actions](.github/workflows/Basic.yml) +and [Circle CI](.circleci/config.yml) in the generated project, so you can +get up and running with CI right away. + +One note is that the CI runs all `cargo` commands +with `--locked` to ensure it uses the exact same versions as you have locally. This also means +you must have an up-to-date `Cargo.lock` file, which is not auto-generated. +The first time you set up the project (or after adding any dep), you should ensure the +`Cargo.lock` file is updated, so the CI will test properly. This can be done simply by +running `cargo check` or `cargo unit-test`. + +## Using your project + +Once you have your custom repo, you should check out [Developing](./Developing.md) to explain +more on how to run tests and develop code. Or go through the +[online tutorial](https://docs.cosmwasm.com/) to get a better feel +of how to develop. + +[Publishing](./Publishing.md) contains useful information on how to publish your contract +to the world, once you are ready to deploy it on a running blockchain. And +[Importing](./Importing.md) contains information about pulling in other contracts or crates +that have been published. + +Please replace this README file with information about your specific project. You can keep +the `Developing.md` and `Publishing.md` files as useful referenced, but please set some +proper description in the README. + +## Gitpod integration + +[Gitpod](https://www.gitpod.io/) container-based development platform will be enabled on your project by default. + +Workspace contains: + - **rust**: for builds + - [wasmd](https://github.com/CosmWasm/wasmd): for local node setup and client + - **jq**: shell JSON manipulation tool + +Follow [Gitpod Getting Started](https://www.gitpod.io/docs/getting-started) and launch your workspace. + diff --git a/contracts/echo/examples/schema.rs b/contracts/echo/examples/schema.rs new file mode 100644 index 0000000..43acb89 --- /dev/null +++ b/contracts/echo/examples/schema.rs @@ -0,0 +1,20 @@ +use std::env::current_dir; +use std::fs::create_dir_all; + +use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; + +use echo::msg::{EchoResponse, ExecuteMsg, InstantiateMsg, QueryMsg}; +use echo::state::State; + +fn main() { + let mut out_dir = current_dir().unwrap(); + out_dir.push("schema"); + create_dir_all(&out_dir).unwrap(); + remove_schemas(&out_dir).unwrap(); + + export_schema(&schema_for!(InstantiateMsg), &out_dir); + export_schema(&schema_for!(ExecuteMsg), &out_dir); + export_schema(&schema_for!(QueryMsg), &out_dir); + export_schema(&schema_for!(State), &out_dir); + export_schema(&schema_for!(EchoResponse), &out_dir); +} diff --git a/contracts/echo/rustfmt.toml b/contracts/echo/rustfmt.toml new file mode 100644 index 0000000..11a85e6 --- /dev/null +++ b/contracts/echo/rustfmt.toml @@ -0,0 +1,15 @@ +# stable +newline_style = "unix" +hard_tabs = false +tab_spaces = 4 + +# unstable... should we require `rustup run nightly cargo fmt` ? +# or just update the style guide when they are stable? +#fn_single_line = true +#format_code_in_doc_comments = true +#overflow_delimited_expr = true +#reorder_impl_items = true +#struct_field_align_threshold = 20 +#struct_lit_single_line = true +#report_todo = "Always" + diff --git a/contracts/echo/schema/echo_response.json b/contracts/echo/schema/echo_response.json new file mode 100644 index 0000000..e34faea --- /dev/null +++ b/contracts/echo/schema/echo_response.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "EchoResponse", + "type": "object", + "required": [ + "echo" + ], + "properties": { + "echo": { + "type": "string" + } + } +} diff --git a/contracts/echo/schema/execute_msg.json b/contracts/echo/schema/execute_msg.json new file mode 100644 index 0000000..279e058 --- /dev/null +++ b/contracts/echo/schema/execute_msg.json @@ -0,0 +1,26 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "echo" + ], + "properties": { + "echo": { + "type": "object", + "required": [ + "echo" + ], + "properties": { + "echo": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/echo/schema/instantiate_msg.json b/contracts/echo/schema/instantiate_msg.json new file mode 100644 index 0000000..44588cf --- /dev/null +++ b/contracts/echo/schema/instantiate_msg.json @@ -0,0 +1,5 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object" +} diff --git a/contracts/echo/schema/query_msg.json b/contracts/echo/schema/query_msg.json new file mode 100644 index 0000000..cac8861 --- /dev/null +++ b/contracts/echo/schema/query_msg.json @@ -0,0 +1,18 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "echo" + ], + "properties": { + "echo": { + "type": "object" + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/echo/schema/state.json b/contracts/echo/schema/state.json new file mode 100644 index 0000000..1ece612 --- /dev/null +++ b/contracts/echo/schema/state.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "State", + "type": "object", + "required": [ + "echo" + ], + "properties": { + "echo": { + "type": "string" + } + } +} diff --git a/contracts/echo/src/error.rs b/contracts/echo/src/error.rs new file mode 100644 index 0000000..820bdbe --- /dev/null +++ b/contracts/echo/src/error.rs @@ -0,0 +1,11 @@ +use cosmwasm_std::StdError; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum ContractError { + #[error("{0}")] + Std(#[from] StdError), + + #[error("Custom Error val: {val:?}")] + CustomError { val: String }, +} diff --git a/contracts/echo/src/execute.rs b/contracts/echo/src/execute.rs new file mode 100644 index 0000000..7c7da89 --- /dev/null +++ b/contracts/echo/src/execute.rs @@ -0,0 +1,96 @@ +use std::ops::Add; + +#[cfg(not(feature = "library"))] +use cosmwasm_std::entry_point; +use cosmwasm_std::{DepsMut, Env, MessageInfo, Response}; + +use crate::error::ContractError; +use crate::msg::{InstantiateMsg, ExecuteMsg}; +use crate::state::{STATE, State}; + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn instantiate( + deps: DepsMut, + _env: Env, + _info: MessageInfo, + _msg: InstantiateMsg, +) -> Result { + let state = State { + echo: "".to_string() + }; + STATE.save(deps.storage, &state)?; + Ok(Response::new() + .add_attribute("action", "instantiate") + .add_attribute("echo", "") + ) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn execute( + deps: DepsMut, + _env: Env, + _info: MessageInfo, + msg: ExecuteMsg, +) -> Result { + match msg { + ExecuteMsg::Echo { echo } => execute_echo(deps, echo), + } +} + +fn execute_echo( + deps: DepsMut, + echo: String, +) -> Result { + STATE.update(deps.storage, |mut state| -> Result<_, ContractError> { + state.echo = echo.clone(); + Ok(state) + }).unwrap(); + Ok(Response::new() + .add_attribute("action", "execute_echo") + .add_attribute("echo", "received: ".to_string().add(echo.as_str())) + ) +} +#[cfg(test)] +mod tests { + use cosmwasm_std::{testing::{mock_dependencies, mock_env, mock_info}, coins, from_binary}; + + use crate::{msg::{InstantiateMsg, ExecuteMsg, QueryMsg, EchoResponse}, query::query}; + + use super::{instantiate, execute}; + + + #[test] + fn proper_initialization() { + let mut deps = mock_dependencies(); + let env = mock_env(); + let info = mock_info("sender", &coins(1000, "denom")); + let msg = InstantiateMsg{}; + let response = instantiate(deps.as_mut(), env, info, msg).unwrap(); + // assert response contains empty echo + let attribute = response.attributes.iter().find(|a| a.key == "echo").unwrap(); + assert_eq!("", attribute.value); + } + + #[test] + fn execute_echo() { + let mut deps = mock_dependencies(); + let env = mock_env(); + let info = mock_info("sender", &coins(1000, "denom")); + let msg = InstantiateMsg{}; + instantiate(deps.as_mut(), env, info.clone(), msg).unwrap(); + + let msg = ExecuteMsg::Echo { echo: "Hello, world!".to_string() }; + let response = execute(deps.as_mut(), mock_env(), info, msg).unwrap(); + // assert response contains hello world echo + let attribute = response.attributes.iter().find(|a| a.key == "echo").unwrap(); + assert_eq!("received: Hello, world!", attribute.value); + + // assert query + let msg = QueryMsg::Echo { }; + let response = query(deps.as_ref(), mock_env(), msg).unwrap(); + let echo_response: EchoResponse = from_binary(&response).unwrap(); + assert_eq!("Hello, world!", echo_response.echo); + + } + +} diff --git a/contracts/echo/src/helpers.rs b/contracts/echo/src/helpers.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/contracts/echo/src/helpers.rs @@ -0,0 +1 @@ + diff --git a/contracts/echo/src/lib.rs b/contracts/echo/src/lib.rs new file mode 100644 index 0000000..c345d92 --- /dev/null +++ b/contracts/echo/src/lib.rs @@ -0,0 +1,8 @@ +mod error; +pub mod execute; +pub mod helpers; +pub mod msg; +pub mod query; +pub mod state; + +pub use crate::error::ContractError; diff --git a/contracts/echo/src/msg.rs b/contracts/echo/src/msg.rs new file mode 100644 index 0000000..7c500d5 --- /dev/null +++ b/contracts/echo/src/msg.rs @@ -0,0 +1,29 @@ +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub struct InstantiateMsg { +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum ExecuteMsg { + Echo { echo: String }, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum QueryMsg { + Echo {}, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub struct EchoResponse { + pub echo: String, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum MigrateMsg {} diff --git a/contracts/echo/src/query.rs b/contracts/echo/src/query.rs new file mode 100644 index 0000000..d260b16 --- /dev/null +++ b/contracts/echo/src/query.rs @@ -0,0 +1,20 @@ +#[cfg(not(feature = "library"))] +use cosmwasm_std::entry_point; +use cosmwasm_std::{Binary, Deps, Env, StdResult, to_binary}; + +use crate::{msg::{QueryMsg, EchoResponse}, state::STATE}; + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { + match msg { + QueryMsg::Echo { } => to_binary(&query_echo(deps)) + } +} + +fn query_echo(deps: Deps) -> EchoResponse { + let state = STATE.load(deps.storage).unwrap(); + EchoResponse{echo: state.echo} +} + +#[cfg(test)] +mod tests {} diff --git a/contracts/echo/src/state.rs b/contracts/echo/src/state.rs new file mode 100644 index 0000000..872d128 --- /dev/null +++ b/contracts/echo/src/state.rs @@ -0,0 +1,12 @@ +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +use cw_storage_plus::Item; + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct State { + // stores last echo message + pub echo: String, +} + +pub const STATE: Item = Item::new("state"); diff --git a/contracts/ibc-controller/.cargo/config b/contracts/ibc-controller/.cargo/config new file mode 100644 index 0000000..336b618 --- /dev/null +++ b/contracts/ibc-controller/.cargo/config @@ -0,0 +1,4 @@ +[alias] +wasm = "build --release --target wasm32-unknown-unknown" +unit-test = "test --lib" +schema = "run --example schema" diff --git a/contracts/ibc-controller/.circleci/config.yml b/contracts/ibc-controller/.circleci/config.yml new file mode 100644 index 0000000..9b07669 --- /dev/null +++ b/contracts/ibc-controller/.circleci/config.yml @@ -0,0 +1,61 @@ +version: 2.1 + +executors: + builder: + docker: + - image: buildpack-deps:trusty + +jobs: + docker-image: + executor: builder + steps: + - checkout + - setup_remote_docker + docker_layer_caching: true + - run: + name: Build Docker artifact + command: docker build --pull -t "cosmwasm/cw-gitpod-base:${CIRCLE_SHA1}" . + - run: + name: Push application Docker image to docker hub + command: | + if [ "${CIRCLE_BRANCH}" = "master" ]; then + docker tag "cosmwasm/cw-gitpod-base:${CIRCLE_SHA1}" cosmwasm/cw-gitpod-base:latest + docker login --password-stdin -u "$DOCKER_USER" \<<<"$DOCKER_PASS" + docker push cosmwasm/cw-gitpod-base:latest + docker logout + fi + + docker-tagged: + executor: builder + steps: + - checkout + - setup_remote_docker + docker_layer_caching: true + - run: + name: Push application Docker image to docker hub + command: | + docker tag "cosmwasm/cw-gitpod-base:${CIRCLE_SHA1}" "cosmwasm/cw-gitpod-base:${CIRCLE_TAG}" + docker login --password-stdin -u "$DOCKER_USER" \<<<"$DOCKER_PASS" + docker push + docker logout + +workflows: + version: 2 + test-suite: + jobs: + # this is now a slow process... let's only run on master + - docker-image: + filters: + branches: + only: + - master + - docker-tagged: + filters: + tags: + only: + - /^v.*/ + branches: + ignore: + - /.*/ + requires: + - docker-image diff --git a/contracts/ibc-controller/.editorconfig b/contracts/ibc-controller/.editorconfig new file mode 100644 index 0000000..3d36f20 --- /dev/null +++ b/contracts/ibc-controller/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.rs] +indent_size = 4 diff --git a/contracts/ibc-controller/.github/workflows/Basic.yml b/contracts/ibc-controller/.github/workflows/Basic.yml new file mode 100644 index 0000000..0aa4193 --- /dev/null +++ b/contracts/ibc-controller/.github/workflows/Basic.yml @@ -0,0 +1,75 @@ +# Based on https://github.com/actions-rs/example/blob/master/.github/workflows/quickstart.yml + +on: [push, pull_request] + +name: Basic + +jobs: + + test: + name: Test Suite + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: 1.58.1 + target: wasm32-unknown-unknown + override: true + + - name: Run unit tests + uses: actions-rs/cargo@v1 + with: + command: unit-test + args: --locked + env: + RUST_BACKTRACE: 1 + + - name: Compile WASM contract + uses: actions-rs/cargo@v1 + with: + command: wasm + args: --locked + env: + RUSTFLAGS: "-C link-arg=-s" + + lints: + name: Lints + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: 1.58.1 + override: true + components: rustfmt, clippy + + - name: Run cargo fmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + - name: Run cargo clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings + + - name: Generate Schema + uses: actions-rs/cargo@v1 + with: + command: schema + args: --locked + + - name: Schema Changes + # fails if any changes not committed + run: git diff --exit-code schema diff --git a/contracts/ibc-controller/.gitignore b/contracts/ibc-controller/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/contracts/ibc-controller/Cargo.lock b/contracts/ibc-controller/Cargo.lock new file mode 100644 index 0000000..91fb09f --- /dev/null +++ b/contracts/ibc-controller/Cargo.lock @@ -0,0 +1,738 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" + +[[package]] +name = "base16ct" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "base64ct" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dea908e7347a8c64e378c17e30ef880ad73e3b4498346b055c2c00ea342f3179" + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-oid" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" + +[[package]] +name = "cosmwasm-crypto" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eb0afef2325df81aadbf9be1233f522ed8f6e91df870c764bc44cca2b1415bd" +dependencies = [ + "digest", + "ed25519-zebra", + "k256", + "rand_core 0.6.3", + "thiserror", +] + +[[package]] +name = "cosmwasm-derive" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b36e527620a2a3e00e46b6e731ab6c9b68d11069c986f7d7be8eba79ef081a4" +dependencies = [ + "syn", +] + +[[package]] +name = "cosmwasm-schema" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "772e80bbad231a47a2068812b723a1ff81dd4a0d56c9391ac748177bea3a61da" +dependencies = [ + "schemars", + "serde_json", +] + +[[package]] +name = "cosmwasm-std" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "875994993c2082a6fcd406937bf0fca21c349e4a624f3810253a14fa83a3a195" +dependencies = [ + "base64", + "cosmwasm-crypto", + "cosmwasm-derive", + "forward_ref", + "schemars", + "serde", + "serde-json-wasm", + "thiserror", + "uint", +] + +[[package]] +name = "cosmwasm-storage" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d18403b07304d15d304dad11040d45bbcaf78d603b4be3fb5e2685c16f9229b5" +dependencies = [ + "cosmwasm-std", + "serde", +] + +[[package]] +name = "cpufeatures" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" +dependencies = [ + "libc", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-bigint" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03c6a1d5fa1de37e071642dfa44ec552ca5b299adb128fab16138e24b548fd21" +dependencies = [ + "generic-array", + "rand_core 0.6.3", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-mac" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +dependencies = [ + "byteorder", + "digest", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "cw-multi-test" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbea57e5be4a682268a5eca1a57efece57a54ff216bfd87603d5e864aad40e12" +dependencies = [ + "anyhow", + "cosmwasm-std", + "cosmwasm-storage", + "cw-storage-plus", + "cw-utils", + "derivative", + "itertools", + "prost", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "cw-storage-plus" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9336ecef1e19d56cf6e3e932475fc6a3dee35eec5a386e07917a1d1ba6bb0e35" +dependencies = [ + "cosmwasm-std", + "schemars", + "serde", +] + +[[package]] +name = "cw-utils" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "babd2c090f39d07ce5bf2556962305e795daa048ce20a93709eb591476e4a29e" +dependencies = [ + "cosmwasm-std", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "cw2" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "993df11574f29574dd443eb0c189484bb91bc0638b6de3e32ab7f9319c92122d" +dependencies = [ + "cosmwasm-std", + "cw-storage-plus", + "schemars", + "serde", +] + +[[package]] +name = "der" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6919815d73839e7ad218de758883aae3a257ba6759ce7a9992501efbb53d705c" +dependencies = [ + "const-oid", +] + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "dyn-clone" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21e50f3adc76d6a43f5ed73b698a87d0760ca74617f60f7c3b879003536fdd28" + +[[package]] +name = "ecdsa" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0d69ae62e0ce582d56380743515fefaf1a8c70cec685d9677636d7e30ae9dc9" +dependencies = [ + "der", + "elliptic-curve", + "rfc6979", + "signature", +] + +[[package]] +name = "ed25519-zebra" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "403ef3e961ab98f0ba902771d29f842058578bb1ce7e3c59dad5a6a93e784c69" +dependencies = [ + "curve25519-dalek", + "hex", + "rand_core 0.6.3", + "serde", + "sha2", + "thiserror", + "zeroize", +] + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + +[[package]] +name = "elliptic-curve" +version = "0.11.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25b477563c2bfed38a3b7a60964c49e058b2510ad3f12ba3483fd8f62c2306d6" +dependencies = [ + "base16ct", + "crypto-bigint", + "der", + "ff", + "generic-array", + "group", + "rand_core 0.6.3", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "ff" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "131655483be284720a17d74ff97592b8e76576dc25563148601df2d7c9080924" +dependencies = [ + "rand_core 0.6.3", + "subtle", +] + +[[package]] +name = "forward_ref" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8cbd1169bd7b4a0a20d92b9af7a7e0422888bd38a6f5ec29c1fd8c1558a272e" + +[[package]] +name = "generic-array" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.10.2+wasi-snapshot-preview1", +] + +[[package]] +name = "group" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5ac374b108929de78460075f3dc439fa66df9d8fc77e8f12caa5165fcf0c89" +dependencies = [ + "ff", + "rand_core 0.6.3", + "subtle", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hmac" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" +dependencies = [ + "crypto-mac", + "digest", +] + +[[package]] +name = "itertools" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" + +[[package]] +name = "k256" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19c3a5e0a0b8450278feda242592512e09f61c72e018b8cd5c859482802daf2d" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "sec1", + "sha2", +] + +[[package]] +name = "libc" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "pkcs8" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cabda3fb821068a9a4fab19a683eac3af12edf0f34b94a8be53c4972b8149d0" +dependencies = [ + "der", + "spki", + "zeroize", +] + +[[package]] +name = "proc-macro2" +version = "1.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "prost" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "444879275cb4fd84958b1a1d5420d15e6fcf7c235fe47f053c9c2a80aceb6001" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9cc1a3263e07e0bf68e96268f37665207b49560d98739662cdfaae215c720fe" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "quote" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom 0.2.6", +] + +[[package]] +name = "rfc6979" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96ef608575f6392792f9ecf7890c00086591d29a83910939d430753f7c050525" +dependencies = [ + "crypto-bigint", + "hmac", + "zeroize", +] + +[[package]] +name = "ryu" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" + +[[package]] +name = "schemars" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d21ecb263bf75fc69d5e74b0f2a60b6dd80cfd9fb0eba15c4b9d1104ceffc77" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "219b924f5b39f25b7d7c9203873a2698fdac8db2b396aaea6fa099b699cc40e9" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn", +] + +[[package]] +name = "sec1" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08da66b8b0965a5555b6bd6639e68ccba85e1e2506f5fbb089e93f8a04e1a2d1" +dependencies = [ + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "serde" +version = "1.0.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-json-wasm" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479b4dbc401ca13ee8ce902851b834893251404c4f3c65370a49e047a6be09a5" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_derive_internals" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer", + "cfg-if", + "cpufeatures", + "digest", + "opaque-debug", +] + +[[package]] +name = "signature" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02658e48d89f2bec991f9a78e69cfa4c316f8d6a6c4ec12fae1aeb263d486788" +dependencies = [ + "digest", + "rand_core 0.6.3", +] + +[[package]] +name = "spki" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d01ac02a6ccf3e07db148d2be087da624fea0221a16152ed01f0496a6b0a27" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + +[[package]] +name = "syn" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "testgen-local" +version = "0.1.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cosmwasm-storage", + "cw-multi-test", + "cw-storage-plus", + "cw2", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "thiserror" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "typenum" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" + +[[package]] +name = "uint" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f03af7ccf01dd611cc450a0d10dbc9b745770d096473e2faf0ca6e2d66d1e0" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + +[[package]] +name = "unicode-ident" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "zeroize" +version = "1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94693807d016b2f2d2e14420eb3bfcca689311ff775dcf113d74ea624b7cdf07" diff --git a/contracts/ibc-controller/Cargo.toml b/contracts/ibc-controller/Cargo.toml new file mode 100644 index 0000000..8e82450 --- /dev/null +++ b/contracts/ibc-controller/Cargo.toml @@ -0,0 +1,51 @@ +# (c) Ark Protocol 2022 +# - ALL rights reserved. +# - No copies, disclosure or forward of all data or any info provided here or by the Ark Protocol team is allowed! +# - In case of any doubt contact Ark Protocol on Discord or Twitter. + +[package] +name = "ibc-controller" +version = "0.1.0" +authors = ["taitruong", "art3mix", "tottruong"] +edition = "2021" + +exclude = [ + # Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. + "contract.wasm", + "hash.txt", +] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +# for more explicit tests, cargo test --features=backtraces +backtraces = ["cosmwasm-std/backtraces"] +# use library feature to disable all instantiate/execute/query exports +library = [] + +[package.metadata.scripts] +optimize = """docker run --rm -v "$(pwd)":/code \ + --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ + --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ + cosmwasm/rust-optimizer:0.12.6 +""" + +[dependencies] +cosmwasm-std = "1.1.0" +cosmwasm-storage = "1.1.0" +cw-storage-plus = "0.15.0" +# cw2 = "0.14.0" +# cw721 = "0.13.4" +# cw721-base = "0.13.4" +schemars = "0.8.10" +serde = { version = "1.0.144", default-features = false, features = ["derive"] } +thiserror = { version = "1.0.34" } +echo = { path = "../echo", version = "0.1.0", features = ["library"]} +ibc-dispatcher = { path = "../ibc-dispatcher", version = "0.1.0", features = ["library"] } + +[dev-dependencies] +cosmwasm-schema = "1.1.0" +# cw-multi-test = "0.14.0" \ No newline at end of file diff --git a/contracts/ibc-controller/LICENSE b/contracts/ibc-controller/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/contracts/ibc-controller/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/contracts/ibc-controller/NOTICE b/contracts/ibc-controller/NOTICE new file mode 100644 index 0000000..7d47f5c --- /dev/null +++ b/contracts/ibc-controller/NOTICE @@ -0,0 +1,13 @@ +Copyright 2022 Tai 'Mr. T' Truong + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/contracts/ibc-controller/README.md b/contracts/ibc-controller/README.md new file mode 100644 index 0000000..954383a --- /dev/null +++ b/contracts/ibc-controller/README.md @@ -0,0 +1,106 @@ +# CosmWasm Starter Pack + +This is a template to build smart contracts in Rust to run inside a +[Cosmos SDK](https://github.com/cosmos/cosmos-sdk) module on all chains that enable it. +To understand the framework better, please read the overview in the +[cosmwasm repo](https://github.com/CosmWasm/cosmwasm/blob/master/README.md), +and dig into the [cosmwasm docs](https://www.cosmwasm.com). +This assumes you understand the theory and just want to get coding. + +## Creating a new repo from template + +Assuming you have a recent version of rust and cargo (v1.58.1+) installed +(via [rustup](https://rustup.rs/)), +then the following should get you a new repo to start a contract: + +Install [cargo-generate](https://github.com/ashleygwilliams/cargo-generate) and cargo-run-script. +Unless you did that before, run this line now: + +```sh +cargo install cargo-generate --features vendored-openssl +cargo install cargo-run-script +``` + +Now, use it to create your new contract. +Go to the folder in which you want to place it and run: + + +**Latest: 1.0.0-beta6** + +```sh +cargo generate --git https://github.com/CosmWasm/cw-template.git --name PROJECT_NAME +```` + +**Older Version** + +Pass version as branch flag: + +```sh +cargo generate --git https://github.com/CosmWasm/cw-template.git --branch --name PROJECT_NAME +```` + +Example: + +```sh +cargo generate --git https://github.com/CosmWasm/cw-template.git --branch 0.16 --name PROJECT_NAME +``` + +You will now have a new folder called `PROJECT_NAME` (I hope you changed that to something else) +containing a simple working contract and build system that you can customize. + +## Create a Repo + +After generating, you have a initialized local git repo, but no commits, and no remote. +Go to a server (eg. github) and create a new upstream repo (called `YOUR-GIT-URL` below). +Then run the following: + +```sh +# this is needed to create a valid Cargo.lock file (see below) +cargo check +git branch -M main +git add . +git commit -m 'Initial Commit' +git remote add origin YOUR-GIT-URL +git push -u origin main +``` + +## CI Support + +We have template configurations for both [GitHub Actions](.github/workflows/Basic.yml) +and [Circle CI](.circleci/config.yml) in the generated project, so you can +get up and running with CI right away. + +One note is that the CI runs all `cargo` commands +with `--locked` to ensure it uses the exact same versions as you have locally. This also means +you must have an up-to-date `Cargo.lock` file, which is not auto-generated. +The first time you set up the project (or after adding any dep), you should ensure the +`Cargo.lock` file is updated, so the CI will test properly. This can be done simply by +running `cargo check` or `cargo unit-test`. + +## Using your project + +Once you have your custom repo, you should check out [Developing](./Developing.md) to explain +more on how to run tests and develop code. Or go through the +[online tutorial](https://docs.cosmwasm.com/) to get a better feel +of how to develop. + +[Publishing](./Publishing.md) contains useful information on how to publish your contract +to the world, once you are ready to deploy it on a running blockchain. And +[Importing](./Importing.md) contains information about pulling in other contracts or crates +that have been published. + +Please replace this README file with information about your specific project. You can keep +the `Developing.md` and `Publishing.md` files as useful referenced, but please set some +proper description in the README. + +## Gitpod integration + +[Gitpod](https://www.gitpod.io/) container-based development platform will be enabled on your project by default. + +Workspace contains: + - **rust**: for builds + - [wasmd](https://github.com/CosmWasm/wasmd): for local node setup and client + - **jq**: shell JSON manipulation tool + +Follow [Gitpod Getting Started](https://www.gitpod.io/docs/getting-started) and launch your workspace. + diff --git a/contracts/ibc-controller/examples/schema.rs b/contracts/ibc-controller/examples/schema.rs new file mode 100644 index 0000000..4ecad23 --- /dev/null +++ b/contracts/ibc-controller/examples/schema.rs @@ -0,0 +1,20 @@ +use std::env::current_dir; +use std::fs::create_dir_all; + +use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; + +use ibc_controller::msg::{CustomResponse, ExecuteMsg, InstantiateMsg, QueryMsg}; +// use ibc_controller::state::State; + +fn main() { + let mut out_dir = current_dir().unwrap(); + out_dir.push("schema"); + create_dir_all(&out_dir).unwrap(); + remove_schemas(&out_dir).unwrap(); + + export_schema(&schema_for!(InstantiateMsg), &out_dir); + export_schema(&schema_for!(ExecuteMsg), &out_dir); + export_schema(&schema_for!(QueryMsg), &out_dir); + // export_schema(&schema_for!(State), &out_dir); + export_schema(&schema_for!(CustomResponse), &out_dir); +} diff --git a/contracts/ibc-controller/rustfmt.toml b/contracts/ibc-controller/rustfmt.toml new file mode 100644 index 0000000..11a85e6 --- /dev/null +++ b/contracts/ibc-controller/rustfmt.toml @@ -0,0 +1,15 @@ +# stable +newline_style = "unix" +hard_tabs = false +tab_spaces = 4 + +# unstable... should we require `rustup run nightly cargo fmt` ? +# or just update the style guide when they are stable? +#fn_single_line = true +#format_code_in_doc_comments = true +#overflow_delimited_expr = true +#reorder_impl_items = true +#struct_field_align_threshold = 20 +#struct_lit_single_line = true +#report_todo = "Always" + diff --git a/contracts/ibc-controller/schema/custom_response.json b/contracts/ibc-controller/schema/custom_response.json new file mode 100644 index 0000000..6194947 --- /dev/null +++ b/contracts/ibc-controller/schema/custom_response.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "CustomResponse", + "type": "object", + "required": [ + "val" + ], + "properties": { + "val": { + "type": "string" + } + } +} diff --git a/contracts/ibc-controller/schema/execute_msg.json b/contracts/ibc-controller/schema/execute_msg.json new file mode 100644 index 0000000..2aff480 --- /dev/null +++ b/contracts/ibc-controller/schema/execute_msg.json @@ -0,0 +1,38 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "dispatch" + ], + "properties": { + "dispatch": { + "type": "object", + "required": [ + "channel", + "dispatcher_address", + "echo", + "target_address" + ], + "properties": { + "channel": { + "type": "string" + }, + "dispatcher_address": { + "type": "string" + }, + "echo": { + "type": "string" + }, + "target_address": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/ibc-controller/schema/instantiate_msg.json b/contracts/ibc-controller/schema/instantiate_msg.json new file mode 100644 index 0000000..44588cf --- /dev/null +++ b/contracts/ibc-controller/schema/instantiate_msg.json @@ -0,0 +1,5 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object" +} diff --git a/contracts/ibc-controller/schema/query_msg.json b/contracts/ibc-controller/schema/query_msg.json new file mode 100644 index 0000000..ad509f7 --- /dev/null +++ b/contracts/ibc-controller/schema/query_msg.json @@ -0,0 +1,26 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "custom_msg" + ], + "properties": { + "custom_msg": { + "type": "object", + "required": [ + "val" + ], + "properties": { + "val": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/ibc-controller/src/error.rs b/contracts/ibc-controller/src/error.rs new file mode 100644 index 0000000..820bdbe --- /dev/null +++ b/contracts/ibc-controller/src/error.rs @@ -0,0 +1,11 @@ +use cosmwasm_std::StdError; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum ContractError { + #[error("{0}")] + Std(#[from] StdError), + + #[error("Custom Error val: {val:?}")] + CustomError { val: String }, +} diff --git a/contracts/ibc-controller/src/execute.rs b/contracts/ibc-controller/src/execute.rs new file mode 100644 index 0000000..45fab7f --- /dev/null +++ b/contracts/ibc-controller/src/execute.rs @@ -0,0 +1,67 @@ +use cosmwasm_std::entry_point; +use cosmwasm_std::{DepsMut, Env, MessageInfo, Response, SubMsg, WasmMsg, to_binary, Reply, StdResult, StdError}; +use ibc_dispatcher::msg::{ExecuteMsg as IbcDispatcherExecuteMsg}; +use echo::msg::{ExecuteMsg as EchoExecuteMsg}; + +use crate::error::ContractError; +use crate::msg::{InstantiateMsg, ExecuteMsg}; + +const REPLY_ID_MINT: u64 = 0; + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn instantiate( + _deps: DepsMut, + _env: Env, + _info: MessageInfo, + _msg: InstantiateMsg, +) -> Result { + Ok(Response::new() + .add_attribute("action", "instantiate") + ) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn execute( + _deps: DepsMut, + _env: Env, + _info: MessageInfo, + msg: ExecuteMsg, +) -> Result { + match msg { + ExecuteMsg::Dispatch { dispatcher_address, channel, target_address, echo } => execute_dispatch_local(dispatcher_address, channel, target_address, echo), + } +} + +fn execute_dispatch_local(dispatcher_address: String, channel: String, target_address: String, echo: String) -> Result { + let echo_execute_msg = EchoExecuteMsg::Echo { echo }; + let dispatch_msg = IbcDispatcherExecuteMsg::Dispatch { channel, target_address, msg: to_binary(&echo_execute_msg)? }; + let submessage = SubMsg::reply_on_success( + WasmMsg::Execute { + contract_addr: dispatcher_address.clone(), + msg: to_binary(&dispatch_msg)?, + funds: vec![], + }, REPLY_ID_MINT); + Ok(Response::new() + .add_attribute("action", "execute_controller") + .add_attribute("ibc-contract", dispatcher_address) + .add_submessage(submessage) + ) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> StdResult { + match msg.id { + REPLY_ID_MINT => handle_target_contract_reply(deps, msg), + id => Err(StdError::generic_err(format!("Unknown reply id: {}", id))), + } +} + +fn handle_target_contract_reply(_deps: DepsMut, _msg: Reply) -> StdResult { + //let sub_msg_response = msg.result.unwrap(); + Ok(Response::new() + .add_attribute("action", "handle_target_contract_reply") + ) +} + +#[cfg(test)] +mod tests {} diff --git a/contracts/ibc-controller/src/helpers.rs b/contracts/ibc-controller/src/helpers.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/contracts/ibc-controller/src/helpers.rs @@ -0,0 +1 @@ + diff --git a/contracts/ibc-controller/src/lib.rs b/contracts/ibc-controller/src/lib.rs new file mode 100644 index 0000000..c345d92 --- /dev/null +++ b/contracts/ibc-controller/src/lib.rs @@ -0,0 +1,8 @@ +mod error; +pub mod execute; +pub mod helpers; +pub mod msg; +pub mod query; +pub mod state; + +pub use crate::error::ContractError; diff --git a/contracts/ibc-controller/src/msg.rs b/contracts/ibc-controller/src/msg.rs new file mode 100644 index 0000000..dc034b3 --- /dev/null +++ b/contracts/ibc-controller/src/msg.rs @@ -0,0 +1,29 @@ +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub struct InstantiateMsg { +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum ExecuteMsg { + Dispatch {dispatcher_address: String, channel: String, target_address: String, echo: String}, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum QueryMsg { + CustomMsg { val: String }, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub struct CustomResponse { + val: String, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum MigrateMsg {} diff --git a/contracts/ibc-controller/src/query.rs b/contracts/ibc-controller/src/query.rs new file mode 100644 index 0000000..037e1a6 --- /dev/null +++ b/contracts/ibc-controller/src/query.rs @@ -0,0 +1,13 @@ +#[cfg(not(feature = "library"))] +use cosmwasm_std::entry_point; +use cosmwasm_std::{Binary, Deps, Env, StdResult}; + +use crate::msg::QueryMsg; + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn query(_deps: Deps, _env: Env, _msg: QueryMsg) -> StdResult { + unimplemented!() +} + +#[cfg(test)] +mod tests {} diff --git a/contracts/ibc-controller/src/state.rs b/contracts/ibc-controller/src/state.rs new file mode 100644 index 0000000..645eaac --- /dev/null +++ b/contracts/ibc-controller/src/state.rs @@ -0,0 +1,11 @@ +// use schemars::JsonSchema; +// use serde::{Deserialize, Serialize}; + +// use cw_storage_plus::Item; + +// #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +// pub struct State { +// pub ibc_contract: String, +// } + +// pub const STATE: Item = Item::new("state"); diff --git a/contracts/ibc-dispatcher/Cargo.toml b/contracts/ibc-dispatcher/Cargo.toml index bfc7ec5..3f9e5e2 100644 --- a/contracts/ibc-dispatcher/Cargo.toml +++ b/contracts/ibc-dispatcher/Cargo.toml @@ -31,12 +31,12 @@ optimize = """docker run --rm -v "$(pwd)":/code \ [dependencies] cosmwasm-std = { version = "1.0.0", features = ["stargate"] } cosmwasm-storage = "1.0.0" -cw-storage-plus = "0.14.0" -cw2 = "0.14.0" +cw-storage-plus = "0.15.0" +cw2 = "0.15.0" schemars = "0.8.8" serde = { version = "1.0.137", default-features = false, features = ["derive"] } thiserror = { version = "1.0.31" } [dev-dependencies] cosmwasm-schema = "1.0.0" -cw-multi-test = "0.14.0" +cw-multi-test = "0.15.0" diff --git a/contracts/ibc-dispatcher/examples/schema.rs b/contracts/ibc-dispatcher/examples/schema.rs index 8bcd362..86bda1f 100644 --- a/contracts/ibc-dispatcher/examples/schema.rs +++ b/contracts/ibc-dispatcher/examples/schema.rs @@ -4,8 +4,8 @@ use std::fs::create_dir_all; use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; use ibc_dispatcher::{ - ibc_msg::{IbcExecuteMsg, IbcPingResponse}, - msg::{ExecuteMsg, GetConnectionsResponse, GetCounterResponse, InstantiateMsg, QueryMsg}, + ibc_msg::IbcExecuteMsg, + msg::{ExecuteMsg, GetConnectionsResponse, InstantiateMsg, QueryMsg}, }; fn main() { @@ -18,7 +18,5 @@ fn main() { export_schema(&schema_for!(ExecuteMsg), &out_dir); export_schema(&schema_for!(QueryMsg), &out_dir); export_schema(&schema_for!(IbcExecuteMsg), &out_dir); - export_schema(&schema_for!(IbcPingResponse), &out_dir); export_schema(&schema_for!(GetConnectionsResponse), &out_dir); - export_schema(&schema_for!(GetCounterResponse), &out_dir); } diff --git a/contracts/ibc-dispatcher/schema/execute_msg.json b/contracts/ibc-dispatcher/schema/execute_msg.json new file mode 100644 index 0000000..cb47368 --- /dev/null +++ b/contracts/ibc-dispatcher/schema/execute_msg.json @@ -0,0 +1,40 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "ExecuteMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "dispatch" + ], + "properties": { + "dispatch": { + "type": "object", + "required": [ + "channel", + "msg", + "target_address" + ], + "properties": { + "channel": { + "type": "string" + }, + "msg": { + "$ref": "#/definitions/Binary" + }, + "target_address": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ], + "definitions": { + "Binary": { + "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec", + "type": "string" + } + } +} diff --git a/contracts/ibc-dispatcher/schema/get_connections_response.json b/contracts/ibc-dispatcher/schema/get_connections_response.json new file mode 100644 index 0000000..7c3d6e4 --- /dev/null +++ b/contracts/ibc-dispatcher/schema/get_connections_response.json @@ -0,0 +1,16 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "GetConnectionsResponse", + "type": "object", + "required": [ + "connections" + ], + "properties": { + "connections": { + "type": "array", + "items": { + "type": "string" + } + } + } +} diff --git a/contracts/ibc-dispatcher/schema/ibc_execute_msg.json b/contracts/ibc-dispatcher/schema/ibc_execute_msg.json new file mode 100644 index 0000000..9cb0f9a --- /dev/null +++ b/contracts/ibc-dispatcher/schema/ibc_execute_msg.json @@ -0,0 +1,37 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "IbcExecuteMsg", + "oneOf": [ + { + "description": "Dispatch msg to target contract.", + "type": "object", + "required": [ + "dispatch" + ], + "properties": { + "dispatch": { + "type": "object", + "required": [ + "msg", + "target_address" + ], + "properties": { + "msg": { + "$ref": "#/definitions/Binary" + }, + "target_address": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ], + "definitions": { + "Binary": { + "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec", + "type": "string" + } + } +} diff --git a/contracts/ibc-dispatcher/schema/instantiate_msg.json b/contracts/ibc-dispatcher/schema/instantiate_msg.json new file mode 100644 index 0000000..44588cf --- /dev/null +++ b/contracts/ibc-dispatcher/schema/instantiate_msg.json @@ -0,0 +1,5 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object" +} diff --git a/contracts/ibc-dispatcher/schema/query_msg.json b/contracts/ibc-dispatcher/schema/query_msg.json new file mode 100644 index 0000000..524b3bd --- /dev/null +++ b/contracts/ibc-dispatcher/schema/query_msg.json @@ -0,0 +1,18 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "QueryMsg", + "oneOf": [ + { + "type": "object", + "required": [ + "get_connections" + ], + "properties": { + "get_connections": { + "type": "object" + } + }, + "additionalProperties": false + } + ] +} diff --git a/contracts/ibc-dispatcher/src/contract.rs b/contracts/ibc-dispatcher/src/contract.rs index 9406df0..0c41d78 100644 --- a/contracts/ibc-dispatcher/src/contract.rs +++ b/contracts/ibc-dispatcher/src/contract.rs @@ -1,16 +1,13 @@ -#[cfg(not(feature = "library"))] -use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Env, IbcMsg, IbcTimeout, MessageInfo, Order, Response, - StdResult, + entry_point, to_binary, Binary, Deps, DepsMut, Env, IbcMsg, IbcTimeout, MessageInfo, Order, Response,StdResult, }; use cw2::set_contract_version; use crate::{ error::ContractError, ibc_msg::IbcExecuteMsg, - msg::{ExecuteMsg, GetConnectionsResponse, GetCounterResponse, InstantiateMsg, QueryMsg}, - state::{CONNECTIONS, COUNTERS}, + msg::{ExecuteMsg, GetConnectionsResponse, InstantiateMsg, QueryMsg}, + state::CONNECTIONS, }; const CONTRACT_NAME: &str = "crates.io:ap-ibc-dispatcher"; @@ -27,6 +24,7 @@ pub fn instantiate( Ok(Response::new().add_attribute("method", "instantiate")) } +/// Receives msg in source chain to be dispatched on target chain. #[cfg_attr(not(feature = "library"), entry_point)] pub fn execute( _deps: DepsMut, @@ -35,28 +33,40 @@ pub fn execute( msg: ExecuteMsg, ) -> Result { match msg { - ExecuteMsg::Ping { channel } => ping(env, channel), + ExecuteMsg::Dispatch { + msg, + channel, + target_address, + } => execute_dispatch_remote(env, msg, channel, target_address), } } -fn ping(env: Env, channel: String) -> Result { - let msg = IbcMsg::SendPacket { +/// Dispatch via channel to target chain by sending an IBC message. +fn execute_dispatch_remote( + env: Env, + msg: Binary, + channel: String, + target_address: String, +) -> Result { + let packet_msg = IbcMsg::SendPacket { channel_id: channel.clone(), - data: to_binary(&IbcExecuteMsg::Ping {})?, + data: to_binary(&IbcExecuteMsg::Dispatch { + msg, + target_address, + })?, timeout: IbcTimeout::with_timestamp(env.block.time.plus_seconds(300)), }; Ok(Response::new() - .add_attribute("method", "execute_ping") + .add_attribute("method", "execute_dispatch_remote") .add_attribute("channel", channel) - .add_message(msg)) + .add_message(packet_msg)) } #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { QueryMsg::GetConnections {} => to_binary(&query_connections(deps)?), - QueryMsg::GetCounter { channel } => to_binary(&query_counter(deps, channel)?), } } @@ -67,12 +77,3 @@ fn query_connections(deps: Deps) -> StdResult { .collect(); Ok(GetConnectionsResponse { connections }) } - -fn query_counter(deps: Deps, channel: String) -> StdResult { - let count = COUNTERS - .may_load(deps.storage, &channel) - .unwrap_or(Some(0)) - .unwrap_or(0); - - Ok(GetCounterResponse { count }) -} diff --git a/contracts/ibc-dispatcher/src/ibc.rs b/contracts/ibc-dispatcher/src/ibc.rs index 05beffd..b534261 100644 --- a/contracts/ibc-dispatcher/src/ibc.rs +++ b/contracts/ibc-dispatcher/src/ibc.rs @@ -5,10 +5,7 @@ use cosmwasm_std::{ IbcChannelOpenMsg, IbcOrder, IbcPacketTimeoutMsg, }; -use crate::{ - state::{CONNECTIONS, COUNTERS}, - ContractError, -}; +use crate::{state::CONNECTIONS, ContractError}; pub const IBC_VERSION: &str = "ping-1"; pub const IBC_ORDER: IbcOrder = IbcOrder::Unordered; @@ -34,7 +31,6 @@ pub fn ibc_channel_connect( // Initialize the count for this channel to zero. let channel = msg.channel().endpoint.channel_id.clone(); CONNECTIONS.save(deps.storage, &channel, &true)?; - COUNTERS.save(deps.storage, &channel, &0)?; Ok(IbcBasicResponse::new() .add_attribute("method", "ibc_channel_connect") diff --git a/contracts/ibc-dispatcher/src/ibc_ack.rs b/contracts/ibc-dispatcher/src/ibc_ack.rs index cfa791e..d2c52f4 100644 --- a/contracts/ibc-dispatcher/src/ibc_ack.rs +++ b/contracts/ibc-dispatcher/src/ibc_ack.rs @@ -1,66 +1,16 @@ -use cosmwasm_std::{entry_point, StdResult}; -use cosmwasm_std::{from_slice, DepsMut, Env, IbcBasicResponse, IbcPacketAckMsg}; +use cosmwasm_std::{entry_point, DepsMut, Env, IbcBasicResponse, IbcPacketAckMsg}; -use crate::{ - ack::Ack, - ibc_msg::{IbcExecuteMsg, IbcPingResponse}, - state::COUNTERS, - ContractError, -}; +use crate::ContractError; #[cfg_attr(not(feature = "library"), entry_point)] pub fn ibc_packet_ack( - deps: DepsMut, - env: Env, - ack: IbcPacketAckMsg, + _deps: DepsMut, + _env: Env, + _ack: IbcPacketAckMsg, ) -> Result { // This will get the ack from the ibc packet we sent, // you either do pending things that you waited for confirmation on // or register something based on the confirmation - // which local channel was this packet send from - let caller = ack.original_packet.src.channel_id.clone(); - // we need to parse the ack based on our request - let original_packet: IbcExecuteMsg = from_slice(&ack.original_packet.data)?; - let res: Ack = from_slice(&ack.acknowledgement.data)?; - - match original_packet { - IbcExecuteMsg::Ping {} => ack_ping(deps, env, caller, res), - } -} - -pub fn ack_ping( - deps: DepsMut, - _env: Env, - caller: String, - res: Ack, -) -> Result { - //Get the result from the ack, and make sure ack is success. - let IbcPingResponse { result } = match res { - Ack::Result(res) => from_slice(&res)?, - Ack::Error(e) => { - return Ok(IbcBasicResponse::new() - .add_attribute("action", "ack_ping") - .add_attribute("error", e)) - } - }; - - //Match the result to what we expect, if its a pong, save a counter. - match result.as_str() { - "pong" => { - COUNTERS.update(deps.storage, &caller, |counter| -> StdResult { - match counter { - Some(count) => Ok(count + 1), - None => Ok(1), - } - })?; - - Ok(IbcBasicResponse::new().add_attribute("action", "ack_ping")) - } - r => { - return Ok(IbcBasicResponse::new() - .add_attribute("action", "ack_ping") - .add_attribute("error", format!("Not pong, Result is: {}", r))) - } - } + Ok(IbcBasicResponse::new()) } diff --git a/contracts/ibc-dispatcher/src/ibc_msg.rs b/contracts/ibc-dispatcher/src/ibc_msg.rs index 51eabb7..c44b898 100644 --- a/contracts/ibc-dispatcher/src/ibc_msg.rs +++ b/contracts/ibc-dispatcher/src/ibc_msg.rs @@ -1,13 +1,10 @@ +use cosmwasm_std::Binary; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum IbcExecuteMsg { - Ping {}, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -pub struct IbcPingResponse { - pub result: String, + /// Dispatch msg to target contract. + Dispatch { target_address: String, msg: Binary }, } diff --git a/contracts/ibc-dispatcher/src/ibc_receive.rs b/contracts/ibc-dispatcher/src/ibc_receive.rs index 44a660e..5428bbe 100644 --- a/contracts/ibc-dispatcher/src/ibc_receive.rs +++ b/contracts/ibc-dispatcher/src/ibc_receive.rs @@ -1,13 +1,11 @@ -use cosmwasm_std::entry_point; -use cosmwasm_std::{from_binary, DepsMut, Env, IbcPacketReceiveMsg, IbcReceiveResponse}; +use cosmwasm_std::{entry_point, Binary, SubMsg, WasmMsg, Reply, StdResult, Response, StdError}; +use cosmwasm_std::{from_binary, to_binary, DepsMut, Env, IbcPacketReceiveMsg, IbcReceiveResponse}; -use crate::{ - ack::Ack, - error::Never, - ibc_msg::{IbcExecuteMsg, IbcPingResponse}, - ContractError, -}; +use crate::{ack::Ack, error::Never, ibc_msg::IbcExecuteMsg, ContractError}; +const REPLY_ID_DISPATCH: u64 = 1; + +/// Receives incoming IBC message from source cain and dispatches to contract in this target chain. #[cfg_attr(not(feature = "library"), entry_point)] pub fn ibc_packet_receive( deps: DepsMut, @@ -31,19 +29,53 @@ pub fn do_ibc_packet_receive( _env: Env, msg: IbcPacketReceiveMsg, ) -> Result { - // The channel this packet is being relayed along on this chain. - //let channel = msg.packet.dest.channel_id; + // The channel this packet is being relayed along on this target chain. let msg: IbcExecuteMsg = from_binary(&msg.packet.data)?; match msg { - IbcExecuteMsg::Ping {} => receive_ping(deps), + IbcExecuteMsg::Dispatch { + msg, + target_address, + } => dispatch_target_contract(deps, target_address, msg), } } -pub fn receive_ping(_deps: DepsMut) -> Result { +pub fn dispatch_target_contract( + _deps: DepsMut, + contract_addr: String, + msg: Binary, +) -> Result { + let msg = SubMsg::reply_on_success( + WasmMsg::Execute { + contract_addr, + msg, + funds: vec![], + }, + REPLY_ID_DISPATCH, + ); + // dispatch via sub message, no set_ack() needed since this is handled by reply (response.set_data() will be used as ack) Ok(IbcReceiveResponse::new() - .add_attribute("method", "execute_ping") - .set_ack(Ack::success_data(IbcPingResponse { - result: "pong".to_string(), - }))) + .add_attribute("method", "dispatch_target_contract") + .add_submessage(msg)) +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> StdResult { + match msg.id { + REPLY_ID_DISPATCH => handle_target_contract_reply(deps, msg), + id => Err(StdError::generic_err(format!("Unknown reply id: {}", id))), + } +} + +fn handle_target_contract_reply(_deps: DepsMut, msg: Reply) -> StdResult { + // match reply.result { + // SubMsgResult::OK(response) => Ok(Response::new().set_data(response)), + // SubMsgResult::Error(error) => E + // } + + let sub_msg_result = to_binary(&msg.result).unwrap(); + Ok(Response::new() + .add_attribute("action", "handle_target_contract_reply") + // set data will be handle as ack + .set_data(sub_msg_result)) } diff --git a/contracts/ibc-dispatcher/src/msg.rs b/contracts/ibc-dispatcher/src/msg.rs index fdbf8ac..957a129 100644 --- a/contracts/ibc-dispatcher/src/msg.rs +++ b/contracts/ibc-dispatcher/src/msg.rs @@ -1,3 +1,4 @@ +use cosmwasm_std::Binary; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -7,7 +8,14 @@ pub struct InstantiateMsg {} #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum ExecuteMsg { - Ping { channel: String }, + Dispatch { + // channel pointing to chain where dispatcher contract is located + channel: String, + // contract on other chain + target_address: String, + // the message being dispatch on other contract + msg: Binary, + }, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] @@ -15,7 +23,6 @@ pub enum ExecuteMsg { pub enum QueryMsg { // GetCount returns the current count as a json-encoded number GetConnections {}, - GetCounter { channel: String }, } // We define a custom struct for each query response @@ -23,8 +30,3 @@ pub enum QueryMsg { pub struct GetConnectionsResponse { pub connections: Vec, } - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -pub struct GetCounterResponse { - pub count: u32, -} diff --git a/contracts/ibc-dispatcher/src/state.rs b/contracts/ibc-dispatcher/src/state.rs index 5f90f20..7459972 100644 --- a/contracts/ibc-dispatcher/src/state.rs +++ b/contracts/ibc-dispatcher/src/state.rs @@ -2,4 +2,3 @@ use cw_storage_plus::Map; // Mapping between connections and the counter on that connection. pub const CONNECTIONS: Map<&str, bool> = Map::new("connections"); -pub const COUNTERS: Map<&str, u32> = Map::new("counters"); diff --git a/contracts/ibc-dispatcher/src/tests.rs b/contracts/ibc-dispatcher/src/tests.rs index 42cfdde..e9a74a4 100644 --- a/contracts/ibc-dispatcher/src/tests.rs +++ b/contracts/ibc-dispatcher/src/tests.rs @@ -2,261 +2,260 @@ #[cfg(test)] mod tests { - use crate::ack::Ack; - use crate::contract::{execute, instantiate, query}; - use crate::ibc::{ - ibc_channel_close, ibc_channel_connect, ibc_channel_open, IBC_ORDER, IBC_VERSION, - }; - use crate::ibc_ack::ibc_packet_ack; - use crate::ibc_msg::IbcPingResponse; - use crate::msg::GetCounterResponse; - use crate::{ - ibc_msg::IbcExecuteMsg, - ibc_receive::ibc_packet_receive, - msg::{ExecuteMsg, GetConnectionsResponse, InstantiateMsg, QueryMsg}, - }; - - use cosmwasm_std::testing::{ - mock_dependencies, mock_env, mock_ibc_channel_close_init, mock_ibc_channel_connect_ack, - mock_ibc_channel_open_init, mock_ibc_channel_open_try, mock_ibc_packet_ack, - mock_ibc_packet_recv, mock_info, MockApi, MockQuerier, MockStorage, - }; - use cosmwasm_std::{ - from_binary, to_binary, Attribute, CosmosMsg, DepsMut, IbcAcknowledgement, IbcMsg, - IbcOrder, IbcTimeout, MessageInfo, OwnedDeps, Response, - }; - - const CREATER_ADDR: &str = "creater"; - const TEST_CHANNEL: &str = "channel-1"; - - pub const BAD_IBC_ORDER: IbcOrder = IbcOrder::Ordered; - - //Quick init of the contract - fn setup( - info: Option, - msg: Option, - ) -> ( - OwnedDeps, - Response, - MessageInfo, - ) { - let mut deps = mock_dependencies(); - - let info = match info { - Some(info) => info, - None => mock_info(CREATER_ADDR, &[]), - }; - - let msg = match msg { - Some(msg) => msg, - None => InstantiateMsg {}, - }; - - let res = instantiate(deps.as_mut(), mock_env(), info.clone(), msg).unwrap(); - - (deps, res, info) - } - - //If you do anything on init for the IBC to work, doesn't require to call this function if your contract doesn't rely on IBC connection to happen. - fn connect(mut deps: DepsMut, channel_id: &str) { - let handshake_open = mock_ibc_channel_open_init(channel_id, IBC_ORDER, IBC_VERSION); - // first we try to open with a valid handshake - ibc_channel_open(deps.branch(), mock_env(), handshake_open).unwrap(); - - // then we connect (with counter-party version set) - let handshake_connect = mock_ibc_channel_connect_ack(channel_id, IBC_ORDER, IBC_VERSION); - let res = ibc_channel_connect(deps.branch(), mock_env(), handshake_connect).unwrap(); - - assert_eq!(0, res.messages.len()); - } - - #[test] - fn proper_initialization() { - let (mut _deps, res, _info) = setup(None, None); - - assert_eq!(0, res.messages.len()); - assert_eq!( - res.attributes, - vec![Attribute { - key: "method".to_string(), - value: "instantiate".to_string() - },] - ); - } - - #[test] - fn enforce_version_in_handshake() { - let (mut deps, _res, _info) = setup(None, None); - - let wrong_order = mock_ibc_channel_open_try(TEST_CHANNEL, BAD_IBC_ORDER, IBC_VERSION); - ibc_channel_open(deps.as_mut(), mock_env(), wrong_order).unwrap_err(); - - let wrong_version = mock_ibc_channel_open_try(TEST_CHANNEL, IBC_ORDER, "wrong_version"); - ibc_channel_open(deps.as_mut(), mock_env(), wrong_version).unwrap_err(); - - let valid_handshake = mock_ibc_channel_open_try(TEST_CHANNEL, IBC_ORDER, IBC_VERSION); - ibc_channel_open(deps.as_mut(), mock_env(), valid_handshake).unwrap(); - } - - #[test] - fn proper_handshake_flow() { - let (mut deps, _res, _info) = setup(None, None); - - let handshake_open = mock_ibc_channel_open_init(TEST_CHANNEL, IBC_ORDER, IBC_VERSION); - ibc_channel_open(deps.as_mut(), mock_env(), handshake_open).unwrap(); - - // then we connect (with counter-party version set) - let handshake_connect = mock_ibc_channel_connect_ack(TEST_CHANNEL, IBC_ORDER, IBC_VERSION); - let res = ibc_channel_connect(deps.as_mut(), mock_env(), handshake_connect).unwrap(); - - assert_eq!(res.messages, vec![]); - assert_eq!( - res.attributes, - vec![ - Attribute { - key: "method".to_string(), - value: "ibc_channel_connect".to_string() - }, - Attribute { - key: "channel_id".to_string(), - value: TEST_CHANNEL.to_string() - } - ] - ); - - //We should have 1 item (test_channel) in the connections. - let raw = query(deps.as_ref(), mock_env(), QueryMsg::GetConnections {}).unwrap(); - let res: GetConnectionsResponse = from_binary(&raw).unwrap(); - - assert_eq!(1, res.connections.len()); - assert_eq!(TEST_CHANNEL, res.connections[0]); - } - - #[test] - fn execute_ping() { - let (mut deps, _res, info) = setup(None, None); - - connect(deps.as_mut(), TEST_CHANNEL); - - let msg = ExecuteMsg::Ping { - channel: TEST_CHANNEL.to_string(), - }; - let res = execute(deps.as_mut(), mock_env(), info, msg).unwrap(); - - //verify attributes are correct. - assert_eq!( - res.attributes, - vec![ - Attribute { - key: "method".to_string(), - value: "execute_ping".to_string() - }, - Attribute { - key: "channel".to_string(), - value: TEST_CHANNEL.to_string() - }, - ] - ); - - //Verify sent IbcPacket is correct - assert_eq!( - res.messages[0].msg, - CosmosMsg::Ibc(IbcMsg::SendPacket { - channel_id: TEST_CHANNEL.to_string(), - data: to_binary(&IbcExecuteMsg::Ping {}).unwrap(), - timeout: IbcTimeout::with_timestamp(mock_env().block.time.plus_seconds(300)) - }) - ); - - // Verify we received the ping, and answered correctly. - let ibc_msg = IbcExecuteMsg::Ping {}; - - let msg = mock_ibc_packet_recv(TEST_CHANNEL, &ibc_msg).unwrap(); - let res = ibc_packet_receive(deps.as_mut(), mock_env(), msg).unwrap(); - - //Verify we got the result attr, pong. - assert_eq!( - res.attributes, - vec![Attribute { - key: "method".to_string(), - value: "execute_ping".to_string() - },] - ); - - let ack: IbcPingResponse = Ack::parse(res.acknowledgement.clone()); - - assert_eq!(ack.result.as_str(), "pong"); - - //Verify we do the ack correctly. - let ack = mock_ibc_packet_ack( - TEST_CHANNEL, - &ibc_msg, - IbcAcknowledgement::new(res.acknowledgement), - ) - .unwrap(); - let res = ibc_packet_ack(deps.as_mut(), mock_env(), ack).unwrap(); - - assert_eq!( - res.attributes, - vec![Attribute { - key: "action".to_string(), - value: "ack_ping".to_string() - },] - ); - - //Verify that after the ack, our counter is 1 and not 0 - let msg = QueryMsg::GetCounter { - channel: TEST_CHANNEL.to_string(), - }; - let res = query(deps.as_ref(), mock_env(), msg).unwrap(); - let value: GetCounterResponse = from_binary(&res).unwrap(); - - assert_eq!(value.count, 1); - - //Do custom query - let msg = QueryMsg::GetConnections {}; - let res = query(deps.as_ref(), mock_env(), msg).unwrap(); - let value: GetConnectionsResponse = from_binary(&res).unwrap(); - - assert_eq!(value.connections, vec![TEST_CHANNEL.to_string()]); - } - - #[test] - fn close_channel() { - let (mut deps, _res, _info) = setup(None, None); - - connect(deps.as_mut(), TEST_CHANNEL); - - let msg = QueryMsg::GetConnections {}; - let res = query(deps.as_ref(), mock_env(), msg).unwrap(); - let value: GetConnectionsResponse = from_binary(&res).unwrap(); - - assert_eq!( - value, - GetConnectionsResponse { - connections: vec![TEST_CHANNEL.to_string()] - } - ); - - let channel = mock_ibc_channel_close_init(TEST_CHANNEL, IBC_ORDER, IBC_VERSION); - let res = ibc_channel_close(deps.as_mut(), mock_env(), channel).unwrap(); - - //Check no messages - assert_eq!(0, res.messages.len()); - - //Verify attributes - assert_eq!( - res.attributes, - vec![ - Attribute { - key: "method".to_string(), - value: "ibc_channel_close".to_string() - }, - Attribute { - key: "channel".to_string(), - value: TEST_CHANNEL.to_string() - }, - ] - ); - } + // use crate::ack::Ack; + // use crate::contract::{execute, instantiate, query}; + // use crate::ibc::{ + // ibc_channel_close, ibc_channel_connect, ibc_channel_open, IBC_ORDER, IBC_VERSION, + // }; + // use crate::ibc_ack::ibc_packet_ack; + // use crate::msg::GetCounterResponse; + // use crate::{ + // ibc_msg::IbcExecuteMsg, + // ibc_receive::ibc_packet_receive, + // msg::{ExecuteMsg, GetConnectionsResponse, InstantiateMsg, QueryMsg}, + // }; + + // use cosmwasm_std::testing::{ + // mock_dependencies, mock_env, mock_ibc_channel_close_init, mock_ibc_channel_connect_ack, + // mock_ibc_channel_open_init, mock_ibc_channel_open_try, mock_ibc_packet_ack, + // mock_ibc_packet_recv, mock_info, MockApi, MockQuerier, MockStorage, + // }; + // use cosmwasm_std::{ + // from_binary, to_binary, Attribute, CosmosMsg, DepsMut, IbcAcknowledgement, IbcMsg, + // IbcOrder, IbcTimeout, MessageInfo, OwnedDeps, Response, + // }; + + // const CREATER_ADDR: &str = "creater"; + // const TEST_CHANNEL: &str = "channel-1"; + + // pub const BAD_IBC_ORDER: IbcOrder = IbcOrder::Ordered; + + // //Quick init of the contract + // fn setup( + // info: Option, + // msg: Option, + // ) -> ( + // OwnedDeps, + // Response, + // MessageInfo, + // ) { + // let mut deps = mock_dependencies(); + + // let info = match info { + // Some(info) => info, + // None => mock_info(CREATER_ADDR, &[]), + // }; + + // let msg = match msg { + // Some(msg) => msg, + // None => InstantiateMsg {}, + // }; + + // let res = instantiate(deps.as_mut(), mock_env(), info.clone(), msg).unwrap(); + + // (deps, res, info) + // } + + // //If you do anything on init for the IBC to work, doesn't require to call this function if your contract doesn't rely on IBC connection to happen. + // fn connect(mut deps: DepsMut, channel_id: &str) { + // let handshake_open = mock_ibc_channel_open_init(channel_id, IBC_ORDER, IBC_VERSION); + // // first we try to open with a valid handshake + // ibc_channel_open(deps.branch(), mock_env(), handshake_open).unwrap(); + + // // then we connect (with counter-party version set) + // let handshake_connect = mock_ibc_channel_connect_ack(channel_id, IBC_ORDER, IBC_VERSION); + // let res = ibc_channel_connect(deps.branch(), mock_env(), handshake_connect).unwrap(); + + // assert_eq!(0, res.messages.len()); + // } + + // #[test] + // fn proper_initialization() { + // let (mut _deps, res, _info) = setup(None, None); + + // assert_eq!(0, res.messages.len()); + // assert_eq!( + // res.attributes, + // vec![Attribute { + // key: "method".to_string(), + // value: "instantiate".to_string() + // },] + // ); + // } + + // #[test] + // fn enforce_version_in_handshake() { + // let (mut deps, _res, _info) = setup(None, None); + + // let wrong_order = mock_ibc_channel_open_try(TEST_CHANNEL, BAD_IBC_ORDER, IBC_VERSION); + // ibc_channel_open(deps.as_mut(), mock_env(), wrong_order).unwrap_err(); + + // let wrong_version = mock_ibc_channel_open_try(TEST_CHANNEL, IBC_ORDER, "wrong_version"); + // ibc_channel_open(deps.as_mut(), mock_env(), wrong_version).unwrap_err(); + + // let valid_handshake = mock_ibc_channel_open_try(TEST_CHANNEL, IBC_ORDER, IBC_VERSION); + // ibc_channel_open(deps.as_mut(), mock_env(), valid_handshake).unwrap(); + // } + + // #[test] + // fn proper_handshake_flow() { + // let (mut deps, _res, _info) = setup(None, None); + + // let handshake_open = mock_ibc_channel_open_init(TEST_CHANNEL, IBC_ORDER, IBC_VERSION); + // ibc_channel_open(deps.as_mut(), mock_env(), handshake_open).unwrap(); + + // // then we connect (with counter-party version set) + // let handshake_connect = mock_ibc_channel_connect_ack(TEST_CHANNEL, IBC_ORDER, IBC_VERSION); + // let res = ibc_channel_connect(deps.as_mut(), mock_env(), handshake_connect).unwrap(); + + // assert_eq!(res.messages, vec![]); + // assert_eq!( + // res.attributes, + // vec![ + // Attribute { + // key: "method".to_string(), + // value: "ibc_channel_connect".to_string() + // }, + // Attribute { + // key: "channel_id".to_string(), + // value: TEST_CHANNEL.to_string() + // } + // ] + // ); + + // //We should have 1 item (test_channel) in the connections. + // let raw = query(deps.as_ref(), mock_env(), QueryMsg::GetConnections {}).unwrap(); + // let res: GetConnectionsResponse = from_binary(&raw).unwrap(); + + // assert_eq!(1, res.connections.len()); + // assert_eq!(TEST_CHANNEL, res.connections[0]); + // } + + // #[test] + // fn execute_ping() { + // let (mut deps, _res, info) = setup(None, None); + + // connect(deps.as_mut(), TEST_CHANNEL); + + // let msg = ExecuteMsg::Ping { + // channel: TEST_CHANNEL.to_string(), + // }; + // let res = execute(deps.as_mut(), mock_env(), info, msg).unwrap(); + + // //verify attributes are correct. + // assert_eq!( + // res.attributes, + // vec![ + // Attribute { + // key: "method".to_string(), + // value: "execute_ping".to_string() + // }, + // Attribute { + // key: "channel".to_string(), + // value: TEST_CHANNEL.to_string() + // }, + // ] + // ); + + // //Verify sent IbcPacket is correct + // assert_eq!( + // res.messages[0].msg, + // CosmosMsg::Ibc(IbcMsg::SendPacket { + // channel_id: TEST_CHANNEL.to_string(), + // data: to_binary(&IbcExecuteMsg::Ping {}).unwrap(), + // timeout: IbcTimeout::with_timestamp(mock_env().block.time.plus_seconds(300)) + // }) + // ); + + // // Verify we received the ping, and answered correctly. + // let ibc_msg = IbcExecuteMsg::Ping {}; + + // let msg = mock_ibc_packet_recv(TEST_CHANNEL, &ibc_msg).unwrap(); + // let res = ibc_packet_receive(deps.as_mut(), mock_env(), msg).unwrap(); + + // //Verify we got the result attr, pong. + // assert_eq!( + // res.attributes, + // vec![Attribute { + // key: "method".to_string(), + // value: "execute_ping".to_string() + // },] + // ); + + // let ack: IbcPingResponse = Ack::parse(res.acknowledgement.clone()); + + // assert_eq!(ack.result.as_str(), "pong"); + + // //Verify we do the ack correctly. + // let ack = mock_ibc_packet_ack( + // TEST_CHANNEL, + // &ibc_msg, + // IbcAcknowledgement::new(res.acknowledgement), + // ) + // .unwrap(); + // let res = ibc_packet_ack(deps.as_mut(), mock_env(), ack).unwrap(); + + // assert_eq!( + // res.attributes, + // vec![Attribute { + // key: "action".to_string(), + // value: "ack_ping".to_string() + // },] + // ); + + // //Verify that after the ack, our counter is 1 and not 0 + // let msg = QueryMsg::GetCounter { + // channel: TEST_CHANNEL.to_string(), + // }; + // let res = query(deps.as_ref(), mock_env(), msg).unwrap(); + // let value: GetCounterResponse = from_binary(&res).unwrap(); + + // assert_eq!(value.count, 1); + + // //Do custom query + // let msg = QueryMsg::GetConnections {}; + // let res = query(deps.as_ref(), mock_env(), msg).unwrap(); + // let value: GetConnectionsResponse = from_binary(&res).unwrap(); + + // assert_eq!(value.connections, vec![TEST_CHANNEL.to_string()]); + // } + + // #[test] + // fn close_channel() { + // let (mut deps, _res, _info) = setup(None, None); + + // connect(deps.as_mut(), TEST_CHANNEL); + + // let msg = QueryMsg::GetConnections {}; + // let res = query(deps.as_ref(), mock_env(), msg).unwrap(); + // let value: GetConnectionsResponse = from_binary(&res).unwrap(); + + // assert_eq!( + // value, + // GetConnectionsResponse { + // connections: vec![TEST_CHANNEL.to_string()] + // } + // ); + + // let channel = mock_ibc_channel_close_init(TEST_CHANNEL, IBC_ORDER, IBC_VERSION); + // let res = ibc_channel_close(deps.as_mut(), mock_env(), channel).unwrap(); + + // //Check no messages + // assert_eq!(0, res.messages.len()); + + // //Verify attributes + // assert_eq!( + // res.attributes, + // vec![ + // Attribute { + // key: "method".to_string(), + // value: "ibc_channel_close".to_string() + // }, + // Attribute { + // key: "channel".to_string(), + // value: TEST_CHANNEL.to_string() + // }, + // ] + // ); + // } } diff --git a/tests/package-lock.json b/tests/package-lock.json index 42bf4dc..7dffea6 100644 --- a/tests/package-lock.json +++ b/tests/package-lock.json @@ -485,42 +485,42 @@ } }, "node_modules/@cosmjs/amino": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/amino/-/amino-0.28.11.tgz", - "integrity": "sha512-WJkQQq8gbk5doJJ/3Gcax26I+VC4HdbbSlNdyT5hc6T+U2Jmyry9RLSE+wEZyFMgEabhr43SbIxf64gWZeR8YA==", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/amino/-/amino-0.28.13.tgz", + "integrity": "sha512-IHnH2zGwaY69qT4mVAavr/pfzx6YE+ud1NHJbvVePlbGiz68CXTi5LHR+K0lrKB5mQ7E+ZErWz2mw5U/x+V1wQ==", "dependencies": { - "@cosmjs/crypto": "0.28.11", - "@cosmjs/encoding": "0.28.11", - "@cosmjs/math": "0.28.11", - "@cosmjs/utils": "0.28.11" + "@cosmjs/crypto": "0.28.13", + "@cosmjs/encoding": "0.28.13", + "@cosmjs/math": "0.28.13", + "@cosmjs/utils": "0.28.13" } }, "node_modules/@cosmjs/cosmwasm-stargate": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/cosmwasm-stargate/-/cosmwasm-stargate-0.28.11.tgz", - "integrity": "sha512-sZ04c9ZvwAC7IngNeOhTnHJLBu7PXX3QfWM2vCVGd9puP9f3Hj3nbre75WKjHZ3DDVvxfS3u3JUJ6LjVWeIRuQ==", - "dependencies": { - "@cosmjs/amino": "0.28.11", - "@cosmjs/crypto": "0.28.11", - "@cosmjs/encoding": "0.28.11", - "@cosmjs/math": "0.28.11", - "@cosmjs/proto-signing": "0.28.11", - "@cosmjs/stargate": "0.28.11", - "@cosmjs/tendermint-rpc": "0.28.11", - "@cosmjs/utils": "0.28.11", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/cosmwasm-stargate/-/cosmwasm-stargate-0.28.13.tgz", + "integrity": "sha512-dVZNOiRd8btQreRUabncGhVXGCS2wToXqxi9l3KEHwCJQ2RWTshuqV+EZAdCaYHE5W6823s2Ol2W/ukA9AXJPw==", + "dependencies": { + "@cosmjs/amino": "0.28.13", + "@cosmjs/crypto": "0.28.13", + "@cosmjs/encoding": "0.28.13", + "@cosmjs/math": "0.28.13", + "@cosmjs/proto-signing": "0.28.13", + "@cosmjs/stargate": "0.28.13", + "@cosmjs/tendermint-rpc": "0.28.13", + "@cosmjs/utils": "0.28.13", "cosmjs-types": "^0.4.0", "long": "^4.0.0", "pako": "^2.0.2" } }, "node_modules/@cosmjs/crypto": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/crypto/-/crypto-0.28.11.tgz", - "integrity": "sha512-oJXOeBX4FP8bp0ZVydJFcRplErHp8cC6vNoULRck+7hcLuvp9tyv3SBOkBkwxTv81VcQyGCgn7WE0NYEKrpUbw==", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/crypto/-/crypto-0.28.13.tgz", + "integrity": "sha512-ynKfM0q/tMBQMHJby6ad8lR3gkgBKaelQhIsCZTjClsnuC7oYT9y3ThSZCUWr7Pa9h0J8ahU2YV2oFWFVWJQzQ==", "dependencies": { - "@cosmjs/encoding": "0.28.11", - "@cosmjs/math": "0.28.11", - "@cosmjs/utils": "0.28.11", + "@cosmjs/encoding": "0.28.13", + "@cosmjs/math": "0.28.13", + "@cosmjs/utils": "0.28.13", "@noble/hashes": "^1", "bn.js": "^5.2.0", "elliptic": "^6.5.3", @@ -528,9 +528,9 @@ } }, "node_modules/@cosmjs/encoding": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/encoding/-/encoding-0.28.11.tgz", - "integrity": "sha512-J7pvlzAt8hBZn316wGRmUlK3xwMgNXUvj4v56DK4fA0fv6VfGwMvVtHCXaqNQtzOGkC6EQcshzA/fL5MBIwu6A==", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/encoding/-/encoding-0.28.13.tgz", + "integrity": "sha512-jtXbAYtV77rLHxoIrjGFsvgGjeTKttuHRv6cvuy3toCZzY7JzTclKH5O2g36IIE4lXwD9xwuhGJ2aa6A3dhNkA==", "dependencies": { "base64-js": "^1.3.0", "bech32": "^1.1.4", @@ -538,68 +538,68 @@ } }, "node_modules/@cosmjs/faucet-client": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/faucet-client/-/faucet-client-0.28.11.tgz", - "integrity": "sha512-alQGznExoZKTFWrA7ejyCVWa3t2VI162MY9uDlV0MbeGOcS9GgAtapHUlapd4q1Ynq6PQ35tlLEITpsBR4VJoQ==", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/faucet-client/-/faucet-client-0.28.13.tgz", + "integrity": "sha512-M6f0Wbw3hvdfYbVpfGDXwjbRAcCgMRm5slWK6cU8BpotckLvBb0xoBvrhklG/ooz6ZTZfAc2e/EJ8GVhksdvpA==", "dependencies": { "axios": "^0.21.2" } }, "node_modules/@cosmjs/json-rpc": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/json-rpc/-/json-rpc-0.28.11.tgz", - "integrity": "sha512-YNZTozu5yWHyGGet5Wfc0CcxQezkMr37YaeU9elCaa11ClHlYAQ2NrPpPBOmgnJKsMhzfiKcAE9Sf6f4a0hCxA==", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/json-rpc/-/json-rpc-0.28.13.tgz", + "integrity": "sha512-fInSvg7x9P6p+GWqet+TMhrMTM3OWWdLJOGS5w2ryubMjgpR1rLiAx77MdTNkArW+/6sUwku0sN4veM4ENQu6A==", "dependencies": { - "@cosmjs/stream": "0.28.11", + "@cosmjs/stream": "0.28.13", "xstream": "^11.14.0" } }, "node_modules/@cosmjs/math": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/math/-/math-0.28.11.tgz", - "integrity": "sha512-MyhPnC4sYu86c2/0PpEeynaPl4nvAmLZH3acPh96SzcjERONbGZjjKtBFPq1avBrev2CCSPrZ4O8u9xpQ4aSvg==", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/math/-/math-0.28.13.tgz", + "integrity": "sha512-PDpL8W/kbyeWi0mQ2OruyqE8ZUAdxPs1xCbDX3WXJwy2oU+X2UTbkuweJHVpS9CIqmZulBoWQAmlf6t6zr1N/g==", "dependencies": { "bn.js": "^5.2.0" } }, "node_modules/@cosmjs/proto-signing": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/proto-signing/-/proto-signing-0.28.11.tgz", - "integrity": "sha512-ym0DpLff+0RBkD/mtFf6wrzyuGhcbcjuDMEdcUWOrJTo6n8DXeRmHkJkyy/mrG3QC4tQX/A81+DhfkANQmgcxw==", - "dependencies": { - "@cosmjs/amino": "0.28.11", - "@cosmjs/crypto": "0.28.11", - "@cosmjs/encoding": "0.28.11", - "@cosmjs/math": "0.28.11", - "@cosmjs/utils": "0.28.11", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/proto-signing/-/proto-signing-0.28.13.tgz", + "integrity": "sha512-nSl/2ZLsUJYz3Ad0RY3ihZUgRHIow2OnYqKsESMu+3RA/jTi9bDYhiBu8mNMHI0xrEJry918B2CyI56pOUHdPQ==", + "dependencies": { + "@cosmjs/amino": "0.28.13", + "@cosmjs/crypto": "0.28.13", + "@cosmjs/encoding": "0.28.13", + "@cosmjs/math": "0.28.13", + "@cosmjs/utils": "0.28.13", "cosmjs-types": "^0.4.0", "long": "^4.0.0" } }, "node_modules/@cosmjs/socket": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/socket/-/socket-0.28.11.tgz", - "integrity": "sha512-4BhsWN984SLBhwPCD89riQ3SEJzJ1RLJPeP6apIGjhh6pguQZmwa2U/TZjnEUOGnJkUG2FZUH99jRGSTYaIvZg==", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/socket/-/socket-0.28.13.tgz", + "integrity": "sha512-lavwGxQ5VdeltyhpFtwCRVfxeWjH5D5mmN7jgx9nuCf3XSFbTcOYxrk2pQ4usenu1Q1KZdL4Yl5RCNrJuHD9Ug==", "dependencies": { - "@cosmjs/stream": "0.28.11", + "@cosmjs/stream": "0.28.13", "isomorphic-ws": "^4.0.1", "ws": "^7", "xstream": "^11.14.0" } }, "node_modules/@cosmjs/stargate": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/stargate/-/stargate-0.28.11.tgz", - "integrity": "sha512-UyFH/mTNNKTZohVhj+SmjCRv/xopqU/UinGedmWzs4MqEZteX9xs6D3HTmRCgpmBQ03lpbTslE/FhhT9Hkl9KQ==", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/stargate/-/stargate-0.28.13.tgz", + "integrity": "sha512-dVBMazDz8/eActHsRcZjDHHptOBMqvibj5CFgEtZBp22gP6ASzoAUXTlkSVk5FBf4sfuUHoff6st134/+PGMAg==", "dependencies": { "@confio/ics23": "^0.6.8", - "@cosmjs/amino": "0.28.11", - "@cosmjs/encoding": "0.28.11", - "@cosmjs/math": "0.28.11", - "@cosmjs/proto-signing": "0.28.11", - "@cosmjs/stream": "0.28.11", - "@cosmjs/tendermint-rpc": "0.28.11", - "@cosmjs/utils": "0.28.11", + "@cosmjs/amino": "0.28.13", + "@cosmjs/encoding": "0.28.13", + "@cosmjs/math": "0.28.13", + "@cosmjs/proto-signing": "0.28.13", + "@cosmjs/stream": "0.28.13", + "@cosmjs/tendermint-rpc": "0.28.13", + "@cosmjs/utils": "0.28.13", "cosmjs-types": "^0.4.0", "long": "^4.0.0", "protobufjs": "~6.11.3", @@ -607,34 +607,34 @@ } }, "node_modules/@cosmjs/stream": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/stream/-/stream-0.28.11.tgz", - "integrity": "sha512-3b6P4Il8mYzvY2bvEQyzgP+cm0HIGSpHNtuGjiWsQF3Wtp450iVRfEJqdt4+91vvxzfdjQEkQOLMaymnswX3sw==", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/stream/-/stream-0.28.13.tgz", + "integrity": "sha512-AnjtfwT8NwPPkd3lhZhjOlOzT0Kn9bgEu2IPOZjQ1nmG2bplsr6TJmnwn0dJxHT7UGtex17h6whKB5N4wU37Wg==", "dependencies": { "xstream": "^11.14.0" } }, "node_modules/@cosmjs/tendermint-rpc": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/tendermint-rpc/-/tendermint-rpc-0.28.11.tgz", - "integrity": "sha512-TUhWsUYxbKftQmHQK5TBH62vNaKB1ybxoFZ2uJtGMVvY3jcBux7P0Ll/u5nwrM0ETAeo2RjucehJUpGBy9q+HQ==", - "dependencies": { - "@cosmjs/crypto": "0.28.11", - "@cosmjs/encoding": "0.28.11", - "@cosmjs/json-rpc": "0.28.11", - "@cosmjs/math": "0.28.11", - "@cosmjs/socket": "0.28.11", - "@cosmjs/stream": "0.28.11", - "@cosmjs/utils": "0.28.11", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/tendermint-rpc/-/tendermint-rpc-0.28.13.tgz", + "integrity": "sha512-GB+ZmfuJIGQm0hsRtLYjeR3lOxF7Z6XyCBR0cX5AAYOZzSEBJjevPgUHD6tLn8zIhvzxaW3/VKnMB+WmlxdH4w==", + "dependencies": { + "@cosmjs/crypto": "0.28.13", + "@cosmjs/encoding": "0.28.13", + "@cosmjs/json-rpc": "0.28.13", + "@cosmjs/math": "0.28.13", + "@cosmjs/socket": "0.28.13", + "@cosmjs/stream": "0.28.13", + "@cosmjs/utils": "0.28.13", "axios": "^0.21.2", "readonly-date": "^1.0.0", "xstream": "^11.14.0" } }, "node_modules/@cosmjs/utils": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/utils/-/utils-0.28.11.tgz", - "integrity": "sha512-FXVEr7Pg6MX9VbY5NemuKbtFVabSlUlArWIV+R74FQg5LIuSa+0QkxSpNldCuOLBEU4/GlrzybT4uEl338vSzg==" + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/utils/-/utils-0.28.13.tgz", + "integrity": "sha512-dVeMBiyg+46x7XBZEfJK8yTihphbCFpjVYmLJVqmTsHfJwymQ65cpyW/C+V/LgWARGK8hWQ/aX9HM5Ao8QmMSg==" }, "node_modules/@dabh/diagnostics": { "version": "2.0.3", @@ -3072,9 +3072,9 @@ "integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==" }, "node_modules/follow-redirects": { - "version": "1.15.1", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz", - "integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==", + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", "funding": [ { "type": "individual", @@ -7346,42 +7346,42 @@ } }, "@cosmjs/amino": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/amino/-/amino-0.28.11.tgz", - "integrity": "sha512-WJkQQq8gbk5doJJ/3Gcax26I+VC4HdbbSlNdyT5hc6T+U2Jmyry9RLSE+wEZyFMgEabhr43SbIxf64gWZeR8YA==", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/amino/-/amino-0.28.13.tgz", + "integrity": "sha512-IHnH2zGwaY69qT4mVAavr/pfzx6YE+ud1NHJbvVePlbGiz68CXTi5LHR+K0lrKB5mQ7E+ZErWz2mw5U/x+V1wQ==", "requires": { - "@cosmjs/crypto": "0.28.11", - "@cosmjs/encoding": "0.28.11", - "@cosmjs/math": "0.28.11", - "@cosmjs/utils": "0.28.11" + "@cosmjs/crypto": "0.28.13", + "@cosmjs/encoding": "0.28.13", + "@cosmjs/math": "0.28.13", + "@cosmjs/utils": "0.28.13" } }, "@cosmjs/cosmwasm-stargate": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/cosmwasm-stargate/-/cosmwasm-stargate-0.28.11.tgz", - "integrity": "sha512-sZ04c9ZvwAC7IngNeOhTnHJLBu7PXX3QfWM2vCVGd9puP9f3Hj3nbre75WKjHZ3DDVvxfS3u3JUJ6LjVWeIRuQ==", - "requires": { - "@cosmjs/amino": "0.28.11", - "@cosmjs/crypto": "0.28.11", - "@cosmjs/encoding": "0.28.11", - "@cosmjs/math": "0.28.11", - "@cosmjs/proto-signing": "0.28.11", - "@cosmjs/stargate": "0.28.11", - "@cosmjs/tendermint-rpc": "0.28.11", - "@cosmjs/utils": "0.28.11", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/cosmwasm-stargate/-/cosmwasm-stargate-0.28.13.tgz", + "integrity": "sha512-dVZNOiRd8btQreRUabncGhVXGCS2wToXqxi9l3KEHwCJQ2RWTshuqV+EZAdCaYHE5W6823s2Ol2W/ukA9AXJPw==", + "requires": { + "@cosmjs/amino": "0.28.13", + "@cosmjs/crypto": "0.28.13", + "@cosmjs/encoding": "0.28.13", + "@cosmjs/math": "0.28.13", + "@cosmjs/proto-signing": "0.28.13", + "@cosmjs/stargate": "0.28.13", + "@cosmjs/tendermint-rpc": "0.28.13", + "@cosmjs/utils": "0.28.13", "cosmjs-types": "^0.4.0", "long": "^4.0.0", "pako": "^2.0.2" } }, "@cosmjs/crypto": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/crypto/-/crypto-0.28.11.tgz", - "integrity": "sha512-oJXOeBX4FP8bp0ZVydJFcRplErHp8cC6vNoULRck+7hcLuvp9tyv3SBOkBkwxTv81VcQyGCgn7WE0NYEKrpUbw==", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/crypto/-/crypto-0.28.13.tgz", + "integrity": "sha512-ynKfM0q/tMBQMHJby6ad8lR3gkgBKaelQhIsCZTjClsnuC7oYT9y3ThSZCUWr7Pa9h0J8ahU2YV2oFWFVWJQzQ==", "requires": { - "@cosmjs/encoding": "0.28.11", - "@cosmjs/math": "0.28.11", - "@cosmjs/utils": "0.28.11", + "@cosmjs/encoding": "0.28.13", + "@cosmjs/math": "0.28.13", + "@cosmjs/utils": "0.28.13", "@noble/hashes": "^1", "bn.js": "^5.2.0", "elliptic": "^6.5.3", @@ -7389,9 +7389,9 @@ } }, "@cosmjs/encoding": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/encoding/-/encoding-0.28.11.tgz", - "integrity": "sha512-J7pvlzAt8hBZn316wGRmUlK3xwMgNXUvj4v56DK4fA0fv6VfGwMvVtHCXaqNQtzOGkC6EQcshzA/fL5MBIwu6A==", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/encoding/-/encoding-0.28.13.tgz", + "integrity": "sha512-jtXbAYtV77rLHxoIrjGFsvgGjeTKttuHRv6cvuy3toCZzY7JzTclKH5O2g36IIE4lXwD9xwuhGJ2aa6A3dhNkA==", "requires": { "base64-js": "^1.3.0", "bech32": "^1.1.4", @@ -7399,68 +7399,68 @@ } }, "@cosmjs/faucet-client": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/faucet-client/-/faucet-client-0.28.11.tgz", - "integrity": "sha512-alQGznExoZKTFWrA7ejyCVWa3t2VI162MY9uDlV0MbeGOcS9GgAtapHUlapd4q1Ynq6PQ35tlLEITpsBR4VJoQ==", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/faucet-client/-/faucet-client-0.28.13.tgz", + "integrity": "sha512-M6f0Wbw3hvdfYbVpfGDXwjbRAcCgMRm5slWK6cU8BpotckLvBb0xoBvrhklG/ooz6ZTZfAc2e/EJ8GVhksdvpA==", "requires": { "axios": "^0.21.2" } }, "@cosmjs/json-rpc": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/json-rpc/-/json-rpc-0.28.11.tgz", - "integrity": "sha512-YNZTozu5yWHyGGet5Wfc0CcxQezkMr37YaeU9elCaa11ClHlYAQ2NrPpPBOmgnJKsMhzfiKcAE9Sf6f4a0hCxA==", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/json-rpc/-/json-rpc-0.28.13.tgz", + "integrity": "sha512-fInSvg7x9P6p+GWqet+TMhrMTM3OWWdLJOGS5w2ryubMjgpR1rLiAx77MdTNkArW+/6sUwku0sN4veM4ENQu6A==", "requires": { - "@cosmjs/stream": "0.28.11", + "@cosmjs/stream": "0.28.13", "xstream": "^11.14.0" } }, "@cosmjs/math": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/math/-/math-0.28.11.tgz", - "integrity": "sha512-MyhPnC4sYu86c2/0PpEeynaPl4nvAmLZH3acPh96SzcjERONbGZjjKtBFPq1avBrev2CCSPrZ4O8u9xpQ4aSvg==", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/math/-/math-0.28.13.tgz", + "integrity": "sha512-PDpL8W/kbyeWi0mQ2OruyqE8ZUAdxPs1xCbDX3WXJwy2oU+X2UTbkuweJHVpS9CIqmZulBoWQAmlf6t6zr1N/g==", "requires": { "bn.js": "^5.2.0" } }, "@cosmjs/proto-signing": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/proto-signing/-/proto-signing-0.28.11.tgz", - "integrity": "sha512-ym0DpLff+0RBkD/mtFf6wrzyuGhcbcjuDMEdcUWOrJTo6n8DXeRmHkJkyy/mrG3QC4tQX/A81+DhfkANQmgcxw==", - "requires": { - "@cosmjs/amino": "0.28.11", - "@cosmjs/crypto": "0.28.11", - "@cosmjs/encoding": "0.28.11", - "@cosmjs/math": "0.28.11", - "@cosmjs/utils": "0.28.11", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/proto-signing/-/proto-signing-0.28.13.tgz", + "integrity": "sha512-nSl/2ZLsUJYz3Ad0RY3ihZUgRHIow2OnYqKsESMu+3RA/jTi9bDYhiBu8mNMHI0xrEJry918B2CyI56pOUHdPQ==", + "requires": { + "@cosmjs/amino": "0.28.13", + "@cosmjs/crypto": "0.28.13", + "@cosmjs/encoding": "0.28.13", + "@cosmjs/math": "0.28.13", + "@cosmjs/utils": "0.28.13", "cosmjs-types": "^0.4.0", "long": "^4.0.0" } }, "@cosmjs/socket": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/socket/-/socket-0.28.11.tgz", - "integrity": "sha512-4BhsWN984SLBhwPCD89riQ3SEJzJ1RLJPeP6apIGjhh6pguQZmwa2U/TZjnEUOGnJkUG2FZUH99jRGSTYaIvZg==", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/socket/-/socket-0.28.13.tgz", + "integrity": "sha512-lavwGxQ5VdeltyhpFtwCRVfxeWjH5D5mmN7jgx9nuCf3XSFbTcOYxrk2pQ4usenu1Q1KZdL4Yl5RCNrJuHD9Ug==", "requires": { - "@cosmjs/stream": "0.28.11", + "@cosmjs/stream": "0.28.13", "isomorphic-ws": "^4.0.1", "ws": "^7", "xstream": "^11.14.0" } }, "@cosmjs/stargate": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/stargate/-/stargate-0.28.11.tgz", - "integrity": "sha512-UyFH/mTNNKTZohVhj+SmjCRv/xopqU/UinGedmWzs4MqEZteX9xs6D3HTmRCgpmBQ03lpbTslE/FhhT9Hkl9KQ==", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/stargate/-/stargate-0.28.13.tgz", + "integrity": "sha512-dVBMazDz8/eActHsRcZjDHHptOBMqvibj5CFgEtZBp22gP6ASzoAUXTlkSVk5FBf4sfuUHoff6st134/+PGMAg==", "requires": { "@confio/ics23": "^0.6.8", - "@cosmjs/amino": "0.28.11", - "@cosmjs/encoding": "0.28.11", - "@cosmjs/math": "0.28.11", - "@cosmjs/proto-signing": "0.28.11", - "@cosmjs/stream": "0.28.11", - "@cosmjs/tendermint-rpc": "0.28.11", - "@cosmjs/utils": "0.28.11", + "@cosmjs/amino": "0.28.13", + "@cosmjs/encoding": "0.28.13", + "@cosmjs/math": "0.28.13", + "@cosmjs/proto-signing": "0.28.13", + "@cosmjs/stream": "0.28.13", + "@cosmjs/tendermint-rpc": "0.28.13", + "@cosmjs/utils": "0.28.13", "cosmjs-types": "^0.4.0", "long": "^4.0.0", "protobufjs": "~6.11.3", @@ -7468,34 +7468,34 @@ } }, "@cosmjs/stream": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/stream/-/stream-0.28.11.tgz", - "integrity": "sha512-3b6P4Il8mYzvY2bvEQyzgP+cm0HIGSpHNtuGjiWsQF3Wtp450iVRfEJqdt4+91vvxzfdjQEkQOLMaymnswX3sw==", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/stream/-/stream-0.28.13.tgz", + "integrity": "sha512-AnjtfwT8NwPPkd3lhZhjOlOzT0Kn9bgEu2IPOZjQ1nmG2bplsr6TJmnwn0dJxHT7UGtex17h6whKB5N4wU37Wg==", "requires": { "xstream": "^11.14.0" } }, "@cosmjs/tendermint-rpc": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/tendermint-rpc/-/tendermint-rpc-0.28.11.tgz", - "integrity": "sha512-TUhWsUYxbKftQmHQK5TBH62vNaKB1ybxoFZ2uJtGMVvY3jcBux7P0Ll/u5nwrM0ETAeo2RjucehJUpGBy9q+HQ==", - "requires": { - "@cosmjs/crypto": "0.28.11", - "@cosmjs/encoding": "0.28.11", - "@cosmjs/json-rpc": "0.28.11", - "@cosmjs/math": "0.28.11", - "@cosmjs/socket": "0.28.11", - "@cosmjs/stream": "0.28.11", - "@cosmjs/utils": "0.28.11", + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/tendermint-rpc/-/tendermint-rpc-0.28.13.tgz", + "integrity": "sha512-GB+ZmfuJIGQm0hsRtLYjeR3lOxF7Z6XyCBR0cX5AAYOZzSEBJjevPgUHD6tLn8zIhvzxaW3/VKnMB+WmlxdH4w==", + "requires": { + "@cosmjs/crypto": "0.28.13", + "@cosmjs/encoding": "0.28.13", + "@cosmjs/json-rpc": "0.28.13", + "@cosmjs/math": "0.28.13", + "@cosmjs/socket": "0.28.13", + "@cosmjs/stream": "0.28.13", + "@cosmjs/utils": "0.28.13", "axios": "^0.21.2", "readonly-date": "^1.0.0", "xstream": "^11.14.0" } }, "@cosmjs/utils": { - "version": "0.28.11", - "resolved": "https://registry.npmjs.org/@cosmjs/utils/-/utils-0.28.11.tgz", - "integrity": "sha512-FXVEr7Pg6MX9VbY5NemuKbtFVabSlUlArWIV+R74FQg5LIuSa+0QkxSpNldCuOLBEU4/GlrzybT4uEl338vSzg==" + "version": "0.28.13", + "resolved": "https://registry.npmjs.org/@cosmjs/utils/-/utils-0.28.13.tgz", + "integrity": "sha512-dVeMBiyg+46x7XBZEfJK8yTihphbCFpjVYmLJVqmTsHfJwymQ65cpyW/C+V/LgWARGK8hWQ/aX9HM5Ao8QmMSg==" }, "@dabh/diagnostics": { "version": "2.0.3", @@ -9343,9 +9343,9 @@ "integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==" }, "follow-redirects": { - "version": "1.15.1", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz", - "integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==" + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==" }, "foreground-child": { "version": "2.0.0", diff --git a/tests/src/controller.ts b/tests/src/controller.ts index 616f429..a594aab 100644 --- a/tests/src/controller.ts +++ b/tests/src/controller.ts @@ -32,17 +32,11 @@ export async function showCounter( return res; } -export async function sendPing( +export async function executeContract( cosmwasm: CosmWasmSigner, contractAddr: string, - channelId: string + msg: Record ): Promise { - const msg = { - ping: { - channel: channelId, - }, - }; - const res = await cosmwasm.sign.execute( cosmwasm.senderAddress, contractAddr, diff --git a/tests/src/cosmwasm.spec.ts b/tests/src/cosmwasm.spec.ts index 406b203..d6eef47 100644 --- a/tests/src/cosmwasm.spec.ts +++ b/tests/src/cosmwasm.spec.ts @@ -7,7 +7,7 @@ const osmosis = { ...oldOsmo, minFee: "0.025uosmo" }; import { ibcPingResponse, - sendPing, + executeContract, showConnections, showCounter, } from "./controller"; @@ -165,7 +165,7 @@ async function demoSetup(): Promise { }; } -test.serial("ping the remote chain", async (t) => { +test.serial("ping from wasm to osmo chain", async (t) => { const { wasmClient, wasmPing, osmoClient, osmoPing, link } = await demoSetup(); @@ -189,7 +189,13 @@ test.serial("ping the remote chain", async (t) => { t.log(`Wasm channel id: ${wasmConnections[0]}`); t.log(`Osmo channel id: ${osmoConnections[0]}`); //Send msg with ping - await sendPing(wasmClient, wasmPing, channelId); + const msg = { + ping: { + channel: channelId, + }, + }; + const pingResponse = await executeContract(wasmClient, wasmPing, msg); + t.log(`>>>ping response: ${JSON.stringify(pingResponse)}`); //relay const info = await link.relayAll(); diff --git a/tests/src/ibc-dispatcher.spec.ts b/tests/src/ibc-dispatcher.spec.ts index 67e92cd..d923566 100644 --- a/tests/src/ibc-dispatcher.spec.ts +++ b/tests/src/ibc-dispatcher.spec.ts @@ -5,12 +5,7 @@ import test from "ava"; const { osmosis: oldOsmo, setup, wasmd } = testutils; const osmosis = { ...oldOsmo, minFee: "0.025uosmo" }; -import { - ibcPingResponse, - sendPing, - showConnections, - showCounter, -} from "./controller"; +import { ibcPingResponse, executeContract, showConnections } from "./controller"; import { assertAckSuccess, IbcOrder, @@ -23,148 +18,274 @@ import { // code ids from instantiated contracts let wasmCodeIds: Record = {}; -let osmosisCodeIds: Record = {}; +let osmoCodeIds: Record = {}; -const WASM_FILE = "./internal/ibc_dispatcher.wasm"; +const WASM_FILE_IBC_DISPATCHER_CONTRACT = "./internal/ibc_dispatcher.wasm"; +const WASM_FILE_IBC_CONTROLLER_CONTRACT = "./internal/ibc_controller.wasm"; +const WASM_FILE_ECHO_CONTRACT = "./internal/echo.wasm"; //Upload contracts to chains. test.before(async (t) => { console.debug("Upload contract to wasmd..."); const wasmContracts = { - contract1: WASM_FILE, + ibcControllerContract: WASM_FILE_IBC_CONTROLLER_CONTRACT, + ibcDispatcherContract: WASM_FILE_IBC_DISPATCHER_CONTRACT, }; const wasmSign = await setupWasmClient(); wasmCodeIds = await setupContracts(wasmSign, wasmContracts); console.debug("Upload contract to osmosis..."); const osmosisContracts = { - contract1: WASM_FILE, + echoContract: WASM_FILE_ECHO_CONTRACT, + ibcDispatcherContract: WASM_FILE_IBC_DISPATCHER_CONTRACT, }; const osmosisSign = await setupOsmosisClient(); - osmosisCodeIds = await setupContracts(osmosisSign, osmosisContracts); + osmoCodeIds = await setupContracts(osmosisSign, osmosisContracts); t.pass(); }); //Test that we init contracts correctly. -test.serial("set up channel with contract", async (t) => { - // instantiate ping on wasmd - const wasmClient = await setupWasmClient(); - const msg = {}; - const { contractAddress: wasmContractAddress } = - await wasmClient.sign.instantiate( - wasmClient.senderAddress, - wasmCodeIds.contract1, - msg, - "wasm contract 1", - "auto" - ); - t.log(`Wasm contract address: ${wasmContractAddress}`); - t.truthy(wasmContractAddress); - const { ibcPortId: wasmIbcPortId } = await wasmClient.sign.getContract( - wasmContractAddress - ); - t.log(`Wasm IBC port id: ${wasmIbcPortId}`); - assert(wasmIbcPortId); +// test.serial( +// "set up ibc controller and ibc dispatcher on Wasm chain, echo and ibc dispatcher on chain Osmo and a channel between dispatcher contract on each chain", +// async (t) => { +// // instantiate ibc contract on wasmd +// const wasmClient = await setupWasmClient(); +// const msg = {}; +// const { contractAddress: wasmIbcDispatcherContractAddress } = +// await wasmClient.sign.instantiate( +// wasmClient.senderAddress, +// wasmCodeIds.ibcDispatcherContract, +// msg, +// "wasm IBC Dispatcher contract", +// "auto" +// ); +// // assert address is returned +// t.log( +// `Wasm IBC Dispatcher contract address: ${wasmIbcDispatcherContractAddress}` +// ); +// t.truthy(wasmIbcDispatcherContractAddress); +// // assert contract is instantiated +// const { ibcPortId: wasmIbcDispatcherContractIbcPortId } = +// await wasmClient.sign.getContract(wasmIbcDispatcherContractAddress); +// t.log(`Wasm IBC Dispatcher port id: ${wasmIbcDispatcherContractIbcPortId}`); +// assert(wasmIbcDispatcherContractIbcPortId); - // instantiate ping on osmosis - const osmoClient = await setupOsmosisClient(); - const { contractAddress: osmoContractAddress } = - await osmoClient.sign.instantiate( - osmoClient.senderAddress, - osmosisCodeIds.contract1, - msg, - "osmosis contract 1", - "auto" - ); - t.truthy(osmoContractAddress); - t.log(`Osmo contract address: ${osmoContractAddress}`); - const { ibcPortId: osmoIbcPortId } = await osmoClient.sign.getContract( - osmoContractAddress - ); - t.log(`Osmo IBC port id: ${osmoIbcPortId}`); - assert(osmoIbcPortId); - - const [src, dest] = await setup(wasmd, osmosis); - const link = await Link.createWithNewConnections(src, dest); - await link.createChannel( - "A", - wasmIbcPortId, - osmoIbcPortId, - IbcOrder, - IbcVersion - ); -}); +// // instantiate IBC Controller contract on wasmd +// t.log(`Instantiate Wasm IBC Controller`); +// const { contractAddress: wasmIbcControllerContractAddress } = +// await wasmClient.sign.instantiate( +// wasmClient.senderAddress, +// wasmCodeIds.ibcControllerContract, +// msg, +// "wasm IBC Controller contract", +// "auto" +// ); +// // assert address is returned +// t.log( +// `Wasm IBC Controller contract address: ${wasmIbcControllerContractAddress}` +// ); +// t.truthy(wasmIbcControllerContractAddress); +// // assert contract is instantiated +// const { address: wasmIbcControllerContractAddressResponse } = +// await wasmClient.sign.getContract(wasmIbcControllerContractAddress); +// t.log( +// `Wasm IBC Controller contract response: ${wasmIbcControllerContractAddressResponse}` +// ); +// assert(wasmIbcControllerContractAddressResponse); + +// // instantiate IBC Dispatcher contract on osmosis +// const osmoClient = await setupOsmosisClient(); +// const { contractAddress: osmoIbcDispatcherContractAddress } = +// await osmoClient.sign.instantiate( +// osmoClient.senderAddress, +// osmoCodeIds.ibcDispatcherContract, +// msg, +// "osmosis IBC Dispatcher contract", +// "auto" +// ); +// // assert address is returned +// t.log(`Osmo contract address: ${osmoIbcDispatcherContractAddress}`); +// t.truthy(osmoIbcDispatcherContractAddress); +// // assert contract is instantiated +// const { ibcPortId: osmoIbcDispatcherContractIbcPortId } = +// await osmoClient.sign.getContract(osmoIbcDispatcherContractAddress); +// t.log(`Osmo IBC port id: ${osmoIbcDispatcherContractIbcPortId}`); +// assert(osmoIbcDispatcherContractIbcPortId); + +// // instantiate Echo contract on osmosis +// const { contractAddress: osmoEchoContractAddress } = +// await osmoClient.sign.instantiate( +// osmoClient.senderAddress, +// osmoCodeIds.echoContract, +// msg, +// "osmosis Echo contract", +// "auto" +// ); +// // assert address is returned +// t.log(`Osmo Echo contract address: ${osmoEchoContractAddress}`); +// t.truthy(osmoEchoContractAddress); +// // assert contract is instantiated +// const { address: osmoEchoContractAddressResponse } = +// await osmoClient.sign.getContract(osmoEchoContractAddress); +// t.log(`Osmo Echo contract response: ${osmoEchoContractAddressResponse}`); +// assert(osmoEchoContractAddressResponse); + +// // create a channel between both ibc contracts +// // - create ibc client for each chain +// t.log(`Create Osmo and Wasm clients`); +// const [ibcClientWasmChain, ibcClientOsmoChain] = await setup( +// wasmd, +// osmosis +// ); +// t.log(`Create connections between both chains`); +// // - create connection between both chains +// const link = await Link.createWithNewConnections( +// ibcClientWasmChain, +// ibcClientOsmoChain +// ); +// t.log(`Create channel between both IBC Dispatcher contracts`); +// // - create channel between ibc contract on wasm chain and ibc contract on osmo chain +// const channelPair = await link.createChannel( +// "A", // initialize from left side (A) +// wasmIbcDispatcherContractIbcPortId, +// osmoIbcDispatcherContractIbcPortId, +// IbcOrder, +// IbcVersion +// ); +// assert(channelPair.src); +// assert(channelPair.dest); +// } +// ); //This is the setupInfo we pass, to make sure we don't forget any data we need. interface SetupInfo { wasmClient: CosmWasmSigner; osmoClient: CosmWasmSigner; - wasmContract1Address: string; - osmoContract1Address: string; + wasmIbcDispatcherContractAddress: string; + wasmIbcControllerContractAddress: string; + osmoIbcDispatcherContractAddress: string; + osmoEchoContractAddress: string; link: Link; } //A setup function to init the contracts for tests. async function demoSetup(): Promise { - // instantiate contract 1 on wasmd + // instantiate ibc contract on wasmd const wasmClient = await setupWasmClient(); const msg = {}; - const { contractAddress: wasmContract1Address } = + const { contractAddress: wasmIbcDispatcherContractAddress } = await wasmClient.sign.instantiate( wasmClient.senderAddress, - wasmCodeIds.contract1, + wasmCodeIds.ibcDispatcherContract, msg, - "contract 1", + "wasm IBC Dispatcher contract", "auto" ); - const { ibcPortId: wasmIbcPortId } = await wasmClient.sign.getContract( - wasmContract1Address + console.log( + `Wasm IBC Dispatcher contract address: ${wasmIbcDispatcherContractAddress}` ); - assert(wasmIbcPortId); + // assert contract is instantiated + const { ibcPortId: wasmIbcDispatcherContractIbcPortId } = + await wasmClient.sign.getContract(wasmIbcDispatcherContractAddress); + assert(wasmIbcDispatcherContractIbcPortId); - // instantiate contract 1 on osmosis + // instantiate IBC Controller contract on wasmd + const { contractAddress: wasmIbcControllerContractAddress } = + await wasmClient.sign.instantiate( + wasmClient.senderAddress, + wasmCodeIds.ibcControllerContract, + msg, + "wasm IBC Controller contract", + "auto" + ); + console.log( + `Wasm IBC Controller contract address: ${wasmIbcControllerContractAddress}` + ); + // assert contract is instantiated + const { address: wasmIbcControllerContractAddressResponse } = + await wasmClient.sign.getContract(wasmIbcControllerContractAddress); + console.log( + `Wasm IBC Controller contract address response: ${wasmIbcControllerContractAddressResponse}` + ); + assert(wasmIbcControllerContractAddressResponse); + + // instantiate IBC Dispatcher contract on osmosis const osmoClient = await setupOsmosisClient(); + const { contractAddress: osmoIbcDispatcherContractAddress } = + await osmoClient.sign.instantiate( + osmoClient.senderAddress, + osmoCodeIds.ibcDispatcherContract, + msg, + "osmosis IBC Dispatcher contract", + "auto" + ); + console.log( + `Osmo IBC Dispatcher contract address: ${osmoIbcDispatcherContractAddress}` + ); + // assert contract is instantiated + const { ibcPortId: osmoIbcDispatcherContractIbcPortId } = + await osmoClient.sign.getContract(osmoIbcDispatcherContractAddress); + assert(osmoIbcDispatcherContractIbcPortId); - const { contractAddress: osmoContract1Address } = + // instantiate Echo contract on osmosis + const { contractAddress: osmoEchoContractAddress } = await osmoClient.sign.instantiate( osmoClient.senderAddress, - osmosisCodeIds.contract1, + osmoCodeIds.echoContract, msg, - "contract 1", + "osmo Echo contract", "auto" ); - const { ibcPortId: osmoIbcPortId } = await osmoClient.sign.getContract( - osmoContract1Address + console.log(`Osmo Echo contract address: ${osmoEchoContractAddress}`); + // assert contract is instantiated + const { address: osmoEchoContractAddressResponse } = + await osmoClient.sign.getContract(osmoEchoContractAddress); + console.log( + `Osmo Echo contract address response: ${osmoEchoContractAddressResponse}` + ); + assert(osmoEchoContractAddressResponse); + + // create a channel between both ibc contracts + // - create ibc client for each chain + console.log(`Create Osmo and Wasm clients`); + const [ibcClientWasmChain, ibcClientOsomoChain] = await setup(wasmd, osmosis); + // - create connection between both chains + console.log(`Create connections between both chains`); + const link = await Link.createWithNewConnections( + ibcClientWasmChain, + ibcClientOsomoChain ); - assert(osmoIbcPortId); - - // create a connection and channel - const [src, dest] = await setup(wasmd, osmosis); - const link = await Link.createWithNewConnections(src, dest); - await link.createChannel( - "A", - wasmIbcPortId, - osmoIbcPortId, + // - create channel between ibc contract on wasm chain and ibc contract on osmo chain + console.log(`Create channel between both IBC Dispatcher contracts`); + const channelPair = await link.createChannel( + "A", // initialize from left side (A) + wasmIbcDispatcherContractIbcPortId, + osmoIbcDispatcherContractIbcPortId, IbcOrder, IbcVersion ); + assert(channelPair.src); + assert(channelPair.dest); return { wasmClient, osmoClient, - wasmContract1Address, - osmoContract1Address, + wasmIbcDispatcherContractAddress, + wasmIbcControllerContractAddress, + osmoIbcDispatcherContractAddress, + osmoEchoContractAddress, link, }; } -test.serial("ping the remote chain", async (t) => { +test.serial("send echo from wasm to osmo chain", async (t) => { const { wasmClient, - wasmContract1Address, + wasmIbcDispatcherContractAddress, osmoClient, - osmoContract1Address, + osmoIbcDispatcherContractAddress, + osmoEchoContractAddress, link, } = await demoSetup(); @@ -173,11 +294,13 @@ test.serial("ping the remote chain", async (t) => { // assertPacketsFromA(info, 1, true); // Query to see connections + t.log("Get Wasm connections"); const wasmConnections = ( - await showConnections(wasmClient, wasmContract1Address) + await showConnections(wasmClient, wasmIbcDispatcherContractAddress) ).connections; + t.log("Get Osmo connections"); const osmoConnections = ( - await showConnections(osmoClient, osmoContract1Address) + await showConnections(osmoClient, osmoIbcDispatcherContractAddress) ).connections; t.is(wasmConnections.length, 1); @@ -187,10 +310,24 @@ test.serial("ping the remote chain", async (t) => { const channelId = wasmConnections[0]; - t.log(`Wasm channel id: ${wasmConnections[0]}`); - t.log(`Osmo channel id: ${osmoConnections[0]}`); - //Send msg with ping - await sendPing(wasmClient, wasmContract1Address, channelId); + t.log(`Wasm channel ids: ${wasmConnections}`); + t.log(`Osmo channel ids: ${osmoConnections}`); + // Send dispatch msg + const msg = { + dispatch: { + dispatcher_address: wasmIbcDispatcherContractAddress, + channel: channelId, + target_address: osmoEchoContractAddress, + echo: "testecho", + }, + }; + t.log(`Executing ${JSON.stringify(msg)} on channel ${channelId}`); + const response = await executeContract( + wasmClient, + wasmIbcDispatcherContractAddress, + msg + ); + t.log(`>>>dispatch response: ${JSON.stringify(response)}`); //relay const info = await link.relayAll(); @@ -205,18 +342,4 @@ test.serial("ping the remote chain", async (t) => { //Assert it is pong. t.is(ackResult.result, "pong"); - - const wasmCounter = ( - await showCounter(wasmClient, wasmContract1Address, channelId) - ).count; - - t.is(wasmCounter, 1); - t.log(`Wasm counter: ${wasmCounter}`); - - const osmoCounter = ( - await showCounter(osmoClient, osmoContract1Address, channelId) - ).count; - - t.is(osmoCounter, 0); - t.log(`Wasm counter: ${osmoCounter}`); }); diff --git a/tests/src/utils.ts b/tests/src/utils.ts index e58f7b4..f0ad951 100644 --- a/tests/src/utils.ts +++ b/tests/src/utils.ts @@ -12,7 +12,6 @@ import { Order } from "cosmjs-types/ibc/core/channel/v1/channel"; const { fundAccount, - generateMnemonic, osmosis: oldOsmo, signingCosmWasmClient, wasmd, @@ -49,7 +48,8 @@ export async function setupContracts( // This creates a client for the CosmWasm chain, that can interact with contracts export async function setupWasmClient(): Promise { // create apps and fund an account - const mnemonic = generateMnemonic(); + const mnemonic = // using same mnemonic as defined in WBA TWT testnet scripts + "harsh adult scrub stadium solution impulse company agree tomorrow poem dirt innocent coyote slight nice digital scissors cool pact person item moon double wagon"; const cosmwasm = await signingCosmWasmClient(wasmd, mnemonic); await fundAccount(wasmd, cosmwasm.senderAddress, "4000000"); return cosmwasm; @@ -58,7 +58,8 @@ export async function setupWasmClient(): Promise { // This creates a client for the CosmWasm chain, that can interact with contracts export async function setupOsmosisClient(): Promise { // create apps and fund an account - const mnemonic = generateMnemonic(); + const mnemonic = // using same mnemonic as defined in WBA TWT testnet scripts + "harsh adult scrub stadium solution impulse company agree tomorrow poem dirt innocent coyote slight nice digital scissors cool pact person item moon double wagon"; const cosmwasm = await signingCosmWasmClient(osmosis, mnemonic); await fundAccount(osmosis, cosmwasm.senderAddress, "4000000"); return cosmwasm;