From ab0c14bb655d0ac1fb995c3fbe379f11f0d23263 Mon Sep 17 00:00:00 2001 From: ibrizsabin Date: Wed, 25 Sep 2024 20:24:47 +0545 Subject: [PATCH] fix: add initial commit --- .cargo/config | 4 - Cargo.lock | 739 +----------------- Cargo.toml | 8 +- .../cw-centralized-connection/Cargo.toml | 45 -- .../cw-centralized-connection/src/contract.rs | 216 ----- .../cw-centralized-connection/src/errors.rs | 21 - .../cw-centralized-connection/src/helper.rs | 85 -- .../cw-centralized-connection/src/lib.rs | 97 --- .../cw-centralized-connection/src/msg.rs | 49 -- .../cw-centralized-connection/src/state.rs | 113 --- .../cw-centralized-connection/src/types.rs | 33 - .../cw-centralized-connection/tests/test.rs | 219 ------ .../cosmwasm-vm/cw-integration/Cargo.toml | 34 - .../cosmwasm-vm/cw-integration/tests/setup.rs | 277 ------- .../cw-integration/tests/test_xcall.rs | 494 ------------ .../Cargo.toml | 4 +- .../cosmwasm-vm/cw-intents-v1/src/contract.rs | 39 + .../src/errors.rs | 0 .../cosmwasm-vm/cw-intents-v1/src/lib.rs | 100 +++ .../cosmwasm-vm/cw-intents-v1/src/msg.rs | 44 ++ .../cosmwasm-vm/cw-intents-v1/src/state.rs | 109 +++ .../cosmwasm-vm/cw-intents-v1/src/types.rs | 210 +++++ .../tests/setup.rs | 0 .../cosmwasm-vm/cw-mock-dapp/src/contract.rs | 143 ---- .../cosmwasm-vm/cw-mock-dapp/src/helper.rs | 25 - contracts/cosmwasm-vm/cw-mock-dapp/src/lib.rs | 113 --- contracts/cosmwasm-vm/cw-mock-dapp/src/msg.rs | 40 - .../cosmwasm-vm/cw-mock-dapp/src/state.rs | 37 - .../cosmwasm-vm/cw-mock-dapp/src/types.rs | 31 - .../cw-mock-dapp/tests/mock_test.rs | 191 ----- .../cosmwasm-vm/cw-mock-dapp/tests/setup.rs | 14 - 31 files changed, 514 insertions(+), 3020 deletions(-) delete mode 100644 .cargo/config delete mode 100644 contracts/cosmwasm-vm/cw-centralized-connection/Cargo.toml delete mode 100644 contracts/cosmwasm-vm/cw-centralized-connection/src/contract.rs delete mode 100644 contracts/cosmwasm-vm/cw-centralized-connection/src/errors.rs delete mode 100644 contracts/cosmwasm-vm/cw-centralized-connection/src/helper.rs delete mode 100644 contracts/cosmwasm-vm/cw-centralized-connection/src/lib.rs delete mode 100644 contracts/cosmwasm-vm/cw-centralized-connection/src/msg.rs delete mode 100644 contracts/cosmwasm-vm/cw-centralized-connection/src/state.rs delete mode 100644 contracts/cosmwasm-vm/cw-centralized-connection/src/types.rs delete mode 100644 contracts/cosmwasm-vm/cw-centralized-connection/tests/test.rs delete mode 100644 contracts/cosmwasm-vm/cw-integration/Cargo.toml delete mode 100644 contracts/cosmwasm-vm/cw-integration/tests/setup.rs delete mode 100644 contracts/cosmwasm-vm/cw-integration/tests/test_xcall.rs rename contracts/cosmwasm-vm/{cw-mock-dapp => cw-intents-v1}/Cargo.toml (95%) create mode 100644 contracts/cosmwasm-vm/cw-intents-v1/src/contract.rs rename contracts/cosmwasm-vm/{cw-mock-dapp => cw-intents-v1}/src/errors.rs (100%) create mode 100644 contracts/cosmwasm-vm/cw-intents-v1/src/lib.rs create mode 100644 contracts/cosmwasm-vm/cw-intents-v1/src/msg.rs create mode 100644 contracts/cosmwasm-vm/cw-intents-v1/src/state.rs create mode 100644 contracts/cosmwasm-vm/cw-intents-v1/src/types.rs rename contracts/cosmwasm-vm/{cw-centralized-connection => cw-intents-v1}/tests/setup.rs (100%) delete mode 100644 contracts/cosmwasm-vm/cw-mock-dapp/src/contract.rs delete mode 100644 contracts/cosmwasm-vm/cw-mock-dapp/src/helper.rs delete mode 100644 contracts/cosmwasm-vm/cw-mock-dapp/src/lib.rs delete mode 100644 contracts/cosmwasm-vm/cw-mock-dapp/src/msg.rs delete mode 100644 contracts/cosmwasm-vm/cw-mock-dapp/src/state.rs delete mode 100644 contracts/cosmwasm-vm/cw-mock-dapp/src/types.rs delete mode 100644 contracts/cosmwasm-vm/cw-mock-dapp/tests/mock_test.rs delete mode 100644 contracts/cosmwasm-vm/cw-mock-dapp/tests/setup.rs diff --git a/.cargo/config b/.cargo/config deleted file mode 100644 index 7e36d9af..00000000 --- a/.cargo/config +++ /dev/null @@ -1,4 +0,0 @@ -[alias] -wasm = "build --workspace --exclude test-utils --release --lib --target wasm32-unknown-unknown" -unit-test = "test --lib" -schema = "run --bin schema" diff --git a/Cargo.lock b/Cargo.lock index ae3ea0de..37e708eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,12 +25,6 @@ version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" -[[package]] -name = "arrayvec" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" - [[package]] name = "autocfg" version = "1.1.0" @@ -109,57 +103,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56953345e39537a3e18bdaeba4cb0c58a78c1f61f361dc0fa7c5c7340ae87c5f" -[[package]] -name = "borsh" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4114279215a005bc675e386011e594e1d9b800918cea18fcadadcce864a2046b" -dependencies = [ - "borsh-derive", - "hashbrown 0.12.3", -] - -[[package]] -name = "borsh-derive" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0754613691538d51f329cce9af41d7b7ca150bc973056f1156611489475f54f7" -dependencies = [ - "borsh-derive-internal", - "borsh-schema-derive-internal", - "proc-macro-crate 0.1.5", - "proc-macro2 1.0.70", - "syn 1.0.109", -] - -[[package]] -name = "borsh-derive-internal" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb438156919598d2c7bad7e1c0adf3d26ed3840dbc010db1a882a65583ca2fb" -dependencies = [ - "proc-macro2 1.0.70", - "quote 1.0.33", - "syn 1.0.109", -] - -[[package]] -name = "borsh-schema-derive-internal" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634205cc43f74a1b9046ef87c4540ebda95696ec0f315024860cad7c5b0f5ccd" -dependencies = [ - "proc-macro2 1.0.70", - "quote 1.0.33", - "syn 1.0.109", -] - -[[package]] -name = "byte-slice-cast" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" - [[package]] name = "byteorder" version = "1.4.3" @@ -338,12 +281,6 @@ 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.4.9" @@ -392,107 +329,7 @@ dependencies = [ ] [[package]] -name = "curve25519-dalek-ng" -version = "4.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c359b7249347e46fb28804470d071c921156ad62b3eef5d34e2ba867533dec8" -dependencies = [ - "byteorder", - "digest 0.9.0", - "rand_core 0.6.4", - "subtle-ng", - "zeroize", -] - -[[package]] -name = "cw-centralized-connection" -version = "0.1.0" -dependencies = [ - "common", - "cosmwasm", - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 1.1.0", - "cw-xcall-lib 0.1.0", - "cw2 1.0.1", - "getrandom", - "hex", - "schemars 0.8.12", - "serde", - "serde-json-wasm 0.5.2", - "thiserror", -] - -[[package]] -name = "cw-common" -version = "0.1.1" -source = "git+https://github.com/icon-project/IBC-Integration.git?branch=main#9a9095926b9141217473745d21ad06c277313015" -dependencies = [ - "bech32", - "bytes", - "common", - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 1.1.0", - "cw-xcall-lib 0.1.0 (git+https://github.com/icon-project/xCall.git?tag=v0.1.0-alpha.5)", - "debug_print", - "hex", - "hex-buffer-serde", - "ibc-proto", - "prost 0.11.9", - "schemars 0.8.12", - "serde", - "serde-json-wasm 0.5.2", - "serde_json", -] - -[[package]] -name = "cw-integration" -version = "0.2.1" -dependencies = [ - "anyhow", - "common", - "cosmwasm-schema", - "cosmwasm-std", - "cw-common", - "cw-mock-dapp", - "cw-mock-dapp-multi", - "cw-mock-ibc-core", - "cw-multi-test 0.15.1", - "cw-storage-plus 1.1.0", - "cw-xcall 0.2.1", - "cw-xcall-ibc-connection", - "cw-xcall-lib 0.1.0", - "cw-xcall-lib 0.1.0 (git+https://github.com/icon-project/xCall.git?tag=v0.1.0-alpha.5)", - "hex", - "ibc", - "prost 0.11.9", - "strum", - "strum_macros", -] - -[[package]] -name = "cw-mock-dapp" -version = "0.1.0" -dependencies = [ - "common", - "cosmwasm", - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-multi-test 0.16.4", - "cw-storage-plus 1.1.0", - "cw-xcall-lib 0.1.0", - "cw2 1.0.1", - "getrandom", - "schemars 0.8.12", - "serde", - "serde-json-wasm 0.5.2", - "thiserror", -] - -[[package]] -name = "cw-mock-dapp-multi" +name = "cw-intents-v1" version = "0.1.0" dependencies = [ "common", @@ -500,52 +337,14 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", - "cw-multi-test 0.16.4", + "cw-multi-test", "cw-storage-plus 1.1.0", - "cw-xcall-lib 0.1.0", - "cw2 1.0.1", + "cw2", "getrandom", - "schemars 0.8.12", - "serde", - "serde-json-wasm 0.5.2", - "thiserror", -] - -[[package]] -name = "cw-mock-ibc-core" -version = "0.1.1" -source = "git+https://github.com/icon-project/IBC-Integration.git?branch=main#9a9095926b9141217473745d21ad06c277313015" -dependencies = [ - "common", - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-common", - "cw-storage-plus 1.1.0", - "cw-xcall 0.2.0", - "cw2 1.0.1", "hex", "schemars 0.8.12", "serde", - "thiserror", -] - -[[package]] -name = "cw-multi-test" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8e81b4a7821d5eeba0d23f737c16027b39a600742ca8c32eb980895ffd270f4" -dependencies = [ - "anyhow", - "cosmwasm-std", - "cosmwasm-storage", - "cw-storage-plus 0.15.1", - "cw-utils 0.15.1", - "derivative", - "itertools", - "prost 0.9.0", - "schemars 0.8.12", - "serde", + "serde-json-wasm 0.5.2", "thiserror", ] @@ -558,7 +357,7 @@ dependencies = [ "anyhow", "cosmwasm-std", "cw-storage-plus 1.0.1", - "cw-utils 1.0.1", + "cw-utils", "derivative", "itertools", "k256 0.11.6", @@ -568,17 +367,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "cw-storage-plus" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc6cf70ef7686e2da9ad7b067c5942cd3e88dd9453f7af42f54557f8af300fb0" -dependencies = [ - "cosmwasm-std", - "schemars 0.8.12", - "serde", -] - [[package]] name = "cw-storage-plus" version = "1.0.1" @@ -600,21 +388,6 @@ dependencies = [ "serde", ] -[[package]] -name = "cw-utils" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ae0b69fa7679de78825b4edeeec045066aa2b2c4b6e063d80042e565bb4da5c" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw2 0.15.1", - "schemars 0.8.12", - "semver", - "serde", - "thiserror", -] - [[package]] name = "cw-utils" version = "1.0.1" @@ -623,158 +396,13 @@ checksum = "c80e93d1deccb8588db03945016a292c3c631e6325d349ebb35d2db6f4f946f7" dependencies = [ "cosmwasm-schema", "cosmwasm-std", - "cw2 1.0.1", + "cw2", "schemars 0.8.12", "semver", "serde", "thiserror", ] -[[package]] -name = "cw-xcall" -version = "0.1.0" -source = "git+https://github.com/icon-project/xCall.git?tag=v0.1.0-alpha.5#7f250bc9c6560591ccc16289cb8159dd100bbe76" -dependencies = [ - "common", - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-storage-plus 1.1.0", - "cw-xcall-lib 0.1.0 (git+https://github.com/icon-project/xCall.git?tag=v0.1.0-alpha.5)", - "cw2 1.0.1", - "debug_print", - "schemars 0.8.12", - "serde", - "thiserror", -] - -[[package]] -name = "cw-xcall" -version = "0.2.0" -source = "git+https://github.com/icon-project/xCall.git?branch=main#1b64d8d3b932842bdc68d7fabc3842a7695860ed" -dependencies = [ - "common", - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-storage-plus 1.1.0", - "cw-xcall-lib 0.1.0 (git+https://github.com/icon-project/xCall.git?branch=main)", - "cw2 1.0.1", - "debug_print", - "schemars 0.8.12", - "serde", - "thiserror", -] - -[[package]] -name = "cw-xcall" -version = "0.2.1" -dependencies = [ - "anyhow", - "common", - "cosmwasm", - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-storage-plus 1.1.0", - "cw-xcall-lib 0.1.0", - "cw2 1.0.1", - "debug_print", - "getrandom", - "hex", - "schemars 0.8.12", - "serde", - "test-utils", - "thiserror", -] - -[[package]] -name = "cw-xcall-ibc-connection" -version = "0.1.1" -source = "git+https://github.com/icon-project/IBC-Integration.git?branch=main#9a9095926b9141217473745d21ad06c277313015" -dependencies = [ - "common", - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-common", - "cw-storage-plus 1.1.0", - "cw-xcall 0.1.0", - "cw-xcall-lib 0.1.0 (git+https://github.com/icon-project/xCall.git?tag=v0.1.0-alpha.5)", - "cw2 1.0.1", - "debug_print", - "hex", - "schemars 0.8.12", - "serde", - "thiserror", -] - -[[package]] -name = "cw-xcall-lib" -version = "0.1.0" -dependencies = [ - "anyhow", - "common", - "cosmwasm", - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-storage-plus 1.1.0", - "cw2 1.0.1", - "debug_print", - "getrandom", - "hex", - "schemars 0.8.12", - "serde", - "test-utils", - "thiserror", -] - -[[package]] -name = "cw-xcall-lib" -version = "0.1.0" -source = "git+https://github.com/icon-project/xCall.git?tag=v0.1.0-alpha.5#7f250bc9c6560591ccc16289cb8159dd100bbe76" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-storage-plus 1.1.0", - "cw2 1.0.1", - "debug_print", - "schemars 0.8.12", - "serde", - "thiserror", -] - -[[package]] -name = "cw-xcall-lib" -version = "0.1.0" -source = "git+https://github.com/icon-project/xCall.git?branch=main#1b64d8d3b932842bdc68d7fabc3842a7695860ed" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cosmwasm-storage", - "cw-storage-plus 1.1.0", - "cw2 1.0.1", - "debug_print", - "schemars 0.8.12", - "serde", - "thiserror", -] - -[[package]] -name = "cw2" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5abb8ecea72e09afff830252963cb60faf945ce6cef2c20a43814516082653da" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 0.15.1", - "schemars 0.8.12", - "serde", -] - [[package]] name = "cw2" version = "1.0.1" @@ -915,19 +543,6 @@ dependencies = [ "signature 1.6.4", ] -[[package]] -name = "ed25519-consensus" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c8465edc8ee7436ffea81d21a019b16676ee3db267aa8d5a8d729581ecf998b" -dependencies = [ - "curve25519-dalek-ng", - "hex", - "rand_core 0.6.4", - "sha2 0.9.9", - "zeroize", -] - [[package]] name = "ed25519-zebra" version = "3.1.0" @@ -935,7 +550,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" dependencies = [ "curve25519-dalek", - "hashbrown 0.12.3", + "hashbrown", "hex", "rand_core 0.6.4", "serde", @@ -988,21 +603,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "erased-serde" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c138974f9d5e7fe373eb04df7cae98833802ae4b11c24ac7039a21d5af4b26c" -dependencies = [ - "serde", -] - [[package]] name = "errno" version = "0.3.1" @@ -1053,15 +653,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "fixed-hash" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" -dependencies = [ - "static_assertions", -] - [[package]] name = "fixedbitset" version = "0.4.2" @@ -1197,12 +788,6 @@ dependencies = [ "ahash", ] -[[package]] -name = "hashbrown" -version = "0.14.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" - [[package]] name = "heck" version = "0.4.1" @@ -1221,16 +806,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "hex-buffer-serde" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7e84645a601cf4a58f40673d51c111d1b5f847b711559c076ebcb779606a6d0" -dependencies = [ - "hex", - "serde", -] - [[package]] name = "hex-literal" version = "0.3.4" @@ -1246,39 +821,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "ibc" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "030b54b02c3f35ea7265da2beedf0d7d22492208919a6582f980ff3eae82c2d0" -dependencies = [ - "bytes", - "cfg-if", - "derive_more", - "displaydoc", - "dyn-clone", - "erased-serde", - "ibc-proto", - "ics23", - "num-traits", - "parity-scale-codec", - "primitive-types", - "prost 0.11.9", - "safe-regex", - "scale-info", - "serde", - "serde_derive", - "serde_json", - "sha2 0.10.6", - "subtle-encoding", - "tendermint", - "tendermint-light-client-verifier", - "tendermint-proto", - "time", - "tracing", - "uint", -] - [[package]] name = "ibc-proto" version = "0.26.0" @@ -1286,12 +828,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9303a1308c886aea769ef0667c5caa422a78b01e9f8177fea8b91b08a4ff50c" dependencies = [ "base64 0.13.1", - "borsh", "bytes", "flex-error", - "parity-scale-codec", "prost 0.11.9", - "scale-info", "serde", "subtle-encoding", "tendermint-proto", @@ -1312,26 +851,6 @@ dependencies = [ "sha3", ] -[[package]] -name = "impl-serde" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc88fc67028ae3db0c853baa36269d398d5f45b6982f95549ff5def78c935cd" -dependencies = [ - "serde", -] - -[[package]] -name = "impl-trait-for-tuples" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" -dependencies = [ - "proc-macro2 1.0.70", - "quote 1.0.33", - "syn 1.0.109", -] - [[package]] name = "indexmap" version = "1.9.3" @@ -1339,17 +858,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", - "hashbrown 0.12.3", -] - -[[package]] -name = "indexmap" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" -dependencies = [ - "equivalent", - "hashbrown 0.14.3", + "hashbrown", ] [[package]] @@ -1446,12 +955,6 @@ version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de" -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - [[package]] name = "multimap" version = "0.8.3" @@ -1490,30 +993,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" -[[package]] -name = "parity-scale-codec" -version = "3.6.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "881331e34fa842a2fb61cc2db9643a8fedc615e47cfcc52597d1af0db9a7e8fe" -dependencies = [ - "arrayvec", - "byte-slice-cast", - "impl-trait-for-tuples", - "parity-scale-codec-derive", -] - -[[package]] -name = "parity-scale-codec-derive" -version = "3.6.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be30eaf4b0a9fba5336683b38de57bb86d179a35862ba6bfcf57625d006bde5b" -dependencies = [ - "proc-macro-crate 2.0.1", - "proc-macro2 1.0.70", - "quote 1.0.33", - "syn 1.0.109", -] - [[package]] name = "paste" version = "1.0.12" @@ -1564,7 +1043,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4" dependencies = [ "fixedbitset", - "indexmap 1.9.3", + "indexmap", ] [[package]] @@ -1609,46 +1088,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "primitive-types" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" -dependencies = [ - "fixed-hash", - "impl-serde", - "uint", -] - -[[package]] -name = "proc-macro-crate" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" -dependencies = [ - "toml", -] - -[[package]] -name = "proc-macro-crate" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" -dependencies = [ - "once_cell", - "toml_edit 0.19.15", -] - -[[package]] -name = "proc-macro-crate" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97dc5fea232fc28d2f597b37c4876b348a40e33f3b02cc975c8d006d78d94b1a" -dependencies = [ - "toml_datetime", - "toml_edit 0.20.2", -] - [[package]] name = "proc-macro2" version = "0.4.30" @@ -1862,12 +1301,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "rustversion" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" - [[package]] name = "ryu" version = "1.0.13" @@ -1921,30 +1354,6 @@ dependencies = [ "safe-regex-compiler", ] -[[package]] -name = "scale-info" -version = "2.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f7d66a1128282b7ef025a8ead62a4a9fcf017382ec53b8ffbf4d7bf77bd3c60" -dependencies = [ - "cfg-if", - "derive_more", - "parity-scale-codec", - "scale-info-derive", -] - -[[package]] -name = "scale-info-derive" -version = "2.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf2c68b89cafb3b8d918dd07b42be0da66ff202cf1155c5739a4e0c1ea0dc19" -dependencies = [ - "proc-macro-crate 1.3.1", - "proc-macro2 1.0.70", - "quote 1.0.33", - "syn 1.0.109", -] - [[package]] name = "schemars" version = "0.5.1" @@ -2218,25 +1627,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "strum" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" - -[[package]] -name = "strum_macros" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" -dependencies = [ - "heck", - "proc-macro2 1.0.70", - "quote 1.0.33", - "rustversion", - "syn 1.0.109", -] - [[package]] name = "subtle" version = "2.5.0" @@ -2252,12 +1642,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "subtle-ng" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "734676eb262c623cec13c3155096e08d1f8f29adce39ba17948b18dad1e54142" - [[package]] name = "syn" version = "0.15.44" @@ -2313,7 +1697,6 @@ dependencies = [ "bytes", "digest 0.10.7", "ed25519", - "ed25519-consensus", "flex-error", "futures", "num-traits", @@ -2324,7 +1707,6 @@ dependencies = [ "serde_bytes", "serde_json", "serde_repr", - "sha2 0.10.6", "signature 1.6.4", "subtle", "subtle-encoding", @@ -2333,19 +1715,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "tendermint-light-client-verifier" -version = "0.29.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11c3dc3c75f7a5708ac0bf98374b2b1a2cf17b3a45ddfd5faab3c111aff7fc0e" -dependencies = [ - "derive_more", - "flex-error", - "serde", - "tendermint", - "time", -] - [[package]] name = "tendermint-proto" version = "0.29.1" @@ -2364,22 +1733,6 @@ dependencies = [ "time", ] -[[package]] -name = "test-utils" -version = "0.1.0" -source = "git+https://github.com/icon-project/IBC-Integration.git?branch=main#9a9095926b9141217473745d21ad06c277313015" -dependencies = [ - "common", - "cosmwasm-std", - "cw-multi-test 0.16.4", - "hex", - "hex-literal", - "ibc-proto", - "prost 0.11.9", - "serde", - "serde_json", -] - [[package]] name = "thiserror" version = "1.0.40" @@ -2425,77 +1778,12 @@ dependencies = [ "time-core", ] -[[package]] -name = "toml" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" -dependencies = [ - "serde", -] - -[[package]] -name = "toml_datetime" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" - -[[package]] -name = "toml_edit" -version = "0.19.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" -dependencies = [ - "indexmap 2.1.0", - "toml_datetime", - "winnow", -] - -[[package]] -name = "toml_edit" -version = "0.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" -dependencies = [ - "indexmap 2.1.0", - "toml_datetime", - "winnow", -] - -[[package]] -name = "tracing" -version = "0.1.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" -dependencies = [ - "pin-project-lite", - "tracing-core", -] - -[[package]] -name = "tracing-core" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" - [[package]] name = "typenum" version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" -[[package]] -name = "uint" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" -dependencies = [ - "byteorder", - "crunchy", - "hex", - "static_assertions", -] - [[package]] name = "unicode-ident" version = "1.0.9" @@ -2669,15 +1957,6 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" -[[package]] -name = "winnow" -version = "0.5.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b5c3db89721d50d0e2a673f5043fc4722f76dcc352d7b1ab8b8288bed4ed2c5" -dependencies = [ - "memchr", -] - [[package]] name = "zeroize" version = "1.8.1" diff --git a/Cargo.toml b/Cargo.toml index 8ee82d52..25ea8802 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,6 @@ [workspace] members = [ "contracts/cosmwasm-vm/*", - "contracts/soroban/contracts/*", - "contracts/soroban/libs/*" ] [workspace.package] @@ -28,15 +26,11 @@ bytes = { version = "1.4.0", default-features = false } thiserror = { version = "1.0.39" } hex ={ version = "0.4.3", default-features = false } debug_print = "1.0.0" -cw-xcall-lib = { path="contracts/cosmwasm-vm/cw-xcall-lib" } -cw-xcall={ path="contracts/cosmwasm-vm/cw-xcall" } -cw-xcall-ibc-connection = { git="https://github.com/icon-project/IBC-Integration.git", branch = "main" } -cw-mock-ibc-core = { git="https://github.com/icon-project/IBC-Integration.git", branch = "main"} + common = { git="https://github.com/icon-project/IBC-Integration.git", branch = "main" } cw-common={ git="https://github.com/icon-project/IBC-Integration.git", branch = "main" } cw-mock-dapp = {path="contracts/cosmwasm-vm/cw-mock-dapp"} -cw-mock-dapp-multi = { path="contracts/cosmwasm-vm/cw-mock-dapp-multi"} soroban-sdk = "21.6.0" diff --git a/contracts/cosmwasm-vm/cw-centralized-connection/Cargo.toml b/contracts/cosmwasm-vm/cw-centralized-connection/Cargo.toml deleted file mode 100644 index 2fe703c7..00000000 --- a/contracts/cosmwasm-vm/cw-centralized-connection/Cargo.toml +++ /dev/null @@ -1,45 +0,0 @@ -[package] -name = "cw-centralized-connection" -version = "0.1.0" -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"] -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.10 -""" - -[dependencies] -cosmwasm-schema = {workspace=true} -cosmwasm-std = { workspace=true} -cw-storage-plus = {workspace=true} -cw2 = {workspace=true} -schemars = {workspace=true} -serde = { workspace=true} -thiserror = { workspace=true} -common ={ workspace=true} -cw-xcall-lib = { path="../cw-xcall-lib" } -hex = "0.4.3" -serde-json-wasm = {workspace=true} - -[dev-dependencies] -cosmwasm = "0.7.2" -getrandom = {version = "0.2", default-features = false, features = ["custom"]} - diff --git a/contracts/cosmwasm-vm/cw-centralized-connection/src/contract.rs b/contracts/cosmwasm-vm/cw-centralized-connection/src/contract.rs deleted file mode 100644 index a50561c8..00000000 --- a/contracts/cosmwasm-vm/cw-centralized-connection/src/contract.rs +++ /dev/null @@ -1,216 +0,0 @@ -use cosmwasm_std::{coins, Addr, BankMsg, Event, SubMsgResult, Uint128}; -use cw_xcall_lib::network_address::NetId; - -use super::*; - -// version info for migration info -const CONTRACT_NAME: &str = "crates.io:cw-mock-dapp"; -const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); - -impl<'a> CwCentralizedConnection<'a> { - pub fn instantiate( - &mut self, - deps: DepsMut, - _env: Env, - _info: MessageInfo, - msg: InstantiateMsg, - ) -> Result { - set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; - - let relayer = deps.api.addr_validate(&msg.relayer)?; - self.store_admin(deps.storage, relayer)?; - - let xcall_address = deps.api.addr_validate(&msg.xcall_address)?; - self.store_xcall(deps.storage, xcall_address)?; - self.store_denom(deps.storage, msg.denom)?; - - let _ = self.store_conn_sn(deps.storage, 0); - - Ok(Response::new() - .add_attribute("action", "instantiate") - .add_attribute("relayer", msg.relayer) - .add_attribute("xcall_address", msg.xcall_address)) - } - - pub fn send_message( - &mut self, - deps: DepsMut, - info: MessageInfo, - to: NetId, - sn: i64, - msg: Vec, - ) -> Result { - self.ensure_xcall(deps.storage, info.sender)?; - - let next_conn_sn = self.get_next_conn_sn(deps.storage)?; - - let mut fee = 0; - - if sn >= 0 { - fee = self.get_fee(deps.storage, to.clone(), sn > 0)?.into(); - } - - let value = self.get_amount_for_denom(&info.funds, self.denom(deps.storage)); - - if fee > value { - return Err(ContractError::InsufficientFunds); - } - - Ok(Response::new() - .add_attribute("action", "send_message") - .add_event( - Event::new("Message") - .add_attribute("targetNetwork", to.to_string()) - .add_attribute("connSn", next_conn_sn.to_string()) - .add_attribute("msg", self.hex_encode(msg)), - )) - } - - pub fn recv_message( - &mut self, - deps: DepsMut, - info: MessageInfo, - src_network: NetId, - conn_sn: u128, - msg: String, - ) -> Result { - self.ensure_admin(deps.storage, info.sender)?; - - let hex_string_trimmed = msg.trim_start_matches("0x"); - let bytes = hex::decode(hex_string_trimmed).expect("Failed to decode to vec"); - - let vec_msg: Vec = Binary(bytes).into(); - if self.get_receipt(deps.as_ref().storage, src_network.clone(), conn_sn) { - return Err(ContractError::DuplicateMessage); - } - self.store_receipt(deps.storage, src_network.clone(), conn_sn)?; - - let xcall_submessage = - self.call_xcall_handle_message(deps.storage, &src_network, vec_msg)?; - - Ok(Response::new().add_submessage(xcall_submessage)) - } - - pub fn claim_fees( - &self, - deps: DepsMut, - env: Env, - info: MessageInfo, - ) -> Result { - self.ensure_admin(deps.storage, info.sender)?; - let contract_balance = self.get_balance(&deps, env, self.denom(deps.storage)); - let msg = BankMsg::Send { - to_address: self.query_admin(deps.storage)?.to_string(), - amount: coins(contract_balance, self.denom(deps.storage)), - }; - Ok(Response::new() - .add_attribute("action", "claim fees") - .add_message(msg)) - } - - pub fn revert_message( - &self, - deps: DepsMut, - info: MessageInfo, - sn: u128, - ) -> Result { - self.ensure_admin(deps.storage, info.sender)?; - let xcall_submessage = self.call_xcall_handle_error(deps.storage, sn)?; - - Ok(Response::new().add_submessage(xcall_submessage)) - } - - pub fn set_admin( - &mut self, - deps: DepsMut, - info: MessageInfo, - address: Addr, - ) -> Result { - self.ensure_admin(deps.storage, info.sender)?; - let admin = deps.api.addr_validate(address.as_str())?; - let _ = self.store_admin(deps.storage, admin); - Ok(Response::new().add_attribute("action", "set_admin")) - } - - pub fn set_fee( - &mut self, - deps: DepsMut, - info: MessageInfo, - network_id: NetId, - message_fee: u128, - response_fee: u128, - ) -> Result { - self.ensure_admin(deps.storage, info.sender)?; - self.store_fee(deps.storage, network_id, message_fee, response_fee)?; - Ok(Response::new().add_attribute("action", "set_fee")) - } - - pub fn get_fee( - &self, - store: &dyn Storage, - network_id: NetId, - response: bool, - ) -> Result { - let mut fee = self.query_message_fee(store, network_id.clone()); - if response { - fee += self.query_response_fee(store, network_id); - } - Ok(fee.into()) - } - - fn xcall_handle_message_reply( - &self, - _deps: DepsMut, - message: Reply, - ) -> Result { - println!("Reply From Forward XCall"); - match message.result { - SubMsgResult::Ok(_) => Ok(Response::new() - .add_attribute("action", "call_message") - .add_attribute("method", "xcall_handle_message_reply")), - SubMsgResult::Err(error) => Err(ContractError::ReplyError { - code: message.id, - msg: error, - }), - } - } - - fn xcall_handle_error_reply( - &self, - _deps: DepsMut, - message: Reply, - ) -> Result { - println!("Reply From Forward XCall"); - match message.result { - SubMsgResult::Ok(_) => Ok(Response::new() - .add_attribute("action", "call_message") - .add_attribute("method", "xcall_handle_error_reply")), - SubMsgResult::Err(error) => Err(ContractError::ReplyError { - code: message.id, - msg: error, - }), - } - } - - pub fn reply(&self, deps: DepsMut, _env: Env, msg: Reply) -> Result { - match msg.id { - XCALL_HANDLE_MESSAGE_REPLY_ID => self.xcall_handle_message_reply(deps, msg), - XCALL_HANDLE_ERROR_REPLY_ID => self.xcall_handle_error_reply(deps, msg), - _ => Err(ContractError::ReplyError { - code: msg.id, - msg: "Unknown".to_string(), - }), - } - } - - pub fn migrate( - &self, - deps: DepsMut, - _env: Env, - _msg: MigrateMsg, - ) -> Result { - set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION) - .map_err(ContractError::Std)?; - Ok(Response::default().add_attribute("migrate", "successful")) - } -} diff --git a/contracts/cosmwasm-vm/cw-centralized-connection/src/errors.rs b/contracts/cosmwasm-vm/cw-centralized-connection/src/errors.rs deleted file mode 100644 index 25760e19..00000000 --- a/contracts/cosmwasm-vm/cw-centralized-connection/src/errors.rs +++ /dev/null @@ -1,21 +0,0 @@ -use super::*; - -#[derive(Error, Debug)] -pub enum ContractError { - #[error("{0}")] - Std(#[from] StdError), - #[error("Unauthorized")] - Unauthorized {}, - #[error("Invalid Address {address}")] - InvalidAddress { address: String }, - #[error("Only Relayer(Admin)")] - OnlyAdmin, - #[error("Only XCall")] - OnlyXCall, - #[error("Duplicate Message")] - DuplicateMessage, - #[error("InsufficientFunds")] - InsufficientFunds, - #[error("ERR_REPLY_ERROR|{code:?}|{msg:?}")] - ReplyError { code: u64, msg: String }, -} diff --git a/contracts/cosmwasm-vm/cw-centralized-connection/src/helper.rs b/contracts/cosmwasm-vm/cw-centralized-connection/src/helper.rs deleted file mode 100644 index 496a16dc..00000000 --- a/contracts/cosmwasm-vm/cw-centralized-connection/src/helper.rs +++ /dev/null @@ -1,85 +0,0 @@ -use cosmwasm_std::{ensure_eq, Addr, BalanceResponse, BankQuery, Coin}; -use cw_xcall_lib::network_address::NetId; - -pub const XCALL_HANDLE_MESSAGE_REPLY_ID: u64 = 1; -pub const XCALL_HANDLE_ERROR_REPLY_ID: u64 = 2; -use super::*; - -impl<'a> CwCentralizedConnection<'a> { - pub fn ensure_admin(&self, store: &dyn Storage, address: Addr) -> Result<(), ContractError> { - let admin = self.query_admin(store)?; - ensure_eq!(admin, address, ContractError::OnlyAdmin); - - Ok(()) - } - - pub fn ensure_xcall(&self, store: &dyn Storage, address: Addr) -> Result<(), ContractError> { - let xcall = self.query_xcall(store)?; - ensure_eq!(xcall, address, ContractError::OnlyXCall); - - Ok(()) - } - - pub fn get_amount_for_denom(&self, funds: &Vec, target_denom: String) -> u128 { - for coin in funds.iter() { - if coin.denom == target_denom { - return coin.amount.into(); - } - } - 0 - } - - pub fn get_balance(&self, deps: &DepsMut, env: Env, denom: String) -> u128 { - let address = env.contract.address.to_string(); - let balance_query = BankQuery::Balance { denom, address }; - let balance_response: BalanceResponse = deps.querier.query(&balance_query.into()).unwrap(); - - balance_response.amount.amount.u128() - } - - pub fn hex_encode(&self, data: Vec) -> String { - if data.is_empty() { - "null".to_string() - } else { - hex::encode(data) - } - } - - pub fn call_xcall_handle_message( - &self, - store: &dyn Storage, - nid: &NetId, - msg: Vec, - ) -> Result { - let xcall_host = self.query_xcall(store)?; - let xcall_msg = cw_xcall_lib::xcall_msg::ExecuteMsg::HandleMessage { - from_nid: nid.clone(), - msg, - }; - let call_message: CosmosMsg = CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: xcall_host.to_string(), - msg: to_json_binary(&xcall_msg).unwrap(), - funds: vec![], - }); - let sub_msg: SubMsg = SubMsg::reply_always(call_message, XCALL_HANDLE_MESSAGE_REPLY_ID); - Ok(sub_msg) - } - - pub fn call_xcall_handle_error( - &self, - store: &dyn Storage, - sn: u128, - ) -> Result { - let xcall_host = self.query_xcall(store)?; - let xcall_msg = cw_xcall_lib::xcall_msg::ExecuteMsg::HandleError { - sn: sn.try_into().unwrap(), - }; - let call_message: CosmosMsg = CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: xcall_host.to_string(), - msg: to_json_binary(&xcall_msg).unwrap(), - funds: vec![], - }); - let sub_msg: SubMsg = SubMsg::reply_always(call_message, XCALL_HANDLE_ERROR_REPLY_ID); - Ok(sub_msg) - } -} diff --git a/contracts/cosmwasm-vm/cw-centralized-connection/src/lib.rs b/contracts/cosmwasm-vm/cw-centralized-connection/src/lib.rs deleted file mode 100644 index 7122325a..00000000 --- a/contracts/cosmwasm-vm/cw-centralized-connection/src/lib.rs +++ /dev/null @@ -1,97 +0,0 @@ -pub mod contract; -pub mod errors; -pub mod helper; -pub mod msg; -pub mod state; -pub mod types; - -use cosmwasm_schema::cw_serde; -use cosmwasm_std::{ - entry_point, to_json_binary, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, MessageInfo, Reply, - Response, StdError, StdResult, Storage, SubMsg, WasmMsg, -}; - -use cw2::set_contract_version; -use cw_storage_plus::{Item, Map}; -pub use errors::*; -pub use helper::*; -use msg::{ExecuteMsg, MigrateMsg, QueryMsg}; -use state::CwCentralizedConnection; -use thiserror::Error; -pub use types::*; - -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn instantiate( - deps: DepsMut, - env: Env, - info: MessageInfo, - msg: InstantiateMsg, -) -> Result { - let mut centralized_connection = CwCentralizedConnection::default(); - - centralized_connection.instantiate(deps, env, info, msg) -} - -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn execute( - deps: DepsMut, - env: Env, - info: MessageInfo, - msg: ExecuteMsg, -) -> Result { - let mut centralized_connection = CwCentralizedConnection::default(); - match msg { - ExecuteMsg::SendMessage { to, sn, msg } => { - centralized_connection.send_message(deps, info, to, sn, msg) - } - ExecuteMsg::RecvMessage { - src_network, - conn_sn, - msg, - } => centralized_connection.recv_message(deps, info, src_network, conn_sn, msg), - ExecuteMsg::ClaimFees {} => centralized_connection.claim_fees(deps, env, info), - ExecuteMsg::RevertMessage { sn } => centralized_connection.revert_message(deps, info, sn), - ExecuteMsg::SetAdmin { address } => centralized_connection.set_admin(deps, info, address), - ExecuteMsg::SetFee { - network_id, - message_fee, - response_fee, - } => centralized_connection.set_fee(deps, info, network_id, message_fee, response_fee), - } -} - -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { - let centralized_connection = CwCentralizedConnection::default(); - match msg { - QueryMsg::GetFee { nid, response } => to_json_binary( - ¢ralized_connection - .get_fee(deps.storage, nid, response) - .unwrap(), - ), - - QueryMsg::GetReceipt { - src_network, - conn_sn, - } => { - to_json_binary(¢ralized_connection.get_receipt(deps.storage, src_network, conn_sn)) - } - - QueryMsg::Admin {} => { - to_json_binary(¢ralized_connection.admin().load(deps.storage).unwrap()) - } - } -} - -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result { - let centralized_connection = CwCentralizedConnection::default(); - - centralized_connection.reply(deps, env, msg) -} - -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { - let centralized_connection = CwCentralizedConnection::default(); - centralized_connection.migrate(deps, _env, _msg) -} diff --git a/contracts/cosmwasm-vm/cw-centralized-connection/src/msg.rs b/contracts/cosmwasm-vm/cw-centralized-connection/src/msg.rs deleted file mode 100644 index bc205bf8..00000000 --- a/contracts/cosmwasm-vm/cw-centralized-connection/src/msg.rs +++ /dev/null @@ -1,49 +0,0 @@ -use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::Addr; -use cw_xcall_lib::network_address::NetId; - -#[cw_serde] -pub enum ExecuteMsg { - SetFee { - network_id: NetId, - message_fee: u128, - response_fee: u128, - }, - SendMessage { - to: NetId, - sn: i64, - msg: Vec, - }, - - RecvMessage { - src_network: NetId, - conn_sn: u128, - msg: String, - }, - - ClaimFees {}, - RevertMessage { - sn: u128, - }, - SetAdmin { - address: Addr, - }, -} - -#[cw_serde] -#[derive(QueryResponses)] -/// This is a Rust enum representing different types of queries that can be made to the contract. Each -/// variant of the enum corresponds to a specific query and has a return type specified using the -/// `#[returns]` attribute. -pub enum QueryMsg { - #[returns(u64)] - GetFee { nid: NetId, response: bool }, - #[returns(bool)] - GetReceipt { src_network: NetId, conn_sn: u128 }, - //return address of admin - #[returns(Addr)] - Admin {}, -} - -#[cw_serde] -pub struct MigrateMsg {} diff --git a/contracts/cosmwasm-vm/cw-centralized-connection/src/state.rs b/contracts/cosmwasm-vm/cw-centralized-connection/src/state.rs deleted file mode 100644 index d4d6fd97..00000000 --- a/contracts/cosmwasm-vm/cw-centralized-connection/src/state.rs +++ /dev/null @@ -1,113 +0,0 @@ -use cosmwasm_std::Addr; -use cw_xcall_lib::network_address::NetId; - -use crate::types::StorageKey; - -use super::*; - -pub struct CwCentralizedConnection<'a> { - message_fee: Map<'a, NetId, u128>, - response_fee: Map<'a, NetId, u128>, - admin: Item<'a, Addr>, - conn_sn: Item<'a, u128>, - receipts: Map<'a, (String, u128), bool>, - xcall: Item<'a, Addr>, - denom: Item<'a, String>, -} - -impl<'a> Default for CwCentralizedConnection<'a> { - fn default() -> Self { - Self::new() - } -} - -impl<'a> CwCentralizedConnection<'a> { - pub fn new() -> Self { - Self { - message_fee: Map::new(StorageKey::MessageFee.as_str()), - response_fee: Map::new(StorageKey::ResponseFee.as_str()), - admin: Item::new(StorageKey::Admin.as_str()), - conn_sn: Item::new(StorageKey::ConnSn.as_str()), - receipts: Map::new(StorageKey::Receipts.as_str()), - xcall: Item::new(StorageKey::XCall.as_str()), - denom: Item::new(StorageKey::Denom.as_str()), - } - } - - pub fn get_next_conn_sn(&self, store: &mut dyn Storage) -> Result { - let mut connsn = self.conn_sn.load(store).unwrap_or(0); - connsn += 1; - self.conn_sn.save(store, &connsn)?; - Ok(connsn) - } - - pub fn store_conn_sn(&mut self, store: &mut dyn Storage, sn: u128) -> StdResult<()> { - self.conn_sn.save(store, &sn)?; - Ok(()) - } - - pub fn store_fee( - &mut self, - store: &mut dyn Storage, - to: NetId, - message_fee: u128, - response_fee: u128, - ) -> StdResult<()> { - self.message_fee.save(store, to.clone(), &message_fee)?; - self.response_fee.save(store, to, &response_fee)?; - Ok(()) - } - pub fn query_message_fee(&self, store: &dyn Storage, to: NetId) -> u128 { - self.message_fee.load(store, to).unwrap_or(0) - } - - pub fn query_response_fee(&self, store: &dyn Storage, to: NetId) -> u128 { - self.response_fee.load(store, to).unwrap_or(0) - } - - pub fn store_receipt( - &mut self, - store: &mut dyn Storage, - src_network: NetId, - connsn: u128, - ) -> StdResult<()> { - self.receipts - .save(store, (src_network.to_string(), connsn), &true)?; - Ok(()) - } - - pub fn get_receipt(&self, store: &dyn Storage, src_network: NetId, sn: u128) -> bool { - self.receipts - .load(store, (src_network.to_string(), sn)) - .unwrap_or(false) - } - - pub fn store_xcall(&mut self, store: &mut dyn Storage, address: Addr) -> StdResult<()> { - self.xcall.save(store, &address)?; - Ok(()) - } - - pub fn store_admin(&mut self, store: &mut dyn Storage, address: Addr) -> StdResult<()> { - self.admin.save(store, &address)?; - Ok(()) - } - - pub fn store_denom(&mut self, store: &mut dyn Storage, denom: String) -> StdResult<()> { - self.denom.save(store, &denom)?; - Ok(()) - } - - pub fn query_admin(&self, store: &dyn Storage) -> Result { - Ok(self.admin.load(store)?) - } - - pub fn query_xcall(&self, store: &dyn Storage) -> Result { - Ok(self.xcall.load(store)?) - } - pub fn denom(&self, store: &dyn Storage) -> String { - self.denom.load(store).unwrap() - } - pub fn admin(&self) -> &Item<'a, Addr> { - &self.admin - } -} diff --git a/contracts/cosmwasm-vm/cw-centralized-connection/src/types.rs b/contracts/cosmwasm-vm/cw-centralized-connection/src/types.rs deleted file mode 100644 index ccd3765f..00000000 --- a/contracts/cosmwasm-vm/cw-centralized-connection/src/types.rs +++ /dev/null @@ -1,33 +0,0 @@ -use super::*; - -#[cw_serde] -pub struct InstantiateMsg { - pub relayer: String, - pub xcall_address: String, - pub denom: String, -} - -#[cw_serde] -pub enum StorageKey { - MessageFee, - ResponseFee, - Receipts, - XCall, - Admin, - ConnSn, - Denom, -} - -impl StorageKey { - pub fn as_str(&self) -> &'static str { - match self { - StorageKey::MessageFee => "message_fee", - StorageKey::ResponseFee => "response_fee", - StorageKey::Receipts => "receipts", - StorageKey::XCall => "xcall", - StorageKey::Admin => "admin", - StorageKey::ConnSn => "conn_sn", - StorageKey::Denom => "denom", - } - } -} diff --git a/contracts/cosmwasm-vm/cw-centralized-connection/tests/test.rs b/contracts/cosmwasm-vm/cw-centralized-connection/tests/test.rs deleted file mode 100644 index 6c906d20..00000000 --- a/contracts/cosmwasm-vm/cw-centralized-connection/tests/test.rs +++ /dev/null @@ -1,219 +0,0 @@ -pub mod setup; -use cosmwasm_std::{testing::mock_env, Env}; -use cosmwasm_std::{ - testing::{mock_dependencies, mock_info, MockApi, MockQuerier}, - Addr, MemoryStorage, OwnedDeps, Uint128, -}; -use cosmwasm_std::{Coin, Event}; -use cw_centralized_connection::{ - execute, msg::ExecuteMsg, state::CwCentralizedConnection, types::InstantiateMsg, -}; -use cw_xcall_lib::network_address::NetId; -use std::str::FromStr; - -const XCALL: &str = "xcall"; -const DENOM: &str = "denom"; -const RELAYER: &str = "relayer"; -const OWNER: &str = "owner"; - -fn instantiate( - sender: &str, -) -> ( - OwnedDeps, - Env, - CwCentralizedConnection<'_>, -) { - let mut deps: OwnedDeps = mock_dependencies(); - let mut ctx: CwCentralizedConnection<'_> = CwCentralizedConnection::default(); - let env = mock_env(); - let info = mock_info(sender, &[]); - let msg = InstantiateMsg { - relayer: RELAYER.to_string(), - xcall_address: XCALL.to_string(), - denom: DENOM.to_string(), - }; - let res = ctx.instantiate(deps.as_mut(), env.clone(), info, msg); - assert!(res.is_ok()); - - (deps, env, ctx) -} - -#[test] -fn test_initialization() { - instantiate(OWNER); -} - -#[test] -fn test_set_admin() { - let (mut deps, env, ctx) = instantiate("sender"); - let msg = ExecuteMsg::SetAdmin { - address: Addr::unchecked("admin"), - }; - - let info = mock_info(OWNER, &[]); - - let res = execute(deps.as_mut(), env.clone(), info, msg.clone()); - assert!(res.is_err()); - - let info = mock_info(RELAYER, &[]); - - let res = execute(deps.as_mut(), env, info, msg); - assert!(res.is_ok()); - - let admin = ctx.query_admin(deps.as_mut().storage).unwrap(); - assert_eq!(admin, Addr::unchecked("admin")); -} - -#[test] -fn test_set_fee() { - let (mut deps, env, ctx) = instantiate(OWNER); - let nid = NetId::from_str("test").unwrap(); - let message_fee: u128 = 200; - let response_fee: u128 = 100; - let msg = ExecuteMsg::SetFee { - network_id: nid.clone(), - message_fee, - response_fee, - }; - - let info = mock_info(OWNER, &[]); - - let res = execute(deps.as_mut(), env.clone(), info, msg.clone()); - assert!(res.is_err()); - - let info = mock_info(RELAYER, &[]); - - let res = execute(deps.as_mut(), env, info, msg); - assert!(res.is_ok()); - - let res = ctx - .get_fee(deps.as_mut().storage, nid.clone(), false) - .unwrap(); - assert_eq!(res, Uint128::from(message_fee)); - - let res = ctx.get_fee(deps.as_mut().storage, nid, true).unwrap(); - assert_eq!(res, Uint128::from(message_fee + response_fee)); -} - -#[test] -pub fn test_send_message() { - let (mut deps, env, _ctx) = instantiate(OWNER); - let msg = ExecuteMsg::SendMessage { - to: NetId::from_str("nid").unwrap(), - sn: 0, - msg: vec![], - }; - - let info = mock_info(OWNER, &[]); - - let res = execute(deps.as_mut(), env.clone(), info, msg.clone()); - - assert!(res.is_err()); - - let info: cosmwasm_std::MessageInfo = mock_info(XCALL, &[]); - - let res = execute(deps.as_mut(), env, info, msg); - let event = Event::new("Message") - .add_attribute("targetNetwork", "nid") - .add_attribute("connSn", 1.to_string()) - .add_attribute("msg", "null"); - assert_eq!(res.unwrap().events[0], event); -} - -#[test] -pub fn test_recv_message() { - let (mut deps, env, mut _ctx) = instantiate(OWNER); - let src_network = NetId::from_str("nid").unwrap(); - let msg = ExecuteMsg::RecvMessage { - src_network, - conn_sn: 1, - msg: "".to_string(), - }; - - let info = mock_info(OWNER, &[]); - - let res = execute(deps.as_mut(), env.clone(), info, msg.clone()); - - assert!(res.is_err()); - assert_eq!("Only Relayer(Admin)", res.unwrap_err().to_string()); - - let info = mock_info(RELAYER, &[]); - - let res = execute(deps.as_mut(), env.clone(), info.clone(), msg.clone()); - - assert!(res.is_ok()); - - let res = execute(deps.as_mut(), env, info, msg); - - assert!(res.is_err()); - - assert_eq!("Duplicate Message", res.unwrap_err().to_string()); -} - -#[test] - -pub fn test_revert_message() { - let (mut deps, env, mut _ctx) = instantiate(OWNER); - let msg = ExecuteMsg::RevertMessage { sn: 1 }; - - let info = mock_info(OWNER, &[]); - - let res = execute(deps.as_mut(), env.clone(), info, msg.clone()); - - assert!(res.is_err()); - - let info = mock_info(RELAYER, &[]); - - let res = execute(deps.as_mut(), env, info, msg); - - assert!(res.is_ok()); -} - -#[test] - -pub fn test_get_receipts() { - let (mut deps, env, ctx) = instantiate(OWNER); - let src_network = NetId::from_str("nid").unwrap(); - let msg = ExecuteMsg::RecvMessage { - src_network: src_network.clone(), - conn_sn: 1, - msg: "".to_string(), - }; - - let receipt = ctx.get_receipt(deps.as_mut().storage, src_network.clone(), 1); - assert!(!receipt); - - let _ = execute(deps.as_mut(), env, mock_info(RELAYER, &[]), msg); - - let receipt = ctx.get_receipt(deps.as_mut().storage, src_network, 1); - assert!(receipt); -} - -#[test] -pub fn test_claim_fees() { - let (mut deps, env, _ctx) = instantiate(OWNER); - let claim_msg = ExecuteMsg::ClaimFees {}; - let info = mock_info(OWNER, &[]); - let res = execute(deps.as_mut(), env.clone(), info, claim_msg.clone()); - assert!(res.is_err()); - assert_eq!("Only Relayer(Admin)", res.unwrap_err().to_string()); - - let msg = ExecuteMsg::SendMessage { - to: NetId::from_str("nid").unwrap(), - sn: 0, - msg: vec![], - }; - - let info = mock_info(XCALL, &[]); - - let _ = execute(deps.as_mut(), env.clone(), info, msg); - - let amount: u128 = 100; - let coin: Coin = Coin { - denom: DENOM.to_string(), - amount: Uint128::from(amount), - }; - let info = mock_info(RELAYER, &[coin]); - let res = execute(deps.as_mut(), env, info, claim_msg); - assert!(res.is_ok()); -} diff --git a/contracts/cosmwasm-vm/cw-integration/Cargo.toml b/contracts/cosmwasm-vm/cw-integration/Cargo.toml deleted file mode 100644 index fcc9572d..00000000 --- a/contracts/cosmwasm-vm/cw-integration/Cargo.toml +++ /dev/null @@ -1,34 +0,0 @@ -[package] -name = "cw-integration" -version.workspace = true -authors.workspace = true -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -cosmwasm-schema = {workspace=true} -cosmwasm-std = {workspace=true} -cw-storage-plus = {workspace=true} -cw-common={workspace=true} -common = { workspace=true, default-features = false } -ibc = { version = "0.32.0", default-features = false, features = ["parity-scale-codec", "mocks-no-std", "serde"]} -prost = { workspace=true} -strum="*" -strum_macros = "0.24" -cw-xcall-lib={package = "cw-xcall-lib",workspace=true} - -[dev-dependencies] -hex = "0.4.3" -cw-multi-test = "0.15.1" -cw-xcall-ibc-connection = { workspace=true } -cw-mock-ibc-core = { workspace=true } -cw-mock-dapp = { workspace=true} -cw-mock-dapp-multi = { workspace=true } -## xcall connection uses the alpha tag need to update -xcall-lib={package="cw-xcall-lib", git="https://github.com/icon-project/xCall.git", tag="v0.1.0-alpha.5"} - -cw-xcall = {workspace=true} -anyhow="*" - - diff --git a/contracts/cosmwasm-vm/cw-integration/tests/setup.rs b/contracts/cosmwasm-vm/cw-integration/tests/setup.rs deleted file mode 100644 index a326167f..00000000 --- a/contracts/cosmwasm-vm/cw-integration/tests/setup.rs +++ /dev/null @@ -1,277 +0,0 @@ -use std::collections::HashMap; - -use cosmwasm_std::{ - coins, - testing::{mock_dependencies, mock_info, MockApi, MockQuerier, MockStorage}, - Addr, Attribute, Empty, Event, IbcEndpoint, MessageInfo, OwnedDeps, -}; -use cw_common::ibc_types::IbcEventType; -use cw_multi_test::{App, AppResponse, Contract, ContractWrapper, Executor}; -use cw_xcall_ibc_connection::state::IbcConfig; - -pub const PORT: &str = "xcall"; -pub const COUNTERPARTY_NID: &str = "0x3.icon"; - -#[derive(Debug, PartialEq, Eq, Hash)] -pub enum TestApps { - Dapp, - XcallApp, - IbcCore, - XcallIbcConnection, -} - -pub struct TestContext { - pub app: App, - pub contracts: HashMap, - pub sender: Addr, - pub admin: Option, - pub caller: Option, -} - -impl TestContext { - pub fn get_dapp(&self) -> Addr { - return self.contracts.get(&TestApps::Dapp).unwrap().clone(); - } - pub fn get_ibc_core(&self) -> Addr { - return self.contracts.get(&TestApps::IbcCore).unwrap().clone(); - } - - pub fn get_xcall_app(&self) -> Addr { - return self.contracts.get(&TestApps::XcallApp).unwrap().clone(); - } - pub fn get_xcall_ibc_connection(&self) -> Addr { - return self - .contracts - .get(&TestApps::XcallIbcConnection) - .unwrap() - .clone(); - } - - pub fn set_dapp(&mut self, addr: Addr) -> Option { - self.contracts.insert(TestApps::Dapp, addr) - } - pub fn set_ibc_core(&mut self, addr: Addr) -> Option { - self.contracts.insert(TestApps::IbcCore, addr) - } - - pub fn set_xcall_app(&mut self, addr: Addr) -> Option { - self.contracts.insert(TestApps::XcallApp, addr) - } - pub fn set_xcall_ibc_connection(&mut self, addr: Addr) -> Option { - self.contracts.insert(TestApps::XcallIbcConnection, addr) - } - - pub fn list_contracts(&self) { - println!("IbcHost {}", self.get_ibc_core()); - println!("IbcConnection {}", self.get_xcall_ibc_connection()); - println!("Xcall {}", self.get_xcall_app()); - println!("Dapp {}", self.get_dapp()) - } -} - -pub fn create_mock_info(creator: &str, denom: &str, amount: u128) -> MessageInfo { - let funds = coins(amount, denom); - mock_info(creator, &funds) -} - -pub fn deps() -> OwnedDeps { - mock_dependencies() -} - -pub fn mock_ibc_config() -> IbcConfig { - let src = IbcEndpoint { - port_id: "xcall".to_string(), - channel_id: "our-channel-id".to_string(), - }; - - let dst = IbcEndpoint { - port_id: "xcall".to_string(), - channel_id: "their-channel-id".to_string(), - }; - - IbcConfig::new(src, dst) -} - -pub fn mock_dapp_contract() -> Box> { - let contract = ContractWrapper::new( - cw_mock_dapp::execute, - cw_mock_dapp::instantiate, - cw_mock_dapp::query, - ); - Box::new(contract) -} - -pub fn mock_dapp_multi_contract() -> Box> { - let contract = ContractWrapper::new( - cw_mock_dapp_multi::execute, - cw_mock_dapp_multi::instantiate, - cw_mock_dapp_multi::query, - ); - Box::new(contract) -} - -pub fn init_mock_dapp_multi_contract(mut ctx: TestContext) -> TestContext { - let code_id = ctx.app.store_code(mock_dapp_multi_contract()); - let contract_addr = ctx - .app - .instantiate_contract( - code_id, - ctx.sender.clone(), - &cw_mock_dapp_multi::types::InstantiateMsg { - address: ctx.get_xcall_app().to_string(), - }, - &[], - "MockApp", - Some(ctx.sender.clone().to_string()), - ) - .unwrap(); - ctx.set_dapp(contract_addr); - - ctx -} - -pub fn init_mock_dapp_contract(mut ctx: TestContext) -> TestContext { - let code_id = ctx.app.store_code(mock_dapp_contract()); - let contract_addr = ctx - .app - .instantiate_contract( - code_id, - ctx.sender.clone(), - &cw_mock_dapp::types::InstantiateMsg { - address: "someaddr".to_string(), - }, - &[], - "MockApp", - Some(ctx.sender.clone().to_string()), - ) - .unwrap(); - ctx.set_dapp(contract_addr); - - ctx -} - -pub fn init_mock_ibc_core_contract(mut ctx: TestContext) -> TestContext { - let ibc_core_code_id = ctx.app.store_code(mock_ibc_core_contract()); - let ibc_core_addr = ctx - .app - .instantiate_contract( - ibc_core_code_id, - ctx.sender.clone(), - &cw_common::core_msg::InstantiateMsg {}, - &[], - "IBCCore", - Some(ctx.sender.clone().to_string()), - ) - .unwrap(); - - ctx.set_ibc_core(ibc_core_addr); - ctx -} - -pub fn ibc_connection_contract() -> Box> { - let contract = ContractWrapper::new( - cw_xcall_ibc_connection::execute, - cw_xcall_ibc_connection::instantiate, - cw_xcall_ibc_connection::query, - ) - .with_reply(cw_xcall_ibc_connection::reply); - Box::new(contract) -} - -pub fn mock_ibc_core_contract() -> Box> { - let contract = ContractWrapper::new( - cw_mock_ibc_core::contract::execute, - cw_mock_ibc_core::contract::instantiate, - cw_mock_ibc_core::contract::query, - ) - .with_reply(cw_mock_ibc_core::contract::reply); - Box::new(contract) -} - -pub fn xcall_app_contract() -> Box> { - let contract = ContractWrapper::new(cw_xcall::execute, cw_xcall::instantiate, cw_xcall::query) - .with_reply(cw_xcall::reply); - Box::new(contract) -} - -pub fn init_xcall_app_contract(mut ctx: TestContext) -> TestContext { - let xcall_app_contractcode_id = ctx.app.store_code(xcall_app_contract()); - let xcall_app_contract_addr = ctx - .app - .instantiate_contract( - xcall_app_contractcode_id, - ctx.sender.clone(), - &cw_xcall::msg::InstantiateMsg { - network_id: "nid".to_string(), - denom: "uarch".to_string(), - }, - &[], - "XCallApp", - Some(ctx.sender.clone().to_string()), - ) - .unwrap(); - - ctx.set_xcall_app(xcall_app_contract_addr); - ctx -} - -pub fn init_xcall_ibc_connection_contract(mut ctx: TestContext) -> TestContext { - let ibc_connection_contract_code_id = ctx.app.store_code(ibc_connection_contract()); - let ibc_connection_contract_addr = ctx - .app - .instantiate_contract( - ibc_connection_contract_code_id, - ctx.sender.clone(), - &cw_xcall_ibc_connection::msg::InstantiateMsg { - ibc_host: ctx.get_ibc_core(), - denom: "uarch".to_string(), - port_id: PORT.to_string(), - xcall_address: ctx.get_xcall_app(), - }, - &[], - "IBCConnection", - Some(ctx.sender.clone().to_string()), - ) - .unwrap(); - - ctx.set_xcall_ibc_connection(ibc_connection_contract_addr); - ctx -} - -pub fn setup_context() -> TestContext { - let router = App::default(); - let sender = Addr::unchecked("sender"); - - TestContext { - app: router, - contracts: HashMap::new(), - sender, - admin: None, - caller: None, - } -} - -pub fn get_event(res: &AppResponse, event: &str) -> Option> { - let event = res - .events - .iter() - .filter(|e| e.ty == event) - .collect::>(); - if !event.is_empty() { - let map = to_attribute_map(&event[0].attributes); - return Some(map); - } - None -} - -pub fn get_event_name(event_type: IbcEventType) -> String { - format!("wasm-{}", event_type.as_str()) -} - -pub fn to_attribute_map(attrs: &Vec) -> HashMap { - let mut map = HashMap::new(); - for attr in attrs { - map.insert(attr.key.clone(), attr.value.clone()); - } - map -} diff --git a/contracts/cosmwasm-vm/cw-integration/tests/test_xcall.rs b/contracts/cosmwasm-vm/cw-integration/tests/test_xcall.rs deleted file mode 100644 index cae79564..00000000 --- a/contracts/cosmwasm-vm/cw-integration/tests/test_xcall.rs +++ /dev/null @@ -1,494 +0,0 @@ -mod setup; -use std::str::FromStr; - -use anyhow::Error as AppError; - -use common::rlp::Nullable; - -use cosmwasm_std::Addr; -use cosmwasm_std::IbcChannel; - -use cw_common::raw_types::channel::RawPacket; - -use cw_multi_test::AppResponse; - -use cw_multi_test::Executor; - -use cw_xcall::types::message::CSMessage; -use cw_xcall::types::request::CSMessageRequest; -use cw_xcall::types::result::CSMessageResult; -use cw_xcall::types::result::CallServiceResponseType; -use cw_xcall_ibc_connection::types::message::Message; -use cw_xcall_lib::message::call_message_rollback::CallMessageWithRollback; -use cw_xcall_lib::message::envelope::Envelope; -use cw_xcall_lib::message::AnyMessage; - -use cw_common::ProstMessage; -use cw_xcall_lib::message::msg_type::MessageType; -use cw_xcall_lib::network_address::NetworkAddress; -use setup::init_mock_dapp_multi_contract; -use setup::{ - init_mock_ibc_core_contract, init_xcall_app_contract, init_xcall_ibc_connection_contract, - TestContext, -}; -use xcall_lib::network_address::NetId; - -use crate::setup::get_event; -use crate::setup::mock_ibc_config; -use crate::setup::setup_context; -const MOCK_CONTRACT_TO_ADDR: &str = "cosmoscontract"; - -fn setup_contracts(mut ctx: TestContext) -> TestContext { - ctx = init_mock_ibc_core_contract(ctx); - // ctx.set_ibc_core(ctx.sender.clone()); - ctx = init_xcall_app_contract(ctx); - ctx = init_xcall_ibc_connection_contract(ctx); - ctx = init_mock_dapp_multi_contract(ctx); - ctx -} - -fn setup_test() -> TestContext { - let mut context = setup_context(); - context = setup_contracts(context); - context -} - -pub fn call_send_call_message( - ctx: &mut TestContext, - to: &str, - sources: Vec, - destinations: Vec, - data: Vec, - rollback: Option>, -) -> Result { - ctx.app.execute_contract( - ctx.sender.clone(), - ctx.get_xcall_app(), - &xcall_lib::xcall_msg::ExecuteMsg::SendCallMessage { - to: xcall_lib::network_address::NetworkAddress::from_str(to).unwrap(), - data, - rollback, - sources: Some(sources), - destinations: Some(destinations), - }, - &[], - ) -} - -pub fn call_execute_call_message( - ctx: &mut TestContext, - request_id: u128, - data: Vec, -) -> Result { - ctx.app.execute_contract( - ctx.sender.clone(), - ctx.get_xcall_app(), - &xcall_lib::xcall_msg::ExecuteMsg::ExecuteCall { request_id, data }, - &[], - ) -} - -pub fn call_dapp_send_call( - ctx: &mut TestContext, - to: String, - envelope: Envelope, -) -> Result { - ctx.app.execute_contract( - ctx.sender.clone(), - ctx.get_dapp(), - &cw_mock_dapp_multi::msg::ExecuteMsg::SendMessageAny { - to: cw_xcall_lib::network_address::NetworkAddress::from_str(&to).unwrap(), - envelope, - }, - &[], - ) -} - -pub fn call_dapp_add_connection( - ctx: &mut TestContext, - src_endpoint: String, - dest_endpoint: String, - network_id: String, -) -> Result { - ctx.app.execute_contract( - ctx.sender.clone(), - ctx.get_dapp(), - &cw_mock_dapp_multi::msg::ExecuteMsg::AddConnection { - src_endpoint, - dest_endpoint, - network_id, - }, - &[], - ) -} - -pub fn call_set_xcall_host(ctx: &mut TestContext) -> Result { - ctx.app.execute_contract( - ctx.sender.clone(), - ctx.get_xcall_ibc_connection(), - &cw_common::xcall_connection_msg::ExecuteMsg::SetXCallHost { - address: ctx.get_xcall_app().to_string(), - }, - &[], - ) -} - -pub fn call_set_default_connection( - ctx: &mut TestContext, - nid: String, -) -> Result { - ctx.app.execute_contract( - ctx.sender.clone(), - ctx.get_xcall_app(), - &xcall_lib::xcall_msg::ExecuteMsg::SetDefaultConnection { - nid: NetId::from(nid), - address: ctx.get_xcall_ibc_connection(), - }, - &[], - ) -} - -pub fn call_configure_connection( - ctx: &mut TestContext, - connection_id: String, - nid: String, - client_id: String, -) -> Result { - ctx.app.execute_contract( - ctx.sender.clone(), - ctx.get_xcall_ibc_connection(), - &cw_common::xcall_connection_msg::ExecuteMsg::ConfigureConnection { - connection_id, - counterparty_port_id: "xcall".to_string(), - counterparty_nid: NetId::from_str(&nid).unwrap(), - client_id, - timeout_height: 10, - }, - &[], - ) -} - -pub fn call_ibc_channel_connect(ctx: &mut TestContext) -> Result { - let ibc_config = mock_ibc_config(); - let channel = IbcChannel::new( - ibc_config.src_endpoint().clone(), - ibc_config.dst_endpoint().clone(), - cosmwasm_std::IbcOrder::Unordered, - "ics-20", - "connection-1", - ); - - ctx.app.execute_contract( - ctx.sender.clone(), - ctx.get_ibc_core(), - &cw_mock_ibc_core::msg::ExecuteMsg::IbcConfig { - msg: cosmwasm_std::IbcChannelConnectMsg::OpenConfirm { channel }, - }, - &[], - ) -} - -pub fn call_ibc_receive_packet( - ctx: &mut TestContext, - msg: Vec, -) -> Result { - let ibc_config = mock_ibc_config(); - let packet = RawPacket { - sequence: 1, - source_port: ibc_config.dst_endpoint().port_id.to_string(), - source_channel: ibc_config.dst_endpoint().channel_id.to_string(), - destination_port: ibc_config.src_endpoint().port_id.to_string(), - destination_channel: ibc_config.src_endpoint().channel_id.to_string(), - data: msg, - timeout_height: Some(cw_common::raw_types::RawHeight { - revision_number: 0, - revision_height: 12345, - }), - timeout_timestamp: 17747483838282, - }; - let packet_bytes = hex::encode(packet.encode_to_vec()); - ctx.app.execute_contract( - ctx.sender.clone(), - ctx.get_ibc_core(), - &cw_mock_ibc_core::msg::ExecuteMsg::ReceivePacket { - message: packet_bytes, - }, - &[], - ) -} - -pub fn call_register_connection(ctx: &mut TestContext) -> Result { - ctx.app.execute_contract( - ctx.sender.clone(), - ctx.get_ibc_core(), - &cw_mock_ibc_core::msg::ExecuteMsg::RegisterXcall { - address: ctx.get_xcall_ibc_connection(), - }, - &[], - ) -} - -#[test] -fn test_xcall_send_call_message() { - let mut ctx = setup_test(); - call_set_xcall_host(&mut ctx).unwrap(); - call_register_connection(&mut ctx).unwrap(); - let src = ctx.get_xcall_ibc_connection().to_string(); - - let nid = "0x3.icon"; - call_configure_connection( - &mut ctx, - "connection-1".to_string(), - nid.to_string(), - "client-1".to_string(), - ) - .unwrap(); - call_ibc_channel_connect(&mut ctx).unwrap(); - let result = call_send_call_message( - &mut ctx, - &format!("{nid}/{MOCK_CONTRACT_TO_ADDR}"), - vec![src], - vec!["somedestination".to_string()], - vec![1, 2, 3], - None, - ); - println!("{result:?}"); - assert!(result.is_ok()); - let result = result.unwrap(); - let event = get_event(&result, "wasm-CallMessageSent").unwrap(); - println!("{event:?}"); - assert_eq!( - &format!("{nid}/{MOCK_CONTRACT_TO_ADDR}"), - event.get("to").unwrap() - ); -} - -#[test] -fn test_xcall_send_call() { - let mut ctx = setup_test(); - call_set_xcall_host(&mut ctx).unwrap(); - call_register_connection(&mut ctx).unwrap(); - let src = ctx.get_xcall_ibc_connection().to_string(); - let dapp = ctx.get_dapp().to_string(); - - let nid = "0x3.icon"; - call_configure_connection( - &mut ctx, - "connection-1".to_string(), - nid.to_string(), - "client-1".to_string(), - ) - .unwrap(); - call_ibc_channel_connect(&mut ctx).unwrap(); - let message = AnyMessage::CallMessageWithRollback(CallMessageWithRollback { - data: vec![1, 2, 3], - rollback: "rollback-reply".as_bytes().to_vec(), - }); - let envelope = Envelope::new(message, vec![src], vec!["somedestination".to_string()]); - let result = call_dapp_send_call(&mut ctx, format!("{nid}/{dapp}"), envelope); - println!("{result:?}"); - assert!(result.is_ok()); - let result = result.unwrap(); - let event = get_event(&result, "wasm-CallMessageSent").unwrap(); - println!("{event:?}"); - assert_eq!(&format!("{nid}/{dapp}"), event.get("to").unwrap()); -} - -#[test] -fn test_rollback_reply() { - let mut ctx = setup_test(); - call_set_xcall_host(&mut ctx).unwrap(); - call_register_connection(&mut ctx).unwrap(); - let src = ctx.get_xcall_ibc_connection().to_string(); - let _dapp = ctx.get_dapp().to_string(); - - let nid = "0x3.icon"; - call_configure_connection( - &mut ctx, - "connection-1".to_string(), - nid.to_string(), - "client-1".to_string(), - ) - .unwrap(); - call_ibc_channel_connect(&mut ctx).unwrap(); - call_dapp_add_connection(&mut ctx, src, "somedest".to_string(), nid.to_string()).unwrap(); - let data = "reply-response".as_bytes().to_vec(); - let msg = CSMessageRequest::new( - NetworkAddress::from_str(&format!("{nid}/{MOCK_CONTRACT_TO_ADDR}")).unwrap(), - ctx.get_dapp(), - 1, - MessageType::CallMessageWithRollback, - data.clone(), - vec![ctx.get_xcall_ibc_connection().to_string()], - ); - let request = CSMessage { - message_type: cw_xcall::types::message::CSMessageType::CSMessageRequest, - payload: msg.as_bytes(), - }; - - let msg = Message { - sn: Nullable::new(Some(1_i64)), - fee: 0_u128, - data: request.as_bytes(), - }; - let bytes: Vec = common::rlp::encode(&msg).to_vec(); - - call_ibc_receive_packet(&mut ctx, bytes).unwrap(); - let expected_reply = CSMessageRequest::new( - NetworkAddress::from_str("nid/contract3").unwrap(), - Addr::unchecked(MOCK_CONTRACT_TO_ADDR), - 1, - MessageType::CallMessage, - vec![1, 2, 3], - vec!["somedest".to_string()], - ); - let reply_message = CSMessageResult::new( - expected_reply.sequence_no(), - CallServiceResponseType::CallServiceResponseSuccess, - Some(expected_reply.as_bytes()), - ); - let message: CSMessage = reply_message.into(); - let expected_hex = hex::encode(message.as_bytes()); - - let result = call_execute_call_message(&mut ctx, 1, data); - println!("{result:?}"); - assert!(result.is_ok()); - let result = result.unwrap(); - let event = get_event(&result, "wasm-write_acknowledgement").unwrap(); - println!("{event:?}"); - assert_eq!(&expected_hex, event.get("data").unwrap()); -} - -fn test_call_message( - ctx: &mut TestContext, - data: Vec, - msg_type: MessageType, -) -> Result { - call_set_xcall_host(ctx).unwrap(); - call_register_connection(ctx).unwrap(); - let src = ctx.get_xcall_ibc_connection().to_string(); - let _dapp = ctx.get_dapp().to_string(); - - let nid = "0x3.icon"; - call_configure_connection( - ctx, - "connection-1".to_string(), - nid.to_string(), - "client-1".to_string(), - ) - .unwrap(); - call_ibc_channel_connect(ctx).unwrap(); - call_dapp_add_connection(ctx, src, "somedest".to_string(), nid.to_string()).unwrap(); - let msg = CSMessageRequest::new( - NetworkAddress::from_str(&format!("{nid}/{MOCK_CONTRACT_TO_ADDR}")).unwrap(), - ctx.get_dapp(), - 1, - msg_type, - data.clone(), - vec![ctx.get_xcall_ibc_connection().to_string()], - ); - let request = CSMessage { - message_type: cw_xcall::types::message::CSMessageType::CSMessageRequest, - payload: msg.as_bytes(), - }; - - let msg = Message { - sn: Nullable::new(Some(1_i64)), - fee: 0_u128, - data: request.as_bytes(), - }; - let bytes: Vec = common::rlp::encode(&msg).to_vec(); - - call_ibc_receive_packet(ctx, bytes).unwrap(); - call_execute_call_message(ctx, 1, data) -} - -#[test] -fn test_call_message_failed() { - let mut ctx = setup_test(); - - let data = "rollback".as_bytes().to_vec(); - let resp = test_call_message(&mut ctx, data, MessageType::CallMessage); - assert!(resp.is_ok()); - - let event = get_event(&resp.unwrap(), "wasm-CallExecuted").unwrap(); - let expected_code: u8 = CallServiceResponseType::CallServiceResponseFailure.into(); - assert_eq!(event.get("code").unwrap(), &expected_code.to_string()); -} - -#[test] -fn test_call_message_success() { - let mut ctx = setup_test(); - - let data = "test".as_bytes().to_vec(); - let resp = test_call_message(&mut ctx, data, MessageType::CallMessage); - assert!(resp.is_ok()); - let result = resp.unwrap(); - let event = get_event(&result, "wasm-CallExecuted").unwrap(); - let ack_event = get_event(&result, "wasm-write_acknowledgement"); - assert!(ack_event.is_none()); - - let expected_code: u8 = CallServiceResponseType::CallServiceResponseSuccess.into(); - assert_eq!(event.get("code").unwrap(), &expected_code.to_string()); -} - -#[test] -#[should_panic(expected = "NotFound { kind: \"cw_xcall::types::request::CSMessageRequest\"")] -fn test_call_message_re_execute() { - let mut ctx = setup_test(); - - let data = "rollback".as_bytes().to_vec(); - let resp = test_call_message(&mut ctx, data.clone(), MessageType::CallMessage); - assert!(resp.is_ok()); - // CallRequest should have been removed even though call failed - let _ = call_execute_call_message(&mut ctx, 1, data); -} - -#[test] -fn test_persistent_call_message_success() { - let mut ctx = setup_test(); - - let data = "test".as_bytes().to_vec(); - let resp = test_call_message(&mut ctx, data, MessageType::CallMessagePersisted); - assert!(resp.is_ok()); - - let result = resp.unwrap(); - let event = get_event(&result, "wasm-CallExecuted").unwrap(); - let ack_event = get_event(&result, "wasm-write_acknowledgement"); - assert!(ack_event.is_none()); - - let expected_code: u8 = CallServiceResponseType::CallServiceResponseSuccess.into(); - assert_eq!(event.get("code").unwrap(), &expected_code.to_string()); -} - -#[test] -#[should_panic(expected = "NotFound { kind: \"cw_xcall::types::request::CSMessageRequest\"")] -fn test_persistent_call_message_re_execute() { - let mut ctx = setup_test(); - - let data = "test".as_bytes().to_vec(); - let resp = test_call_message(&mut ctx, data.clone(), MessageType::CallMessagePersisted); - assert!(resp.is_ok()); - - let result = resp.unwrap(); - let event = get_event(&result, "wasm-CallExecuted").unwrap(); - - let expected_code: u8 = CallServiceResponseType::CallServiceResponseSuccess.into(); - assert_eq!(event.get("code").unwrap(), &expected_code.to_string()); - - // removed after a successful execution - let _ = call_execute_call_message(&mut ctx, 1, data); -} - -#[test] -fn test_persistent_call_message_retry() { - let mut ctx = setup_test(); - - let data = "rollback".as_bytes().to_vec(); - let resp = test_call_message(&mut ctx, data.clone(), MessageType::CallMessagePersisted); - assert!(resp.is_err()); - - // can retry - let resp = call_execute_call_message(&mut ctx, 1, data); - assert!(resp.is_err()); -} diff --git a/contracts/cosmwasm-vm/cw-mock-dapp/Cargo.toml b/contracts/cosmwasm-vm/cw-intents-v1/Cargo.toml similarity index 95% rename from contracts/cosmwasm-vm/cw-mock-dapp/Cargo.toml rename to contracts/cosmwasm-vm/cw-intents-v1/Cargo.toml index e80fcc03..ab5ccd85 100644 --- a/contracts/cosmwasm-vm/cw-mock-dapp/Cargo.toml +++ b/contracts/cosmwasm-vm/cw-intents-v1/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "cw-mock-dapp" +name = "cw-intents-v1" version = "0.1.0" edition = "2021" @@ -36,8 +36,8 @@ schemars = {workspace=true} serde = { workspace=true} thiserror = { workspace=true} common ={ git = "https://github.com/icon-project/IBC-Integration.git",branch="main" } -cw-xcall-lib = { workspace=true } serde-json-wasm = {workspace=true} +hex="*" [dev-dependencies] cosmwasm = "0.7.2" diff --git a/contracts/cosmwasm-vm/cw-intents-v1/src/contract.rs b/contracts/cosmwasm-vm/cw-intents-v1/src/contract.rs new file mode 100644 index 00000000..7a4553cd --- /dev/null +++ b/contracts/cosmwasm-vm/cw-intents-v1/src/contract.rs @@ -0,0 +1,39 @@ +use std::str::from_utf8; + +use cosmwasm_std::Addr; + +use super::*; + +// version info for migration info +const CONTRACT_NAME: &str = "crates.io:cw-mock-dapp"; +const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); + +impl<'a> CwIntentV1Service<'a> { + pub fn instantiate( + &self, + deps: DepsMut, + env: Env, + _info: MessageInfo, + msg: InstantiateMsg, + ) -> Result { + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + self.set_nid(deps.storage, msg.nid)?; + self.set_fee_handler(deps.storage, deps.api.addr_validate(&msg.fee_handler)?)?; + self.set_deposit_id(deps.storage, 0)?; + + Ok(Response::new()) + } + + pub fn swap(&self, order: SwapOrder, deps: DepsMut, env: Env, info: MessageInfo) {} + + pub fn fill(&self, order: SwapOrder, deps: DepsMut, env: Env, info: MessageInfo) {} + + pub fn receive_msg(&self, src_network: String, conn_sn: u128, order_msg: OrderMsg) {} + + pub fn get_next_deposit_id(&self, storage: &mut dyn Storage) -> StdResult { + let id = self.get_deposit_id(storage)?; + let new_id = id + 1; + self.set_deposit_id(storage, new_id)?; + Ok(new_id) + } +} diff --git a/contracts/cosmwasm-vm/cw-mock-dapp/src/errors.rs b/contracts/cosmwasm-vm/cw-intents-v1/src/errors.rs similarity index 100% rename from contracts/cosmwasm-vm/cw-mock-dapp/src/errors.rs rename to contracts/cosmwasm-vm/cw-intents-v1/src/errors.rs diff --git a/contracts/cosmwasm-vm/cw-intents-v1/src/lib.rs b/contracts/cosmwasm-vm/cw-intents-v1/src/lib.rs new file mode 100644 index 00000000..f1ca7758 --- /dev/null +++ b/contracts/cosmwasm-vm/cw-intents-v1/src/lib.rs @@ -0,0 +1,100 @@ +pub mod contract; +pub mod errors; +pub mod msg; +pub mod state; +pub mod types; + +use cosmwasm_schema::cw_serde; +use cosmwasm_std::{ + entry_point, to_json_binary, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, MessageInfo, + Response, StdError, StdResult, Storage, SubMsg, WasmMsg, +}; + +use cw2::set_contract_version; +use cw_storage_plus::{Item, Map}; +pub use errors::*; +use msg::{ExecuteMsg, QueryMsg}; +use state::CwIntentV1Service; +use thiserror::Error; +pub use types::*; + +#[entry_point] +pub fn instantiate( + deps: DepsMut, + env: Env, + info: MessageInfo, + msg: InstantiateMsg, +) -> Result { + let call_service = CwIntentV1Service::default(); + + call_service.instantiate(deps, env, info, msg) +} + +#[entry_point] +pub fn execute( + deps: DepsMut, + env: Env, + info: MessageInfo, + msg: ExecuteMsg, +) -> Result { + let call_service = CwIntentV1Service::default(); + match msg { + ExecuteMsg::Swap { + dst_nid, + token, + amount, + to_token, + destination_address, + min_receive, + data, + } => { + let id = call_service.get_next_deposit_id(deps.storage)?; + let src_nid = call_service.get_nid(deps.storage)?; + let order = SwapOrder::new( + id, + env.contract.address.to_string(), + src_nid, + dst_nid, + info.sender.to_string(), + destination_address, + token, + amount, + to_token, + min_receive, + data, + ); + call_service.swap(order, deps, env, info); + Ok(Response::new()) + } + ExecuteMsg::Fill { + id, + emitter, + src_nid, + dst_nid, + creator, + destination_address, + token, + amount, + to_token, + min_receive, + data, + fill_amount, + solver_address, + } => Ok(Response::new()), + ExecuteMsg::RecvMessage { + src_network, + conn_sn, + msg, + } => Ok(Response::new()), + } +} + +#[entry_point] +pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { + let call_service = CwIntentV1Service::default(); + match msg { + QueryMsg::GetOrder { id } => { + to_json_binary(&call_service.get_order(deps.storage, id).unwrap()) + } + } +} diff --git a/contracts/cosmwasm-vm/cw-intents-v1/src/msg.rs b/contracts/cosmwasm-vm/cw-intents-v1/src/msg.rs new file mode 100644 index 00000000..58561780 --- /dev/null +++ b/contracts/cosmwasm-vm/cw-intents-v1/src/msg.rs @@ -0,0 +1,44 @@ +use cosmwasm_schema::{cw_serde, QueryResponses}; + +#[cw_serde] +pub enum ExecuteMsg { + Swap { + dst_nid: String, + token: String, + amount: u128, + to_token: String, + destination_address: String, + min_receive: u128, + data: Vec, + }, + Fill { + id: u128, + emitter: String, + src_nid: String, + dst_nid: String, + creator: String, + destination_address: String, + token: String, + amount: u128, + to_token: String, + min_receive: u128, + data: Vec, + fill_amount: u128, + solver_address: String, + }, + RecvMessage { + src_network: String, + conn_sn: u128, + msg: String, + }, +} + +#[cw_serde] +#[derive(QueryResponses)] +/// This is a Rust enum representing different types of queries that can be made to the contract. Each +/// variant of the enum corresponds to a specific query and has a return type specified using the +/// `#[returns]` attribute. +pub enum QueryMsg { + #[returns(u64)] + GetOrder { id: u128 }, +} diff --git a/contracts/cosmwasm-vm/cw-intents-v1/src/state.rs b/contracts/cosmwasm-vm/cw-intents-v1/src/state.rs new file mode 100644 index 00000000..d983bf5a --- /dev/null +++ b/contracts/cosmwasm-vm/cw-intents-v1/src/state.rs @@ -0,0 +1,109 @@ +use cosmwasm_std::Addr; + +use crate::types::StorageKey; + +use super::*; + +pub struct CwIntentV1Service<'a> { + deposit_id: Item<'a, u128>, + nid: Item<'a, String>, + protocol_fee: Item<'a, u8>, + fee_handler: Item<'a, Addr>, + orders: Map<'a, u128, SwapOrder>, + pending_fills: Map<'a, Vec, u128>, + finished_orders: Map<'a, Vec, bool>, +} + +impl<'a> Default for CwIntentV1Service<'a> { + fn default() -> Self { + Self::new() + } +} + +impl<'a> CwIntentV1Service<'a> { + pub fn new() -> Self { + Self { + deposit_id: Item::new(StorageKey::DepositId.as_str()), + nid: Item::new(StorageKey::Nid.as_str()), + protocol_fee: Item::new(StorageKey::ProtocolFee.as_str()), + fee_handler: Item::new(StorageKey::FeeHandler.as_str()), + orders: Map::new(StorageKey::Orders.as_str()), + pending_fills: Map::new(StorageKey::PendingFills.as_str()), + finished_orders: Map::new(StorageKey::FinishedOrders.as_str()), + } + } + + pub fn get_deposit_id(&self, storage: &dyn Storage) -> StdResult { + self.deposit_id.load(storage) + } + + pub fn get_nid(&self, storage: &dyn Storage) -> StdResult { + self.nid.load(storage) + } + + pub fn get_protocol_fee(&self, storage: &dyn Storage) -> StdResult { + self.protocol_fee.load(storage) + } + + pub fn get_fee_handler(&self, storage: &dyn Storage) -> StdResult { + self.fee_handler.load(storage) + } + + pub fn get_order(&self, storage: &dyn Storage, key: u128) -> StdResult> { + self.orders.may_load(storage, key) + } + + pub fn get_pending_fill(&self, storage: &dyn Storage, key: &[u8]) -> Option { + self.pending_fills.load(storage, key.to_vec()).ok() + } + + pub fn is_order_finished(&self, storage: &dyn Storage, key: &[u8]) -> bool { + self.finished_orders + .load(storage, key.to_vec()) + .unwrap_or(false) + } + + // Setters + pub fn set_deposit_id(&self, storage: &mut dyn Storage, value: u128) -> StdResult<()> { + self.deposit_id.save(storage, &value) + } + + pub fn set_nid(&self, storage: &mut dyn Storage, value: String) -> StdResult<()> { + self.nid.save(storage, &value) + } + + pub fn set_protocol_fee(&self, storage: &mut dyn Storage, value: u8) -> StdResult<()> { + self.protocol_fee.save(storage, &value) + } + + pub fn set_fee_handler(&self, storage: &mut dyn Storage, value: Addr) -> StdResult<()> { + self.fee_handler.save(storage, &value) + } + + pub fn set_order( + &self, + storage: &mut dyn Storage, + key: u128, + value: &SwapOrder, + ) -> StdResult<()> { + self.orders.save(storage, key, value) + } + + pub fn set_pending_fill( + &self, + storage: &mut dyn Storage, + key: &[u8], + value: u128, + ) -> StdResult<()> { + self.pending_fills.save(storage, key.to_vec(), &value) + } + + pub fn set_order_finished( + &self, + storage: &mut dyn Storage, + key: &[u8], + value: bool, + ) -> StdResult<()> { + self.finished_orders.save(storage, key.to_vec(), &value) + } +} diff --git a/contracts/cosmwasm-vm/cw-intents-v1/src/types.rs b/contracts/cosmwasm-vm/cw-intents-v1/src/types.rs new file mode 100644 index 00000000..83ca95c7 --- /dev/null +++ b/contracts/cosmwasm-vm/cw-intents-v1/src/types.rs @@ -0,0 +1,210 @@ +use super::*; +use common::rlp::{self, Decodable, DecoderError, Encodable, RlpStream}; + +const ORDER_FILL: u8 = 1; +const ORDER_CANCEL: u8 = 2; +#[cw_serde] +pub struct InstantiateMsg { + pub fee_handler: String, + pub nid: String, + pub fee: u8, +} + +#[cw_serde] +pub enum StorageKey { + DepositId, + Nid, + ProtocolFee, + FeeHandler, + Orders, + PendingOrderAmount, + PendingFills, + FinishedOrders, +} + +impl StorageKey { + pub fn as_str(&self) -> &'static str { + match self { + StorageKey::DepositId => "deposit_id", + StorageKey::Nid => "nid", + StorageKey::ProtocolFee => "protocol_fee", + StorageKey::FeeHandler => "fee_handler", + StorageKey::Orders => "orders", + StorageKey::PendingOrderAmount => "pending_order_amount", + StorageKey::PendingFills => "pending_fills", + StorageKey::FinishedOrders => "finished_orders", + } + } +} + +#[cw_serde] +pub struct SwapOrder { + pub id: u128, + pub emitter: String, + pub src_nid: String, + pub dst_nid: String, + pub creator: String, + pub destination_address: String, + pub token: String, + pub amount: u128, + pub to_token: String, + pub min_receive: u128, + pub data: Vec, +} + +impl SwapOrder { + pub fn new( + id: u128, + emitter: String, + src_nid: String, + dst_nid: String, + creator: String, + destination_address: String, + token: String, + amount: u128, + to_token: String, + min_receive: u128, + data: Vec, + ) -> Self { + Self { + id, + emitter, + src_nid, + dst_nid, + creator, + destination_address, + token, + amount, + to_token, + min_receive, + data, + } + } +} + +pub struct OrderMsg { + msg_type: u8, + message: Vec, +} + +impl Encodable for OrderMsg { + fn rlp_append(&self, stream: &mut RlpStream) { + stream.begin_list(2); + stream.append(&Into::::into(self.msg_type)); + stream.append(&self.message); + } +} + +impl Decodable for OrderMsg { + fn decode(rlp: &rlp::Rlp) -> Result { + let msg_type: u8 = rlp.val_at(0)?; + let message: Vec = rlp.val_at(1)?; + Ok(OrderMsg { msg_type, message }) + } +} + +pub struct OrderFill { + id: u128, + order_bytes: Vec, + solver_address: String, + amount: u128, + closed: bool, +} + +impl Encodable for OrderFill { + fn rlp_append(&self, stream: &mut RlpStream) { + stream.begin_list(5); + stream.append(&self.id); + stream.append(&self.order_bytes); + stream.append(&self.solver_address); + stream.append(&self.amount); + stream.append(&self.closed); + } +} + +impl Decodable for OrderFill { + fn decode(rlp: &rlp::Rlp) -> Result { + Ok(OrderFill { + id: rlp.val_at(0)?, + order_bytes: rlp.val_at(1)?, + solver_address: rlp.val_at(2)?, + amount: rlp.val_at(3)?, + closed: rlp.val_at(4)?, + }) + } +} + +pub struct OrderCancel { + order_bytes: Vec, +} + +impl Encodable for OrderCancel { + fn rlp_append(&self, s: &mut RlpStream) { + s.begin_list(1); + s.append(&self.order_bytes); + } +} + +impl Decodable for OrderCancel { + fn decode(rlp: &rlp::Rlp) -> Result { + Ok(OrderCancel { + order_bytes: rlp.val_at(0)?, + }) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_order_msg_encoding_fill() { + let msg = OrderMsg { + msg_type: ORDER_FILL, + message: hex::decode("6c449988e2f33302803c93f8287dc1d8cb33848a").unwrap(), + }; + assert!( + msg.rlp_bytes() + == hex::decode("d601946c449988e2f33302803c93f8287dc1d8cb33848a").unwrap() + ) + } + + #[test] + fn test_order_msg_encoding_cancel() { + let msg = OrderMsg { + msg_type: ORDER_CANCEL, + message: hex::decode("6c449988e2f33302803c93f8287dc1d8cb33848a").unwrap(), + }; + assert!( + msg.rlp_bytes() + == hex::decode("d602946c449988e2f33302803c93f8287dc1d8cb33848a").unwrap() + ) + } + + #[test] + fn test_order_fill_encoding() { + let fill = OrderFill { + id: 1, + order_bytes: hex::decode("6c449988e2f33302803c93f8287dc1d8cb33848a").unwrap(), + solver_address: "0xcb0a6bbccfccde6be9f10ae781b9d9b00d6e63".to_string(), + amount: 500, + closed: true, + }; + assert!(fill.rlp_bytes()==hex::decode("f84301946c449988e2f33302803c93f8287dc1d8cb33848aa8307863623061366262636366636364653662653966313061653738316239643962303064366536338201f401").unwrap()); + } + + #[test] + fn test_order_fill_encoding2() { + let fill = OrderFill { + id: 2, + order_bytes: hex::decode("cb0a6bbccfccde6be9f10ae781b9d9b00d6e63").unwrap(), + solver_address: "0x6c449988e2f33302803c93f8287dc1d8cb33848a".to_string(), + amount: 750 * 1000000000000000000, + closed: false, + }; + assert!(fill.rlp_bytes()==hex::decode("f84b0293cb0a6bbccfccde6be9f10ae781b9d9b00d6e63aa3078366334343939383865326633333330323830336339336638323837646331643863623333383438618928a857425466f8000000").unwrap()); + } + + #[test] + fn test_order_cancel_encoding() {} +} diff --git a/contracts/cosmwasm-vm/cw-centralized-connection/tests/setup.rs b/contracts/cosmwasm-vm/cw-intents-v1/tests/setup.rs similarity index 100% rename from contracts/cosmwasm-vm/cw-centralized-connection/tests/setup.rs rename to contracts/cosmwasm-vm/cw-intents-v1/tests/setup.rs diff --git a/contracts/cosmwasm-vm/cw-mock-dapp/src/contract.rs b/contracts/cosmwasm-vm/cw-mock-dapp/src/contract.rs deleted file mode 100644 index 01aaa80a..00000000 --- a/contracts/cosmwasm-vm/cw-mock-dapp/src/contract.rs +++ /dev/null @@ -1,143 +0,0 @@ -use std::str::from_utf8; - -use super::*; -use cw_xcall_lib::message::call_message_persisted::CallMessagePersisted; -use cw_xcall_lib::message::AnyMessage; -use cw_xcall_lib::message::{ - call_message::CallMessage, call_message_rollback::CallMessageWithRollback, envelope::Envelope, -}; -use cw_xcall_lib::{network_address::NetworkAddress, xcall_msg::ExecuteMsg}; - -// version info for migration info -const CONTRACT_NAME: &str = "crates.io:cw-mock-dapp"; -const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); - -impl<'a> CwMockService<'a> { - pub fn instantiate( - &self, - deps: DepsMut, - _env: Env, - _info: MessageInfo, - msg: InstantiateMsg, - ) -> Result { - set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; - let sequence = u64::default(); - self.sequence().save(deps.storage, &sequence)?; - self.xcall_address().save(deps.storage, &msg.address)?; - - Ok(Response::new()) - } - - pub fn send_call_message( - &self, - deps: DepsMut, - info: MessageInfo, - to: NetworkAddress, - data: Vec, - rollback: Option>, - ) -> Result { - let _sequence = self.increment_sequence(deps.storage)?; - let address = self - .xcall_address() - .load(deps.storage) - .map_err(|_e| ContractError::ModuleAddressNotFound)?; - - let msg = ExecuteMsg::SendCallMessage { - to, - data, - sources: None, - destinations: None, - rollback, - }; - let message: CosmosMsg = CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: address, - msg: to_json_binary(&msg).unwrap(), - funds: info.funds, - }); - - println!("{:?}", message); - - Ok(Response::new() - .add_attribute("Action", "SendMessage") - .add_message(message)) - } - - pub fn send_new_call_message( - &self, - deps: DepsMut, - info: MessageInfo, - to: NetworkAddress, - data: Vec, - rollback: Option>, - is_persistent: bool, - ) -> Result { - let _sequence = self.increment_sequence(deps.storage)?; - let address = self - .xcall_address() - .load(deps.storage) - .map_err(|_e| ContractError::ModuleAddressNotFound)?; - - let msg = if is_persistent { - AnyMessage::CallMessagePersisted(CallMessagePersisted { data }) - } else if let Some(rollback) = rollback { - AnyMessage::CallMessageWithRollback(CallMessageWithRollback { data, rollback }) - } else { - AnyMessage::CallMessage(CallMessage { data }) - }; - let envelope = Envelope::new(msg, vec![], vec![]); - - let msg = ExecuteMsg::SendCall { envelope, to }; - let message: CosmosMsg = CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: address, - msg: to_json_binary(&msg).unwrap(), - funds: info.funds, - }); - - println!("{:?}", message); - - Ok(Response::new() - .add_attribute("Action", "SendNewMessage") - .add_message(message)) - } - - pub fn handle_call_message( - &self, - deps: DepsMut, - info: MessageInfo, - from: NetworkAddress, - data: Vec, - ) -> Result { - if info.sender == from.account() { - let recieved_rollback = - serde_json_wasm::from_slice::(&data).map_err(|e| { - ContractError::DecodeError { - error: e.to_string(), - } - })?; - let seq = recieved_rollback.id; - let rollback_store = self - .roll_back() - .load(deps.storage, seq) - .map_err(|_e| ContractError::MisiingRollBack { sequence: seq })?; - if rollback_store != recieved_rollback.rollback { - return Err(ContractError::RollBackMismatch { sequence: seq }); - } - self.roll_back().remove(deps.storage, seq); - - Ok(Response::new() - .add_attribute("action", "RollbackDataReceived") - .add_attribute("from", from.to_string()) - .add_attribute("sequence", seq.to_string())) - } else { - let msg_data = from_utf8(&data).map_err(|e| ContractError::DecodeError { - error: e.to_string(), - })?; - if "rollback" == msg_data { - return Err(ContractError::RevertFromDAPP); - } - Ok(Response::new() - .add_attribute("from", from.to_string()) - .add_attribute("data", msg_data)) - } - } -} diff --git a/contracts/cosmwasm-vm/cw-mock-dapp/src/helper.rs b/contracts/cosmwasm-vm/cw-mock-dapp/src/helper.rs deleted file mode 100644 index 9c6d3832..00000000 --- a/contracts/cosmwasm-vm/cw-mock-dapp/src/helper.rs +++ /dev/null @@ -1,25 +0,0 @@ -use super::*; - -impl<'a> CwMockService<'a> { - pub fn init_sequence( - &self, - store: &mut dyn Storage, - sequence_no: u64, - ) -> Result<(), ContractError> { - match self.sequence().save(store, &sequence_no) { - Ok(_) => Ok(()), - Err(error) => Err(ContractError::Std(error)), - } - } - - pub fn increment_sequence(&self, store: &mut dyn Storage) -> Result { - self.sequence().update(store, |seq| Ok(seq + 1)) - } - - pub fn get_sequence(&self, store: &dyn Storage) -> Result { - match self.sequence().load(store) { - Ok(sequence) => Ok(sequence), - Err(error) => Err(ContractError::Std(error)), - } - } -} diff --git a/contracts/cosmwasm-vm/cw-mock-dapp/src/lib.rs b/contracts/cosmwasm-vm/cw-mock-dapp/src/lib.rs deleted file mode 100644 index 6990cd6a..00000000 --- a/contracts/cosmwasm-vm/cw-mock-dapp/src/lib.rs +++ /dev/null @@ -1,113 +0,0 @@ -pub mod contract; -pub mod errors; -pub mod helper; -pub mod msg; -pub mod state; -pub mod types; - -use cosmwasm_schema::cw_serde; -use cosmwasm_std::{ - entry_point, to_json_binary, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, MessageInfo, - Response, StdError, StdResult, Storage, SubMsg, WasmMsg, -}; - -use cw2::set_contract_version; -use cw_storage_plus::{Item, Map}; -pub use errors::*; -use msg::{ExecuteMsg, QueryMsg}; -use state::CwMockService; -use thiserror::Error; -pub use types::*; - -#[entry_point] -pub fn instantiate( - deps: DepsMut, - env: Env, - info: MessageInfo, - msg: InstantiateMsg, -) -> Result { - let call_service = CwMockService::default(); - - call_service.instantiate(deps, env, info, msg) -} - -#[entry_point] -pub fn execute( - deps: DepsMut, - _env: Env, - info: MessageInfo, - msg: ExecuteMsg, -) -> Result { - let call_service = CwMockService::default(); - match msg { - ExecuteMsg::SendCallMessage { to, data, rollback } => { - call_service.send_call_message(deps, info, to, data, rollback) - } - ExecuteMsg::SendNewCallMessage { - to, - data, - rollback, - is_persistent, - } => call_service.send_new_call_message(deps, info, to, data, rollback, is_persistent), - ExecuteMsg::HandleCallMessage { from, data } => { - call_service.handle_call_message(deps, info, from, data) - } - ExecuteMsg::XCallMessage { data } => Ok(Response::new() - .add_attribute("action", "success execute call") - .set_data(data)), - ExecuteMsg::SuccessCall {} => { - let resukt = call_service.increment_sequence(deps.storage)?; - Ok(Response::new().add_attribute("sequence", resukt.to_string())) - } - ExecuteMsg::FailureCall {} => Err(ContractError::ModuleAddressNotFound), - ExecuteMsg::TestCall { - success_addr, - fail_addr, - } => { - let success = ExecuteMsg::SuccessCall {}; - let fail = ExecuteMsg::FailureCall {}; - let success_wasm = CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: success_addr, - msg: to_json_binary(&success).map_err(ContractError::Std)?, - funds: info.funds.clone(), - }); - let fail_wasm = CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: fail_addr, - msg: to_json_binary(&fail).map_err(ContractError::Std)?, - funds: info.funds, - }); - let submessages = vec![ - SubMsg { - msg: success_wasm.clone(), - gas_limit: None, - id: 2, - reply_on: cosmwasm_std::ReplyOn::Never, - }, - SubMsg { - msg: fail_wasm, - gas_limit: None, - id: 6, - reply_on: cosmwasm_std::ReplyOn::Never, - }, - SubMsg { - msg: success_wasm, - gas_limit: None, - id: 2, - reply_on: cosmwasm_std::ReplyOn::Never, - }, - ]; - - Ok(Response::new().add_submessages(submessages)) - } - } -} - -#[entry_point] -pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { - let call_service = CwMockService::default(); - match msg { - QueryMsg::GetSequence {} => { - to_json_binary(&call_service.get_sequence(deps.storage).unwrap()) - } - } -} diff --git a/contracts/cosmwasm-vm/cw-mock-dapp/src/msg.rs b/contracts/cosmwasm-vm/cw-mock-dapp/src/msg.rs deleted file mode 100644 index 8662db3f..00000000 --- a/contracts/cosmwasm-vm/cw-mock-dapp/src/msg.rs +++ /dev/null @@ -1,40 +0,0 @@ -use cosmwasm_schema::{cw_serde, QueryResponses}; -use cw_xcall_lib::network_address::NetworkAddress; - -#[cw_serde] -pub enum ExecuteMsg { - SendCallMessage { - to: NetworkAddress, - data: Vec, - rollback: Option>, - }, - SendNewCallMessage { - to: NetworkAddress, - data: Vec, - rollback: Option>, - is_persistent: bool, - }, - HandleCallMessage { - from: NetworkAddress, - data: Vec, - }, - XCallMessage { - data: Vec, - }, - SuccessCall {}, - FailureCall {}, - TestCall { - success_addr: String, - fail_addr: String, - }, -} - -#[cw_serde] -#[derive(QueryResponses)] -/// This is a Rust enum representing different types of queries that can be made to the contract. Each -/// variant of the enum corresponds to a specific query and has a return type specified using the -/// `#[returns]` attribute. -pub enum QueryMsg { - #[returns(u64)] - GetSequence {}, -} diff --git a/contracts/cosmwasm-vm/cw-mock-dapp/src/state.rs b/contracts/cosmwasm-vm/cw-mock-dapp/src/state.rs deleted file mode 100644 index dc68fa9e..00000000 --- a/contracts/cosmwasm-vm/cw-mock-dapp/src/state.rs +++ /dev/null @@ -1,37 +0,0 @@ -use crate::types::StorageKey; - -use super::*; - -pub struct CwMockService<'a> { - sequence: Item<'a, u64>, - xcall_address: Item<'a, String>, - rollback: Map<'a, u64, Vec>, -} - -impl<'a> Default for CwMockService<'a> { - fn default() -> Self { - Self::new() - } -} - -impl<'a> CwMockService<'a> { - pub fn new() -> Self { - Self { - sequence: Item::new(StorageKey::SequenceNo.as_str()), - xcall_address: Item::new(StorageKey::Address.as_str()), - rollback: Map::new(StorageKey::RollBack.as_str()), - } - } - - pub fn sequence(&self) -> &Item<'a, u64> { - &self.sequence - } - - pub fn xcall_address(&self) -> &Item<'a, String> { - &self.xcall_address - } - - pub fn roll_back(&self) -> &Map<'a, u64, Vec> { - &self.rollback - } -} diff --git a/contracts/cosmwasm-vm/cw-mock-dapp/src/types.rs b/contracts/cosmwasm-vm/cw-mock-dapp/src/types.rs deleted file mode 100644 index ad1e740b..00000000 --- a/contracts/cosmwasm-vm/cw-mock-dapp/src/types.rs +++ /dev/null @@ -1,31 +0,0 @@ -use super::*; - -#[cw_serde] -pub struct InstantiateMsg { - pub address: String, -} - -#[cw_serde] -pub enum StorageKey { - SequenceNo, - Address, - Request, - RollBack, -} - -impl StorageKey { - pub fn as_str(&self) -> &'static str { - match self { - StorageKey::Address => "admin", - StorageKey::Request => "message_request", - StorageKey::SequenceNo => "sequenceno", - StorageKey::RollBack => "rollback", - } - } -} - -#[cw_serde] -pub struct RollbackData { - pub id: u64, - pub rollback: Vec, -} diff --git a/contracts/cosmwasm-vm/cw-mock-dapp/tests/mock_test.rs b/contracts/cosmwasm-vm/cw-mock-dapp/tests/mock_test.rs deleted file mode 100644 index 1c4b9681..00000000 --- a/contracts/cosmwasm-vm/cw-mock-dapp/tests/mock_test.rs +++ /dev/null @@ -1,191 +0,0 @@ -pub mod setup; -use std::str::FromStr; - -use cosmwasm::serde::to_vec; -use cosmwasm_std::testing::mock_env; -use cw_mock_dapp::{state::CwMockService, types::InstantiateMsg, RollbackData}; -use cw_xcall_lib::network_address::NetworkAddress; -use setup::*; - -#[test] -fn test_initialization() { - let mut deps = deps(); - let ctx = CwMockService::default(); - let info = create_mock_info("dapp", "umlg", 2000); - let env = mock_env(); - let msg = InstantiateMsg { - address: "xcall-address".to_string(), - }; - - let res = ctx.instantiate(deps.as_mut(), env, info, msg); - println!("{res:?}") -} - -#[test] -fn test_sequence() { - let mut deps = deps(); - let ctx = CwMockService::default(); - - ctx.init_sequence(&mut deps.storage, u64::default()) - .unwrap(); - ctx.increment_sequence(&mut deps.storage).unwrap(); - let res = ctx.get_sequence(&deps.storage); - - assert!(res.is_ok()); - assert_eq!(res.unwrap(), 1) -} - -#[test] -fn test_send_message() { - let mut deps = deps(); - let ctx = CwMockService::default(); - let info = create_mock_info("hugobyte", "umlg", 2000); - let env = mock_env(); - - ctx.init_sequence(&mut deps.storage, u64::default()) - .unwrap(); - let msg = InstantiateMsg { - address: "xcall-address".to_string(), - }; - ctx.instantiate(deps.as_mut(), env, info.clone(), msg) - .unwrap(); - - let res = ctx.send_call_message( - deps.as_mut(), - info, - NetworkAddress::from_str("netid/xcall").unwrap(), - vec![1, 2, 3, 4], - Some(vec![1, 2, 3, 4, 5]), - ); - - assert!(res.is_ok()); - assert_eq!(res.unwrap().messages[0].id, 0) -} - -#[test] -#[should_panic(expected = "ModuleAddressNotFound")] -fn test_send_message_fail() { - let mut deps = deps(); - let ctx = CwMockService::default(); - let info = create_mock_info("hugobyte", "umlg", 2000); - ctx.init_sequence(&mut deps.storage, u64::default()) - .unwrap(); - ctx.send_call_message( - deps.as_mut(), - info, - NetworkAddress::from_str("netid/xcall").unwrap(), - vec![1, 2, 3, 4], - Some(vec![1, 2, 3, 4, 5]), - ) - .unwrap(); -} - -#[test] -fn test_handle_message() { - let mut deps = deps(); - let ctx = CwMockService::default(); - let info = create_mock_info("hugobyte", "umlg", 2000); - let env = mock_env(); - - ctx.init_sequence(&mut deps.storage, u64::default()) - .unwrap(); - let msg = InstantiateMsg { - address: "xcall-address".to_string(), - }; - ctx.instantiate(deps.as_mut(), env, info.clone(), msg) - .unwrap(); - let res = ctx.handle_call_message( - deps.as_mut(), - info, - NetworkAddress::from_str("netid/xcall").unwrap(), - "helloError".as_bytes().to_vec(), - ); - assert!(res.is_ok()) -} - -#[test] -#[should_panic(expected = "RevertFromDAPP")] -fn test_handle_message_fail_revert() { - let mut deps = deps(); - let ctx = CwMockService::default(); - let info = create_mock_info("hugobyte", "umlg", 2000); - let env = mock_env(); - - ctx.init_sequence(&mut deps.storage, u64::default()) - .unwrap(); - let msg = InstantiateMsg { - address: "xcall-address".to_string(), - }; - ctx.instantiate(deps.as_mut(), env, info.clone(), msg) - .unwrap(); - ctx.handle_call_message( - deps.as_mut(), - info, - NetworkAddress::from_str("netid/xcall").unwrap(), - "rollback".as_bytes().to_vec(), - ) - .unwrap(); -} - -#[test] -fn test_handle_message_pass_true() { - let mut deps = deps(); - let ctx = CwMockService::default(); - let info = create_mock_info("hugobyte", "umlg", 2000); - let env = mock_env(); - - ctx.init_sequence(&mut deps.storage, u64::default()) - .unwrap(); - let msg = InstantiateMsg { - address: "xcall-address".to_string(), - }; - ctx.instantiate(deps.as_mut(), env, info.clone(), msg) - .unwrap(); - - ctx.roll_back() - .save(&mut deps.storage, 1, &vec![1, 2, 3]) - .unwrap(); - - let rollback_data = RollbackData { - id: 1, - rollback: vec![1, 2, 3], - }; - let res = ctx.handle_call_message( - deps.as_mut(), - info, - NetworkAddress::from_str("netid/hugobyte").unwrap(), - to_vec(&rollback_data).unwrap(), - ); - assert!(res.is_ok()); - println!("{:?}", res); - assert_eq!(res.unwrap().attributes[0].value, "RollbackDataReceived") -} - -#[test] -#[should_panic(expected = "MisiingRollBack")] -fn test_handle_message_fail_true() { - let mut deps = deps(); - let ctx = CwMockService::default(); - let info = create_mock_info("hugobyte", "umlg", 2000); - let env = mock_env(); - - ctx.init_sequence(&mut deps.storage, u64::default()) - .unwrap(); - let msg = InstantiateMsg { - address: "xcall-address".to_string(), - }; - ctx.instantiate(deps.as_mut(), env, info.clone(), msg) - .unwrap(); - - let rollback_data = RollbackData { - id: 1, - rollback: vec![1, 2, 3], - }; - ctx.handle_call_message( - deps.as_mut(), - info, - NetworkAddress::from_str("netid/hugobyte").unwrap(), - to_vec(&rollback_data).unwrap(), - ) - .unwrap(); -} diff --git a/contracts/cosmwasm-vm/cw-mock-dapp/tests/setup.rs b/contracts/cosmwasm-vm/cw-mock-dapp/tests/setup.rs deleted file mode 100644 index 42b4cf97..00000000 --- a/contracts/cosmwasm-vm/cw-mock-dapp/tests/setup.rs +++ /dev/null @@ -1,14 +0,0 @@ -use cosmwasm_std::{ - coins, - testing::{mock_dependencies, mock_info, MockApi, MockQuerier, MockStorage}, - Empty, MessageInfo, OwnedDeps, -}; - -pub fn create_mock_info(creator: &str, denom: &str, amount: u128) -> MessageInfo { - let funds = coins(amount, denom); - mock_info(creator, &funds) -} - -pub fn deps() -> OwnedDeps { - mock_dependencies() -}