From f69e348d67fd6eac494730fb9557173667d4add3 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Fri, 17 Dec 2021 13:04:33 +1300 Subject: [PATCH 01/21] poc --- Cargo.lock | 207 +++++++++++++++--- Cargo.toml | 36 +-- runtime/integration-tests/Cargo.toml | 3 +- .../src/relaychain/kusama_test_net.rs | 9 + .../integration-tests/src/relaychain/mod.rs | 1 + .../src/relaychain/statemine.rs | 49 +++++ 6 files changed, 262 insertions(+), 43 deletions(-) create mode 100644 runtime/integration-tests/src/relaychain/statemine.rs diff --git a/Cargo.lock b/Cargo.lock index 551ece280..444264e21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1677,7 +1677,7 @@ dependencies = [ [[package]] name = "cumulus-client-cli" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "sc-cli", "sc-service", @@ -1687,7 +1687,7 @@ dependencies = [ [[package]] name = "cumulus-client-collator" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "cumulus-client-consensus-common", "cumulus-client-network", @@ -1710,7 +1710,7 @@ dependencies = [ [[package]] name = "cumulus-client-consensus-aura" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "async-trait", "cumulus-client-consensus-common", @@ -1740,7 +1740,7 @@ dependencies = [ [[package]] name = "cumulus-client-consensus-common" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "async-trait", "dyn-clone", @@ -1760,7 +1760,7 @@ dependencies = [ [[package]] name = "cumulus-client-consensus-relay-chain" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "async-trait", "cumulus-client-consensus-common", @@ -1784,7 +1784,7 @@ dependencies = [ [[package]] name = "cumulus-client-network" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "derive_more", "futures 0.3.18", @@ -1807,7 +1807,7 @@ dependencies = [ [[package]] name = "cumulus-client-pov-recovery" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "cumulus-primitives-core", "futures 0.3.18", @@ -1830,7 +1830,7 @@ dependencies = [ [[package]] name = "cumulus-client-service" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "cumulus-client-collator", "cumulus-client-consensus-common", @@ -1859,7 +1859,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-aura-ext" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "frame-executive", "frame-support", @@ -1877,7 +1877,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-dmp-queue" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -1895,7 +1895,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-parachain-system" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "cumulus-pallet-parachain-system-proc-macro", "cumulus-primitives-core", @@ -1924,7 +1924,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-parachain-system-proc-macro" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "proc-macro-crate 1.1.0", "proc-macro2", @@ -1932,10 +1932,22 @@ dependencies = [ "syn", ] +[[package]] +name = "cumulus-pallet-session-benchmarking" +version = "3.0.0" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +dependencies = [ + "frame-support", + "frame-system", + "pallet-session", + "sp-runtime", + "sp-std", +] + [[package]] name = "cumulus-pallet-xcm" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -1952,7 +1964,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-xcmp-queue" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -1967,10 +1979,27 @@ dependencies = [ "xcm-executor", ] +[[package]] +name = "cumulus-ping" +version = "0.1.0" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +dependencies = [ + "cumulus-pallet-xcm", + "cumulus-primitives-core", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "serde", + "sp-runtime", + "sp-std", + "xcm", +] + [[package]] name = "cumulus-primitives-core" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "frame-support", "impl-trait-for-tuples 0.2.1", @@ -1987,7 +2016,7 @@ dependencies = [ [[package]] name = "cumulus-primitives-parachain-inherent" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -2009,7 +2038,7 @@ dependencies = [ [[package]] name = "cumulus-primitives-timestamp" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "cumulus-primitives-core", "sp-inherents", @@ -2020,7 +2049,7 @@ dependencies = [ [[package]] name = "cumulus-primitives-utility" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -2037,7 +2066,7 @@ dependencies = [ [[package]] name = "cumulus-test-relay-sproof-builder" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "cumulus-primitives-core", "parity-scale-codec", @@ -6121,7 +6150,7 @@ dependencies = [ "frame-try-runtime", "log", "node-primitives", - "pallet-asset-tx-payment", + "pallet-asset-tx-payment 4.0.0-dev", "pallet-assets", "pallet-authority-discovery", "pallet-authorship", @@ -6770,6 +6799,23 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "pallet-asset-tx-payment" +version = "0.1.0" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +dependencies = [ + "frame-support", + "frame-system", + "pallet-transaction-payment", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-asset-tx-payment" version = "4.0.0-dev" @@ -7026,6 +7072,26 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-collator-selection" +version = "3.0.0" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-authorship", + "pallet-session", + "parity-scale-codec", + "rand 0.7.3", + "scale-info", + "serde", + "sp-runtime", + "sp-staking", + "sp-std", +] + [[package]] name = "pallet-collective" version = "4.0.0-dev" @@ -7773,7 +7839,7 @@ dependencies = [ [[package]] name = "parachain-info" version = "0.1.0" -source = "git+https://github.com/paritytech//cumulus?rev=0be8e8fc214641e306e4f913dd64ff1913e46e95#0be8e8fc214641e306e4f913dd64ff1913e46e95" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -7783,6 +7849,33 @@ dependencies = [ "serde", ] +[[package]] +name = "parachains-common" +version = "1.0.0" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +dependencies = [ + "frame-executive", + "frame-support", + "frame-system", + "pallet-asset-tx-payment 0.1.0", + "pallet-assets", + "pallet-authorship", + "pallet-balances", + "pallet-collator-selection", + "parity-scale-codec", + "polkadot-primitives", + "polkadot-runtime-common", + "scale-info", + "sp-consensus-aura", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "substrate-wasm-builder", + "xcm", + "xcm-executor", +] + [[package]] name = "parity-db" version = "0.3.5" @@ -10014,6 +10107,7 @@ dependencies = [ "sp-transaction-pool", "sp-trie", "sp-version", + "westmint-runtime", "xcm", "xcm-builder", "xcm-emulator", @@ -11298,18 +11392,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.130" +version = "1.0.131" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" +checksum = "b4ad69dfbd3e45369132cc64e6748c2d65cdfb001a2b1c232d128b4ad60561c1" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.130" +version = "1.0.131" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" +checksum = "b710a83c4e0dff6a3d511946b95274ad9ca9e5d3ae497b63fda866ac955358d2" dependencies = [ "proc-macro2", "quote", @@ -13742,6 +13836,69 @@ dependencies = [ "xcm-executor", ] +[[package]] +name = "westmint-runtime" +version = "1.0.0" +source = "git+https://github.com/paritytech//cumulus?rev=05cc5f0e2acacc18796f45ffa3c7b4626fd1046d#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +dependencies = [ + "cumulus-pallet-aura-ext", + "cumulus-pallet-dmp-queue", + "cumulus-pallet-parachain-system", + "cumulus-pallet-session-benchmarking", + "cumulus-pallet-xcm", + "cumulus-pallet-xcmp-queue", + "cumulus-ping", + "cumulus-primitives-core", + "cumulus-primitives-timestamp", + "cumulus-primitives-utility", + "frame-executive", + "frame-support", + "frame-system", + "frame-system-rpc-runtime-api", + "log", + "node-primitives", + "pallet-asset-tx-payment 0.1.0", + "pallet-assets", + "pallet-aura", + "pallet-authorship", + "pallet-balances", + "pallet-collator-selection", + "pallet-multisig", + "pallet-proxy", + "pallet-session", + "pallet-sudo", + "pallet-timestamp", + "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", + "pallet-uniques", + "pallet-utility", + "pallet-xcm", + "parachain-info", + "parachains-common", + "parity-scale-codec", + "polkadot-parachain", + "polkadot-runtime-common", + "scale-info", + "serde", + "smallvec", + "sp-api", + "sp-block-builder", + "sp-consensus-aura", + "sp-core", + "sp-inherents", + "sp-io", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-std", + "sp-transaction-pool", + "sp-version", + "substrate-wasm-builder", + "xcm", + "xcm-builder", + "xcm-executor", +] + [[package]] name = "which" version = "4.2.2" diff --git a/Cargo.toml b/Cargo.toml index 0a018a285..30213cdf6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -279,20 +279,22 @@ xcm-executor = { git = "https://github.com/paritytech//polkadot", rev = "7d8f00b xcm-simulator = { git = "https://github.com/paritytech//polkadot", rev = "7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" } [patch."https://github.com/paritytech/cumulus"] -cumulus-client-cli = { git = "https://github.com/paritytech//cumulus", rev = "0be8e8fc214641e306e4f913dd64ff1913e46e95" } -cumulus-client-consensus-aura = { git = "https://github.com/paritytech//cumulus", rev = "0be8e8fc214641e306e4f913dd64ff1913e46e95" } -cumulus-client-consensus-common = { git = "https://github.com/paritytech//cumulus", rev = "0be8e8fc214641e306e4f913dd64ff1913e46e95" } -cumulus-client-consensus-relay-chain = { git = "https://github.com/paritytech//cumulus", rev = "0be8e8fc214641e306e4f913dd64ff1913e46e95" } -cumulus-client-network = { git = "https://github.com/paritytech//cumulus", rev = "0be8e8fc214641e306e4f913dd64ff1913e46e95" } -cumulus-client-service = { git = "https://github.com/paritytech//cumulus", rev = "0be8e8fc214641e306e4f913dd64ff1913e46e95" } -cumulus-pallet-aura-ext = { git = "https://github.com/paritytech//cumulus", rev = "0be8e8fc214641e306e4f913dd64ff1913e46e95" } -cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech//cumulus", rev = "0be8e8fc214641e306e4f913dd64ff1913e46e95" } -cumulus-pallet-parachain-system = { git = "https://github.com/paritytech//cumulus", rev = "0be8e8fc214641e306e4f913dd64ff1913e46e95" } -cumulus-pallet-xcm = { git = "https://github.com/paritytech//cumulus", rev = "0be8e8fc214641e306e4f913dd64ff1913e46e95" } -cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech//cumulus", rev = "0be8e8fc214641e306e4f913dd64ff1913e46e95" } -cumulus-primitives-core = { git = "https://github.com/paritytech//cumulus", rev = "0be8e8fc214641e306e4f913dd64ff1913e46e95" } -cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech//cumulus", rev = "0be8e8fc214641e306e4f913dd64ff1913e46e95" } -cumulus-primitives-timestamp = { git = "https://github.com/paritytech//cumulus", rev = "0be8e8fc214641e306e4f913dd64ff1913e46e95" } -cumulus-primitives-utility = { git = "https://github.com/paritytech//cumulus", rev = "0be8e8fc214641e306e4f913dd64ff1913e46e95" } -cumulus-test-relay-sproof-builder = { git = "https://github.com/paritytech//cumulus", rev = "0be8e8fc214641e306e4f913dd64ff1913e46e95" } -parachain-info = { git = "https://github.com/paritytech//cumulus", rev = "0be8e8fc214641e306e4f913dd64ff1913e46e95" } +cumulus-client-cli = { git = "https://github.com/paritytech//cumulus", rev = "05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" } +cumulus-client-consensus-aura = { git = "https://github.com/paritytech//cumulus", rev = "05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" } +cumulus-client-consensus-common = { git = "https://github.com/paritytech//cumulus", rev = "05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" } +cumulus-client-consensus-relay-chain = { git = "https://github.com/paritytech//cumulus", rev = "05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" } +cumulus-client-network = { git = "https://github.com/paritytech//cumulus", rev = "05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" } +cumulus-client-service = { git = "https://github.com/paritytech//cumulus", rev = "05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" } +cumulus-pallet-aura-ext = { git = "https://github.com/paritytech//cumulus", rev = "05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" } +cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech//cumulus", rev = "05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" } +cumulus-pallet-parachain-system = { git = "https://github.com/paritytech//cumulus", rev = "05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" } +cumulus-pallet-xcm = { git = "https://github.com/paritytech//cumulus", rev = "05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" } +cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech//cumulus", rev = "05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" } +cumulus-primitives-core = { git = "https://github.com/paritytech//cumulus", rev = "05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" } +cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech//cumulus", rev = "05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" } +cumulus-primitives-timestamp = { git = "https://github.com/paritytech//cumulus", rev = "05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" } +cumulus-primitives-utility = { git = "https://github.com/paritytech//cumulus", rev = "05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" } +cumulus-test-relay-sproof-builder = { git = "https://github.com/paritytech//cumulus", rev = "05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" } +parachain-info = { git = "https://github.com/paritytech//cumulus", rev = "05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" } +westmint-runtime = { git = "https://github.com/paritytech//cumulus", rev = "05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" } +parachains-common = { git = "https://github.com/paritytech//cumulus", rev = "05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" } diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index 43f76cc64..8adad3f9e 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -126,6 +126,7 @@ sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot- cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.13" } cumulus-test-relay-sproof-builder = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.13" } +westmint-runtime = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.13" } polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.13" } polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.13" } @@ -136,7 +137,7 @@ xcm-emulator = { git = "https://github.com/shaunxw/xcm-simulator", rev = "4d3bb9 acala-service = { path = "../../node/service", features = ["with-all-runtime"] } [features] -default = ["std"] +default = ["std", "with-karura-runtime"] no_std = [] with-mandala-runtime = [ "acala-service/with-mandala-runtime", diff --git a/runtime/integration-tests/src/relaychain/kusama_test_net.rs b/runtime/integration-tests/src/relaychain/kusama_test_net.rs index 3ff38e63c..7a4e62f84 100644 --- a/runtime/integration-tests/src/relaychain/kusama_test_net.rs +++ b/runtime/integration-tests/src/relaychain/kusama_test_net.rs @@ -52,10 +52,19 @@ decl_test_parachain! { } } +decl_test_parachain! { + pub struct Statemine { + Runtime = westmint_runtime::Runtime, + Origin = westmint_runtime::Origin, + new_ext = para_ext(1000), + } +} + decl_test_network! { pub struct TestNet { relay_chain = KusamaNet, parachains = vec![ + (1000, Statemine), (2000, Karura), (2001, Sibling), ], diff --git a/runtime/integration-tests/src/relaychain/mod.rs b/runtime/integration-tests/src/relaychain/mod.rs index 1f704d479..6aace3746 100644 --- a/runtime/integration-tests/src/relaychain/mod.rs +++ b/runtime/integration-tests/src/relaychain/mod.rs @@ -19,3 +19,4 @@ mod kusama_cross_chain_transfer; pub mod kusama_test_net; mod relay_chain; +mod statemine; diff --git a/runtime/integration-tests/src/relaychain/statemine.rs b/runtime/integration-tests/src/relaychain/statemine.rs new file mode 100644 index 000000000..448eb1ec9 --- /dev/null +++ b/runtime/integration-tests/src/relaychain/statemine.rs @@ -0,0 +1,49 @@ +// This file is part of Acala. + +// Copyright (C) 2020-2021 Acala Foundation. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Cross-chain transfer tests within Kusama network. + +use crate::relaychain::kusama_test_net::*; +use crate::setup::*; + +use frame_support::assert_ok; + +use xcm_emulator::TestExt; + +#[test] +fn statemine() { + env_logger::init(); + Statemine::execute_with(|| { + use westmint_runtime::*; + assert_ok!(PolkadotXcm::reserve_transfer_assets( + Origin::signed(ALICE.into()), + Box::new(Parachain(1000).into().into()), + Box::new( + Junction::AccountId32 { + id: BOB, + network: NetworkId::Any + } + .into() + .into() + ), + Box::new((Parent, dollar(KSM)).into()), + 0 + )); + println!("{:?}", System::events()); + }); +} From e3014cc4937913c1271d3ed1083201d9105d7f52 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Mon, 20 Dec 2021 12:39:15 +1300 Subject: [PATCH 02/21] wip --- .../src/relaychain/statemine.rs | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/runtime/integration-tests/src/relaychain/statemine.rs b/runtime/integration-tests/src/relaychain/statemine.rs index 448eb1ec9..a33e44844 100644 --- a/runtime/integration-tests/src/relaychain/statemine.rs +++ b/runtime/integration-tests/src/relaychain/statemine.rs @@ -22,17 +22,37 @@ use crate::relaychain::kusama_test_net::*; use crate::setup::*; use frame_support::assert_ok; - +use polkadot_parachain::primitives::Sibling; +use xcm::VersionedMultiLocation; +use xcm_builder::AccountId32Aliases; use xcm_emulator::TestExt; +use xcm_executor::traits::Convert; #[test] fn statemine() { env_logger::init(); Statemine::execute_with(|| { use westmint_runtime::*; + + let origin = Origin::signed(ALICE.into()); + + Balances::make_free_balance_be(&ALICE.into(), 10 * dollar(KSM)); + + // need to have some KSM to be able to receive user assets + Balances::make_free_balance_be(&Sibling::from(2000).into_account(), 10 * dollar(KSM)); + + assert_ok!(Assets::create(origin.clone(), 0, MultiAddress::Id(ALICE.into()), 10,)); + + assert_ok!(Assets::mint(origin.clone(), 0, MultiAddress::Id(ALICE.into()), 1000)); + + System::reset_events(); + + let para_acc: AccountId = Sibling::from(2000).into_account(); + println!("{:?}", para_acc); + assert_ok!(PolkadotXcm::reserve_transfer_assets( - Origin::signed(ALICE.into()), - Box::new(Parachain(1000).into().into()), + origin.clone(), + Box::new(MultiLocation::new(1, X1(Parachain(2000),)).into()), Box::new( Junction::AccountId32 { id: BOB, @@ -41,7 +61,7 @@ fn statemine() { .into() .into() ), - Box::new((Parent, dollar(KSM)).into()), + Box::new((GeneralIndex(0), 100).into()), 0 )); println!("{:?}", System::events()); From 06c053a1c259a3d7ebe5b2a3ed8d3b1430a8a222 Mon Sep 17 00:00:00 2001 From: Roy Yang Date: Tue, 18 Jan 2022 13:28:41 +1300 Subject: [PATCH 03/21] WIP: Transfer assets from westmint /statemine to karura --- .../src/relaychain/statemine.rs | 134 +++++++++++------- 1 file changed, 84 insertions(+), 50 deletions(-) diff --git a/runtime/integration-tests/src/relaychain/statemine.rs b/runtime/integration-tests/src/relaychain/statemine.rs index a33e44844..84599d5be 100644 --- a/runtime/integration-tests/src/relaychain/statemine.rs +++ b/runtime/integration-tests/src/relaychain/statemine.rs @@ -16,54 +16,88 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -//! Cross-chain transfer tests within Kusama network. - -use crate::relaychain::kusama_test_net::*; -use crate::setup::*; - -use frame_support::assert_ok; -use polkadot_parachain::primitives::Sibling; -use xcm::VersionedMultiLocation; -use xcm_builder::AccountId32Aliases; -use xcm_emulator::TestExt; -use xcm_executor::traits::Convert; - -#[test] -fn statemine() { - env_logger::init(); - Statemine::execute_with(|| { - use westmint_runtime::*; - - let origin = Origin::signed(ALICE.into()); - - Balances::make_free_balance_be(&ALICE.into(), 10 * dollar(KSM)); - - // need to have some KSM to be able to receive user assets - Balances::make_free_balance_be(&Sibling::from(2000).into_account(), 10 * dollar(KSM)); - - assert_ok!(Assets::create(origin.clone(), 0, MultiAddress::Id(ALICE.into()), 10,)); - - assert_ok!(Assets::mint(origin.clone(), 0, MultiAddress::Id(ALICE.into()), 1000)); - - System::reset_events(); - - let para_acc: AccountId = Sibling::from(2000).into_account(); - println!("{:?}", para_acc); - - assert_ok!(PolkadotXcm::reserve_transfer_assets( - origin.clone(), - Box::new(MultiLocation::new(1, X1(Parachain(2000),)).into()), - Box::new( - Junction::AccountId32 { - id: BOB, - network: NetworkId::Any - } - .into() - .into() - ), - Box::new((GeneralIndex(0), 100).into()), - 0 - )); - println!("{:?}", System::events()); - }); +//! Tests parachain to parachain xcm communication between Statemine and Karura. + +#[cfg(feature = "with-karura-runtime")] +mod statemine_tests { + use crate::relaychain::kusama_test_net::*; + use crate::setup::*; + + use frame_support::{assert_ok, traits::Hooks}; + use polkadot_parachain::primitives::Sibling; + use xcm::{ + v1::{Junction, Junctions, MultiAsset, MultiAssets, MultiLocation}, + VersionedMultiAssets, VersionedMultiLocation, + }; + use xcm_builder::AccountId32Aliases; + use xcm_emulator::TestExt; + use xcm_executor::traits::Convert; + + #[test] + fn can_transfer_custom_asset_into_karura() { + env_logger::init(); + Statemine::execute_with(|| { + use westmint_runtime::*; + + let origin = Origin::signed(ALICE.into()); + Balances::make_free_balance_be(&ALICE.into(), 10 * dollar(KSM)); + + // need to have some KSM to be able to receive user assets + Balances::make_free_balance_be(&Sibling::from(2000).into_account(), 10 * dollar(KSM)); + + assert_ok!(Assets::create(origin.clone(), 0, MultiAddress::Id(ALICE.into()), 10,)); + assert_ok!(Assets::mint(origin.clone(), 0, MultiAddress::Id(ALICE.into()), 1000)); + + let para_acc: AccountId = Sibling::from(2000).into_account(); + + // KSM is used to pay for xcm execution + let multi_asset: VersionedMultiAssets = VersionedMultiAssets::V1( + vec![ + MultiAsset { + id: Concrete(MultiLocation::here()), + fun: Fungibility::Fungible(dollar(KSM)), + }, + MultiAsset { + id: Concrete(MultiLocation { + parents: 0, + interior: Junctions::X1(Junction::GeneralIndex(0)), + }), + fun: Fungibility::Fungible(100), + }, + ] + .into(), + ); + // !todo : Figure out how to represent GeneralIndex(0) in MultiAsset so the transaction can go + // through + + assert_ok!(PolkadotXcm::reserve_transfer_assets( + origin.clone(), + Box::new(MultiLocation::new(1, X1(Parachain(2000))).into()), + Box::new( + Junction::AccountId32 { + id: BOB, + network: NetworkId::Any + } + .into() + .into() + ), + Box::new(multi_asset), + 0 + )); + assert_eq!(Balances::free_balance(&ALICE.into()), 9 * dollar(KSM)); + assert_eq!(Assets::balance(0, ¶_acc), 100); + }); + + // Rerun the Statemine::execute to actually send the egress message via XCM + Statemine::execute_with(|| { + let para_acc: AccountId = Sibling::from(2000).into_account(); + assert_eq!(westmint_runtime::Assets::balance(0, ¶_acc), 100); + println!("Westmint: {:?}", westmint_runtime::System::events()); + }); + + Karura::execute_with(|| { + println!("Karura: {:?}", karura_runtime::System::events()); + // assert_eq!(Tokens::free_balance(KSM, &AccountId::from(BOB)), 0); + }); + } } From 05f8c513acc473ac51a6adbb7c2ec2d7771dd6de Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Mon, 24 Jan 2022 14:49:41 +1300 Subject: [PATCH 04/21] update --- .../src/relaychain/statemine.rs | 24 ++----------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/runtime/integration-tests/src/relaychain/statemine.rs b/runtime/integration-tests/src/relaychain/statemine.rs index 84599d5be..5968c3abd 100644 --- a/runtime/integration-tests/src/relaychain/statemine.rs +++ b/runtime/integration-tests/src/relaychain/statemine.rs @@ -50,26 +50,6 @@ mod statemine_tests { let para_acc: AccountId = Sibling::from(2000).into_account(); - // KSM is used to pay for xcm execution - let multi_asset: VersionedMultiAssets = VersionedMultiAssets::V1( - vec![ - MultiAsset { - id: Concrete(MultiLocation::here()), - fun: Fungibility::Fungible(dollar(KSM)), - }, - MultiAsset { - id: Concrete(MultiLocation { - parents: 0, - interior: Junctions::X1(Junction::GeneralIndex(0)), - }), - fun: Fungibility::Fungible(100), - }, - ] - .into(), - ); - // !todo : Figure out how to represent GeneralIndex(0) in MultiAsset so the transaction can go - // through - assert_ok!(PolkadotXcm::reserve_transfer_assets( origin.clone(), Box::new(MultiLocation::new(1, X1(Parachain(2000))).into()), @@ -81,10 +61,10 @@ mod statemine_tests { .into() .into() ), - Box::new(multi_asset), + Box::new((GeneralIndex(0), 100).into()), 0 )); - assert_eq!(Balances::free_balance(&ALICE.into()), 9 * dollar(KSM)); + assert_eq!(Assets::balance(0, ¶_acc), 100); }); From d490d9b25653fe71414356539bbf5e3a2ac0e893 Mon Sep 17 00:00:00 2001 From: zqh Date: Fri, 18 Feb 2022 15:46:43 +0800 Subject: [PATCH 05/21] fix statemine test --- .../src/relaychain/statemine.rs | 138 ++++++++++-------- 1 file changed, 77 insertions(+), 61 deletions(-) diff --git a/runtime/integration-tests/src/relaychain/statemine.rs b/runtime/integration-tests/src/relaychain/statemine.rs index 5968c3abd..ac123f761 100644 --- a/runtime/integration-tests/src/relaychain/statemine.rs +++ b/runtime/integration-tests/src/relaychain/statemine.rs @@ -17,67 +17,83 @@ // along with this program. If not, see . //! Tests parachain to parachain xcm communication between Statemine and Karura. +use crate::relaychain::kusama_test_net::*; +use crate::setup::*; + +use frame_support::assert_ok; +use module_asset_registry::AssetMetadata; +use polkadot_parachain::primitives::Sibling; +use xcm::v1::{Junction, MultiLocation}; +use xcm_emulator::TestExt; #[cfg(feature = "with-karura-runtime")] -mod statemine_tests { - use crate::relaychain::kusama_test_net::*; - use crate::setup::*; - - use frame_support::{assert_ok, traits::Hooks}; - use polkadot_parachain::primitives::Sibling; - use xcm::{ - v1::{Junction, Junctions, MultiAsset, MultiAssets, MultiLocation}, - VersionedMultiAssets, VersionedMultiLocation, - }; - use xcm_builder::AccountId32Aliases; - use xcm_emulator::TestExt; - use xcm_executor::traits::Convert; - - #[test] - fn can_transfer_custom_asset_into_karura() { - env_logger::init(); - Statemine::execute_with(|| { - use westmint_runtime::*; - - let origin = Origin::signed(ALICE.into()); - Balances::make_free_balance_be(&ALICE.into(), 10 * dollar(KSM)); - - // need to have some KSM to be able to receive user assets - Balances::make_free_balance_be(&Sibling::from(2000).into_account(), 10 * dollar(KSM)); - - assert_ok!(Assets::create(origin.clone(), 0, MultiAddress::Id(ALICE.into()), 10,)); - assert_ok!(Assets::mint(origin.clone(), 0, MultiAddress::Id(ALICE.into()), 1000)); - - let para_acc: AccountId = Sibling::from(2000).into_account(); - - assert_ok!(PolkadotXcm::reserve_transfer_assets( - origin.clone(), - Box::new(MultiLocation::new(1, X1(Parachain(2000))).into()), - Box::new( - Junction::AccountId32 { - id: BOB, - network: NetworkId::Any - } - .into() - .into() - ), - Box::new((GeneralIndex(0), 100).into()), - 0 - )); - - assert_eq!(Assets::balance(0, ¶_acc), 100); - }); - - // Rerun the Statemine::execute to actually send the egress message via XCM - Statemine::execute_with(|| { - let para_acc: AccountId = Sibling::from(2000).into_account(); - assert_eq!(westmint_runtime::Assets::balance(0, ¶_acc), 100); - println!("Westmint: {:?}", westmint_runtime::System::events()); - }); - - Karura::execute_with(|| { - println!("Karura: {:?}", karura_runtime::System::events()); - // assert_eq!(Tokens::free_balance(KSM, &AccountId::from(BOB)), 0); - }); - } +#[test] +fn can_transfer_custom_asset_into_karura() { + env_logger::init(); + + Karura::execute_with(|| { + // register foreign asset + assert_ok!(AssetRegistry::register_foreign_asset( + Origin::root(), + Box::new(MultiLocation::new(1, X3(Parachain(1000), PalletInstance(50), GeneralIndex(0))).into()), + Box::new(AssetMetadata { + name: b"Sibling Token".to_vec(), + symbol: b"ST".to_vec(), + decimals: 12, + minimal_balance: Balances::minimum_balance() / 10, // 10% + }) + )); + }); + + Statemine::execute_with(|| { + use westmint_runtime::*; + + let origin = Origin::signed(ALICE.into()); + Balances::make_free_balance_be(&ALICE.into(), 10 * dollar(KSM)); + + // need to have some KSM to be able to receive user assets + Balances::make_free_balance_be(&Sibling::from(2000).into_account(), 10 * dollar(KSM)); + + assert_ok!(Assets::create( + origin.clone(), + 0, + MultiAddress::Id(ALICE.into()), + cent(KSM) + )); + assert_ok!(Assets::mint( + origin.clone(), + 0, + MultiAddress::Id(ALICE.into()), + 1000 * dollar(KSM) + )); + + let para_acc: AccountId = Sibling::from(2000).into_account(); + + assert_ok!(PolkadotXcm::reserve_transfer_assets( + origin.clone(), + Box::new(MultiLocation::new(1, X1(Parachain(2000))).into()), + Box::new( + Junction::AccountId32 { + id: BOB, + network: NetworkId::Any + } + .into() + .into() + ), + Box::new((X2(PalletInstance(50), GeneralIndex(0)), dollar(KSM)).into()), + 0 + )); + + assert_eq!(Assets::balance(0, ¶_acc), dollar(KSM)); + }); + + // Rerun the Statemine::execute to actually send the egress message via XCM + Statemine::execute_with(|| {}); + + Karura::execute_with(|| { + assert_eq!( + 999_360_000_000, + Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) + ); + }); } From b2b003d3d41e940f9a16d26031c80138a74f200c Mon Sep 17 00:00:00 2001 From: zqh Date: Fri, 18 Feb 2022 23:02:45 +0800 Subject: [PATCH 06/21] transfer back to statemine failed --- .../src/relaychain/statemine.rs | 94 ++++++++++++++++++- 1 file changed, 89 insertions(+), 5 deletions(-) diff --git a/runtime/integration-tests/src/relaychain/statemine.rs b/runtime/integration-tests/src/relaychain/statemine.rs index ac123f761..97319bd53 100644 --- a/runtime/integration-tests/src/relaychain/statemine.rs +++ b/runtime/integration-tests/src/relaychain/statemine.rs @@ -22,6 +22,7 @@ use crate::setup::*; use frame_support::assert_ok; use module_asset_registry::AssetMetadata; +use orml_traits::location::Reserve; use polkadot_parachain::primitives::Sibling; use xcm::v1::{Junction, MultiLocation}; use xcm_emulator::TestExt; @@ -45,6 +46,8 @@ fn can_transfer_custom_asset_into_karura() { )); }); + let para_acc: AccountId = Sibling::from(2000).into_account(); + Statemine::execute_with(|| { use westmint_runtime::*; @@ -67,8 +70,6 @@ fn can_transfer_custom_asset_into_karura() { 1000 * dollar(KSM) )); - let para_acc: AccountId = Sibling::from(2000).into_account(); - assert_ok!(PolkadotXcm::reserve_transfer_assets( origin.clone(), Box::new(MultiLocation::new(1, X1(Parachain(2000))).into()), @@ -80,11 +81,11 @@ fn can_transfer_custom_asset_into_karura() { .into() .into() ), - Box::new((X2(PalletInstance(50), GeneralIndex(0)), dollar(KSM)).into()), + Box::new((X2(PalletInstance(50), GeneralIndex(0)), 10 * dollar(KSM)).into()), 0 )); - assert_eq!(Assets::balance(0, ¶_acc), dollar(KSM)); + assert_eq!(Assets::balance(0, ¶_acc), 10 * dollar(KSM)); }); // Rerun the Statemine::execute to actually send the egress message via XCM @@ -92,8 +93,91 @@ fn can_transfer_custom_asset_into_karura() { Karura::execute_with(|| { assert_eq!( - 999_360_000_000, + 9_999_360_000_000, Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) ); + // Transfer statemine asset back to Statemine + + // Error: TooExpensive because Statemine trader not matched + // 1. westmint/statemine use `Parent` as AssetId + // https://github.com/paritytech/cumulus/blob/master/polkadot-parachains/westmint/src/xcm_config.rs#L159 + // 2. trader required is (Parent, amount) + // https://github.com/paritytech/polkadot/blob/release-v0.9.16/xcm/xcm-builder/src/weight.rs#L270 + // 3. the asset sent to statemine is (PalletInstance(50), GeneralIndex(0)) not matched `required` + // so when excecute `BuyExecution`, throw TooExpensive error making xcm failed + assert_ok!(XTokens::transfer( + Origin::signed(BOB.into()), + CurrencyId::ForeignAsset(0), + dollar(KSM), + Box::new( + MultiLocation::new( + 1, + X2( + Parachain(2001), + Junction::AccountId32 { + network: NetworkId::Any, + id: BOB.into(), + } + ) + ) + .into() + ), + 5_000_000_000, + )); + + // for matching with `required` => (Parent, amount), we should use KSM as fee + // Error: DistinctReserveForAssetAndFee in orml-xTokens check + let statemine_asset = MultiAsset { + id: AssetId::Concrete(MultiLocation::new( + 1, + Junctions::X3( + Junction::Parachain(1000), + Junction::PalletInstance(50), + Junction::GeneralIndex(0), + ), + )), + fun: Fungibility::Fungible(dollar(KSM)), + }; + let fee_asset = MultiAsset { + id: AssetId::Concrete(MultiLocation::new(1, Junctions::Here)), + fun: Fungibility::Fungible(5_000_000_000), + }; + // current not support different reserve + // statemine_asset.reserve() == (Parent, Parachain(1000)) + // fee_asset.reserve() = (Parent) + assert_ok!(XTokens::transfer_multiasset_with_fee( + Origin::signed(BOB.into()), + Box::new(statemine_asset.into()), + Box::new(fee_asset.into()), + Box::new( + MultiLocation::new( + 1, + X2( + Parachain(1000), + Junction::AccountId32 { + network: NetworkId::Any, + id: BOB.into(), + } + ) + ) + .into() + ), + 5_000_000_000, + )); + assert_eq!( + 8_999_360_000_000, + Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) + ); + println!( + "Karura - Bob: {}", + Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) + ); + }); + + Statemine::execute_with(|| { + use westmint_runtime::*; + + println!("Statemine - para: {}", Assets::balance(0, ¶_acc)); + println!("Statemine - Bob: {}", Assets::balance(0, &AccountId::from(BOB))); }); } From 8b3700aa341760befed90347cf5840de9fab2125 Mon Sep 17 00:00:00 2001 From: zqh Date: Tue, 22 Feb 2022 14:34:37 +0800 Subject: [PATCH 07/21] transfer back RMRK to statmine ok --- Cargo.lock | 157 +++++++++--------- Cargo.toml | 2 +- orml | 2 +- runtime/integration-tests/Cargo.toml | 4 +- .../src/relaychain/kusama_test_net.rs | 8 +- .../src/relaychain/statemine.rs | 100 ++++------- runtime/karura/src/lib.rs | 2 +- 7 files changed, 116 insertions(+), 159 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8d611b785..3dfe8c744 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4703,7 +4703,7 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex-literal", - "kusama-runtime-constants", + "kusama-runtime-constants 0.9.16 (git+https://github.com/paritytech//polkadot?rev=41ab002d7451766324a9f314fee11c9c53314350)", "log", "pallet-authority-discovery", "pallet-authorship", @@ -4775,6 +4775,18 @@ dependencies = [ "xcm-executor", ] +[[package]] +name = "kusama-runtime-constants" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" +dependencies = [ + "frame-support", + "polkadot-primitives", + "polkadot-runtime-common", + "smallvec", + "sp-runtime", +] + [[package]] name = "kusama-runtime-constants" version = "0.9.16" @@ -10915,7 +10927,7 @@ dependencies = [ "sp-transaction-pool", "sp-trie", "sp-version", - "westmint-runtime", + "statemine-runtime", "xcm", "xcm-builder", "xcm-emulator", @@ -13264,6 +13276,70 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +[[package]] +name = "statemine-runtime" +version = "2.0.0" +source = "git+https://github.com/paritytech//cumulus?rev=867bfcd8f87cc986d1a3e9eeaf16c8b4e9a27790#867bfcd8f87cc986d1a3e9eeaf16c8b4e9a27790" +dependencies = [ + "cumulus-pallet-aura-ext", + "cumulus-pallet-dmp-queue", + "cumulus-pallet-parachain-system", + "cumulus-pallet-session-benchmarking", + "cumulus-pallet-xcm", + "cumulus-pallet-xcmp-queue", + "cumulus-ping", + "cumulus-primitives-core", + "cumulus-primitives-timestamp", + "cumulus-primitives-utility", + "frame-executive", + "frame-support", + "frame-system", + "frame-system-rpc-runtime-api", + "kusama-runtime-constants 0.9.16 (git+https://github.com/paritytech/polkadot?branch=release-v0.9.16)", + "log", + "node-primitives", + "pallet-asset-tx-payment", + "pallet-assets", + "pallet-aura", + "pallet-authorship", + "pallet-balances", + "pallet-collator-selection", + "pallet-multisig", + "pallet-proxy", + "pallet-session", + "pallet-sudo", + "pallet-timestamp", + "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", + "pallet-uniques", + "pallet-utility", + "pallet-xcm", + "parachain-info", + "parachains-common", + "parity-scale-codec", + "polkadot-parachain", + "polkadot-runtime-common", + "scale-info", + "serde", + "smallvec", + "sp-api", + "sp-block-builder", + "sp-consensus-aura", + "sp-core", + "sp-inherents", + "sp-io", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-std", + "sp-transaction-pool", + "sp-version", + "substrate-wasm-builder", + "xcm", + "xcm-builder", + "xcm-executor", +] + [[package]] name = "static_assertions" version = "1.1.0" @@ -14784,24 +14860,12 @@ dependencies = [ "sp-transaction-pool", "sp-version", "substrate-wasm-builder", - "westend-runtime-constants 0.9.16 (git+https://github.com/paritytech//polkadot?rev=41ab002d7451766324a9f314fee11c9c53314350)", + "westend-runtime-constants", "xcm", "xcm-builder", "xcm-executor", ] -[[package]] -name = "westend-runtime-constants" -version = "0.9.16" -source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" -dependencies = [ - "frame-support", - "polkadot-primitives", - "polkadot-runtime-common", - "smallvec", - "sp-runtime", -] - [[package]] name = "westend-runtime-constants" version = "0.9.16" @@ -14814,69 +14878,6 @@ dependencies = [ "sp-runtime", ] -[[package]] -name = "westmint-runtime" -version = "1.0.0" -source = "git+https://github.com/paritytech//cumulus?rev=867bfcd8f87cc986d1a3e9eeaf16c8b4e9a27790#867bfcd8f87cc986d1a3e9eeaf16c8b4e9a27790" -dependencies = [ - "cumulus-pallet-aura-ext", - "cumulus-pallet-dmp-queue", - "cumulus-pallet-parachain-system", - "cumulus-pallet-session-benchmarking", - "cumulus-pallet-xcm", - "cumulus-pallet-xcmp-queue", - "cumulus-ping", - "cumulus-primitives-core", - "cumulus-primitives-timestamp", - "cumulus-primitives-utility", - "frame-executive", - "frame-support", - "frame-system", - "frame-system-rpc-runtime-api", - "log", - "node-primitives", - "pallet-asset-tx-payment", - "pallet-assets", - "pallet-aura", - "pallet-authorship", - "pallet-balances", - "pallet-collator-selection", - "pallet-multisig", - "pallet-proxy", - "pallet-session", - "pallet-timestamp", - "pallet-transaction-payment", - "pallet-transaction-payment-rpc-runtime-api", - "pallet-uniques", - "pallet-utility", - "pallet-xcm", - "parachain-info", - "parachains-common", - "parity-scale-codec", - "polkadot-parachain", - "polkadot-runtime-common", - "scale-info", - "serde", - "smallvec", - "sp-api", - "sp-block-builder", - "sp-consensus-aura", - "sp-core", - "sp-inherents", - "sp-io", - "sp-offchain", - "sp-runtime", - "sp-session", - "sp-std", - "sp-transaction-pool", - "sp-version", - "substrate-wasm-builder", - "westend-runtime-constants 0.9.16 (git+https://github.com/paritytech/polkadot?branch=release-v0.9.16)", - "xcm", - "xcm-builder", - "xcm-executor", -] - [[package]] name = "which" version = "4.2.4" diff --git a/Cargo.toml b/Cargo.toml index 484ca7247..a86ccd80d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -317,5 +317,5 @@ parachain-info = { git = "https://github.com/paritytech//cumulus", rev = "867bfc cumulus-relay-chain-interface = { git = "https://github.com/paritytech//cumulus", rev = "867bfcd8f87cc986d1a3e9eeaf16c8b4e9a27790" } cumulus-relay-chain-local = { git = "https://github.com/paritytech//cumulus", rev = "867bfcd8f87cc986d1a3e9eeaf16c8b4e9a27790" } cumulus-test-relay-validation-worker-provider = { git = "https://github.com/paritytech//cumulus", rev = "867bfcd8f87cc986d1a3e9eeaf16c8b4e9a27790" } -westmint-runtime = { git = "https://github.com/paritytech//cumulus", rev = "867bfcd8f87cc986d1a3e9eeaf16c8b4e9a27790" } +statemine-runtime = { git = "https://github.com/paritytech//cumulus", rev = "867bfcd8f87cc986d1a3e9eeaf16c8b4e9a27790" } parachains-common = { git = "https://github.com/paritytech//cumulus", rev = "867bfcd8f87cc986d1a3e9eeaf16c8b4e9a27790" } diff --git a/orml b/orml index 4a66b2990..9344a777d 160000 --- a/orml +++ b/orml @@ -1 +1 @@ -Subproject commit 4a66b299037cc3997689538f82847785f9afa65d +Subproject commit 9344a777d07e6d22433a1cc9fb386e444e7e75a3 diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index d2be6d7f4..32404b092 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -130,7 +130,7 @@ sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot- cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.16" } cumulus-test-relay-sproof-builder = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.16" } -westmint-runtime = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.16" } +statemine-runtime = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.16" } polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.16" } polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.16" } @@ -141,7 +141,7 @@ xcm-emulator = { git = "https://github.com/shaunxw/xcm-simulator", rev = "a250ff acala-service = { path = "../../node/service", features = ["with-all-runtime"] } [features] -default = ["std", "with-karura-runtime"] +default = ["std"] no_std = [] with-mandala-runtime = [ "mandala-runtime", diff --git a/runtime/integration-tests/src/relaychain/kusama_test_net.rs b/runtime/integration-tests/src/relaychain/kusama_test_net.rs index e3135cd45..7ebc57c6f 100644 --- a/runtime/integration-tests/src/relaychain/kusama_test_net.rs +++ b/runtime/integration-tests/src/relaychain/kusama_test_net.rs @@ -58,10 +58,10 @@ decl_test_parachain! { decl_test_parachain! { pub struct Statemine { - Runtime = westmint_runtime::Runtime, - Origin = westmint_runtime::Origin, - XcmpMessageHandler = westmint_runtime::XcmpQueue, - DmpMessageHandler = westmint_runtime::DmpQueue, + Runtime = statemine_runtime::Runtime, + Origin = statemine_runtime::Origin, + XcmpMessageHandler = statemine_runtime::XcmpQueue, + DmpMessageHandler = statemine_runtime::DmpQueue, new_ext = para_ext(1000), } } diff --git a/runtime/integration-tests/src/relaychain/statemine.rs b/runtime/integration-tests/src/relaychain/statemine.rs index 97319bd53..66ae329a1 100644 --- a/runtime/integration-tests/src/relaychain/statemine.rs +++ b/runtime/integration-tests/src/relaychain/statemine.rs @@ -22,7 +22,6 @@ use crate::setup::*; use frame_support::assert_ok; use module_asset_registry::AssetMetadata; -use orml_traits::location::Reserve; use polkadot_parachain::primitives::Sibling; use xcm::v1::{Junction, MultiLocation}; use xcm_emulator::TestExt; @@ -40,36 +39,41 @@ fn can_transfer_custom_asset_into_karura() { Box::new(AssetMetadata { name: b"Sibling Token".to_vec(), symbol: b"ST".to_vec(), - decimals: 12, - minimal_balance: Balances::minimum_balance() / 10, // 10% + decimals: 10, + minimal_balance: Balances::minimum_balance() / 100, // 10% }) )); }); let para_acc: AccountId = Sibling::from(2000).into_account(); + let asset_units: u128 = dollar(KSM); Statemine::execute_with(|| { - use westmint_runtime::*; + use statemine_runtime::*; let origin = Origin::signed(ALICE.into()); Balances::make_free_balance_be(&ALICE.into(), 10 * dollar(KSM)); + Balances::make_free_balance_be(&BOB.into(), dollar(KSM)); - // need to have some KSM to be able to receive user assets - Balances::make_free_balance_be(&Sibling::from(2000).into_account(), 10 * dollar(KSM)); - + // create asset cost 1 KSM assert_ok!(Assets::create( origin.clone(), 0, MultiAddress::Id(ALICE.into()), - cent(KSM) + asset_units / 100 )); + assert_eq!(9 * asset_units, Balances::free_balance(&AccountId::from(ALICE))); + assert_ok!(Assets::mint( origin.clone(), 0, MultiAddress::Id(ALICE.into()), - 1000 * dollar(KSM) + 1000 * asset_units )); + // need to have some KSM to be able to receive user assets + Balances::make_free_balance_be(¶_acc, 10 * asset_units); + assert_ok!(PolkadotXcm::reserve_transfer_assets( origin.clone(), Box::new(MultiLocation::new(1, X1(Parachain(2000))).into()), @@ -81,11 +85,12 @@ fn can_transfer_custom_asset_into_karura() { .into() .into() ), - Box::new((X2(PalletInstance(50), GeneralIndex(0)), 10 * dollar(KSM)).into()), + Box::new((X2(PalletInstance(50), GeneralIndex(0)), 10 * asset_units).into()), 0 )); - assert_eq!(Assets::balance(0, ¶_acc), 10 * dollar(KSM)); + assert_eq!(Assets::balance(0, ¶_acc), 10 * asset_units); + assert_eq!(10 * asset_units, Balances::free_balance(¶_acc)); }); // Rerun the Statemine::execute to actually send the egress message via XCM @@ -93,62 +98,16 @@ fn can_transfer_custom_asset_into_karura() { Karura::execute_with(|| { assert_eq!( - 9_999_360_000_000, + 9_999_936_000_000, Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) ); - // Transfer statemine asset back to Statemine + assert_ok!(Tokens::deposit(KSM, &AccountId::from(BOB), 10 * asset_units)); - // Error: TooExpensive because Statemine trader not matched - // 1. westmint/statemine use `Parent` as AssetId - // https://github.com/paritytech/cumulus/blob/master/polkadot-parachains/westmint/src/xcm_config.rs#L159 - // 2. trader required is (Parent, amount) - // https://github.com/paritytech/polkadot/blob/release-v0.9.16/xcm/xcm-builder/src/weight.rs#L270 - // 3. the asset sent to statemine is (PalletInstance(50), GeneralIndex(0)) not matched `required` - // so when excecute `BuyExecution`, throw TooExpensive error making xcm failed - assert_ok!(XTokens::transfer( + // Transfer statemine asset back to Statemine + assert_ok!(XTokens::transfer_using_relaychain_as_fee( Origin::signed(BOB.into()), CurrencyId::ForeignAsset(0), - dollar(KSM), - Box::new( - MultiLocation::new( - 1, - X2( - Parachain(2001), - Junction::AccountId32 { - network: NetworkId::Any, - id: BOB.into(), - } - ) - ) - .into() - ), - 5_000_000_000, - )); - - // for matching with `required` => (Parent, amount), we should use KSM as fee - // Error: DistinctReserveForAssetAndFee in orml-xTokens check - let statemine_asset = MultiAsset { - id: AssetId::Concrete(MultiLocation::new( - 1, - Junctions::X3( - Junction::Parachain(1000), - Junction::PalletInstance(50), - Junction::GeneralIndex(0), - ), - )), - fun: Fungibility::Fungible(dollar(KSM)), - }; - let fee_asset = MultiAsset { - id: AssetId::Concrete(MultiLocation::new(1, Junctions::Here)), - fun: Fungibility::Fungible(5_000_000_000), - }; - // current not support different reserve - // statemine_asset.reserve() == (Parent, Parachain(1000)) - // fee_asset.reserve() = (Parent) - assert_ok!(XTokens::transfer_multiasset_with_fee( - Origin::signed(BOB.into()), - Box::new(statemine_asset.into()), - Box::new(fee_asset.into()), + asset_units, Box::new( MultiLocation::new( 1, @@ -162,22 +121,19 @@ fn can_transfer_custom_asset_into_karura() { ) .into() ), - 5_000_000_000, + 4_000_000_000 )); + assert_eq!( - 8_999_360_000_000, - Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) - ); - println!( - "Karura - Bob: {}", + 8_999_936_000_000, Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) ); + assert_eq!(9_996_000_000_000, Tokens::free_balance(KSM, &AccountId::from(BOB))); }); Statemine::execute_with(|| { - use westmint_runtime::*; - - println!("Statemine - para: {}", Assets::balance(0, ¶_acc)); - println!("Statemine - Bob: {}", Assets::balance(0, &AccountId::from(BOB))); + use statemine_runtime::*; + assert_eq!(Assets::balance(0, ¶_acc), 9 * asset_units); + assert_eq!(asset_units, Assets::balance(0, &AccountId::from(BOB))); }); } diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index 03c95ef64..137626e3c 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -1920,7 +1920,7 @@ impl Convert for AccountIdToMultiLocation { } parameter_types! { - pub const BaseXcmWeight: Weight = 100_000_000; + pub const BaseXcmWeight: Weight = 1_000_000_000; pub const MaxAssetsForTransfer: usize = 2; } From 034251cc676789cbe7c90435b48982d4d14624d8 Mon Sep 17 00:00:00 2001 From: zqh Date: Tue, 22 Feb 2022 14:40:38 +0800 Subject: [PATCH 08/21] revert BaseXcmWeight --- runtime/karura/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index 137626e3c..03c95ef64 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -1920,7 +1920,7 @@ impl Convert for AccountIdToMultiLocation { } parameter_types! { - pub const BaseXcmWeight: Weight = 1_000_000_000; + pub const BaseXcmWeight: Weight = 100_000_000; pub const MaxAssetsForTransfer: usize = 2; } From 62cfee81134e3b310e0b8400d71a2d246feee201 Mon Sep 17 00:00:00 2001 From: zqh Date: Tue, 22 Feb 2022 14:50:50 +0800 Subject: [PATCH 09/21] rename method --- runtime/integration-tests/src/relaychain/statemine.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/runtime/integration-tests/src/relaychain/statemine.rs b/runtime/integration-tests/src/relaychain/statemine.rs index 66ae329a1..35cc53ba8 100644 --- a/runtime/integration-tests/src/relaychain/statemine.rs +++ b/runtime/integration-tests/src/relaychain/statemine.rs @@ -28,9 +28,7 @@ use xcm_emulator::TestExt; #[cfg(feature = "with-karura-runtime")] #[test] -fn can_transfer_custom_asset_into_karura() { - env_logger::init(); - +fn transfer_custom_asset_works() { Karura::execute_with(|| { // register foreign asset assert_ok!(AssetRegistry::register_foreign_asset( From cd29c19ed483c763582ef8f6b3f3d1595a79db2c Mon Sep 17 00:00:00 2001 From: zqh Date: Wed, 23 Feb 2022 15:28:44 +0800 Subject: [PATCH 10/21] update orml --- orml | 2 +- .../src/relaychain/statemine.rs | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/orml b/orml index 9344a777d..9af1b35ef 160000 --- a/orml +++ b/orml @@ -1 +1 @@ -Subproject commit 9344a777d07e6d22433a1cc9fb386e444e7e75a3 +Subproject commit 9af1b35ef7713adedd6781b9bbd423dd02d72628 diff --git a/runtime/integration-tests/src/relaychain/statemine.rs b/runtime/integration-tests/src/relaychain/statemine.rs index 35cc53ba8..69bd9dbd0 100644 --- a/runtime/integration-tests/src/relaychain/statemine.rs +++ b/runtime/integration-tests/src/relaychain/statemine.rs @@ -53,7 +53,7 @@ fn transfer_custom_asset_works() { Balances::make_free_balance_be(&ALICE.into(), 10 * dollar(KSM)); Balances::make_free_balance_be(&BOB.into(), dollar(KSM)); - // create asset cost 1 KSM + // create custom asset cost 1 KSM assert_ok!(Assets::create( origin.clone(), 0, @@ -88,6 +88,8 @@ fn transfer_custom_asset_works() { )); assert_eq!(Assets::balance(0, ¶_acc), 10 * asset_units); + + // the KSM balance of sibling parachain sovereign account is not changed assert_eq!(10 * asset_units, Balances::free_balance(¶_acc)); }); @@ -99,13 +101,14 @@ fn transfer_custom_asset_works() { 9_999_936_000_000, Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) ); + // ensure sender has enough KSM balance to be charged as fee assert_ok!(Tokens::deposit(KSM, &AccountId::from(BOB), 10 * asset_units)); // Transfer statemine asset back to Statemine - assert_ok!(XTokens::transfer_using_relaychain_as_fee( + assert_ok!(XTokens::transfer_multicurrencies( Origin::signed(BOB.into()), - CurrencyId::ForeignAsset(0), - asset_units, + vec![(CurrencyId::ForeignAsset(0), asset_units), (KSM, 4_000_000_000)], + 1, Box::new( MultiLocation::new( 1, @@ -131,7 +134,10 @@ fn transfer_custom_asset_works() { Statemine::execute_with(|| { use statemine_runtime::*; - assert_eq!(Assets::balance(0, ¶_acc), 9 * asset_units); + // Karura send back custom asset to Statemine, ensure recipient got custom asset assert_eq!(asset_units, Assets::balance(0, &AccountId::from(BOB))); + // KSM and custom asset balance of sibling parachain sovereign account also changed + assert_eq!(9 * asset_units, Assets::balance(0, ¶_acc)); + assert_eq!(9_996_000_000_000, Balances::free_balance(¶_acc)); }); } From 5c92debd5ae63f7f8164b5865e4bb734889faf8b Mon Sep 17 00:00:00 2001 From: zqh Date: Sat, 26 Feb 2022 23:30:49 +0800 Subject: [PATCH 11/21] deduplicate dmp --- Cargo.lock | 4 +- orml | 2 +- runtime/integration-tests/Cargo.toml | 4 +- .../src/relaychain/statemine.rs | 199 +++++++++++++----- 4 files changed, 152 insertions(+), 57 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3dfe8c744..f04c5183f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10838,6 +10838,7 @@ dependencies = [ "karura-runtime", "kusama-runtime", "libsecp256k1 0.6.0", + "log", "mandala-runtime", "module-asset-registry", "module-auction-manager", @@ -15037,7 +15038,7 @@ dependencies = [ [[package]] name = "xcm-emulator" version = "0.1.0" -source = "git+https://github.com/shaunxw/xcm-simulator?rev=a250ffc998bac4831c5692c591dee7bc13f3aead#a250ffc998bac4831c5692c591dee7bc13f3aead" +source = "git+https://github.com/zqhxuyuan/xcm-simulator?rev=65832f73b21f55b10dcb09460f8c8ad6ac8083f9#65832f73b21f55b10dcb09460f8c8ad6ac8083f9" dependencies = [ "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", @@ -15047,6 +15048,7 @@ dependencies = [ "cumulus-test-relay-sproof-builder", "frame-support", "frame-system", + "log", "parachain-info", "parity-scale-codec", "paste", diff --git a/orml b/orml index 9af1b35ef..67d76e6a8 160000 --- a/orml +++ b/orml @@ -1 +1 @@ -Subproject commit 9af1b35ef7713adedd6781b9bbd423dd02d72628 +Subproject commit 67d76e6a8e743ccd86a52ac32ab4f90174a0a6ee diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index 32404b092..36d6d31cd 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -125,6 +125,7 @@ ecosystem-compound-cash = { path = "../../ecosystem-modules/compound-cash" } [dev-dependencies] env_logger = "0.9.0" +log = "0.4.14" sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16" } sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16" } @@ -136,7 +137,8 @@ polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.16" } kusama-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.16" } -xcm-emulator = { git = "https://github.com/shaunxw/xcm-simulator", rev = "a250ffc998bac4831c5692c591dee7bc13f3aead" } +#xcm-emulator = { git = "https://github.com/shaunxw/xcm-simulator", rev = "a250ffc998bac4831c5692c591dee7bc13f3aead" } +xcm-emulator = { git = "https://github.com/zqhxuyuan/xcm-simulator", rev = "65832f73b21f55b10dcb09460f8c8ad6ac8083f9" } acala-service = { path = "../../node/service", features = ["with-all-runtime"] } diff --git a/runtime/integration-tests/src/relaychain/statemine.rs b/runtime/integration-tests/src/relaychain/statemine.rs index 69bd9dbd0..2e3fcbc68 100644 --- a/runtime/integration-tests/src/relaychain/statemine.rs +++ b/runtime/integration-tests/src/relaychain/statemine.rs @@ -19,6 +19,7 @@ //! Tests parachain to parachain xcm communication between Statemine and Karura. use crate::relaychain::kusama_test_net::*; use crate::setup::*; +use cumulus_primitives_core::ParaId; use frame_support::assert_ok; use module_asset_registry::AssetMetadata; @@ -29,20 +30,138 @@ use xcm_emulator::TestExt; #[cfg(feature = "with-karura-runtime")] #[test] fn transfer_custom_asset_works() { + statemine_side(); + let para_acc: AccountId = Sibling::from(2000).into_account(); + let asset_units: u128 = dollar(KSM); + Karura::execute_with(|| { - // register foreign asset - assert_ok!(AssetRegistry::register_foreign_asset( - Origin::root(), - Box::new(MultiLocation::new(1, X3(Parachain(1000), PalletInstance(50), GeneralIndex(0))).into()), - Box::new(AssetMetadata { - name: b"Sibling Token".to_vec(), - symbol: b"ST".to_vec(), - decimals: 10, - minimal_balance: Balances::minimum_balance() / 100, // 10% - }) + assert_eq!( + 9_999_936_000_000, + Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) + ); + // ensure sender has enough KSM balance to be charged as fee + assert_ok!(Tokens::deposit(KSM, &AccountId::from(BOB), 10 * asset_units)); + + // Transfer statemine asset back to Statemine + assert_ok!(XTokens::transfer_multicurrencies( + Origin::signed(BOB.into()), + vec![(CurrencyId::ForeignAsset(0), asset_units), (KSM, 4_000_000_000)], + 1, + Box::new( + MultiLocation::new( + 1, + X2( + Parachain(1000), + Junction::AccountId32 { + network: NetworkId::Any, + id: BOB.into(), + } + ) + ) + .into() + ), + 4_000_000_000 )); + + assert_eq!( + 8_999_936_000_000, + Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) + ); + assert_eq!(9_996_000_000_000, Tokens::free_balance(KSM, &AccountId::from(BOB))); + }); + + Statemine::execute_with(|| { + use statemine_runtime::*; + // Karura send back custom asset to Statemine, ensure recipient got custom asset + assert_eq!(asset_units, Assets::balance(0, &AccountId::from(BOB))); + // KSM and custom asset balance of sibling parachain sovereign account also changed + assert_eq!(9 * asset_units, Assets::balance(0, ¶_acc)); + // assert_eq!(9_996_000_000_000, Balances::free_balance(¶_acc)); + // assert_eq!(6000000000, Balances::free_balance(¶_acc)); + }); +} + +#[cfg(feature = "with-karura-runtime")] +#[test] +fn user_set_too_large_fee_works() { + env_logger::init(); + statemine_side(); + let para_2000: AccountId = Sibling::from(2000).into_account(); + let para_1000: AccountId = Sibling::from(1000).into_account(); + let child_2000: AccountId = ParaId::from(2000).into_account(); + let child_1000: AccountId = ParaId::from(1000).into_account(); + + let asset_units: u128 = dollar(KSM); + let xcm_weight: u128 = 4_000_000_000; + + KusamaNet::execute_with(|| { + let _ = kusama_runtime::Balances::make_free_balance_be(&child_2000, 10 * asset_units); }); + Karura::execute_with(|| { + assert_eq!( + 9_999_936_000_000, + Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) + ); + // ensure sender has enough KSM balance to be charged as fee + assert_ok!(Tokens::deposit(KSM, &AccountId::from(BOB), 10 * asset_units)); + + // Transfer statemine asset back to Statemine + assert_ok!(XTokens::transfer_multicurrencies( + Origin::signed(BOB.into()), + vec![ + (CurrencyId::ForeignAsset(0), asset_units), + (KSM, 9 * asset_units + xcm_weight) + ], + 1, + Box::new( + MultiLocation::new( + 1, + X2( + Parachain(1000), + Junction::AccountId32 { + network: NetworkId::Any, + id: BOB.into(), + } + ) + ) + .into() + ), + xcm_weight as u64 + )); + + assert_eq!( + 8_999_936_000_000, + Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) + ); + assert_eq!( + asset_units - xcm_weight, + Tokens::free_balance(KSM, &AccountId::from(BOB)) + ); + }); + + KusamaNet::execute_with(|| { + assert_eq!(asset_units, kusama_runtime::Balances::free_balance(&child_2000)); + assert_eq!(8_999_893_333_340, kusama_runtime::Balances::free_balance(&child_1000)); + }); + + Statemine::execute_with(|| { + use statemine_runtime::*; + // Karura send back custom asset to Statemine, ensure recipient got custom asset + assert_eq!(asset_units, Assets::balance(0, &AccountId::from(BOB))); + println!("{}", Balances::free_balance(&AccountId::from(BOB))); // 1 000 000 000 000 + println!("{}", Balances::free_balance(¶_2000)); // 17 992 786 666 680 18 987 786 666 680 + + // KSM and custom asset balance of sibling parachain sovereign account also changed + assert_eq!(9 * asset_units, Assets::balance(0, ¶_2000)); + // assert_eq!(9_996_000_000_000, Balances::free_balance(¶_acc)); + // assert_eq!(6000000000, Balances::free_balance(¶_acc)); + }); +} + +fn statemine_side() { + register_asset(); + let para_acc: AccountId = Sibling::from(2000).into_account(); let asset_units: u128 = dollar(KSM); @@ -70,7 +189,8 @@ fn transfer_custom_asset_works() { )); // need to have some KSM to be able to receive user assets - Balances::make_free_balance_be(¶_acc, 10 * asset_units); + let initial_ksm_para_acc = asset_units; + Balances::make_free_balance_be(¶_acc, initial_ksm_para_acc); assert_ok!(PolkadotXcm::reserve_transfer_assets( origin.clone(), @@ -87,57 +207,28 @@ fn transfer_custom_asset_works() { 0 )); - assert_eq!(Assets::balance(0, ¶_acc), 10 * asset_units); + assert_eq!(10 * asset_units, Assets::balance(0, ¶_acc)); // the KSM balance of sibling parachain sovereign account is not changed - assert_eq!(10 * asset_units, Balances::free_balance(¶_acc)); + assert_eq!(initial_ksm_para_acc, Balances::free_balance(¶_acc)); }); // Rerun the Statemine::execute to actually send the egress message via XCM Statemine::execute_with(|| {}); +} +fn register_asset() { Karura::execute_with(|| { - assert_eq!( - 9_999_936_000_000, - Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) - ); - // ensure sender has enough KSM balance to be charged as fee - assert_ok!(Tokens::deposit(KSM, &AccountId::from(BOB), 10 * asset_units)); - - // Transfer statemine asset back to Statemine - assert_ok!(XTokens::transfer_multicurrencies( - Origin::signed(BOB.into()), - vec![(CurrencyId::ForeignAsset(0), asset_units), (KSM, 4_000_000_000)], - 1, - Box::new( - MultiLocation::new( - 1, - X2( - Parachain(1000), - Junction::AccountId32 { - network: NetworkId::Any, - id: BOB.into(), - } - ) - ) - .into() - ), - 4_000_000_000 + // register foreign asset + assert_ok!(AssetRegistry::register_foreign_asset( + Origin::root(), + Box::new(MultiLocation::new(1, X3(Parachain(1000), PalletInstance(50), GeneralIndex(0))).into()), + Box::new(AssetMetadata { + name: b"Sibling Token".to_vec(), + symbol: b"ST".to_vec(), + decimals: 10, + minimal_balance: Balances::minimum_balance() / 100, // 10% + }) )); - - assert_eq!( - 8_999_936_000_000, - Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) - ); - assert_eq!(9_996_000_000_000, Tokens::free_balance(KSM, &AccountId::from(BOB))); - }); - - Statemine::execute_with(|| { - use statemine_runtime::*; - // Karura send back custom asset to Statemine, ensure recipient got custom asset - assert_eq!(asset_units, Assets::balance(0, &AccountId::from(BOB))); - // KSM and custom asset balance of sibling parachain sovereign account also changed - assert_eq!(9 * asset_units, Assets::balance(0, ¶_acc)); - assert_eq!(9_996_000_000_000, Balances::free_balance(¶_acc)); }); } From 5627b8aecac15e65fac462182470432826e93860 Mon Sep 17 00:00:00 2001 From: zqh Date: Mon, 28 Feb 2022 21:02:16 +0800 Subject: [PATCH 12/21] update orml --- Cargo.lock | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++- orml | 2 +- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f04c5183f..15468b4e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7112,7 +7112,7 @@ dependencies = [ "hash-db", "linregress", "parity-scale-codec", - "parking_lot 0.11.2", + "parking_lot 0.12.0", "paste", "rand 0.8.5", "sc-client-db", @@ -8587,6 +8587,16 @@ dependencies = [ "parking_lot_core 0.8.5", ] +[[package]] +name = "parking_lot" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58" +dependencies = [ + "lock_api 0.4.6", + "parking_lot_core 0.9.1", +] + [[package]] name = "parking_lot_core" version = "0.7.2" @@ -8615,6 +8625,19 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "parking_lot_core" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28141e0cc4143da2443301914478dc976a61ffdb3f043058310c70df2fed8954" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall 0.2.10", + "smallvec", + "windows-sys", +] + [[package]] name = "password-hash" version = "0.2.3" @@ -14939,6 +14962,49 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3df6e476185f92a12c072be4a189a0210dcdcf512a1891d6dff9edb874deadc6" +dependencies = [ + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_msvc" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5" + +[[package]] +name = "windows_i686_gnu" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615" + +[[package]] +name = "windows_i686_msvc" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316" + [[package]] name = "winreg" version = "0.6.2" diff --git a/orml b/orml index 67d76e6a8..662981c37 160000 --- a/orml +++ b/orml @@ -1 +1 @@ -Subproject commit 67d76e6a8e743ccd86a52ac32ab4f90174a0a6ee +Subproject commit 662981c370a5be0198fd5f4858ce430d1836fd8c From 35e1e9e293e16c2005457015b80d26e7a6f577b8 Mon Sep 17 00:00:00 2001 From: zqh Date: Mon, 28 Feb 2022 21:03:49 +0800 Subject: [PATCH 13/21] merge master --- evm-tests | 2 +- predeploy-contracts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/evm-tests b/evm-tests index ad9ceebba..755a4a52c 160000 --- a/evm-tests +++ b/evm-tests @@ -1 +1 @@ -Subproject commit ad9ceebba4e2f0f7a7ef7803e97ba7ff62ad5b0c +Subproject commit 755a4a52cadecba211f15bb8cffd6a2b9fbdc165 diff --git a/predeploy-contracts b/predeploy-contracts index 1a0a4029b..30cfe0157 160000 --- a/predeploy-contracts +++ b/predeploy-contracts @@ -1 +1 @@ -Subproject commit 1a0a4029b90b0c781eb448e8686f8818c69b4e98 +Subproject commit 30cfe0157a4ffd94c837c027c1d8b9e435bdfc00 From c0f5cdbd818fa63986acae11f056cf2c6cb65a1f Mon Sep 17 00:00:00 2001 From: zqh Date: Tue, 1 Mar 2022 08:48:08 +0800 Subject: [PATCH 14/21] integration tests --- Cargo.lock | 70 +----- orml | 2 +- runtime/acala/src/xcm_config.rs | 12 +- .../src/relaychain/statemine.rs | 200 +++++++++--------- runtime/karura/src/constants.rs | 4 + runtime/karura/src/xcm_config.rs | 13 +- runtime/mandala/src/xcm_config.rs | 12 +- 7 files changed, 145 insertions(+), 168 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ae0e062bc..c593553b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7172,7 +7172,7 @@ dependencies = [ "hash-db", "linregress", "parity-scale-codec", - "parking_lot 0.12.0", + "parking_lot 0.11.2", "paste", "rand 0.8.5", "sc-client-db", @@ -8647,16 +8647,6 @@ dependencies = [ "parking_lot_core 0.8.5", ] -[[package]] -name = "parking_lot" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58" -dependencies = [ - "lock_api 0.4.6", - "parking_lot_core 0.9.1", -] - [[package]] name = "parking_lot_core" version = "0.7.2" @@ -8685,19 +8675,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "parking_lot_core" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28141e0cc4143da2443301914478dc976a61ffdb3f043058310c70df2fed8954" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "redox_syscall 0.2.10", - "smallvec", - "windows-sys", -] - [[package]] name = "password-hash" version = "0.2.3" @@ -13563,7 +13540,7 @@ dependencies = [ "byteorder", "crunchy", "lazy_static", - "rand 0.8.4", + "rand 0.8.5", "rustc-hex", ] @@ -15035,49 +15012,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3df6e476185f92a12c072be4a189a0210dcdcf512a1891d6dff9edb874deadc6" -dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_msvc" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5" - -[[package]] -name = "windows_i686_gnu" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615" - -[[package]] -name = "windows_i686_msvc" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316" - [[package]] name = "winreg" version = "0.6.2" diff --git a/orml b/orml index 662981c37..83e030483 160000 --- a/orml +++ b/orml @@ -1 +1 @@ -Subproject commit 662981c370a5be0198fd5f4858ce430d1836fd8c +Subproject commit 83e0304834398491a72d8d104da1d9b40c274880 diff --git a/runtime/acala/src/xcm_config.rs b/runtime/acala/src/xcm_config.rs index bdb536299..457099ce6 100644 --- a/runtime/acala/src/xcm_config.rs +++ b/runtime/acala/src/xcm_config.rs @@ -29,7 +29,7 @@ pub use frame_support::{ traits::{Everything, Get, Nothing}, weights::Weight, }; -use orml_traits::MultiCurrency; +use orml_traits::{parameter_type_with_key, MultiCurrency}; use orml_xcm_support::{DepositToAlternative, IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset}; use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; @@ -319,6 +319,15 @@ parameter_types! { pub const MaxAssetsForTransfer: usize = 2; } +parameter_type_with_key! { + pub ParachainMinFee: |location: MultiLocation| -> u128 { + #[allow(clippy::match_ref_pats)] // false positive + match (location.parents, location.first_interior()) { + _ => u128::MAX, + } + }; +} + impl orml_xtokens::Config for Runtime { type Event = Event; type Balance = Balance; @@ -331,4 +340,5 @@ impl orml_xtokens::Config for Runtime { type BaseXcmWeight = BaseXcmWeight; type LocationInverter = LocationInverter; type MaxAssetsForTransfer = MaxAssetsForTransfer; + type MinXcmFee = ParachainMinFee; } diff --git a/runtime/integration-tests/src/relaychain/statemine.rs b/runtime/integration-tests/src/relaychain/statemine.rs index 2e3fcbc68..bd388f6c1 100644 --- a/runtime/integration-tests/src/relaychain/statemine.rs +++ b/runtime/integration-tests/src/relaychain/statemine.rs @@ -27,92 +27,121 @@ use polkadot_parachain::primitives::Sibling; use xcm::v1::{Junction, MultiLocation}; use xcm_emulator::TestExt; +pub const UNIT: Balance = 1_000_000_000_000; +pub const TEN: Balance = 10_000_000_000_000; +pub const FEE_STATEMINE: Balance = 4_000_000_000; +pub const FEE_KUSAMA: Balance = 106_666_660; + #[cfg(feature = "with-karura-runtime")] #[test] -fn transfer_custom_asset_works() { - statemine_side(); - let para_acc: AccountId = Sibling::from(2000).into_account(); - let asset_units: u128 = dollar(KSM); - - Karura::execute_with(|| { - assert_eq!( - 9_999_936_000_000, - Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) - ); - // ensure sender has enough KSM balance to be charged as fee - assert_ok!(Tokens::deposit(KSM, &AccountId::from(BOB), 10 * asset_units)); - - // Transfer statemine asset back to Statemine - assert_ok!(XTokens::transfer_multicurrencies( - Origin::signed(BOB.into()), - vec![(CurrencyId::ForeignAsset(0), asset_units), (KSM, 4_000_000_000)], - 1, - Box::new( - MultiLocation::new( - 1, - X2( - Parachain(1000), - Junction::AccountId32 { - network: NetworkId::Any, - id: BOB.into(), - } - ) - ) - .into() - ), - 4_000_000_000 - )); - - assert_eq!( - 8_999_936_000_000, - Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) - ); - assert_eq!(9_996_000_000_000, Tokens::free_balance(KSM, &AccountId::from(BOB))); - }); - - Statemine::execute_with(|| { - use statemine_runtime::*; - // Karura send back custom asset to Statemine, ensure recipient got custom asset - assert_eq!(asset_units, Assets::balance(0, &AccountId::from(BOB))); - // KSM and custom asset balance of sibling parachain sovereign account also changed - assert_eq!(9 * asset_units, Assets::balance(0, ¶_acc)); - // assert_eq!(9_996_000_000_000, Balances::free_balance(¶_acc)); - // assert_eq!(6000000000, Balances::free_balance(¶_acc)); - }); +fn user_different_ksm_fee() { + let para_2000: AccountId = Sibling::from(2000).into_account(); + let child_2000: AccountId = ParaId::from(2000).into_account(); + let child_1000: AccountId = ParaId::from(1000).into_account(); + let user_fees = vec![ + FEE_STATEMINE + FEE_KUSAMA - 1, + FEE_STATEMINE + FEE_KUSAMA, + FEE_STATEMINE + FEE_KUSAMA + 1, + 2 * FEE_STATEMINE - 1, + 2 * FEE_STATEMINE, + 2 * FEE_STATEMINE + 1, + 2 * FEE_STATEMINE + FEE_KUSAMA, + ]; + let min_user_fee = 2 * FEE_STATEMINE; + for user_fee in user_fees { + TestNet::reset(); + + statemine_side(); + + KusamaNet::execute_with(|| { + let _ = kusama_runtime::Balances::make_free_balance_be(&child_2000, UNIT); + }); + + // user fee amount split into two parts + // first part is `FEE_STATEMINE` sent to statemine + // second part left sent to kusama + karura_side(user_fee + FEE_STATEMINE); + + KusamaNet::execute_with(|| { + assert_eq!(UNIT - user_fee, kusama_runtime::Balances::free_balance(&child_2000)); + assert_eq!( + user_fee - FEE_KUSAMA, + kusama_runtime::Balances::free_balance(&child_1000) + ); + }); + + Statemine::execute_with(|| { + use statemine_runtime::*; + // Karura send back custom asset to Statemine, ensure recipient got custom asset + assert_eq!(UNIT, Assets::balance(0, &AccountId::from(BOB))); + // the recipient's ksm not changed + assert_eq!(UNIT, Balances::free_balance(&AccountId::from(BOB))); + // and withdraw sibling parachain sovereign account + assert_eq!(TEN - UNIT, Assets::balance(0, ¶_2000)); + + if user_fee < min_user_fee { + assert_eq!(UNIT - FEE_STATEMINE, Balances::free_balance(¶_2000)); + } else { + assert_eq!( + UNIT - FEE_STATEMINE + user_fee - (FEE_STATEMINE + FEE_KUSAMA), + Balances::free_balance(¶_2000) + ); + } + }); + } } #[cfg(feature = "with-karura-runtime")] #[test] -fn user_set_too_large_fee_works() { - env_logger::init(); +fn user_large_fee_fund_to_sovereign_account_works() { statemine_side(); let para_2000: AccountId = Sibling::from(2000).into_account(); - let para_1000: AccountId = Sibling::from(1000).into_account(); let child_2000: AccountId = ParaId::from(2000).into_account(); let child_1000: AccountId = ParaId::from(1000).into_account(); - let asset_units: u128 = dollar(KSM); - let xcm_weight: u128 = 4_000_000_000; + KusamaNet::execute_with(|| { + let _ = kusama_runtime::Balances::make_free_balance_be(&child_2000, TEN); + }); + + karura_side(9 * UNIT + FEE_STATEMINE); KusamaNet::execute_with(|| { - let _ = kusama_runtime::Balances::make_free_balance_be(&child_2000, 10 * asset_units); + // first xcm send to relaychain with 9 KSM. 10 KSM - 9 KSM = 1 KSM + assert_eq!(UNIT, kusama_runtime::Balances::free_balance(&child_2000)); + // 9 KSM - fee on relaychain = 9 KSM - 106_666_660 + assert_eq!(8_999_893_333_340, kusama_runtime::Balances::free_balance(&child_1000)); }); + Statemine::execute_with(|| { + use statemine_runtime::*; + // Karura send back custom asset to Statemine, ensure recipient got custom asset + assert_eq!(UNIT, Assets::balance(0, &AccountId::from(BOB))); + // the recipient's ksm not changed + assert_eq!(UNIT, Balances::free_balance(&AccountId::from(BOB))); + // and withdraw sibling parachain sovereign account + assert_eq!(9 * UNIT, Assets::balance(0, ¶_2000)); + + // before karura transfer asset back to Statemine, para_2000 already have 1 KSM. + // after second xcm executed, para_2000 balance - xcm_weight + // after first xcm executed, para_2000 balance + (8_999_893_333_340 - xcm_weight) + // the result of para_2000 balance = 1KSM-4_000_000_000+8_999_893_333_340-4_000_000_000 + assert_eq!(9_991_893_333_340, Balances::free_balance(¶_2000)); + }); +} + +// transfer custom asset from Karura to Statemine +fn karura_side(fee_amount: u128) { Karura::execute_with(|| { assert_eq!( 9_999_936_000_000, Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) ); // ensure sender has enough KSM balance to be charged as fee - assert_ok!(Tokens::deposit(KSM, &AccountId::from(BOB), 10 * asset_units)); + assert_ok!(Tokens::deposit(KSM, &AccountId::from(BOB), TEN)); - // Transfer statemine asset back to Statemine assert_ok!(XTokens::transfer_multicurrencies( Origin::signed(BOB.into()), - vec![ - (CurrencyId::ForeignAsset(0), asset_units), - (KSM, 9 * asset_units + xcm_weight) - ], + vec![(CurrencyId::ForeignAsset(0), UNIT), (KSM, fee_amount)], 1, Box::new( MultiLocation::new( @@ -127,70 +156,48 @@ fn user_set_too_large_fee_works() { ) .into() ), - xcm_weight as u64 + FEE_STATEMINE as u64 )); assert_eq!( 8_999_936_000_000, Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) ); - assert_eq!( - asset_units - xcm_weight, - Tokens::free_balance(KSM, &AccountId::from(BOB)) - ); - }); - - KusamaNet::execute_with(|| { - assert_eq!(asset_units, kusama_runtime::Balances::free_balance(&child_2000)); - assert_eq!(8_999_893_333_340, kusama_runtime::Balances::free_balance(&child_1000)); - }); - - Statemine::execute_with(|| { - use statemine_runtime::*; - // Karura send back custom asset to Statemine, ensure recipient got custom asset - assert_eq!(asset_units, Assets::balance(0, &AccountId::from(BOB))); - println!("{}", Balances::free_balance(&AccountId::from(BOB))); // 1 000 000 000 000 - println!("{}", Balances::free_balance(¶_2000)); // 17 992 786 666 680 18 987 786 666 680 - - // KSM and custom asset balance of sibling parachain sovereign account also changed - assert_eq!(9 * asset_units, Assets::balance(0, ¶_2000)); - // assert_eq!(9_996_000_000_000, Balances::free_balance(¶_acc)); - // assert_eq!(6000000000, Balances::free_balance(¶_acc)); + assert_eq!(TEN - fee_amount, Tokens::free_balance(KSM, &AccountId::from(BOB))); }); } +// transfer custom asset from Statemine to Karura fn statemine_side() { register_asset(); let para_acc: AccountId = Sibling::from(2000).into_account(); - let asset_units: u128 = dollar(KSM); Statemine::execute_with(|| { use statemine_runtime::*; let origin = Origin::signed(ALICE.into()); - Balances::make_free_balance_be(&ALICE.into(), 10 * dollar(KSM)); - Balances::make_free_balance_be(&BOB.into(), dollar(KSM)); + Balances::make_free_balance_be(&ALICE.into(), TEN); + Balances::make_free_balance_be(&BOB.into(), UNIT); // create custom asset cost 1 KSM assert_ok!(Assets::create( origin.clone(), 0, MultiAddress::Id(ALICE.into()), - asset_units / 100 + UNIT / 100 )); - assert_eq!(9 * asset_units, Balances::free_balance(&AccountId::from(ALICE))); + assert_eq!(9 * UNIT, Balances::free_balance(&AccountId::from(ALICE))); assert_ok!(Assets::mint( origin.clone(), 0, MultiAddress::Id(ALICE.into()), - 1000 * asset_units + 1000 * UNIT )); // need to have some KSM to be able to receive user assets - let initial_ksm_para_acc = asset_units; - Balances::make_free_balance_be(¶_acc, initial_ksm_para_acc); + Balances::make_free_balance_be(¶_acc, UNIT); assert_ok!(PolkadotXcm::reserve_transfer_assets( origin.clone(), @@ -203,14 +210,15 @@ fn statemine_side() { .into() .into() ), - Box::new((X2(PalletInstance(50), GeneralIndex(0)), 10 * asset_units).into()), + Box::new((X2(PalletInstance(50), GeneralIndex(0)), TEN).into()), 0 )); - assert_eq!(10 * asset_units, Assets::balance(0, ¶_acc)); + assert_eq!(0, Assets::balance(0, &AccountId::from(BOB))); + assert_eq!(TEN, Assets::balance(0, ¶_acc)); // the KSM balance of sibling parachain sovereign account is not changed - assert_eq!(initial_ksm_para_acc, Balances::free_balance(¶_acc)); + assert_eq!(UNIT, Balances::free_balance(¶_acc)); }); // Rerun the Statemine::execute to actually send the egress message via XCM diff --git a/runtime/karura/src/constants.rs b/runtime/karura/src/constants.rs index 4cd8b3a2e..e708667a9 100644 --- a/runtime/karura/src/constants.rs +++ b/runtime/karura/src/constants.rs @@ -107,6 +107,10 @@ pub mod parachains { pub const KBTC_KEY: &[u8] = &[0, 11]; pub const KINT_KEY: &[u8] = &[0, 12]; } + + pub mod statemine { + pub const ID: u32 = 1000; + } } #[cfg(test)] diff --git a/runtime/karura/src/xcm_config.rs b/runtime/karura/src/xcm_config.rs index 7f7570906..25a8e5aef 100644 --- a/runtime/karura/src/xcm_config.rs +++ b/runtime/karura/src/xcm_config.rs @@ -29,7 +29,7 @@ pub use frame_support::{ traits::{Everything, Get, Nothing}, weights::Weight, }; -use orml_traits::MultiCurrency; +use orml_traits::{parameter_type_with_key, MultiCurrency}; use orml_xcm_support::{DepositToAlternative, IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset}; use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; @@ -287,6 +287,16 @@ parameter_types! { pub const MaxAssetsForTransfer: usize = 2; } +parameter_type_with_key! { + pub ParachainMinFee: |location: MultiLocation| -> u128 { + #[allow(clippy::match_ref_pats)] // false positive + match (location.parents, location.first_interior()) { + (1, Some(Parachain(parachains::statemine::ID))) => 4_000_000_000, + _ => u128::MAX, + } + }; +} + impl orml_xtokens::Config for Runtime { type Event = Event; type Balance = Balance; @@ -299,6 +309,7 @@ impl orml_xtokens::Config for Runtime { type BaseXcmWeight = BaseXcmWeight; type LocationInverter = LocationInverter; type MaxAssetsForTransfer = MaxAssetsForTransfer; + type MinXcmFee = ParachainMinFee; } pub type LocalAssetTransactor = MultiCurrencyAdapter< diff --git a/runtime/mandala/src/xcm_config.rs b/runtime/mandala/src/xcm_config.rs index 09e0e11cd..13d5cdeb6 100644 --- a/runtime/mandala/src/xcm_config.rs +++ b/runtime/mandala/src/xcm_config.rs @@ -29,7 +29,7 @@ pub use frame_support::{ traits::{Everything, Get, Nothing}, weights::Weight, }; -use orml_traits::MultiCurrency; +use orml_traits::{parameter_type_with_key, MultiCurrency}; use orml_xcm_support::{DepositToAlternative, IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset}; use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; @@ -309,6 +309,15 @@ parameter_types! { pub const MaxAssetsForTransfer: usize = 2; } +parameter_type_with_key! { + pub ParachainMinFee: |location: MultiLocation| -> u128 { + #[allow(clippy::match_ref_pats)] // false positive + match (location.parents, location.first_interior()) { + _ => u128::MAX, + } + }; +} + impl orml_xtokens::Config for Runtime { type Event = Event; type Balance = Balance; @@ -321,4 +330,5 @@ impl orml_xtokens::Config for Runtime { type BaseXcmWeight = BaseXcmWeight; type LocationInverter = LocationInverter; type MaxAssetsForTransfer = MaxAssetsForTransfer; + type MinXcmFee = ParachainMinFee; } From 0743ded7deeed48474625879055ad6b450d4fb45 Mon Sep 17 00:00:00 2001 From: zqh Date: Tue, 1 Mar 2022 10:10:28 +0800 Subject: [PATCH 15/21] simplify new default config --- runtime/acala/src/xcm_config.rs | 7 ++----- runtime/mandala/src/xcm_config.rs | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/runtime/acala/src/xcm_config.rs b/runtime/acala/src/xcm_config.rs index 457099ce6..e2abf25cd 100644 --- a/runtime/acala/src/xcm_config.rs +++ b/runtime/acala/src/xcm_config.rs @@ -320,11 +320,8 @@ parameter_types! { } parameter_type_with_key! { - pub ParachainMinFee: |location: MultiLocation| -> u128 { - #[allow(clippy::match_ref_pats)] // false positive - match (location.parents, location.first_interior()) { - _ => u128::MAX, - } + pub ParachainMinFee: |_location: MultiLocation| -> u128 { + u128::MAX }; } diff --git a/runtime/mandala/src/xcm_config.rs b/runtime/mandala/src/xcm_config.rs index 13d5cdeb6..48004d8fd 100644 --- a/runtime/mandala/src/xcm_config.rs +++ b/runtime/mandala/src/xcm_config.rs @@ -310,11 +310,8 @@ parameter_types! { } parameter_type_with_key! { - pub ParachainMinFee: |location: MultiLocation| -> u128 { - #[allow(clippy::match_ref_pats)] // false positive - match (location.parents, location.first_interior()) { - _ => u128::MAX, - } + pub ParachainMinFee: |_location: MultiLocation| -> u128 { + u128::MAX }; } From ddd64e54805f6c6a9e54791ca8bcd2b52ac9f147 Mon Sep 17 00:00:00 2001 From: zqh Date: Tue, 1 Mar 2022 17:26:38 +0800 Subject: [PATCH 16/21] update tests --- .../src/relaychain/statemine.rs | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/runtime/integration-tests/src/relaychain/statemine.rs b/runtime/integration-tests/src/relaychain/statemine.rs index bd388f6c1..6484eac15 100644 --- a/runtime/integration-tests/src/relaychain/statemine.rs +++ b/runtime/integration-tests/src/relaychain/statemine.rs @@ -94,39 +94,45 @@ fn user_different_ksm_fee() { #[cfg(feature = "with-karura-runtime")] #[test] fn user_large_fee_fund_to_sovereign_account_works() { - statemine_side(); let para_2000: AccountId = Sibling::from(2000).into_account(); let child_2000: AccountId = ParaId::from(2000).into_account(); let child_1000: AccountId = ParaId::from(1000).into_account(); - KusamaNet::execute_with(|| { - let _ = kusama_runtime::Balances::make_free_balance_be(&child_2000, TEN); - }); + let assets: Vec<(u128, u128, u128, u128)> = vec![ + (9 * UNIT + FEE_STATEMINE, UNIT, 8_999_893_333_340, 9_991_893_333_340), + (UNIT, 9_004_000_000_000, 995_893_333_340, 1_987_893_333_340), + ]; - karura_side(9 * UNIT + FEE_STATEMINE); + for (asset, c_2000, c_1000, p_2000) in assets { + TestNet::reset(); - KusamaNet::execute_with(|| { - // first xcm send to relaychain with 9 KSM. 10 KSM - 9 KSM = 1 KSM - assert_eq!(UNIT, kusama_runtime::Balances::free_balance(&child_2000)); - // 9 KSM - fee on relaychain = 9 KSM - 106_666_660 - assert_eq!(8_999_893_333_340, kusama_runtime::Balances::free_balance(&child_1000)); - }); + statemine_side(); - Statemine::execute_with(|| { - use statemine_runtime::*; - // Karura send back custom asset to Statemine, ensure recipient got custom asset - assert_eq!(UNIT, Assets::balance(0, &AccountId::from(BOB))); - // the recipient's ksm not changed - assert_eq!(UNIT, Balances::free_balance(&AccountId::from(BOB))); - // and withdraw sibling parachain sovereign account - assert_eq!(9 * UNIT, Assets::balance(0, ¶_2000)); - - // before karura transfer asset back to Statemine, para_2000 already have 1 KSM. - // after second xcm executed, para_2000 balance - xcm_weight - // after first xcm executed, para_2000 balance + (8_999_893_333_340 - xcm_weight) - // the result of para_2000 balance = 1KSM-4_000_000_000+8_999_893_333_340-4_000_000_000 - assert_eq!(9_991_893_333_340, Balances::free_balance(¶_2000)); - }); + KusamaNet::execute_with(|| { + let _ = kusama_runtime::Balances::make_free_balance_be(&child_2000, TEN); + }); + + karura_side(asset); + + KusamaNet::execute_with(|| { + // first xcm send to relaychain with 9 KSM. 10 KSM - 9 KSM = 1 KSM + assert_eq!(c_2000, kusama_runtime::Balances::free_balance(&child_2000)); + // 9 KSM - fee on relaychain = 9 KSM - 106_666_660 + assert_eq!(c_1000, kusama_runtime::Balances::free_balance(&child_1000)); + }); + + Statemine::execute_with(|| { + use statemine_runtime::*; + // Karura send back custom asset to Statemine, ensure recipient got custom asset + assert_eq!(UNIT, Assets::balance(0, &AccountId::from(BOB))); + // the recipient's ksm not changed + assert_eq!(UNIT, Balances::free_balance(&AccountId::from(BOB))); + // and withdraw sibling parachain sovereign account + assert_eq!(9 * UNIT, Assets::balance(0, ¶_2000)); + + assert_eq!(p_2000, Balances::free_balance(¶_2000)); + }); + } } // transfer custom asset from Karura to Statemine From 21efbd11061f7d7d4e7b4dcbd735af32af74b7ac Mon Sep 17 00:00:00 2001 From: zqh Date: Wed, 2 Mar 2022 17:13:40 +0800 Subject: [PATCH 17/21] update orml --- orml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orml b/orml index 83e030483..cadcc9fb1 160000 --- a/orml +++ b/orml @@ -1 +1 @@ -Subproject commit 83e0304834398491a72d8d104da1d9b40c274880 +Subproject commit cadcc9fb10b8212f92668138fc8f83dc0c53acf5 From daff9e00737e8db3cc718ea66db5b79da3bb8462 Mon Sep 17 00:00:00 2001 From: zqh Date: Thu, 3 Mar 2022 17:43:33 +0800 Subject: [PATCH 18/21] update orml --- orml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orml b/orml index cadcc9fb1..0a5a2df3b 160000 --- a/orml +++ b/orml @@ -1 +1 @@ -Subproject commit cadcc9fb10b8212f92668138fc8f83dc0c53acf5 +Subproject commit 0a5a2df3b796f1fcfec3c4c32cc853716fa6c3da From f6fa9b39422f80fc4493b5747d76d249064b26fb Mon Sep 17 00:00:00 2001 From: zqh Date: Thu, 3 Mar 2022 17:58:33 +0800 Subject: [PATCH 19/21] reset sub-module --- evm-bench | 2 +- evm-tests | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/evm-bench b/evm-bench index 5c7084ddd..1d32bc1f0 160000 --- a/evm-bench +++ b/evm-bench @@ -1 +1 @@ -Subproject commit 5c7084ddd818498cdd6c8daabc9b2754f4d0b152 +Subproject commit 1d32bc1f0a40107fd64ec2d2212475514878b3d5 diff --git a/evm-tests b/evm-tests index f0e5cf76f..2907f4cd1 160000 --- a/evm-tests +++ b/evm-tests @@ -1 +1 @@ -Subproject commit f0e5cf76fcd32a02691c146b98d30a88cc71076a +Subproject commit 2907f4cd1f08dd292377a7d1d2ba5b1497aabfad From 1c2df4508c0c4283dde6e8795ff170e7c23a0125 Mon Sep 17 00:00:00 2001 From: zqh Date: Thu, 3 Mar 2022 22:01:43 +0800 Subject: [PATCH 20/21] update test --- Cargo.lock | 2 +- runtime/integration-tests/Cargo.toml | 2 +- .../src/relaychain/statemine.rs | 98 +++++++++++-------- 3 files changed, 59 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e522959ce..900cf254e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15254,7 +15254,7 @@ dependencies = [ [[package]] name = "xcm-emulator" version = "0.1.0" -source = "git+https://github.com/zqhxuyuan/xcm-simulator?rev=65832f73b21f55b10dcb09460f8c8ad6ac8083f9#65832f73b21f55b10dcb09460f8c8ad6ac8083f9" +source = "git+https://github.com/zqhxuyuan/xcm-simulator?rev=3119d273777be17d23683076dbfd30cb17e489d6#3119d273777be17d23683076dbfd30cb17e489d6" dependencies = [ "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index 2b9191d1f..a64baf077 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -138,7 +138,7 @@ polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", kusama-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.17" } #xcm-emulator = { git = "https://github.com/shaunxw/xcm-simulator", rev = "a250ffc998bac4831c5692c591dee7bc13f3aead" } -xcm-emulator = { git = "https://github.com/zqhxuyuan/xcm-simulator", rev = "65832f73b21f55b10dcb09460f8c8ad6ac8083f9" } +xcm-emulator = { git = "https://github.com/zqhxuyuan/xcm-simulator", rev = "3119d273777be17d23683076dbfd30cb17e489d6" } acala-service = { path = "../../node/service", features = ["with-all-runtime"] } diff --git a/runtime/integration-tests/src/relaychain/statemine.rs b/runtime/integration-tests/src/relaychain/statemine.rs index 6484eac15..dec5cc7a5 100644 --- a/runtime/integration-tests/src/relaychain/statemine.rs +++ b/runtime/integration-tests/src/relaychain/statemine.rs @@ -32,62 +32,78 @@ pub const TEN: Balance = 10_000_000_000_000; pub const FEE_STATEMINE: Balance = 4_000_000_000; pub const FEE_KUSAMA: Balance = 106_666_660; +// Statemine ED +pub const EXISTENTIAL_DEPOSIT: Balance = CENTS / 10; +pub const UNITS: Balance = 1_000_000_000_000; +pub const CENTS: Balance = UNITS / 30_000; + #[cfg(feature = "with-karura-runtime")] #[test] fn user_different_ksm_fee() { + env_logger::init(); let para_2000: AccountId = Sibling::from(2000).into_account(); let child_2000: AccountId = ParaId::from(2000).into_account(); let child_1000: AccountId = ParaId::from(1000).into_account(); - let user_fees = vec![ - FEE_STATEMINE + FEE_KUSAMA - 1, - FEE_STATEMINE + FEE_KUSAMA, - FEE_STATEMINE + FEE_KUSAMA + 1, + let user1_fees = vec![ 2 * FEE_STATEMINE - 1, 2 * FEE_STATEMINE, 2 * FEE_STATEMINE + 1, 2 * FEE_STATEMINE + FEE_KUSAMA, ]; - let min_user_fee = 2 * FEE_STATEMINE; - for user_fee in user_fees { - TestNet::reset(); + let min_user_fee1 = 2 * FEE_STATEMINE; + let para_init_amount1 = UNIT; - statemine_side(); + let user2_fees = vec![2 * FEE_STATEMINE + FEE_KUSAMA]; + let min_user_fee2 = 2 * FEE_STATEMINE + FEE_KUSAMA; + let para_init_amount2 = FEE_STATEMINE + EXISTENTIAL_DEPOSIT; - KusamaNet::execute_with(|| { - let _ = kusama_runtime::Balances::make_free_balance_be(&child_2000, UNIT); - }); + let data1 = vec![ + (user1_fees, min_user_fee1, para_init_amount1), + (user2_fees, min_user_fee2, para_init_amount2), + ]; - // user fee amount split into two parts - // first part is `FEE_STATEMINE` sent to statemine - // second part left sent to kusama - karura_side(user_fee + FEE_STATEMINE); + for (user_fees, min_user_fee, init_amount) in data1 { + for user_fee in user_fees { + TestNet::reset(); - KusamaNet::execute_with(|| { - assert_eq!(UNIT - user_fee, kusama_runtime::Balances::free_balance(&child_2000)); - assert_eq!( - user_fee - FEE_KUSAMA, - kusama_runtime::Balances::free_balance(&child_1000) - ); - }); + statemine_side(init_amount); - Statemine::execute_with(|| { - use statemine_runtime::*; - // Karura send back custom asset to Statemine, ensure recipient got custom asset - assert_eq!(UNIT, Assets::balance(0, &AccountId::from(BOB))); - // the recipient's ksm not changed - assert_eq!(UNIT, Balances::free_balance(&AccountId::from(BOB))); - // and withdraw sibling parachain sovereign account - assert_eq!(TEN - UNIT, Assets::balance(0, ¶_2000)); + KusamaNet::execute_with(|| { + let _ = kusama_runtime::Balances::make_free_balance_be(&child_2000, UNIT); + }); + + // User fee amount split into two parts: + // First part is `FEE_STATEMINE` sent to statemine. + // Second part `user_fee` sent to kusama then route to statemine. + karura_side(user_fee + FEE_STATEMINE); - if user_fee < min_user_fee { - assert_eq!(UNIT - FEE_STATEMINE, Balances::free_balance(¶_2000)); - } else { + KusamaNet::execute_with(|| { + assert_eq!(UNIT - user_fee, kusama_runtime::Balances::free_balance(&child_2000)); assert_eq!( - UNIT - FEE_STATEMINE + user_fee - (FEE_STATEMINE + FEE_KUSAMA), - Balances::free_balance(¶_2000) + user_fee - FEE_KUSAMA, + kusama_runtime::Balances::free_balance(&child_1000) ); - } - }); + }); + + Statemine::execute_with(|| { + use statemine_runtime::*; + // Karura send back custom asset to Statemine, ensure recipient got custom asset + assert_eq!(UNIT, Assets::balance(0, &AccountId::from(BOB))); + // the recipient's ksm not changed + assert_eq!(UNIT, Balances::free_balance(&AccountId::from(BOB))); + // and withdraw sibling parachain sovereign account + assert_eq!(TEN - UNIT, Assets::balance(0, ¶_2000)); + + if user_fee < min_user_fee { + assert_eq!(UNIT - FEE_STATEMINE, Balances::free_balance(¶_2000)); + } else { + assert_eq!( + init_amount - FEE_STATEMINE + user_fee - (FEE_STATEMINE + FEE_KUSAMA), + Balances::free_balance(¶_2000) + ); + } + }); + } } } @@ -106,7 +122,7 @@ fn user_large_fee_fund_to_sovereign_account_works() { for (asset, c_2000, c_1000, p_2000) in assets { TestNet::reset(); - statemine_side(); + statemine_side(UNIT); KusamaNet::execute_with(|| { let _ = kusama_runtime::Balances::make_free_balance_be(&child_2000, TEN); @@ -174,7 +190,7 @@ fn karura_side(fee_amount: u128) { } // transfer custom asset from Statemine to Karura -fn statemine_side() { +fn statemine_side(para_2000_init_amount: u128) { register_asset(); let para_acc: AccountId = Sibling::from(2000).into_account(); @@ -203,7 +219,7 @@ fn statemine_side() { )); // need to have some KSM to be able to receive user assets - Balances::make_free_balance_be(¶_acc, UNIT); + Balances::make_free_balance_be(¶_acc, para_2000_init_amount); assert_ok!(PolkadotXcm::reserve_transfer_assets( origin.clone(), @@ -224,7 +240,7 @@ fn statemine_side() { assert_eq!(TEN, Assets::balance(0, ¶_acc)); // the KSM balance of sibling parachain sovereign account is not changed - assert_eq!(UNIT, Balances::free_balance(¶_acc)); + assert_eq!(para_2000_init_amount, Balances::free_balance(¶_acc)); }); // Rerun the Statemine::execute to actually send the egress message via XCM From cbb8dbc419cc1bf6a9e43a7865c630a5f4c5831e Mon Sep 17 00:00:00 2001 From: zqh Date: Thu, 3 Mar 2022 23:29:42 +0800 Subject: [PATCH 21/21] update test --- .../src/relaychain/statemine.rs | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/runtime/integration-tests/src/relaychain/statemine.rs b/runtime/integration-tests/src/relaychain/statemine.rs index dec5cc7a5..ca5c8e7b5 100644 --- a/runtime/integration-tests/src/relaychain/statemine.rs +++ b/runtime/integration-tests/src/relaychain/statemine.rs @@ -23,6 +23,7 @@ use cumulus_primitives_core::ParaId; use frame_support::assert_ok; use module_asset_registry::AssetMetadata; +pub use orml_traits::GetByKey; use polkadot_parachain::primitives::Sibling; use xcm::v1::{Junction, MultiLocation}; use xcm_emulator::TestExt; @@ -37,10 +38,26 @@ pub const EXISTENTIAL_DEPOSIT: Balance = CENTS / 10; pub const UNITS: Balance = 1_000_000_000_000; pub const CENTS: Balance = UNITS / 30_000; -#[cfg(feature = "with-karura-runtime")] +#[test] +fn statemine_min_xcm_fee_matched() { + Statemine::execute_with(|| { + use frame_support::weights::{IdentityFee, WeightToFeePolynomial}; + let weight = FEE_STATEMINE as u64; + + let fee: Balance = IdentityFee::calc(&weight); + let statemine: MultiLocation = (1, Parachain(parachains::statemine::ID)).into(); + let bifrost: MultiLocation = (1, Parachain(parachains::bifrost::ID)).into(); + + let statemine_fee: u128 = ParachainMinFee::get(&statemine); + assert_eq!(fee, statemine_fee); + + let bifrost_fee: u128 = ParachainMinFee::get(&bifrost); + assert_eq!(u128::MAX, bifrost_fee); + }); +} + #[test] fn user_different_ksm_fee() { - env_logger::init(); let para_2000: AccountId = Sibling::from(2000).into_account(); let child_2000: AccountId = ParaId::from(2000).into_account(); let child_1000: AccountId = ParaId::from(1000).into_account(); @@ -107,7 +124,6 @@ fn user_different_ksm_fee() { } } -#[cfg(feature = "with-karura-runtime")] #[test] fn user_large_fee_fund_to_sovereign_account_works() { let para_2000: AccountId = Sibling::from(2000).into_account();