From 73a4799beff021774b91c9d6f0e746726e326a62 Mon Sep 17 00:00:00 2001 From: cr4pt0 Date: Wed, 29 Mar 2023 18:37:50 +0100 Subject: [PATCH 01/18] update pendulum runtime to support XCM reserve transfer for USDT --- runtime/pendulum/src/xcm_config.rs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/runtime/pendulum/src/xcm_config.rs b/runtime/pendulum/src/xcm_config.rs index 722d2ff1e..8450aa20e 100644 --- a/runtime/pendulum/src/xcm_config.rs +++ b/runtime/pendulum/src/xcm_config.rs @@ -7,7 +7,7 @@ use frame_support::{ log, match_types, parameter_types, traits::{Everything, Nothing}, }; -use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key}; +use orml_traits::{location::{RelativeReserveProvider, Reserve}, parameter_type_with_key}; use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; use polkadot_runtime_common::impls::ToAuthor; @@ -16,12 +16,12 @@ use sp_runtime::traits::Convert; use xcm::latest::{prelude::*, Weight as XCMWeight}; use xcm_builder::{ AccountId32Aliases, AllowUnpaidExecutionFrom, ConvertedConcreteAssetId, EnsureXcmOrigin, - FixedWeightBounds, FungiblesAdapter, LocationInverter, NativeAsset, ParentIsPreset, + FixedWeightBounds, FungiblesAdapter, LocationInverter, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, UsingComponents, }; use xcm_executor::{ - traits::{JustTry, ShouldExecute}, + traits::{JustTry, ShouldExecute, FilterAssetLocation}, XcmExecutor, }; @@ -114,6 +114,23 @@ impl xcm_executor::traits::Convert for CurrencyIdConv } } +/// A `FilterAssetLocation` implementation. Filters multi native assets whose +/// reserve is same with `origin`. +pub struct MultiNativeAsset(PhantomData); +impl FilterAssetLocation for MultiNativeAsset +where + ReserveProvider: Reserve, +{ + fn filter_asset_location(asset: &MultiAsset, origin: &MultiLocation) -> bool { + if let Some(ref reserve) = ReserveProvider::reserve(asset) { + if reserve == origin { + return true; + } + } + false + } +} + /// Means for transacting the fungibles assets of ths parachain. pub type FungiblesTransactor = FungiblesAdapter< // Use this fungibles implementation @@ -240,7 +257,7 @@ impl xcm_executor::Config for XcmConfig { // How to withdraw and deposit an asset. type AssetTransactor = FungiblesTransactor; type OriginConverter = XcmOriginToTransactDispatchOrigin; - type IsReserve = NativeAsset; + type IsReserve = MultiNativeAsset; type IsTeleporter = (); // Teleporting is disabled. type LocationInverter = LocationInverter; type Barrier = Barrier; @@ -306,7 +323,7 @@ impl orml_xtokens::Config for Runtime { type MaxAssetsForTransfer = MaxAssetsForTransfer; type MinXcmFee = ParachainMinFee; //TODO to support hrmp transfer beetween parachain adjust this parameter type MultiLocationsFilter = Everything; - type ReserveProvider = AbsoluteReserveProvider; + type ReserveProvider = RelativeReserveProvider; } pub struct AccountIdToMultiLocation; From 0761f1a15870a17f33aa263e3435156f8fded300 Mon Sep 17 00:00:00 2001 From: Rust Ninja <102041955+RustNinja@users.noreply.github.com> Date: Wed, 29 Mar 2023 19:33:32 +0100 Subject: [PATCH 02/18] add pendulum integration tests for XCM (#190) add pendulum integration tests --- Cargo.lock | 413 +++++++++++------- Cargo.toml | 2 + runtime/integration-tests/pendulum/Cargo.toml | 27 ++ runtime/integration-tests/pendulum/src/lib.rs | 2 + 4 files changed, 278 insertions(+), 166 deletions(-) create mode 100644 runtime/integration-tests/pendulum/Cargo.toml create mode 100644 runtime/integration-tests/pendulum/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 00b4e9ca5..c497d77b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,7 +42,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fc95d1bdb8e6666b2b217308eeeb09f2d6728d104be3e31916cc74d15420331" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] @@ -51,7 +51,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", "rand_core 0.6.4", ] @@ -62,7 +62,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c192eb8f11fc081b0fe4259ba5af04217d4e0faddd02417310a927911abd7c8" dependencies = [ "crypto-common", - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] @@ -288,6 +288,46 @@ dependencies = [ "winapi", ] +[[package]] +name = "anstream" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "342258dd14006105c2b75ab1bd7543a03bdf0cfc94383303ac212a04939dff6f" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-wincon", + "concolor-override", + "concolor-query", + "is-terminal", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23ea9e81bd02e310c216d080f6223c179012256e5151c41db88d12c88a1684d2" + +[[package]] +name = "anstyle-parse" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7d1bb534e9efed14f3e5f44e7dd1a4f709384023a4165199a4241e18dff0116" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-wincon" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3127af6145b149f3287bb9a0d10ad9c5692dba8c53ad48285e5bec4063834fa" +dependencies = [ + "anstyle", + "windows-sys 0.45.0", +] + [[package]] name = "anyhow" version = "1.0.70" @@ -432,7 +472,7 @@ dependencies = [ "log", "parking", "polling", - "rustix 0.37.3", + "rustix 0.37.4", "slab", "socket2", "waker-fn", @@ -449,13 +489,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.67" +version = "0.1.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ea188f25f0255d8f92797797c97ebf5631fa88178beb1a46fdf5622c9a00e4" +checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" dependencies = [ "proc-macro2", "quote", - "syn 2.0.8", + "syn 2.0.11", ] [[package]] @@ -632,7 +672,7 @@ version = "0.64.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" dependencies = [ - "bitflags 1.3.2", + "bitflags", "cexpr", "clang-sys", "lazy_static", @@ -652,12 +692,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitflags" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "487f1e0fcbe47deb8b0574e646def1c903389d95241dd1bbcc6ce4a715dfc0c1" - [[package]] name = "bitvec" version = "1.0.1" @@ -733,7 +767,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] @@ -742,7 +776,7 @@ version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] @@ -991,7 +1025,7 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] @@ -1000,7 +1034,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] @@ -1035,40 +1069,45 @@ dependencies = [ [[package]] name = "clap" -version = "4.1.11" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42dfd32784433290c51d92c438bb72ea5063797fc3cc9a21a8c4346bebbb2098" +checksum = "6efb5f0a41b5ef5b50c5da28c07609c20091df0c1fc33d418fa2a7e693c2b624" dependencies = [ - "bitflags 2.0.2", + "clap_builder", "clap_derive", - "clap_lex", - "is-terminal", "once_cell", +] + +[[package]] +name = "clap_builder" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "671fcaa5debda4b9a84aa7fde49c907c8986c0e6ab927e04217c9cb74e7c8bc9" +dependencies = [ + "anstream", + "anstyle", + "bitflags", + "clap_lex", "strsim", - "termcolor", ] [[package]] name = "clap_derive" -version = "4.1.9" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fddf67631444a3a3e3e5ac51c36a5e01335302de677bd78759eaa90ab1f46644" +checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4" dependencies = [ "heck", - "proc-macro-error", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.11", ] [[package]] name = "clap_lex" -version = "0.3.3" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "033f6b7a4acb1f358c742aaca805c939ee73b4c6209ae4318ec7aca81c42e646" -dependencies = [ - "os_str_bytes", -] +checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" [[package]] name = "coarsetime" @@ -1103,6 +1142,21 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "concolor-override" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a855d4a1978dc52fb0536a04d384c2c0c1aa273597f08b77c8c4d3b2eec6037f" + +[[package]] +name = "concolor-query" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d11d52c3d7ca2e6d0040212be9e4dbbcd78b6447f535b6b561f449427944cf" +dependencies = [ + "windows-sys 0.45.0", +] + [[package]] name = "concurrent-queue" version = "2.1.0" @@ -1176,9 +1230,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +checksum = "280a9f2d8b3a38871a3c8a46fb80db65e5e5ed97da80c4d08bf27fb63e35e181" dependencies = [ "libc", ] @@ -1370,7 +1424,7 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", "rand_core 0.6.4", "subtle", "zeroize", @@ -1382,7 +1436,7 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", "rand_core 0.6.4", "typenum", ] @@ -1393,7 +1447,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", "subtle", ] @@ -1403,7 +1457,7 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", "subtle", ] @@ -1966,9 +2020,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9c00419335c41018365ddf7e4d5f1c12ee3659ddcf3e01974650ba1de73d038" +checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93" dependencies = [ "cc", "cxxbridge-flags", @@ -1978,9 +2032,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb8307ad413a98fff033c8545ecf133e3257747b3bae935e7602aab8aa92d4ca" +checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b" dependencies = [ "cc", "codespan-reporting", @@ -1988,24 +2042,24 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.8", + "syn 2.0.11", ] [[package]] name = "cxxbridge-flags" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edc52e2eb08915cb12596d29d55f0b5384f00d697a646dbd269b6ecb0fbd9d31" +checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb" [[package]] name = "cxxbridge-macro" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "631569015d0d8d54e6c241733f944042623ab6df7bc3be7466874b05fcdb1c5f" +checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.8", + "syn 2.0.11", ] [[package]] @@ -2271,7 +2325,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] @@ -2448,7 +2502,7 @@ dependencies = [ "der", "digest 0.10.6", "ff", - "generic-array 0.14.6", + "generic-array 0.14.7", "group", "hkdf", "pem-rfc7468", @@ -2499,7 +2553,7 @@ checksum = "48016319042fb7c87b78d2993084a831793a897a5cd1a2a67cab9d1eeb4b7d76" dependencies = [ "proc-macro2", "quote", - "syn 2.0.8", + "syn 2.0.11", ] [[package]] @@ -2719,7 +2773,7 @@ checksum = "8a3de6e8d11b22ff9edc6d916f890800597d60f8b2da1caf2955c274638d6412" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.2.16", "windows-sys 0.45.0", ] @@ -3063,7 +3117,7 @@ name = "frame-support" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.37#f38bd6671d460293c93062cc1e4fe9e9e490cb29" dependencies = [ - "bitflags 1.3.2", + "bitflags", "frame-metadata", "frame-support-procedural", "impl-trait-for-tuples", @@ -3344,9 +3398,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.6" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", @@ -3595,7 +3649,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1" dependencies = [ "digest 0.9.0", - "generic-array 0.14.6", + "generic-array 0.14.7", "hmac 0.8.1", ] @@ -3812,9 +3866,9 @@ checksum = "4161ceaf2f41b6cd3f6502f5da085d4ad4393a51e0c70ed2fce1d5698d798fae" [[package]] name = "indexmap" -version = "1.9.2" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown", @@ -3833,7 +3887,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] @@ -3916,19 +3970,19 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.7.1" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" +checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f" [[package]] name = "is-terminal" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8687c819457e979cc940d09cb16e42a1bf70aa6b60a549de6d3a62a0ee90c69e" +checksum = "256017f749ab3117e93acb91063009e1f1bb56d03965b14c2c8df4eb02c524d8" dependencies = [ "hermit-abi 0.3.1", "io-lifetimes 1.0.9", - "rustix 0.36.11", + "rustix 0.37.4", "windows-sys 0.45.0", ] @@ -4897,12 +4951,6 @@ version = "0.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" -[[package]] -name = "linux-raw-sys" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" - [[package]] name = "linux-raw-sys" version = "0.3.0" @@ -5022,11 +5070,11 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memfd" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b20a59d985586e4a5aef64564ac77299f8586d8be6cf9106a5a40207e8908efb" +checksum = "ffc89ccdc6e10d6907450f753537ebc5c5d3460d2e4e62ea74bd571db62c0f9e" dependencies = [ - "rustix 0.36.11", + "rustix 0.37.4", ] [[package]] @@ -5159,9 +5207,9 @@ dependencies = [ [[package]] name = "mockall" -version = "0.11.3" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50e4a1c770583dac7ab5e2f6c139153b783a53a1bbee9729613f193e59828326" +checksum = "4c84490118f2ee2d74570d114f3d0493cbf02790df303d2707606c3e14e07c96" dependencies = [ "cfg-if", "downcast", @@ -5174,9 +5222,9 @@ dependencies = [ [[package]] name = "mockall_derive" -version = "0.11.3" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "832663583d5fa284ca8810bf7015e46c9fff9622d3cf34bd1eea5003fec06dd0" +checksum = "22ce75669015c4f47b289fd4d4f56e894e4c96003ffdf3ac51313126f94c6cbb" dependencies = [ "cfg-if", "proc-macro2", @@ -5489,7 +5537,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9ea4302b9759a7a88242299225ea3688e63c85ea136371bb6cf94fd674efaab" dependencies = [ "anyhow", - "bitflags 1.3.2", + "bitflags", "byteorder", "libc", "netlink-packet-core", @@ -5542,7 +5590,7 @@ version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" dependencies = [ - "bitflags 1.3.2", + "bitflags", "cfg-if", "libc", "memoffset 0.6.5", @@ -5988,12 +6036,6 @@ dependencies = [ "xcm-executor", ] -[[package]] -name = "os_str_bytes" -version = "6.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" - [[package]] name = "p256" version = "0.11.1" @@ -6249,7 +6291,7 @@ name = "pallet-contracts" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.37#f38bd6671d460293c93062cc1e4fe9e9e490cb29" dependencies = [ - "bitflags 1.3.2", + "bitflags", "frame-benchmarking", "frame-support", "frame-system", @@ -6277,7 +6319,7 @@ name = "pallet-contracts-primitives" version = "7.0.0" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.37#f38bd6671d460293c93062cc1e4fe9e9e490cb29" dependencies = [ - "bitflags 1.3.2", + "bitflags", "parity-scale-codec", "sp-runtime", "sp-std", @@ -7181,7 +7223,7 @@ dependencies = [ "cfg-if", "instant", "libc", - "redox_syscall", + "redox_syscall 0.2.16", "smallvec", "winapi", ] @@ -7194,7 +7236,7 @@ checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.2.16", "smallvec", "windows-sys 0.45.0", ] @@ -8481,7 +8523,7 @@ name = "polkadot-runtime-parachains" version = "0.9.37" source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.37#645723987cf9662244be8faf4e9b63e8b9a1b3a3" dependencies = [ - "bitflags 1.3.2", + "bitflags", "bitvec", "derive_more", "frame-benchmarking", @@ -8663,7 +8705,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e1f879b2998099c2d69ab9605d145d5b661195627eccc680002c4918a7fb6fa" dependencies = [ "autocfg", - "bitflags 1.3.2", + "bitflags", "cfg-if", "concurrent-queue", "libc", @@ -8818,9 +8860,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.53" +version = "1.0.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba466839c78239c09faf015484e5cc04860f88242cff4d03eb038f04b4699b73" +checksum = "e472a104799c74b514a57226160104aa483546de37e839ec50e3c2e41dd87534" dependencies = [ "unicode-ident", ] @@ -8966,9 +9008,9 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72ef4ced82a24bb281af338b9e8f94429b6eca01b4e66d899f40031f074e74c9" +checksum = "67c10f662eee9c94ddd7135043e544f3c82fa839a1e7b865911331961b53186c" dependencies = [ "bytes", "rand 0.8.5", @@ -9177,7 +9219,16 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags 1.3.2", + "bitflags", +] + +[[package]] +name = "redox_syscall" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +dependencies = [ + "bitflags", ] [[package]] @@ -9187,7 +9238,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ "getrandom 0.2.8", - "redox_syscall", + "redox_syscall 0.2.16", "thiserror", ] @@ -9221,7 +9272,7 @@ checksum = "8d2275aab483050ab2a7364c1a46604865ee7d6906684e08db0f090acf74f9e7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.8", + "syn 2.0.11", ] [[package]] @@ -9238,9 +9289,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.2" +version = "1.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cce168fea28d3e05f158bda4576cf0c844d5045bc2cc3620fa0292ed5bb5814c" +checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" dependencies = [ "aho-corasick", "memchr", @@ -9534,9 +9585,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" +checksum = "d4a36c42d1873f9a77c53bde094f9664d9891bc604a45b4798fd2c389ed12e5b" [[package]] name = "rustc-hash" @@ -9583,7 +9634,7 @@ version = "0.35.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "727a1a6d65f786ec22df8a81ca3121107f235970dc1705ed681d3e6e8b9cd5f9" dependencies = [ - "bitflags 1.3.2", + "bitflags", "errno 0.2.8", "io-lifetimes 0.7.5", "libc", @@ -9593,25 +9644,11 @@ dependencies = [ [[package]] name = "rustix" -version = "0.36.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db4165c9963ab29e422d6c26fbc1d37f15bace6b2810221f9d925023480fcf0e" -dependencies = [ - "bitflags 1.3.2", - "errno 0.2.8", - "io-lifetimes 1.0.9", - "libc", - "linux-raw-sys 0.1.4", - "windows-sys 0.45.0", -] - -[[package]] -name = "rustix" -version = "0.37.3" +version = "0.37.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b24138615de35e32031d041a09032ef3487a616d901ca4db224e7d557efae2" +checksum = "c348b5dc624ecee40108aa2922fed8bad89d7fcc2b9f8cb18f632898ac4a37f9" dependencies = [ - "bitflags 1.3.2", + "bitflags", "errno 0.3.0", "io-lifetimes 1.0.9", "libc", @@ -10274,7 +10311,7 @@ version = "0.10.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.37#f38bd6671d460293c93062cc1e4fe9e9e490cb29" dependencies = [ "async-trait", - "bitflags 1.3.2", + "bitflags", "bytes", "futures", "futures-timer", @@ -10756,9 +10793,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.3.1" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "001cf62ece89779fd16105b5f515ad0e5cedcd5440d3dd806bb067978e7c3608" +checksum = "61471dff9096de1d8b2319efed7162081e96793f5ebb147e50db10d50d648a4d" dependencies = [ "bitvec", "cfg-if", @@ -10770,9 +10807,9 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.3.1" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "303959cf613a6f6efd19ed4b4ad5bf79966a13352716299ad532cfb115f4205c" +checksum = "219580e803a66b3f05761fd06f1f879a872444e49ce23f73694d26e5a954c7e6" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -10859,7 +10896,7 @@ checksum = "3be24c1842290c45df0a7bf069e0c268a747ad05a192f2fd7dcfdbc1cba40928" dependencies = [ "base16ct", "der", - "generic-array 0.14.6", + "generic-array 0.14.7", "pkcs8", "subtle", "zeroize", @@ -10914,7 +10951,7 @@ version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" dependencies = [ - "bitflags 1.3.2", + "bitflags", "core-foundation", "core-foundation-sys", "libc", @@ -10966,29 +11003,29 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.158" +version = "1.0.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "771d4d9c4163ee138805e12c710dd365e4f44be8be0503cb1bb9eb989425d9c9" +checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.158" +version = "1.0.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e801c1712f48475582b7696ac71e0ca34ebb30e09338425384269d9717c62cad" +checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" dependencies = [ "proc-macro2", "quote", - "syn 2.0.8", + "syn 2.0.11", ] [[package]] name = "serde_json" -version = "1.0.94" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea" +checksum = "d721eca97ac802aa7777b701877c8004d950fc142651367300d21c1cc0194744" dependencies = [ "itoa", "ryu", @@ -11438,7 +11475,7 @@ source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.37#f3 dependencies = [ "array-bytes 4.2.0", "base58", - "bitflags 1.3.2", + "bitflags", "blake2", "dyn-clonable", "ed25519-zebra", @@ -11956,9 +11993,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "spin" -version = "0.9.6" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5d6e0250b93c8427a177b849d144a96d5acc57006149479403d7861ab721e34" +checksum = "c0959fd6f767df20b231736396e4f602171e00d95205676286e79d4a4eb67bef" [[package]] name = "spki" @@ -12036,7 +12073,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a2a1c578e98c1c16fc3b8ec1328f7659a500737d7a0c6d625e73e830ff9c1f6" dependencies = [ - "bitflags 1.3.2", + "bitflags", "cfg_aliases", "libc", "parking_lot 0.11.2", @@ -12298,9 +12335,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.8" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc02725fd69ab9f26eab07fad303e2497fad6fb9eba4f96c4d1687bdf704ad9" +checksum = "21e3787bb71465627110e7d87ed4faaa36c1f61042ee67badb9e2ef173accc40" dependencies = [ "proc-macro2", "quote", @@ -12325,7 +12362,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d75182f12f490e953596550b65ee31bda7c8e043d9386174b353bda50838c3fd" dependencies = [ - "bitflags 1.3.2", + "bitflags", "core-foundation", "system-configuration-sys", ] @@ -12354,15 +12391,15 @@ checksum = "8ae9980cab1db3fceee2f6c6f643d5d8de2997c58ee8d25fb0cc8a9e9e7348e5" [[package]] name = "tempfile" -version = "3.4.0" +version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95" +checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" dependencies = [ "cfg-if", "fastrand", - "redox_syscall", - "rustix 0.36.11", - "windows-sys 0.42.0", + "redox_syscall 0.3.5", + "rustix 0.37.4", + "windows-sys 0.45.0", ] [[package]] @@ -12397,7 +12434,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.8", + "syn 2.0.11", ] [[package]] @@ -12543,14 +12580,13 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.26.0" +version = "1.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03201d01c3c27a29c8a5cee5b55a93ddae1ccf6f08f65365c2c918f8c1b76f64" +checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" dependencies = [ "autocfg", "bytes", "libc", - "memchr", "mio", "num_cpus", "parking_lot 0.12.1", @@ -12563,13 +12599,13 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.8.2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" +checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.11", ] [[package]] @@ -12653,7 +12689,7 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f873044bf02dd1e8239e9c1293ea39dad76dc594ec16185d0a1bf31d8dc8d858" dependencies = [ - "bitflags 1.3.2", + "bitflags", "bytes", "futures-core", "futures-util", @@ -12993,7 +13029,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", "subtle", ] @@ -13036,6 +13072,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "uuid" version = "1.3.0" @@ -13329,7 +13371,7 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01bf50edb2ea9d922aa75a7bf3c15e26a6c9e2d18c56e862b49737a582901729" dependencies = [ - "spin 0.9.6", + "spin 0.9.7", "wasmi_arena", "wasmi_core 0.5.0", "wasmparser-nostd", @@ -13799,7 +13841,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93f1db1727772c05cf7a2cfece52c3aca8045ca1e176cd517d323489aa3c6d87" dependencies = [ "async-trait", - "bitflags 1.3.2", + "bitflags", "bytes", "cc", "ipnet", @@ -14143,9 +14185,9 @@ checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" [[package]] name = "winnow" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deac0939bd6e4f24ab5919fbf751c97a8cfc8543bb083a305ed5c0c10bb241d1" +checksum = "ae8970b36c66498d8ff1d66685dc86b91b29db0c7739899012f63a63814b4b28" dependencies = [ "memchr", ] @@ -14290,6 +14332,46 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "xcm-simulator" +version = "0.9.37" +source = "git+https://github.com/paritytech/polkadot?branch=release-v0.9.37#645723987cf9662244be8faf4e9b63e8b9a1b3a3" +dependencies = [ + "frame-support", + "parity-scale-codec", + "paste", + "polkadot-core-primitives", + "polkadot-parachain", + "polkadot-runtime-parachains", + "sp-io", + "sp-std", + "xcm", + "xcm-executor", +] + +[[package]] +name = "xcm-simulator-example" +version = "0.1.0" +dependencies = [ + "frame-support", + "frame-system", + "pallet-balances", + "pallet-xcm", + "parity-scale-codec", + "polkadot-core-primitives", + "polkadot-parachain", + "polkadot-runtime-parachains", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "xcm", + "xcm-builder", + "xcm-executor", + "xcm-simulator", +] + [[package]] name = "yamux" version = "0.10.2" @@ -14349,23 +14431,22 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.5.7" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" dependencies = [ "zeroize_derive", ] [[package]] name = "zeroize_derive" -version = "1.3.3" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44bf07cb3e50ea2003396695d58bf46bc9887a1f362260446fad6bc4e79bd36c" +checksum = "25588073e5216b50bca71d61cb8595cdb9745e87032a58c199730def2862c934" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", - "synstructure", + "syn 2.0.11", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a7a5cffe2..22848bb72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,4 +11,6 @@ members = [ "runtime/foucoco", "runtime/pendulum", "runtime/development", + "runtime/development", + "runtime/integration-tests/pendulum", ] diff --git a/runtime/integration-tests/pendulum/Cargo.toml b/runtime/integration-tests/pendulum/Cargo.toml new file mode 100644 index 000000000..a85a81de4 --- /dev/null +++ b/runtime/integration-tests/pendulum/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "xcm-simulator-example" +description = "Examples of xcm-simulator usage." +authors = ["Pendulum"] +edition = "2021" +version = "0.1.0" + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0" } +scale-info = { version = "2.1.2", features = ["derive"] } + +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } + +xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } +xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } +xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } +xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } +pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } +polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } +polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } +polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } \ No newline at end of file diff --git a/runtime/integration-tests/pendulum/src/lib.rs b/runtime/integration-tests/pendulum/src/lib.rs new file mode 100644 index 000000000..8c2b99c11 --- /dev/null +++ b/runtime/integration-tests/pendulum/src/lib.rs @@ -0,0 +1,2 @@ +use sp_runtime::traits::AccountIdConversion; +use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain}; \ No newline at end of file From 08a81de512dcef241e2692081306ee032adef18e Mon Sep 17 00:00:00 2001 From: cr4pt0 Date: Wed, 29 Mar 2023 19:45:18 +0100 Subject: [PATCH 03/18] add polkadot runtime to integration tests --- Cargo.lock | 3 +++ runtime/integration-tests/pendulum/Cargo.toml | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index c497d77b7..f898ed235 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14360,6 +14360,9 @@ dependencies = [ "parity-scale-codec", "polkadot-core-primitives", "polkadot-parachain", + "polkadot-primitives", + "polkadot-runtime", + "polkadot-runtime-common", "polkadot-runtime-parachains", "scale-info", "sp-core", diff --git a/runtime/integration-tests/pendulum/Cargo.toml b/runtime/integration-tests/pendulum/Cargo.toml index a85a81de4..5d16aadf4 100644 --- a/runtime/integration-tests/pendulum/Cargo.toml +++ b/runtime/integration-tests/pendulum/Cargo.toml @@ -24,4 +24,7 @@ xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "releas pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } -polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } \ No newline at end of file +polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } +polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } +polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } +polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } From 2717818d5563900c40c16d9493e23caa86883acf Mon Sep 17 00:00:00 2001 From: cr4pt0 Date: Wed, 29 Mar 2023 21:48:29 +0100 Subject: [PATCH 04/18] add xcm test configuration --- runtime/integration-tests/pendulum/src/lib.rs | 134 +++++++++++++++++- 1 file changed, 133 insertions(+), 1 deletion(-) diff --git a/runtime/integration-tests/pendulum/src/lib.rs b/runtime/integration-tests/pendulum/src/lib.rs index 8c2b99c11..9fc69563b 100644 --- a/runtime/integration-tests/pendulum/src/lib.rs +++ b/runtime/integration-tests/pendulum/src/lib.rs @@ -1,2 +1,134 @@ +use frame_support::{ + construct_runtime, parameter_types, + traits::{Everything, Nothing}, +}; +use sp_core::H256; +use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; + +use polkadot_parachain::primitives::Id as ParaId; +use polkadot_runtime_parachains::{configuration, origin, shared, ump}; +use xcm::latest::prelude::*; +use xcm_builder::{ + AccountId32Aliases, AllowUnpaidExecutionFrom, ChildParachainAsNative, + ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, + CurrencyAdapter as XcmCurrencyAdapter, FixedRateOfFungible, FixedWeightBounds, IsConcrete, + LocationInverter, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, +}; +use xcm_executor::{Config, XcmExecutor}; + +pub type AccountId = AccountId32; +pub type Balance = u128; + +use polkadot_core_primitives::BlockNumber; +use polkadot_primitives::v2::{MAX_CODE_SIZE, MAX_POV_SIZE}; +use polkadot_runtime_parachains::configuration::HostConfiguration; use sp_runtime::traits::AccountIdConversion; -use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain}; \ No newline at end of file +use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain}; +use frame_support::traits::GenesisBuild; +use frame_support::weights::Weight; +use polkadot_parachain::primitives::{ + DmpMessageHandler, Sibling, XcmpMessageFormat, XcmpMessageHandler, +}; + + +decl_test_relay_chain! { + pub struct Relay { + Runtime = polkadot_runtime::Runtime, + XcmConfig = polkadot_runtime::xcm_config::XCMConfig, + new_ext = relay_ext(), + } +} + +decl_test_network! { + pub struct TestNet{ + relay_chain = Relay, + parachains = vec![ ] + } +} + + +pub fn relay_ext() -> sp_io::TestExternalities { + use polkadot_runtime::{Runtime, System}; + let mut t = frame_system::GenesisConfig::default() + .build_storage::() + .unwrap(); + pallet_balances::GenesisConfig:: { + balances: vec![ + // (AccountId::from(ALICE), cfg(2002)), + // ( + // ParaId::from(parachains::polkadot::centrifuge::ID).into_account_truncating(), + // cfg(7), + // ), + // ( + // ParaId::from(PARA_ID_SIBLING).into_account_truncating(), + // cfg(7), + // ), + ], + } + .assimilate_storage(&mut t) + .unwrap(); + polkadot_runtime_parachains::configuration::GenesisConfig:: { + config: default_parachains_host_configuration(), + } + .assimilate_storage(&mut t) + .unwrap(); + >::assimilate_storage( + &pallet_xcm::GenesisConfig { + safe_xcm_version: Some(2), + }, + &mut t, + ) + .unwrap(); + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext +} + +fn default_parachains_host_configuration() -> HostConfiguration { + HostConfiguration { + minimum_validation_upgrade_delay: 5, + validation_upgrade_cooldown: 5u32, + validation_upgrade_delay: 5, + code_retention_period: 1200, + max_code_size: MAX_CODE_SIZE, + max_pov_size: MAX_POV_SIZE, + max_head_data_size: 32 * 1024, + group_rotation_frequency: 20, + chain_availability_period: 4, + thread_availability_period: 4, + max_upward_queue_count: 8, + max_upward_queue_size: 1024 * 1024, + max_downward_message_size: 1024, + ump_service_total_weight: Weight::from_ref_time(4 * 1_000_000_000), + max_upward_message_size: 50 * 1024, + max_upward_message_num_per_candidate: 5, + hrmp_sender_deposit: 0, + hrmp_recipient_deposit: 0, + hrmp_channel_max_capacity: 8, + hrmp_channel_max_total_size: 8 * 1024, + hrmp_max_parachain_inbound_channels: 4, + hrmp_max_parathread_inbound_channels: 4, + hrmp_channel_max_message_size: 1024 * 1024, + hrmp_max_parachain_outbound_channels: 4, + hrmp_max_parathread_outbound_channels: 4, + hrmp_max_message_num_per_candidate: 5, + dispute_period: 6, + no_show_slots: 2, + n_delay_tranches: 25, + needed_approvals: 2, + relay_vrf_modulo_samples: 2, + zeroth_delay_tranche_width: 0, + ..Default::default() + } +} + + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn dmp() { + + } +} \ No newline at end of file From 1c9aad6824eb75cf22ad2382f96ab2cf1bc8d944 Mon Sep 17 00:00:00 2001 From: cr4pt0 Date: Wed, 29 Mar 2023 21:53:38 +0100 Subject: [PATCH 05/18] fix type XcmConfig instead of XCMConfig --- runtime/integration-tests/pendulum/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/integration-tests/pendulum/src/lib.rs b/runtime/integration-tests/pendulum/src/lib.rs index 9fc69563b..b1c77f8dc 100644 --- a/runtime/integration-tests/pendulum/src/lib.rs +++ b/runtime/integration-tests/pendulum/src/lib.rs @@ -34,7 +34,7 @@ use polkadot_parachain::primitives::{ decl_test_relay_chain! { pub struct Relay { Runtime = polkadot_runtime::Runtime, - XcmConfig = polkadot_runtime::xcm_config::XCMConfig, + XcmConfig = polkadot_runtime::xcm_config::XcmConfig, new_ext = relay_ext(), } } From cb5346aaeb200670d7fd85bfa850c6313e2d9109 Mon Sep 17 00:00:00 2001 From: cr4pt0 Date: Wed, 29 Mar 2023 22:08:55 +0100 Subject: [PATCH 06/18] add relay chain + parachain base integration tests --- runtime/integration-tests/pendulum/src/lib.rs | 392 +++++++++++++----- .../pendulum/src/parachain.rs | 316 ++++++++++++++ .../pendulum/src/relay_chain.rs | 174 ++++++++ 3 files changed, 775 insertions(+), 107 deletions(-) create mode 100644 runtime/integration-tests/pendulum/src/parachain.rs create mode 100644 runtime/integration-tests/pendulum/src/relay_chain.rs diff --git a/runtime/integration-tests/pendulum/src/lib.rs b/runtime/integration-tests/pendulum/src/lib.rs index b1c77f8dc..5bfa146a0 100644 --- a/runtime/integration-tests/pendulum/src/lib.rs +++ b/runtime/integration-tests/pendulum/src/lib.rs @@ -1,35 +1,30 @@ -use frame_support::{ - construct_runtime, parameter_types, - traits::{Everything, Nothing}, -}; -use sp_core::H256; -use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; +// mod parachain; +// mod relay_chain; use polkadot_parachain::primitives::Id as ParaId; -use polkadot_runtime_parachains::{configuration, origin, shared, ump}; -use xcm::latest::prelude::*; -use xcm_builder::{ - AccountId32Aliases, AllowUnpaidExecutionFrom, ChildParachainAsNative, - ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, - CurrencyAdapter as XcmCurrencyAdapter, FixedRateOfFungible, FixedWeightBounds, IsConcrete, - LocationInverter, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, -}; -use xcm_executor::{Config, XcmExecutor}; - -pub type AccountId = AccountId32; -pub type Balance = u128; - -use polkadot_core_primitives::BlockNumber; -use polkadot_primitives::v2::{MAX_CODE_SIZE, MAX_POV_SIZE}; -use polkadot_runtime_parachains::configuration::HostConfiguration; use sp_runtime::traits::AccountIdConversion; use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain}; -use frame_support::traits::GenesisBuild; -use frame_support::weights::Weight; -use polkadot_parachain::primitives::{ - DmpMessageHandler, Sibling, XcmpMessageFormat, XcmpMessageHandler, -}; +pub const ALICE: sp_runtime::AccountId32 = sp_runtime::AccountId32::new([0u8; 32]); +pub const INITIAL_BALANCE: u128 = 1_000_000_000; + +// decl_test_parachain! { +// pub struct ParaA { +// Runtime = parachain::Runtime, +// XcmpMessageHandler = parachain::MsgQueue, +// DmpMessageHandler = parachain::MsgQueue, +// new_ext = para_ext(1), +// } +// } + +// decl_test_parachain! { +// pub struct ParaB { +// Runtime = parachain::Runtime, +// XcmpMessageHandler = parachain::MsgQueue, +// DmpMessageHandler = parachain::MsgQueue, +// new_ext = para_ext(2), +// } +// } decl_test_relay_chain! { pub struct Relay { @@ -40,95 +35,278 @@ decl_test_relay_chain! { } decl_test_network! { - pub struct TestNet{ - relay_chain = Relay, - parachains = vec![ ] - } + pub struct MockNet { + relay_chain = Relay, + parachains = vec![ + // (1, ParaA), + // (2, ParaB), + ], + } } +// pub fn para_account_id(id: u32) -> relay_chain::AccountId { +// ParaId::from(id).into_account_truncating() +// } + +// pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { +// use parachain::{MsgQueue, Runtime, System}; + +// let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + +// pallet_balances::GenesisConfig:: { balances: vec![(ALICE, INITIAL_BALANCE)] } +// .assimilate_storage(&mut t) +// .unwrap(); + +// let mut ext = sp_io::TestExternalities::new(t); +// ext.execute_with(|| { +// System::set_block_number(1); +// MsgQueue::set_para_id(para_id.into()); +// }); +// ext +// } pub fn relay_ext() -> sp_io::TestExternalities { - use polkadot_runtime::{Runtime, System}; - let mut t = frame_system::GenesisConfig::default() - .build_storage::() - .unwrap(); - pallet_balances::GenesisConfig:: { - balances: vec![ - // (AccountId::from(ALICE), cfg(2002)), - // ( - // ParaId::from(parachains::polkadot::centrifuge::ID).into_account_truncating(), - // cfg(7), - // ), - // ( - // ParaId::from(PARA_ID_SIBLING).into_account_truncating(), - // cfg(7), - // ), - ], - } - .assimilate_storage(&mut t) - .unwrap(); - polkadot_runtime_parachains::configuration::GenesisConfig:: { - config: default_parachains_host_configuration(), - } - .assimilate_storage(&mut t) - .unwrap(); - >::assimilate_storage( - &pallet_xcm::GenesisConfig { - safe_xcm_version: Some(2), - }, - &mut t, - ) - .unwrap(); - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); - ext -} + // use relay_chain::{Runtime, System}; + use polkadot_runtime::{Runtime, System}; -fn default_parachains_host_configuration() -> HostConfiguration { - HostConfiguration { - minimum_validation_upgrade_delay: 5, - validation_upgrade_cooldown: 5u32, - validation_upgrade_delay: 5, - code_retention_period: 1200, - max_code_size: MAX_CODE_SIZE, - max_pov_size: MAX_POV_SIZE, - max_head_data_size: 32 * 1024, - group_rotation_frequency: 20, - chain_availability_period: 4, - thread_availability_period: 4, - max_upward_queue_count: 8, - max_upward_queue_size: 1024 * 1024, - max_downward_message_size: 1024, - ump_service_total_weight: Weight::from_ref_time(4 * 1_000_000_000), - max_upward_message_size: 50 * 1024, - max_upward_message_num_per_candidate: 5, - hrmp_sender_deposit: 0, - hrmp_recipient_deposit: 0, - hrmp_channel_max_capacity: 8, - hrmp_channel_max_total_size: 8 * 1024, - hrmp_max_parachain_inbound_channels: 4, - hrmp_max_parathread_inbound_channels: 4, - hrmp_channel_max_message_size: 1024 * 1024, - hrmp_max_parachain_outbound_channels: 4, - hrmp_max_parathread_outbound_channels: 4, - hrmp_max_message_num_per_candidate: 5, - dispute_period: 6, - no_show_slots: 2, - n_delay_tranches: 25, - needed_approvals: 2, - relay_vrf_modulo_samples: 2, - zeroth_delay_tranche_width: 0, - ..Default::default() - } + let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![ + // (ALICE, INITIAL_BALANCE), (para_account_id(1), INITIAL_BALANCE) + ], + } + .assimilate_storage(&mut t) + .unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext } +// pub type RelayChainPalletXcm = pallet_xcm::Pallet; +// pub type ParachainPalletXcm = pallet_xcm::Pallet; #[cfg(test)] mod tests { - use super::*; - #[test] - fn dmp() { + fn dmp() {} +} + +// #[cfg(test)] +// mod tests { +// use super::*; + +// use codec::Encode; +// use frame_support::assert_ok; +// use xcm::latest::prelude::*; +// use xcm_simulator::TestExt; + +// // Helper function for forming buy execution message +// fn buy_execution(fees: impl Into) -> Instruction { +// BuyExecution { fees: fees.into(), weight_limit: Unlimited } +// } + +// #[test] +// fn dmp() { +// MockNet::reset(); + +// let remark = parachain::RuntimeCall::System( +// frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, +// ); +// Relay::execute_with(|| { +// assert_ok!(RelayChainPalletXcm::send_xcm( +// Here, +// Parachain(1), +// Xcm(vec![Transact { +// origin_type: OriginKind::SovereignAccount, +// require_weight_at_most: INITIAL_BALANCE as u64, +// call: remark.encode().into(), +// }]), +// )); +// }); + +// ParaA::execute_with(|| { +// use parachain::{RuntimeEvent, System}; +// assert!(System::events().iter().any(|r| matches!( +// r.event, +// RuntimeEvent::System(frame_system::Event::Remarked { .. }) +// ))); +// }); +// } + +// #[test] +// fn ump() { +// MockNet::reset(); + +// let remark = relay_chain::RuntimeCall::System( +// frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, +// ); +// ParaA::execute_with(|| { +// assert_ok!(ParachainPalletXcm::send_xcm( +// Here, +// Parent, +// Xcm(vec![Transact { +// origin_type: OriginKind::SovereignAccount, +// require_weight_at_most: INITIAL_BALANCE as u64, +// call: remark.encode().into(), +// }]), +// )); +// }); + +// Relay::execute_with(|| { +// use relay_chain::{RuntimeEvent, System}; +// assert!(System::events().iter().any(|r| matches!( +// r.event, +// RuntimeEvent::System(frame_system::Event::Remarked { .. }) +// ))); +// }); +// } + +// #[test] +// fn xcmp() { +// MockNet::reset(); + +// let remark = parachain::RuntimeCall::System( +// frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, +// ); +// ParaA::execute_with(|| { +// assert_ok!(ParachainPalletXcm::send_xcm( +// Here, +// (Parent, Parachain(2)), +// Xcm(vec![Transact { +// origin_type: OriginKind::SovereignAccount, +// require_weight_at_most: INITIAL_BALANCE as u64, +// call: remark.encode().into(), +// }]), +// )); +// }); + +// ParaB::execute_with(|| { +// use parachain::{RuntimeEvent, System}; +// assert!(System::events().iter().any(|r| matches!( +// r.event, +// RuntimeEvent::System(frame_system::Event::Remarked { .. }) +// ))); +// }); +// } + +// #[test] +// fn reserve_transfer() { +// MockNet::reset(); + +// let withdraw_amount = 123; + +// Relay::execute_with(|| { +// assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( +// relay_chain::RuntimeOrigin::signed(ALICE), +// Box::new(X1(Parachain(1)).into().into()), +// Box::new(X1(AccountId32 { network: Any, id: ALICE.into() }).into().into()), +// Box::new((Here, withdraw_amount).into()), +// 0, +// )); +// assert_eq!( +// parachain::Balances::free_balance(¶_account_id(1)), +// INITIAL_BALANCE + withdraw_amount +// ); +// }); + +// ParaA::execute_with(|| { +// // free execution, full amount received +// assert_eq!( +// pallet_balances::Pallet::::free_balance(&ALICE), +// INITIAL_BALANCE + withdraw_amount +// ); +// }); +// } + +// /// Scenario: +// /// A parachain transfers funds on the relay chain to another parachain account. +// /// +// /// Asserts that the parachain accounts are updated as expected. +// #[test] +// fn withdraw_and_deposit() { +// MockNet::reset(); + +// let send_amount = 10; + +// ParaA::execute_with(|| { +// let message = Xcm(vec![ +// WithdrawAsset((Here, send_amount).into()), +// buy_execution((Here, send_amount)), +// DepositAsset { +// assets: All.into(), +// max_assets: 1, +// beneficiary: Parachain(2).into(), +// }, +// ]); +// // Send withdraw and deposit +// assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone())); +// }); + +// Relay::execute_with(|| { +// assert_eq!( +// relay_chain::Balances::free_balance(para_account_id(1)), +// INITIAL_BALANCE - send_amount +// ); +// assert_eq!(relay_chain::Balances::free_balance(para_account_id(2)), send_amount); +// }); +// } + +// /// Scenario: +// /// A parachain wants to be notified that a transfer worked correctly. +// /// It sends a `QueryHolding` after the deposit to get notified on success. +// /// +// /// Asserts that the balances are updated correctly and the expected XCM is sent. +// #[test] +// fn query_holding() { +// MockNet::reset(); + +// let send_amount = 10; +// let query_id_set = 1234; + +// // Send a message which fully succeeds on the relay chain +// ParaA::execute_with(|| { +// let message = Xcm(vec![ +// WithdrawAsset((Here, send_amount).into()), +// buy_execution((Here, send_amount)), +// DepositAsset { +// assets: All.into(), +// max_assets: 1, +// beneficiary: Parachain(2).into(), +// }, +// QueryHolding { +// query_id: query_id_set, +// dest: Parachain(1).into(), +// assets: All.into(), +// max_response_weight: 1_000_000_000, +// }, +// ]); +// // Send withdraw and deposit with query holding +// assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone(),)); +// }); + +// // Check that transfer was executed +// Relay::execute_with(|| { +// // Withdraw executed +// assert_eq!( +// relay_chain::Balances::free_balance(para_account_id(1)), +// INITIAL_BALANCE - send_amount +// ); +// // Deposit executed +// assert_eq!(relay_chain::Balances::free_balance(para_account_id(2)), send_amount); +// }); - } -} \ No newline at end of file +// // Check that QueryResponse message was received +// ParaA::execute_with(|| { +// assert_eq!( +// parachain::MsgQueue::received_dmp(), +// vec![Xcm(vec![QueryResponse { +// query_id: query_id_set, +// response: Response::Assets(MultiAssets::new()), +// max_weight: 1_000_000_000, +// }])], +// ); +// }); +// } +// } diff --git a/runtime/integration-tests/pendulum/src/parachain.rs b/runtime/integration-tests/pendulum/src/parachain.rs new file mode 100644 index 000000000..ac791102f --- /dev/null +++ b/runtime/integration-tests/pendulum/src/parachain.rs @@ -0,0 +1,316 @@ +// use codec::{Decode, Encode}; +// use frame_support::{ +// construct_runtime, parameter_types, +// traits::{Everything, Nothing}, +// weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, +// }; +// use sp_core::H256; +// use sp_runtime::{ +// testing::Header, +// traits::{Hash, IdentityLookup}, +// AccountId32, +// }; +// use sp_std::prelude::*; + +// use pallet_xcm::XcmPassthrough; +// use polkadot_core_primitives::BlockNumber as RelayBlockNumber; +// use polkadot_parachain::primitives::{ +// DmpMessageHandler, Id as ParaId, Sibling, XcmpMessageFormat, XcmpMessageHandler, +// }; +// use xcm::{latest::prelude::*, VersionedXcm}; +// use xcm_builder::{ +// AccountId32Aliases, AllowUnpaidExecutionFrom, CurrencyAdapter as XcmCurrencyAdapter, +// EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, IsConcrete, LocationInverter, +// NativeAsset, ParentIsPreset, SiblingParachainConvertsVia, SignedAccountId32AsNative, +// SignedToAccountId32, SovereignSignedViaLocation, +// }; +// use xcm_executor::{Config, XcmExecutor}; + +// pub type AccountId = AccountId32; +// pub type Balance = u128; + +// parameter_types! { +// pub const BlockHashCount: u64 = 250; +// } + +// impl frame_system::Config for Runtime { +// type RuntimeOrigin = RuntimeOrigin; +// type RuntimeCall = RuntimeCall; +// type Index = u64; +// type BlockNumber = u64; +// type Hash = H256; +// type Hashing = ::sp_runtime::traits::BlakeTwo256; +// type AccountId = AccountId; +// type Lookup = IdentityLookup; +// type Header = Header; +// type RuntimeEvent = RuntimeEvent; +// type BlockHashCount = BlockHashCount; +// type BlockWeights = (); +// type BlockLength = (); +// type Version = (); +// type PalletInfo = PalletInfo; +// type AccountData = pallet_balances::AccountData; +// type OnNewAccount = (); +// type OnKilledAccount = (); +// type DbWeight = (); +// type BaseCallFilter = Everything; +// type SystemWeightInfo = (); +// type SS58Prefix = (); +// type OnSetCode = (); +// type MaxConsumers = frame_support::traits::ConstU32<16>; +// } + +// parameter_types! { +// pub ExistentialDeposit: Balance = 1; +// pub const MaxLocks: u32 = 50; +// pub const MaxReserves: u32 = 50; +// } + +// impl pallet_balances::Config for Runtime { +// type MaxLocks = MaxLocks; +// type Balance = Balance; +// type RuntimeEvent = RuntimeEvent; +// type DustRemoval = (); +// type ExistentialDeposit = ExistentialDeposit; +// type AccountStore = System; +// type WeightInfo = (); +// type MaxReserves = MaxReserves; +// type ReserveIdentifier = [u8; 8]; +// } + +// parameter_types! { +// pub const ReservedXcmpWeight: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4)); +// pub const ReservedDmpWeight: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4)); +// } + +// parameter_types! { +// pub const KsmLocation: MultiLocation = MultiLocation::parent(); +// pub const RelayNetwork: NetworkId = NetworkId::Kusama; +// pub Ancestry: MultiLocation = Parachain(MsgQueue::parachain_id().into()).into(); +// } + +// pub type LocationToAccountId = ( +// ParentIsPreset, +// SiblingParachainConvertsVia, +// AccountId32Aliases, +// ); + +// pub type XcmOriginToCallOrigin = ( +// SovereignSignedViaLocation, +// SignedAccountId32AsNative, +// XcmPassthrough, +// ); + +// parameter_types! { +// pub const UnitWeightCost: u64 = 1; +// pub KsmPerSecond: (AssetId, u128) = (Concrete(Parent.into()), 1); +// pub const MaxInstructions: u32 = 100; +// } + +// pub type LocalAssetTransactor = +// XcmCurrencyAdapter, LocationToAccountId, AccountId, ()>; + +// pub type XcmRouter = super::ParachainXcmRouter; +// pub type Barrier = AllowUnpaidExecutionFrom; + +// pub struct XcmConfig; +// impl Config for XcmConfig { +// type RuntimeCall = RuntimeCall; +// type XcmSender = XcmRouter; +// type AssetTransactor = LocalAssetTransactor; +// type OriginConverter = XcmOriginToCallOrigin; +// type IsReserve = NativeAsset; +// type IsTeleporter = (); +// type LocationInverter = LocationInverter; +// type Barrier = Barrier; +// type Weigher = FixedWeightBounds; +// type Trader = FixedRateOfFungible; +// type ResponseHandler = (); +// type AssetTrap = (); +// type AssetClaims = (); +// type SubscriptionService = (); +// } + +// #[frame_support::pallet] +// pub mod mock_msg_queue { +// use super::*; +// use frame_support::pallet_prelude::*; + +// #[pallet::config] +// pub trait Config: frame_system::Config { +// type RuntimeEvent: From> + IsType<::RuntimeEvent>; +// type XcmExecutor: ExecuteXcm; +// } + +// #[pallet::call] +// impl Pallet {} + +// #[pallet::pallet] +// #[pallet::generate_store(pub(super) trait Store)] +// #[pallet::without_storage_info] +// pub struct Pallet(_); + +// #[pallet::storage] +// #[pallet::getter(fn parachain_id)] +// pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; + +// #[pallet::storage] +// #[pallet::getter(fn received_dmp)] +// /// A queue of received DMP messages +// pub(super) type ReceivedDmp = StorageValue<_, Vec>, ValueQuery>; + +// impl Get for Pallet { +// fn get() -> ParaId { +// Self::parachain_id() +// } +// } + +// pub type MessageId = [u8; 32]; + +// #[pallet::event] +// #[pallet::generate_deposit(pub(super) fn deposit_event)] +// pub enum Event { +// // XCMP +// /// Some XCM was executed OK. +// Success(Option), +// /// Some XCM failed. +// Fail(Option, XcmError), +// /// Bad XCM version used. +// BadVersion(Option), +// /// Bad XCM format used. +// BadFormat(Option), + +// // DMP +// /// Downward message is invalid XCM. +// InvalidFormat(MessageId), +// /// Downward message is unsupported version of XCM. +// UnsupportedVersion(MessageId), +// /// Downward message executed with the given outcome. +// ExecutedDownward(MessageId, Outcome), +// } + +// impl Pallet { +// pub fn set_para_id(para_id: ParaId) { +// ParachainId::::put(para_id); +// } + +// fn handle_xcmp_message( +// sender: ParaId, +// _sent_at: RelayBlockNumber, +// xcm: VersionedXcm, +// max_weight: Weight, +// ) -> Result { +// let hash = Encode::using_encoded(&xcm, T::Hashing::hash); +// let (result, event) = match Xcm::::try_from(xcm) { +// Ok(xcm) => { +// let location = (1, Parachain(sender.into())); +// match T::XcmExecutor::execute_xcm(location, xcm, max_weight.ref_time()) { +// Outcome::Error(e) => (Err(e.clone()), Event::Fail(Some(hash), e)), +// Outcome::Complete(w) => +// (Ok(Weight::from_ref_time(w)), Event::Success(Some(hash))), +// // As far as the caller is concerned, this was dispatched without error, so +// // we just report the weight used. +// Outcome::Incomplete(w, e) => +// (Ok(Weight::from_ref_time(w)), Event::Fail(Some(hash), e)), +// } +// }, +// Err(()) => (Err(XcmError::UnhandledXcmVersion), Event::BadVersion(Some(hash))), +// }; +// Self::deposit_event(event); +// result +// } +// } + +// impl XcmpMessageHandler for Pallet { +// fn handle_xcmp_messages<'a, I: Iterator>( +// iter: I, +// max_weight: Weight, +// ) -> Weight { +// for (sender, sent_at, data) in iter { +// let mut data_ref = data; +// let _ = XcmpMessageFormat::decode(&mut data_ref) +// .expect("Simulator encodes with versioned xcm format; qed"); + +// let mut remaining_fragments = &data_ref[..]; +// while !remaining_fragments.is_empty() { +// if let Ok(xcm) = +// VersionedXcm::::decode(&mut remaining_fragments) +// { +// let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); +// } else { +// debug_assert!(false, "Invalid incoming XCMP message data"); +// } +// } +// } +// max_weight +// } +// } + +// impl DmpMessageHandler for Pallet { +// fn handle_dmp_messages( +// iter: impl Iterator)>, +// limit: Weight, +// ) -> Weight { +// for (_i, (_sent_at, data)) in iter.enumerate() { +// let id = sp_io::hashing::blake2_256(&data[..]); +// let maybe_msg = VersionedXcm::::decode(&mut &data[..]) +// .map(Xcm::::try_from); +// match maybe_msg { +// Err(_) => { +// Self::deposit_event(Event::InvalidFormat(id)); +// }, +// Ok(Err(())) => { +// Self::deposit_event(Event::UnsupportedVersion(id)); +// }, +// Ok(Ok(x)) => { +// let outcome = +// T::XcmExecutor::execute_xcm(Parent, x.clone(), limit.ref_time()); +// >::append(x); +// Self::deposit_event(Event::ExecutedDownward(id, outcome)); +// }, +// } +// } +// limit +// } +// } +// } + +// impl mock_msg_queue::Config for Runtime { +// type RuntimeEvent = RuntimeEvent; +// type XcmExecutor = XcmExecutor; +// } + +// pub type LocalOriginToLocation = SignedToAccountId32; + +// impl pallet_xcm::Config for Runtime { +// type RuntimeEvent = RuntimeEvent; +// type SendXcmOrigin = EnsureXcmOrigin; +// type XcmRouter = XcmRouter; +// type ExecuteXcmOrigin = EnsureXcmOrigin; +// type XcmExecuteFilter = Everything; +// type XcmExecutor = XcmExecutor; +// type XcmTeleportFilter = Nothing; +// type XcmReserveTransferFilter = Everything; +// type Weigher = FixedWeightBounds; +// type LocationInverter = LocationInverter; +// type RuntimeOrigin = RuntimeOrigin; +// type RuntimeCall = RuntimeCall; +// const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; +// type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; +// } + +// type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +// type Block = frame_system::mocking::MockBlock; + +// construct_runtime!( +// pub enum Runtime where +// Block = Block, +// NodeBlock = Block, +// UncheckedExtrinsic = UncheckedExtrinsic, +// { +// System: frame_system::{Pallet, Call, Storage, Config, Event}, +// Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, +// MsgQueue: mock_msg_queue::{Pallet, Storage, Event}, +// PolkadotXcm: pallet_xcm::{Pallet, Call, Event, Origin}, +// } +// ); diff --git a/runtime/integration-tests/pendulum/src/relay_chain.rs b/runtime/integration-tests/pendulum/src/relay_chain.rs new file mode 100644 index 000000000..11dd8b74a --- /dev/null +++ b/runtime/integration-tests/pendulum/src/relay_chain.rs @@ -0,0 +1,174 @@ +// use frame_support::{ +// construct_runtime, parameter_types, +// traits::{Everything, Nothing}, +// }; +// use sp_core::H256; +// use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; + +// use polkadot_parachain::primitives::Id as ParaId; +// use polkadot_runtime_parachains::{configuration, origin, shared, ump}; +// use xcm::latest::prelude::*; +// use xcm_builder::{ +// AccountId32Aliases, AllowUnpaidExecutionFrom, ChildParachainAsNative, +// ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, +// CurrencyAdapter as XcmCurrencyAdapter, FixedRateOfFungible, FixedWeightBounds, IsConcrete, +// LocationInverter, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, +// }; +// use xcm_executor::{Config, XcmExecutor}; + +// pub type AccountId = AccountId32; +// pub type Balance = u128; + +// parameter_types! { +// pub const BlockHashCount: u64 = 250; +// } + +// impl frame_system::Config for Runtime { +// type RuntimeOrigin = RuntimeOrigin; +// type RuntimeCall = RuntimeCall; +// type Index = u64; +// type BlockNumber = u64; +// type Hash = H256; +// type Hashing = ::sp_runtime::traits::BlakeTwo256; +// type AccountId = AccountId; +// type Lookup = IdentityLookup; +// type Header = Header; +// type RuntimeEvent = RuntimeEvent; +// type BlockHashCount = BlockHashCount; +// type BlockWeights = (); +// type BlockLength = (); +// type Version = (); +// type PalletInfo = PalletInfo; +// type AccountData = pallet_balances::AccountData; +// type OnNewAccount = (); +// type OnKilledAccount = (); +// type DbWeight = (); +// type BaseCallFilter = Everything; +// type SystemWeightInfo = (); +// type SS58Prefix = (); +// type OnSetCode = (); +// type MaxConsumers = frame_support::traits::ConstU32<16>; +// } + +// parameter_types! { +// pub ExistentialDeposit: Balance = 1; +// pub const MaxLocks: u32 = 50; +// pub const MaxReserves: u32 = 50; +// } + +// impl pallet_balances::Config for Runtime { +// type MaxLocks = MaxLocks; +// type Balance = Balance; +// type RuntimeEvent = RuntimeEvent; +// type DustRemoval = (); +// type ExistentialDeposit = ExistentialDeposit; +// type AccountStore = System; +// type WeightInfo = (); +// type MaxReserves = MaxReserves; +// type ReserveIdentifier = [u8; 8]; +// } + +// impl shared::Config for Runtime {} + +// impl configuration::Config for Runtime { +// type WeightInfo = configuration::TestWeightInfo; +// } + +// parameter_types! { +// pub const KsmLocation: MultiLocation = Here.into(); +// pub const KusamaNetwork: NetworkId = NetworkId::Kusama; +// pub const AnyNetwork: NetworkId = NetworkId::Any; +// pub Ancestry: MultiLocation = Here.into(); +// pub UnitWeightCost: u64 = 1_000; +// } + +// pub type SovereignAccountOf = +// (ChildParachainConvertsVia, AccountId32Aliases); + +// pub type LocalAssetTransactor = +// XcmCurrencyAdapter, SovereignAccountOf, AccountId, ()>; + +// type LocalOriginConverter = ( +// SovereignSignedViaLocation, +// ChildParachainAsNative, +// SignedAccountId32AsNative, +// ChildSystemParachainAsSuperuser, +// ); + +// parameter_types! { +// pub const BaseXcmWeight: u64 = 1_000; +// pub KsmPerSecond: (AssetId, u128) = (Concrete(KsmLocation::get()), 1); +// pub const MaxInstructions: u32 = 100; +// } + +// pub type XcmRouter = super::RelayChainXcmRouter; +// pub type Barrier = AllowUnpaidExecutionFrom; + +// pub struct XcmConfig; +// impl Config for XcmConfig { +// type RuntimeCall = RuntimeCall; +// type XcmSender = XcmRouter; +// type AssetTransactor = LocalAssetTransactor; +// type OriginConverter = LocalOriginConverter; +// type IsReserve = (); +// type IsTeleporter = (); +// type LocationInverter = LocationInverter; +// type Barrier = Barrier; +// type Weigher = FixedWeightBounds; +// type Trader = FixedRateOfFungible; +// type ResponseHandler = (); +// type AssetTrap = (); +// type AssetClaims = (); +// type SubscriptionService = (); +// } + +// pub type LocalOriginToLocation = SignedToAccountId32; + +// impl pallet_xcm::Config for Runtime { +// type RuntimeEvent = RuntimeEvent; +// type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; +// type XcmRouter = XcmRouter; +// // Anyone can execute XCM messages locally... +// type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; +// type XcmExecuteFilter = Nothing; +// type XcmExecutor = XcmExecutor; +// type XcmTeleportFilter = Everything; +// type XcmReserveTransferFilter = Everything; +// type Weigher = FixedWeightBounds; +// type LocationInverter = LocationInverter; +// type RuntimeOrigin = RuntimeOrigin; +// type RuntimeCall = RuntimeCall; +// const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; +// type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; +// } + +// parameter_types! { +// pub const FirstMessageFactorPercent: u64 = 100; +// } + +// impl ump::Config for Runtime { +// type RuntimeEvent = RuntimeEvent; +// type UmpSink = ump::XcmSink, Runtime>; +// type FirstMessageFactorPercent = FirstMessageFactorPercent; +// type ExecuteOverweightOrigin = frame_system::EnsureRoot; +// type WeightInfo = ump::TestWeightInfo; +// } + +// impl origin::Config for Runtime {} + +// type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +// type Block = frame_system::mocking::MockBlock; + +// construct_runtime!( +// pub enum Runtime where +// Block = Block, +// NodeBlock = Block, +// UncheckedExtrinsic = UncheckedExtrinsic, +// { +// System: frame_system::{Pallet, Call, Storage, Config, Event}, +// Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, +// ParasOrigin: origin::{Pallet, Origin}, +// ParasUmp: ump::{Pallet, Call, Storage, Event}, +// XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event, Origin}, +// } +// ); From 8396e3f71038d57ab72587559e7ddd5ffc4f7e0e Mon Sep 17 00:00:00 2001 From: cr4pt0 Date: Wed, 29 Mar 2023 22:20:19 +0100 Subject: [PATCH 07/18] add Pendulum parachain to decl_test_network in xcm integration tests --- Cargo.lock | 1 + runtime/integration-tests/pendulum/Cargo.toml | 2 + runtime/integration-tests/pendulum/src/lib.rs | 55 ++++++++----------- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f898ed235..c09b8391b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14358,6 +14358,7 @@ dependencies = [ "pallet-balances", "pallet-xcm", "parity-scale-codec", + "pendulum-runtime", "polkadot-core-primitives", "polkadot-parachain", "polkadot-primitives", diff --git a/runtime/integration-tests/pendulum/Cargo.toml b/runtime/integration-tests/pendulum/Cargo.toml index 5d16aadf4..930184425 100644 --- a/runtime/integration-tests/pendulum/Cargo.toml +++ b/runtime/integration-tests/pendulum/Cargo.toml @@ -28,3 +28,5 @@ polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } + +pendulum-runtime = { path = "../../pendulum"} diff --git a/runtime/integration-tests/pendulum/src/lib.rs b/runtime/integration-tests/pendulum/src/lib.rs index 5bfa146a0..7dcd384b5 100644 --- a/runtime/integration-tests/pendulum/src/lib.rs +++ b/runtime/integration-tests/pendulum/src/lib.rs @@ -8,23 +8,14 @@ use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chai pub const ALICE: sp_runtime::AccountId32 = sp_runtime::AccountId32::new([0u8; 32]); pub const INITIAL_BALANCE: u128 = 1_000_000_000; -// decl_test_parachain! { -// pub struct ParaA { -// Runtime = parachain::Runtime, -// XcmpMessageHandler = parachain::MsgQueue, -// DmpMessageHandler = parachain::MsgQueue, -// new_ext = para_ext(1), -// } -// } - -// decl_test_parachain! { -// pub struct ParaB { -// Runtime = parachain::Runtime, -// XcmpMessageHandler = parachain::MsgQueue, -// DmpMessageHandler = parachain::MsgQueue, -// new_ext = para_ext(2), -// } -// } +decl_test_parachain! { + pub struct PendulumParachain { + Runtime = pendulum_runtime::Runtime, + XcmpMessageHandler = pendulum_runtime::XcmpQueue, + DmpMessageHandler = pendulum_runtime::DmpQueue, + new_ext = para_ext(1), + } +} decl_test_relay_chain! { pub struct Relay { @@ -38,8 +29,8 @@ decl_test_network! { pub struct MockNet { relay_chain = Relay, parachains = vec![ - // (1, ParaA), - // (2, ParaB), + (1, PendulumParachain), + // (2, Statemint), ], } } @@ -48,22 +39,22 @@ decl_test_network! { // ParaId::from(id).into_account_truncating() // } -// pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { -// use parachain::{MsgQueue, Runtime, System}; +pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { + use pendulum_runtime::{Runtime, System}; -// let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); -// pallet_balances::GenesisConfig:: { balances: vec![(ALICE, INITIAL_BALANCE)] } -// .assimilate_storage(&mut t) -// .unwrap(); + pallet_balances::GenesisConfig:: { balances: vec![(ALICE, INITIAL_BALANCE)] } + .assimilate_storage(&mut t) + .unwrap(); -// let mut ext = sp_io::TestExternalities::new(t); -// ext.execute_with(|| { -// System::set_block_number(1); -// MsgQueue::set_para_id(para_id.into()); -// }); -// ext -// } + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| { + System::set_block_number(1); + // MsgQueue::set_para_id(para_id.into()); + }); + ext +} pub fn relay_ext() -> sp_io::TestExternalities { // use relay_chain::{Runtime, System}; From e4b60ce694803a5d0134d6950aa45faea2d89457 Mon Sep 17 00:00:00 2001 From: Rust Ninja <102041955+RustNinja@users.noreply.github.com> Date: Fri, 31 Mar 2023 11:17:07 +0100 Subject: [PATCH 08/18] Configure pendulum runtime for xcm simulator (#193) configure pendulum runtime for xcm simulator --- Cargo.lock | 1 + runtime/integration-tests/pendulum/Cargo.toml | 2 + runtime/integration-tests/pendulum/src/lib.rs | 105 +++++++++++++++++- runtime/pendulum/src/lib.rs | 1 + runtime/pendulum/src/xcm_config.rs | 15 ++- 5 files changed, 112 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c09b8391b..0758095c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14357,6 +14357,7 @@ dependencies = [ "frame-system", "pallet-balances", "pallet-xcm", + "parachain-info", "parity-scale-codec", "pendulum-runtime", "polkadot-core-primitives", diff --git a/runtime/integration-tests/pendulum/Cargo.toml b/runtime/integration-tests/pendulum/Cargo.toml index 930184425..af93a70f1 100644 --- a/runtime/integration-tests/pendulum/Cargo.toml +++ b/runtime/integration-tests/pendulum/Cargo.toml @@ -16,6 +16,7 @@ sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" } xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } @@ -29,4 +30,5 @@ polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } + pendulum-runtime = { path = "../../pendulum"} diff --git a/runtime/integration-tests/pendulum/src/lib.rs b/runtime/integration-tests/pendulum/src/lib.rs index 7dcd384b5..f4d04909d 100644 --- a/runtime/integration-tests/pendulum/src/lib.rs +++ b/runtime/integration-tests/pendulum/src/lib.rs @@ -1,9 +1,14 @@ // mod parachain; // mod relay_chain; +use frame_support::traits::GenesisBuild; +use pendulum_runtime::{PendulumCurrencyId, Runtime, System}; +use polkadot_core_primitives::{AccountId, Balance, BlockNumber}; use polkadot_parachain::primitives::Id as ParaId; +use polkadot_primitives::v2::{MAX_CODE_SIZE, MAX_POV_SIZE}; +use polkadot_runtime_parachains::configuration::HostConfiguration; use sp_runtime::traits::AccountIdConversion; -use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain}; +use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, Weight}; pub const ALICE: sp_runtime::AccountId32 = sp_runtime::AccountId32::new([0u8; 32]); pub const INITIAL_BALANCE: u128 = 1_000_000_000; @@ -13,7 +18,7 @@ decl_test_parachain! { Runtime = pendulum_runtime::Runtime, XcmpMessageHandler = pendulum_runtime::XcmpQueue, DmpMessageHandler = pendulum_runtime::DmpQueue, - new_ext = para_ext(1), + new_ext = para_ext_pendulum(1234), } } @@ -29,7 +34,7 @@ decl_test_network! { pub struct MockNet { relay_chain = Relay, parachains = vec![ - (1, PendulumParachain), + (1234, PendulumParachain), // (2, Statemint), ], } @@ -64,8 +69,8 @@ pub fn relay_ext() -> sp_io::TestExternalities { pallet_balances::GenesisConfig:: { balances: vec![ - // (ALICE, INITIAL_BALANCE), (para_account_id(1), INITIAL_BALANCE) - ], + // (ALICE, INITIAL_BALANCE), (para_account_id(1), INITIAL_BALANCE) + ], } .assimilate_storage(&mut t) .unwrap(); @@ -75,12 +80,100 @@ pub fn relay_ext() -> sp_io::TestExternalities { ext } +pub struct ExtBuilderPendulum { + balances: Vec<(AccountId, PendulumCurrencyId, Balance)>, + parachain_id: u32, +} +impl Default for ExtBuilderPendulum { + fn default() -> Self { + Self { balances: vec![], parachain_id: 1234 } + } +} + +pub fn para_ext_pendulum(parachain_id: u32) -> sp_io::TestExternalities { + ExtBuilderPendulum::default() + .balances(vec![]) + .parachain_id(parachain_id) + .build() +} + +impl ExtBuilderPendulum { + pub fn balances(mut self, balances: Vec<(AccountId, PendulumCurrencyId, Balance)>) -> Self { + self.balances = balances; + self + } + pub fn parachain_id(mut self, parachain_id: u32) -> Self { + self.parachain_id = parachain_id; + self + } + pub fn build(self) -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + // let native_currency_id = Pendulum_runtime::Native::get(); + pallet_balances::GenesisConfig:: { + balances: vec![(AccountId::from(ALICE), INITIAL_BALANCE)], + } + .assimilate_storage(&mut t) + .unwrap(); + >::assimilate_storage( + ¶chain_info::GenesisConfig { parachain_id: self.parachain_id.into() }, + &mut t, + ) + .unwrap(); + >::assimilate_storage( + &pallet_xcm::GenesisConfig { safe_xcm_version: Some(2) }, + &mut t, + ) + .unwrap(); + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext + } +} + +fn default_parachains_host_configuration() -> HostConfiguration { + HostConfiguration { + minimum_validation_upgrade_delay: 5, + validation_upgrade_cooldown: 5u32, + validation_upgrade_delay: 5, + code_retention_period: 1200, + max_code_size: MAX_CODE_SIZE, + max_pov_size: MAX_POV_SIZE, + max_head_data_size: 32 * 1024, + group_rotation_frequency: 20, + chain_availability_period: 4, + thread_availability_period: 4, + max_upward_queue_count: 8, + max_upward_queue_size: 1024 * 1024, + max_downward_message_size: 1024, + ump_service_total_weight: Weight::from_ref_time(4 * 1_000_000_000), + max_upward_message_size: 50 * 1024, + max_upward_message_num_per_candidate: 5, + hrmp_sender_deposit: 0, + hrmp_recipient_deposit: 0, + hrmp_channel_max_capacity: 8, + hrmp_channel_max_total_size: 8 * 1024, + hrmp_max_parachain_inbound_channels: 4, + hrmp_max_parathread_inbound_channels: 4, + hrmp_channel_max_message_size: 1024 * 1024, + hrmp_max_parachain_outbound_channels: 4, + hrmp_max_parathread_outbound_channels: 4, + hrmp_max_message_num_per_candidate: 5, + dispute_period: 6, + no_show_slots: 2, + n_delay_tranches: 25, + needed_approvals: 2, + relay_vrf_modulo_samples: 2, + zeroth_delay_tranche_width: 0, + ..Default::default() + } +} + // pub type RelayChainPalletXcm = pallet_xcm::Pallet; // pub type ParachainPalletXcm = pallet_xcm::Pallet; #[cfg(test)] mod tests { - #[test] + #[test] fn dmp() {} } diff --git a/runtime/pendulum/src/lib.rs b/runtime/pendulum/src/lib.rs index 6a9cd32a3..a6490a8e0 100644 --- a/runtime/pendulum/src/lib.rs +++ b/runtime/pendulum/src/lib.rs @@ -14,6 +14,7 @@ use crate::zenlink::*; use xcm::v1::MultiLocation; use zenlink_protocol::{AssetBalance, MultiAssetsHandler, PairInfo}; +pub use currency::CurrencyId as PendulumCurrencyId; pub use parachain_staking::InflationInfo; use codec::Encode; diff --git a/runtime/pendulum/src/xcm_config.rs b/runtime/pendulum/src/xcm_config.rs index 8450aa20e..460d81a29 100644 --- a/runtime/pendulum/src/xcm_config.rs +++ b/runtime/pendulum/src/xcm_config.rs @@ -7,7 +7,10 @@ use frame_support::{ log, match_types, parameter_types, traits::{Everything, Nothing}, }; -use orml_traits::{location::{RelativeReserveProvider, Reserve}, parameter_type_with_key}; +use orml_traits::{ + location::{RelativeReserveProvider, Reserve}, + parameter_type_with_key, +}; use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; use polkadot_runtime_common::impls::ToAuthor; @@ -16,12 +19,12 @@ use sp_runtime::traits::Convert; use xcm::latest::{prelude::*, Weight as XCMWeight}; use xcm_builder::{ AccountId32Aliases, AllowUnpaidExecutionFrom, ConvertedConcreteAssetId, EnsureXcmOrigin, - FixedWeightBounds, FungiblesAdapter, LocationInverter, ParentIsPreset, - RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, UsingComponents, + FixedWeightBounds, FungiblesAdapter, LocationInverter, ParentIsPreset, RelayChainAsNative, + SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, UsingComponents, }; use xcm_executor::{ - traits::{JustTry, ShouldExecute, FilterAssetLocation}, + traits::{FilterAssetLocation, JustTry, ShouldExecute}, XcmExecutor, }; @@ -124,7 +127,7 @@ where fn filter_asset_location(asset: &MultiAsset, origin: &MultiLocation) -> bool { if let Some(ref reserve) = ReserveProvider::reserve(asset) { if reserve == origin { - return true; + return true } } false From 82e3409255c6e6778c56ec8f39ef5a28ba5cf33a Mon Sep 17 00:00:00 2001 From: Rust Ninja <102041955+RustNinja@users.noreply.github.com> Date: Fri, 31 Mar 2023 21:54:41 +0100 Subject: [PATCH 09/18] Add xcm tests for pendulum (#195) * finished configuration of polkadot + pendulum TestNet * add transfer_ksm_from_relay_chain_to_pendulum * add unit tests to integration * use xcm emulator instead of xcm simulator from polkadot repo. (#194) * transfer_polkadot_from_relay_chain_to_pendulum works --- Cargo.lock | 238 +++++++---- runtime/integration-tests/pendulum/Cargo.toml | 4 + runtime/integration-tests/pendulum/src/lib.rs | 396 ++++++------------ .../pendulum/src/parachain.rs | 316 -------------- .../pendulum/src/relay_chain.rs | 174 -------- 5 files changed, 304 insertions(+), 824 deletions(-) delete mode 100644 runtime/integration-tests/pendulum/src/parachain.rs delete mode 100644 runtime/integration-tests/pendulum/src/relay_chain.rs diff --git a/Cargo.lock b/Cargo.lock index 0758095c5..9b624f1cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -472,7 +472,7 @@ dependencies = [ "log", "parking", "polling", - "rustix 0.37.4", + "rustix 0.37.5", "slab", "socket2", "waker-fn", @@ -495,7 +495,7 @@ checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" dependencies = [ "proc-macro2", "quote", - "syn 2.0.11", + "syn 2.0.12", ] [[package]] @@ -1058,9 +1058,9 @@ dependencies = [ [[package]] name = "clang-sys" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ed9a53e5d4d9c573ae844bfac6872b159cb1d1585a83b29e7a64b7eef7332a" +checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f" dependencies = [ "glob", "libc", @@ -1069,9 +1069,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.2.0" +version = "4.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6efb5f0a41b5ef5b50c5da28c07609c20091df0c1fc33d418fa2a7e693c2b624" +checksum = "046ae530c528f252094e4a77886ee1374437744b2bff1497aa898bbddbbb29b3" dependencies = [ "clap_builder", "clap_derive", @@ -1080,9 +1080,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.2.0" +version = "4.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "671fcaa5debda4b9a84aa7fde49c907c8986c0e6ab927e04217c9cb74e7c8bc9" +checksum = "223163f58c9a40c3b0a43e1c4b50a9ce09f007ea2cb1ec258a687945b4b7929f" dependencies = [ "anstream", "anstyle", @@ -1100,7 +1100,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.11", + "syn 2.0.12", ] [[package]] @@ -2042,7 +2042,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.11", + "syn 2.0.12", ] [[package]] @@ -2059,7 +2059,7 @@ checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.11", + "syn 2.0.12", ] [[package]] @@ -2553,7 +2553,7 @@ checksum = "48016319042fb7c87b78d2993084a831793a897a5cd1a2a67cab9d1eeb4b7d76" dependencies = [ "proc-macro2", "quote", - "syn 2.0.11", + "syn 2.0.12", ] [[package]] @@ -3086,9 +3086,9 @@ dependencies = [ [[package]] name = "frame-metadata" -version = "15.0.0" +version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df6bb8542ef006ef0de09a5c4420787d79823c0ed7924225822362fd2bf2ff2d" +checksum = "878babb0b136e731cc77ec2fd883ff02745ff21e6fb662729953d44923df009c" dependencies = [ "cfg-if", "parity-scale-codec", @@ -3258,9 +3258,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "531ac96c6ff5fd7c62263c5e3c67a603af4fcaee2e1a0ae5565ba3a11e69e549" +checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" dependencies = [ "futures-channel", "futures-core", @@ -3273,9 +3273,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "164713a5a0dcc3e7b4b1ed7d3b433cabc18025386f9339346e8daf15963cf7ac" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" dependencies = [ "futures-core", "futures-sink", @@ -3283,15 +3283,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" [[package]] name = "futures-executor" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1997dd9df74cdac935c76252744c1ed5794fac083242ea4fe77ef3ed60ba0f83" +checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" dependencies = [ "futures-core", "futures-task", @@ -3301,9 +3301,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d422fa3cbe3b40dca574ab087abb5bc98258ea57eea3fd6f1fa7162c778b91" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" [[package]] name = "futures-lite" @@ -3322,13 +3322,13 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6" +checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.12", ] [[package]] @@ -3344,15 +3344,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec93083a4aecafb2a80a885c9de1f0ccae9dbd32c2bb54b0c3a65690e0b8d2f2" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" [[package]] name = "futures-task" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd65540d33b37b16542a0438c12e6aeead10d4ac5d05bd3f805b8f35ab592879" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" [[package]] name = "futures-timer" @@ -3362,9 +3362,9 @@ checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" [[package]] name = "futures-util" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" +checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" dependencies = [ "futures-channel", "futures-core", @@ -3751,16 +3751,16 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.54" +version = "0.1.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c17cc76786e99f8d2f055c11159e7f0091c42474dcc3189fbab96072e873e6d" +checksum = "716f12fbcfac6ffab0a5e9ec51d0a0ff70503742bb2dc7b99396394c9dc323f0" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows 0.46.0", + "windows 0.47.0", ] [[package]] @@ -3812,9 +3812,9 @@ dependencies = [ [[package]] name = "if-watch" -version = "3.0.0" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba7abdbb86e485125dad06c2691e1e393bf3b08c7b743b43aa162a00fd39062e" +checksum = "a9465340214b296cd17a0009acdb890d6160010b8adf8f78a00d0d7ab270f79f" dependencies = [ "async-io", "core-foundation", @@ -3982,7 +3982,7 @@ checksum = "256017f749ab3117e93acb91063009e1f1bb56d03965b14c2c8df4eb02c524d8" dependencies = [ "hermit-abi 0.3.1", "io-lifetimes 1.0.9", - "rustix 0.37.4", + "rustix 0.37.5", "windows-sys 0.45.0", ] @@ -4953,9 +4953,9 @@ checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" [[package]] name = "linux-raw-sys" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd550e73688e6d578f0ac2119e32b797a327631a42f9433e59d02e139c8df60d" +checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" [[package]] name = "lock_api" @@ -5074,7 +5074,7 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffc89ccdc6e10d6907450f753537ebc5c5d3460d2e4e62ea74bd571db62c0f9e" dependencies = [ - "rustix 0.37.4", + "rustix 0.37.5", ] [[package]] @@ -7449,9 +7449,9 @@ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pest" -version = "2.5.6" +version = "2.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cbd939b234e95d72bc393d51788aec68aeeb5d51e748ca08ff3aad58cb722f7" +checksum = "7b1403e8401ad5dedea73c626b99758535b342502f8d1e361f4a2dd952749122" dependencies = [ "thiserror", "ucd-trie", @@ -7459,9 +7459,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.5.6" +version = "2.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a81186863f3d0a27340815be8f2078dd8050b14cd71913db9fbda795e5f707d7" +checksum = "be99c4c1d2fc2769b1d00239431d711d08f6efedcecb8b6e30707160aee99c15" dependencies = [ "pest", "pest_generator", @@ -7469,22 +7469,22 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.5.6" +version = "2.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75a1ef20bf3193c15ac345acb32e26b3dc3223aff4d77ae4fc5359567683796b" +checksum = "e56094789873daa36164de2e822b3888c6ae4b4f9da555a1103587658c805b1e" dependencies = [ "pest", "pest_meta", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.12", ] [[package]] name = "pest_meta" -version = "2.5.6" +version = "2.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e3b284b1f13a20dc5ebc90aff59a51b8d7137c221131b52a7260c08cbc1cc80" +checksum = "6733073c7cff3d8459fda0e42f13a047870242aed8b509fe98000928975f359e" dependencies = [ "once_cell", "pest", @@ -9272,7 +9272,7 @@ checksum = "8d2275aab483050ab2a7364c1a46604865ee7d6906684e08db0f090acf74f9e7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.11", + "syn 2.0.12", ] [[package]] @@ -9644,15 +9644,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.4" +version = "0.37.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c348b5dc624ecee40108aa2922fed8bad89d7fcc2b9f8cb18f632898ac4a37f9" +checksum = "0e78cc525325c06b4a7ff02db283472f3c042b7ff0c391f96c6d5ac6f4f91b75" dependencies = [ "bitflags", "errno 0.3.0", "io-lifetimes 1.0.9", "libc", - "linux-raw-sys 0.3.0", + "linux-raw-sys 0.3.1", "windows-sys 0.45.0", ] @@ -10793,9 +10793,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61471dff9096de1d8b2319efed7162081e96793f5ebb147e50db10d50d648a4d" +checksum = "0cfdffd972d76b22f3d7f81c8be34b2296afd3a25e0a547bd9abe340a4dbbe97" dependencies = [ "bitvec", "cfg-if", @@ -10807,9 +10807,9 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "219580e803a66b3f05761fd06f1f879a872444e49ce23f73694d26e5a954c7e6" +checksum = "61fa974aea2d63dd18a4ec3a49d59af9f34178c73a4f56d2f18205628d00681e" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -11018,7 +11018,7 @@ checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" dependencies = [ "proc-macro2", "quote", - "syn 2.0.11", + "syn 2.0.12", ] [[package]] @@ -12335,9 +12335,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.11" +version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21e3787bb71465627110e7d87ed4faaa36c1f61042ee67badb9e2ef173accc40" +checksum = "79d9531f94112cfc3e4c8f5f02cb2b58f72c97b7efd85f70203cc6d8efda5927" dependencies = [ "proc-macro2", "quote", @@ -12398,7 +12398,7 @@ dependencies = [ "cfg-if", "fastrand", "redox_syscall 0.3.5", - "rustix 0.37.4", + "rustix 0.37.5", "windows-sys 0.45.0", ] @@ -12434,7 +12434,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.11", + "syn 2.0.12", ] [[package]] @@ -12605,7 +12605,7 @@ checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" dependencies = [ "proc-macro2", "quote", - "syn 2.0.11", + "syn 2.0.12", ] [[package]] @@ -14022,11 +14022,11 @@ dependencies = [ [[package]] name = "windows" -version = "0.46.0" +version = "0.47.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdacb41e6a96a052c6cb63a144f24900236121c6f63f4f8219fef5977ecb0c25" +checksum = "2649ff315bee4c98757f15dac226efe3d81927adbb6e882084bb1ee3e0c330a7" dependencies = [ - "windows-targets", + "windows-targets 0.47.0", ] [[package]] @@ -14048,12 +14048,12 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ - "windows_aarch64_gnullvm", + "windows_aarch64_gnullvm 0.42.2", "windows_aarch64_msvc 0.42.2", "windows_i686_gnu 0.42.2", "windows_i686_msvc 0.42.2", "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm", + "windows_x86_64_gnullvm 0.42.2", "windows_x86_64_msvc 0.42.2", ] @@ -14063,7 +14063,7 @@ version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows-targets", + "windows-targets 0.42.2", ] [[package]] @@ -14072,21 +14072,42 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ - "windows_aarch64_gnullvm", + "windows_aarch64_gnullvm 0.42.2", "windows_aarch64_msvc 0.42.2", "windows_i686_gnu 0.42.2", "windows_i686_msvc 0.42.2", "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm", + "windows_x86_64_gnullvm 0.42.2", "windows_x86_64_msvc 0.42.2", ] +[[package]] +name = "windows-targets" +version = "0.47.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f8996d3f43b4b2d44327cd71b7b0efd1284ab60e6e9d0e8b630e18555d87d3e" +dependencies = [ + "windows_aarch64_gnullvm 0.47.0", + "windows_aarch64_msvc 0.47.0", + "windows_i686_gnu 0.47.0", + "windows_i686_msvc 0.47.0", + "windows_x86_64_gnu 0.47.0", + "windows_x86_64_gnullvm 0.47.0", + "windows_x86_64_msvc 0.47.0", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.47.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "831d567d53d4f3cb1db332b68e6e2b6260228eb4d99a777d8b2e8ed794027c90" + [[package]] name = "windows_aarch64_msvc" version = "0.34.0" @@ -14105,6 +14126,12 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +[[package]] +name = "windows_aarch64_msvc" +version = "0.47.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a42d54a417c60ce4f0e31661eed628f0fa5aca73448c093ec4d45fab4c51cdf" + [[package]] name = "windows_i686_gnu" version = "0.34.0" @@ -14123,6 +14150,12 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +[[package]] +name = "windows_i686_gnu" +version = "0.47.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1925beafdbb22201a53a483db861a5644123157c1c3cee83323a2ed565d71e3" + [[package]] name = "windows_i686_msvc" version = "0.34.0" @@ -14141,6 +14174,12 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +[[package]] +name = "windows_i686_msvc" +version = "0.47.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a8ef8f2f1711b223947d9b69b596cf5a4e452c930fb58b6fc3fdae7d0ec6b31" + [[package]] name = "windows_x86_64_gnu" version = "0.34.0" @@ -14159,12 +14198,24 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +[[package]] +name = "windows_x86_64_gnu" +version = "0.47.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7acaa0c2cf0d2ef99b61c308a0c3dbae430a51b7345dedec470bd8f53f5a3642" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.47.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5a0628f71be1d11e17ca4a0e9e15b3a5180f6fbf1c2d55e3ba3f850378052c1" + [[package]] name = "windows_x86_64_msvc" version = "0.34.0" @@ -14183,6 +14234,12 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +[[package]] +name = "windows_x86_64_msvc" +version = "0.47.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d6e62c256dc6d40b8c8707df17df8d774e60e39db723675241e7c15e910bce7" + [[package]] name = "winnow" version = "0.4.1" @@ -14303,6 +14360,32 @@ dependencies = [ "xcm-executor", ] +[[package]] +name = "xcm-emulator" +version = "0.1.0" +source = "git+https://github.com/shaunxw/xcm-simulator?rev=6847a58888e483f0ed2e0b72f90e00767ea0ecac#6847a58888e483f0ed2e0b72f90e00767ea0ecac" +dependencies = [ + "cumulus-pallet-dmp-queue", + "cumulus-pallet-parachain-system", + "cumulus-pallet-xcmp-queue", + "cumulus-primitives-core", + "cumulus-primitives-parachain-inherent", + "cumulus-test-relay-sproof-builder", + "frame-support", + "frame-system", + "parachain-info", + "parity-scale-codec", + "paste", + "polkadot-primitives", + "polkadot-runtime-parachains", + "quote", + "sp-arithmetic", + "sp-io", + "sp-std", + "xcm", + "xcm-executor", +] + [[package]] name = "xcm-executor" version = "0.9.37" @@ -14353,8 +14436,10 @@ dependencies = [ name = "xcm-simulator-example" version = "0.1.0" dependencies = [ + "cumulus-pallet-dmp-queue", "frame-support", "frame-system", + "orml-tokens 0.4.1-dev (git+https://github.com/open-web3-stack/open-runtime-module-library.git?branch=polkadot-v0.9.37)", "pallet-balances", "pallet-xcm", "parachain-info", @@ -14373,6 +14458,7 @@ dependencies = [ "sp-std", "xcm", "xcm-builder", + "xcm-emulator", "xcm-executor", "xcm-simulator", ] @@ -14445,13 +14531,13 @@ dependencies = [ [[package]] name = "zeroize_derive" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25588073e5216b50bca71d61cb8595cdb9745e87032a58c199730def2862c934" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.11", + "syn 2.0.12", ] [[package]] diff --git a/runtime/integration-tests/pendulum/Cargo.toml b/runtime/integration-tests/pendulum/Cargo.toml index af93a70f1..c71aa24f0 100644 --- a/runtime/integration-tests/pendulum/Cargo.toml +++ b/runtime/integration-tests/pendulum/Cargo.toml @@ -30,5 +30,9 @@ polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } +xcm-emulator = { git = "https://github.com/shaunxw/xcm-simulator", rev = "6847a58888e483f0ed2e0b72f90e00767ea0ecac" } + +orml-tokens = {git = "https://github.com/open-web3-stack/open-runtime-module-library.git", default-features = false, branch = "polkadot-v0.9.37" } +cumulus-pallet-dmp-queue = {git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.37"} pendulum-runtime = { path = "../../pendulum"} diff --git a/runtime/integration-tests/pendulum/src/lib.rs b/runtime/integration-tests/pendulum/src/lib.rs index f4d04909d..6096376d1 100644 --- a/runtime/integration-tests/pendulum/src/lib.rs +++ b/runtime/integration-tests/pendulum/src/lib.rs @@ -1,27 +1,30 @@ -// mod parachain; -// mod relay_chain; - -use frame_support::traits::GenesisBuild; -use pendulum_runtime::{PendulumCurrencyId, Runtime, System}; +use frame_support::{ + assert_ok, + traits::{fungibles::Inspect, GenesisBuild}, +}; +use pendulum_runtime::{Balances, PendulumCurrencyId, Runtime, System, Tokens}; use polkadot_core_primitives::{AccountId, Balance, BlockNumber}; use polkadot_parachain::primitives::Id as ParaId; use polkadot_primitives::v2::{MAX_CODE_SIZE, MAX_POV_SIZE}; use polkadot_runtime_parachains::configuration::HostConfiguration; use sp_runtime::traits::AccountIdConversion; -use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, Weight}; - -pub const ALICE: sp_runtime::AccountId32 = sp_runtime::AccountId32::new([0u8; 32]); +use xcm::{ + latest::{ + AssetId, Fungibility, Junction, Junction::*, Junctions::*, MultiAsset, MultiLocation, + NetworkId, WeightLimit, + }, + v2::{Instruction::WithdrawAsset, Xcm}, + VersionedMultiLocation, +}; +const DOT_FEE: Balance = 3200000000; +use xcm_emulator::{ + decl_test_network, decl_test_parachain, decl_test_relay_chain, Junctions, TestExt, Weight, +}; + +pub const ALICE: [u8; 32] = [4u8; 32]; +pub const BOB: [u8; 32] = [5u8; 32]; pub const INITIAL_BALANCE: u128 = 1_000_000_000; -decl_test_parachain! { - pub struct PendulumParachain { - Runtime = pendulum_runtime::Runtime, - XcmpMessageHandler = pendulum_runtime::XcmpQueue, - DmpMessageHandler = pendulum_runtime::DmpQueue, - new_ext = para_ext_pendulum(1234), - } -} - decl_test_relay_chain! { pub struct Relay { Runtime = polkadot_runtime::Runtime, @@ -30,51 +33,50 @@ decl_test_relay_chain! { } } +decl_test_parachain! { + pub struct PendulumParachain { + Runtime = pendulum_runtime::Runtime, + RuntimeOrigin = pendulum_runtime::RuntimeOrigin, + XcmpMessageHandler = pendulum_runtime::XcmpQueue, + DmpMessageHandler = pendulum_runtime::DmpQueue, + new_ext = para_ext_pendulum(2094), + } +} + decl_test_network! { pub struct MockNet { relay_chain = Relay, parachains = vec![ - (1234, PendulumParachain), - // (2, Statemint), + (2094, PendulumParachain), ], } } -// pub fn para_account_id(id: u32) -> relay_chain::AccountId { -// ParaId::from(id).into_account_truncating() -// } - -pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { - use pendulum_runtime::{Runtime, System}; - - let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - - pallet_balances::GenesisConfig:: { balances: vec![(ALICE, INITIAL_BALANCE)] } - .assimilate_storage(&mut t) - .unwrap(); - - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| { - System::set_block_number(1); - // MsgQueue::set_para_id(para_id.into()); - }); - ext +pub fn para_account_id(id: u32) -> polkadot_core_primitives::AccountId { + ParaId::from(id).into_account_truncating() } pub fn relay_ext() -> sp_io::TestExternalities { - // use relay_chain::{Runtime, System}; use polkadot_runtime::{Runtime, System}; - let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - pallet_balances::GenesisConfig:: { balances: vec![ - // (ALICE, INITIAL_BALANCE), (para_account_id(1), INITIAL_BALANCE) + (AccountId::from(ALICE), dot(100000)), + (ParaId::from(2094).into_account_truncating(), 10 * dot(100000)), ], } .assimilate_storage(&mut t) .unwrap(); - + polkadot_runtime_parachains::configuration::GenesisConfig:: { + config: default_parachains_host_configuration(), + } + .assimilate_storage(&mut t) + .unwrap(); + >::assimilate_storage( + &pallet_xcm::GenesisConfig { safe_xcm_version: Some(2) }, + &mut t, + ) + .unwrap(); let mut ext = sp_io::TestExternalities::new(t); ext.execute_with(|| System::set_block_number(1)); ext @@ -86,7 +88,7 @@ pub struct ExtBuilderPendulum { } impl Default for ExtBuilderPendulum { fn default() -> Self { - Self { balances: vec![], parachain_id: 1234 } + Self { balances: vec![], parachain_id: 2094 } } } @@ -168,229 +170,107 @@ fn default_parachains_host_configuration() -> HostConfiguration { } } -// pub type RelayChainPalletXcm = pallet_xcm::Pallet; -// pub type ParachainPalletXcm = pallet_xcm::Pallet; - -#[cfg(test)] -mod tests { - #[test] - fn dmp() {} +pub fn dot(amount: Balance) -> Balance { + amount * one(9) } -// #[cfg(test)] -// mod tests { -// use super::*; - -// use codec::Encode; -// use frame_support::assert_ok; -// use xcm::latest::prelude::*; -// use xcm_simulator::TestExt; - -// // Helper function for forming buy execution message -// fn buy_execution(fees: impl Into) -> Instruction { -// BuyExecution { fees: fees.into(), weight_limit: Unlimited } -// } - -// #[test] -// fn dmp() { -// MockNet::reset(); - -// let remark = parachain::RuntimeCall::System( -// frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, -// ); -// Relay::execute_with(|| { -// assert_ok!(RelayChainPalletXcm::send_xcm( -// Here, -// Parachain(1), -// Xcm(vec![Transact { -// origin_type: OriginKind::SovereignAccount, -// require_weight_at_most: INITIAL_BALANCE as u64, -// call: remark.encode().into(), -// }]), -// )); -// }); - -// ParaA::execute_with(|| { -// use parachain::{RuntimeEvent, System}; -// assert!(System::events().iter().any(|r| matches!( -// r.event, -// RuntimeEvent::System(frame_system::Event::Remarked { .. }) -// ))); -// }); -// } - -// #[test] -// fn ump() { -// MockNet::reset(); - -// let remark = relay_chain::RuntimeCall::System( -// frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, -// ); -// ParaA::execute_with(|| { -// assert_ok!(ParachainPalletXcm::send_xcm( -// Here, -// Parent, -// Xcm(vec![Transact { -// origin_type: OriginKind::SovereignAccount, -// require_weight_at_most: INITIAL_BALANCE as u64, -// call: remark.encode().into(), -// }]), -// )); -// }); - -// Relay::execute_with(|| { -// use relay_chain::{RuntimeEvent, System}; -// assert!(System::events().iter().any(|r| matches!( -// r.event, -// RuntimeEvent::System(frame_system::Event::Remarked { .. }) -// ))); -// }); -// } - -// #[test] -// fn xcmp() { -// MockNet::reset(); - -// let remark = parachain::RuntimeCall::System( -// frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, -// ); -// ParaA::execute_with(|| { -// assert_ok!(ParachainPalletXcm::send_xcm( -// Here, -// (Parent, Parachain(2)), -// Xcm(vec![Transact { -// origin_type: OriginKind::SovereignAccount, -// require_weight_at_most: INITIAL_BALANCE as u64, -// call: remark.encode().into(), -// }]), -// )); -// }); - -// ParaB::execute_with(|| { -// use parachain::{RuntimeEvent, System}; -// assert!(System::events().iter().any(|r| matches!( -// r.event, -// RuntimeEvent::System(frame_system::Event::Remarked { .. }) -// ))); -// }); -// } - -// #[test] -// fn reserve_transfer() { -// MockNet::reset(); - -// let withdraw_amount = 123; - -// Relay::execute_with(|| { -// assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( -// relay_chain::RuntimeOrigin::signed(ALICE), -// Box::new(X1(Parachain(1)).into().into()), -// Box::new(X1(AccountId32 { network: Any, id: ALICE.into() }).into().into()), -// Box::new((Here, withdraw_amount).into()), -// 0, -// )); -// assert_eq!( -// parachain::Balances::free_balance(¶_account_id(1)), -// INITIAL_BALANCE + withdraw_amount -// ); -// }); +pub fn one(decimals: u32) -> Balance { + 10u128.saturating_pow(decimals.into()) +} -// ParaA::execute_with(|| { -// // free execution, full amount received -// assert_eq!( -// pallet_balances::Pallet::::free_balance(&ALICE), -// INITIAL_BALANCE + withdraw_amount -// ); -// }); -// } +#[test] +fn transfer_polkadot_from_relay_chain_to_pendulum() { + MockNet::reset(); + + let transfer_amount: Balance = dot(20); + println!("transfer DOT amount : {} ", transfer_amount); + let mut balance_before = 0; + let mut orml_tokens_before = 0; + PendulumParachain::execute_with(|| { + balance_before = Balances::free_balance(&ALICE.into()); + println!("Alice balance_before {}", balance_before); + let orml_tokens_before = pendulum_runtime::Tokens::balance( + pendulum_runtime::PendulumCurrencyId::XCM(0), + &ALICE.into(), + ); + println!("Alice orml tokens DOT before {}", orml_tokens_before); + }); -// /// Scenario: -// /// A parachain transfers funds on the relay chain to another parachain account. -// /// -// /// Asserts that the parachain accounts are updated as expected. -// #[test] -// fn withdraw_and_deposit() { -// MockNet::reset(); + Relay::execute_with(|| { + assert_ok!(polkadot_runtime::XcmPallet::reserve_transfer_assets( + polkadot_runtime::RuntimeOrigin::signed(ALICE.into()), + Box::new(Parachain(2094).into().into()), + Box::new(Junction::AccountId32 { network: NetworkId::Any, id: ALICE }.into().into()), + Box::new((Here, transfer_amount).into()), + 0 + )); + }); -// let send_amount = 10; + Relay::execute_with(|| { + use polkadot_runtime::{RuntimeEvent, System}; + for i in System::events().iter() { + println!("polkadot_runtime {:?}", i); + } + }); -// ParaA::execute_with(|| { -// let message = Xcm(vec![ -// WithdrawAsset((Here, send_amount).into()), -// buy_execution((Here, send_amount)), -// DepositAsset { -// assets: All.into(), -// max_assets: 1, -// beneficiary: Parachain(2).into(), -// }, -// ]); -// // Send withdraw and deposit -// assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone())); -// }); + println!("____________________________________________________"); -// Relay::execute_with(|| { -// assert_eq!( -// relay_chain::Balances::free_balance(para_account_id(1)), -// INITIAL_BALANCE - send_amount -// ); -// assert_eq!(relay_chain::Balances::free_balance(para_account_id(2)), send_amount); -// }); -// } + PendulumParachain::execute_with(|| { + use pendulum_runtime::{RuntimeEvent, System, Tokens}; + for i in System::events().iter() { + println!(" Pendulum_runtime {:?}", i); + } -// /// Scenario: -// /// A parachain wants to be notified that a transfer worked correctly. -// /// It sends a `QueryHolding` after the deposit to get notified on success. -// /// -// /// Asserts that the balances are updated correctly and the expected XCM is sent. -// #[test] -// fn query_holding() { -// MockNet::reset(); + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::Tokens(orml_tokens::Event::Deposited { .. }) + ))); -// let send_amount = 10; -// let query_id_set = 1234; + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::DmpQueue(cumulus_pallet_dmp_queue::Event::ExecutedDownward { .. }) + ))); + }); -// // Send a message which fully succeeds on the relay chain -// ParaA::execute_with(|| { -// let message = Xcm(vec![ -// WithdrawAsset((Here, send_amount).into()), -// buy_execution((Here, send_amount)), -// DepositAsset { -// assets: All.into(), -// max_assets: 1, -// beneficiary: Parachain(2).into(), -// }, -// QueryHolding { -// query_id: query_id_set, -// dest: Parachain(1).into(), -// assets: All.into(), -// max_response_weight: 1_000_000_000, -// }, -// ]); -// // Send withdraw and deposit with query holding -// assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone(),)); -// }); + PendulumParachain::execute_with(|| { + assert_eq!( + pendulum_runtime::Tokens::balance( + pendulum_runtime::PendulumCurrencyId::XCM(0), + &ALICE.into() + ), + orml_tokens_before + transfer_amount - DOT_FEE + ); + }); -// // Check that transfer was executed -// Relay::execute_with(|| { -// // Withdraw executed -// assert_eq!( -// relay_chain::Balances::free_balance(para_account_id(1)), -// INITIAL_BALANCE - send_amount -// ); -// // Deposit executed -// assert_eq!(relay_chain::Balances::free_balance(para_account_id(2)), send_amount); -// }); + return + //TODO move to another test. + //TODO rewrite the test with correct assert statements + Relay::execute_with(|| { + let before_bob_free_balance = polkadot_runtime::Balances::free_balance(&BOB.into()); + println!("BOB DOT BEFORE balance on relay chain {} ", before_bob_free_balance); + assert_eq!(before_bob_free_balance, 0); + }); -// // Check that QueryResponse message was received -// ParaA::execute_with(|| { -// assert_eq!( -// parachain::MsgQueue::received_dmp(), -// vec![Xcm(vec![QueryResponse { -// query_id: query_id_set, -// response: Response::Assets(MultiAssets::new()), -// max_weight: 1_000_000_000, -// }])], -// ); -// }); -// } -// } + PendulumParachain::execute_with(|| { + assert_ok!(pendulum_runtime::XTokens::transfer( + pendulum_runtime::RuntimeOrigin::signed(ALICE.into()), + pendulum_runtime::PendulumCurrencyId::XCM(0), + dot(1), + Box::new( + MultiLocation::new( + 1, + Junctions::X1(Junction::AccountId32 { id: BOB, network: NetworkId::Any }) + ) + .into() + ), + WeightLimit::Limited(4_000_000_000), + )); + }); + //h horozin rmp hrmp + // ump dmp + Relay::execute_with(|| { + let after_bob_free_balance = polkadot_runtime::Balances::free_balance(&BOB.into()); + println!("BOB DOT AFTER balance on relay chain {} ", after_bob_free_balance); + assert_eq!(after_bob_free_balance, 999988476752); + }); +} diff --git a/runtime/integration-tests/pendulum/src/parachain.rs b/runtime/integration-tests/pendulum/src/parachain.rs deleted file mode 100644 index ac791102f..000000000 --- a/runtime/integration-tests/pendulum/src/parachain.rs +++ /dev/null @@ -1,316 +0,0 @@ -// use codec::{Decode, Encode}; -// use frame_support::{ -// construct_runtime, parameter_types, -// traits::{Everything, Nothing}, -// weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, -// }; -// use sp_core::H256; -// use sp_runtime::{ -// testing::Header, -// traits::{Hash, IdentityLookup}, -// AccountId32, -// }; -// use sp_std::prelude::*; - -// use pallet_xcm::XcmPassthrough; -// use polkadot_core_primitives::BlockNumber as RelayBlockNumber; -// use polkadot_parachain::primitives::{ -// DmpMessageHandler, Id as ParaId, Sibling, XcmpMessageFormat, XcmpMessageHandler, -// }; -// use xcm::{latest::prelude::*, VersionedXcm}; -// use xcm_builder::{ -// AccountId32Aliases, AllowUnpaidExecutionFrom, CurrencyAdapter as XcmCurrencyAdapter, -// EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, IsConcrete, LocationInverter, -// NativeAsset, ParentIsPreset, SiblingParachainConvertsVia, SignedAccountId32AsNative, -// SignedToAccountId32, SovereignSignedViaLocation, -// }; -// use xcm_executor::{Config, XcmExecutor}; - -// pub type AccountId = AccountId32; -// pub type Balance = u128; - -// parameter_types! { -// pub const BlockHashCount: u64 = 250; -// } - -// impl frame_system::Config for Runtime { -// type RuntimeOrigin = RuntimeOrigin; -// type RuntimeCall = RuntimeCall; -// type Index = u64; -// type BlockNumber = u64; -// type Hash = H256; -// type Hashing = ::sp_runtime::traits::BlakeTwo256; -// type AccountId = AccountId; -// type Lookup = IdentityLookup; -// type Header = Header; -// type RuntimeEvent = RuntimeEvent; -// type BlockHashCount = BlockHashCount; -// type BlockWeights = (); -// type BlockLength = (); -// type Version = (); -// type PalletInfo = PalletInfo; -// type AccountData = pallet_balances::AccountData; -// type OnNewAccount = (); -// type OnKilledAccount = (); -// type DbWeight = (); -// type BaseCallFilter = Everything; -// type SystemWeightInfo = (); -// type SS58Prefix = (); -// type OnSetCode = (); -// type MaxConsumers = frame_support::traits::ConstU32<16>; -// } - -// parameter_types! { -// pub ExistentialDeposit: Balance = 1; -// pub const MaxLocks: u32 = 50; -// pub const MaxReserves: u32 = 50; -// } - -// impl pallet_balances::Config for Runtime { -// type MaxLocks = MaxLocks; -// type Balance = Balance; -// type RuntimeEvent = RuntimeEvent; -// type DustRemoval = (); -// type ExistentialDeposit = ExistentialDeposit; -// type AccountStore = System; -// type WeightInfo = (); -// type MaxReserves = MaxReserves; -// type ReserveIdentifier = [u8; 8]; -// } - -// parameter_types! { -// pub const ReservedXcmpWeight: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4)); -// pub const ReservedDmpWeight: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4)); -// } - -// parameter_types! { -// pub const KsmLocation: MultiLocation = MultiLocation::parent(); -// pub const RelayNetwork: NetworkId = NetworkId::Kusama; -// pub Ancestry: MultiLocation = Parachain(MsgQueue::parachain_id().into()).into(); -// } - -// pub type LocationToAccountId = ( -// ParentIsPreset, -// SiblingParachainConvertsVia, -// AccountId32Aliases, -// ); - -// pub type XcmOriginToCallOrigin = ( -// SovereignSignedViaLocation, -// SignedAccountId32AsNative, -// XcmPassthrough, -// ); - -// parameter_types! { -// pub const UnitWeightCost: u64 = 1; -// pub KsmPerSecond: (AssetId, u128) = (Concrete(Parent.into()), 1); -// pub const MaxInstructions: u32 = 100; -// } - -// pub type LocalAssetTransactor = -// XcmCurrencyAdapter, LocationToAccountId, AccountId, ()>; - -// pub type XcmRouter = super::ParachainXcmRouter; -// pub type Barrier = AllowUnpaidExecutionFrom; - -// pub struct XcmConfig; -// impl Config for XcmConfig { -// type RuntimeCall = RuntimeCall; -// type XcmSender = XcmRouter; -// type AssetTransactor = LocalAssetTransactor; -// type OriginConverter = XcmOriginToCallOrigin; -// type IsReserve = NativeAsset; -// type IsTeleporter = (); -// type LocationInverter = LocationInverter; -// type Barrier = Barrier; -// type Weigher = FixedWeightBounds; -// type Trader = FixedRateOfFungible; -// type ResponseHandler = (); -// type AssetTrap = (); -// type AssetClaims = (); -// type SubscriptionService = (); -// } - -// #[frame_support::pallet] -// pub mod mock_msg_queue { -// use super::*; -// use frame_support::pallet_prelude::*; - -// #[pallet::config] -// pub trait Config: frame_system::Config { -// type RuntimeEvent: From> + IsType<::RuntimeEvent>; -// type XcmExecutor: ExecuteXcm; -// } - -// #[pallet::call] -// impl Pallet {} - -// #[pallet::pallet] -// #[pallet::generate_store(pub(super) trait Store)] -// #[pallet::without_storage_info] -// pub struct Pallet(_); - -// #[pallet::storage] -// #[pallet::getter(fn parachain_id)] -// pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; - -// #[pallet::storage] -// #[pallet::getter(fn received_dmp)] -// /// A queue of received DMP messages -// pub(super) type ReceivedDmp = StorageValue<_, Vec>, ValueQuery>; - -// impl Get for Pallet { -// fn get() -> ParaId { -// Self::parachain_id() -// } -// } - -// pub type MessageId = [u8; 32]; - -// #[pallet::event] -// #[pallet::generate_deposit(pub(super) fn deposit_event)] -// pub enum Event { -// // XCMP -// /// Some XCM was executed OK. -// Success(Option), -// /// Some XCM failed. -// Fail(Option, XcmError), -// /// Bad XCM version used. -// BadVersion(Option), -// /// Bad XCM format used. -// BadFormat(Option), - -// // DMP -// /// Downward message is invalid XCM. -// InvalidFormat(MessageId), -// /// Downward message is unsupported version of XCM. -// UnsupportedVersion(MessageId), -// /// Downward message executed with the given outcome. -// ExecutedDownward(MessageId, Outcome), -// } - -// impl Pallet { -// pub fn set_para_id(para_id: ParaId) { -// ParachainId::::put(para_id); -// } - -// fn handle_xcmp_message( -// sender: ParaId, -// _sent_at: RelayBlockNumber, -// xcm: VersionedXcm, -// max_weight: Weight, -// ) -> Result { -// let hash = Encode::using_encoded(&xcm, T::Hashing::hash); -// let (result, event) = match Xcm::::try_from(xcm) { -// Ok(xcm) => { -// let location = (1, Parachain(sender.into())); -// match T::XcmExecutor::execute_xcm(location, xcm, max_weight.ref_time()) { -// Outcome::Error(e) => (Err(e.clone()), Event::Fail(Some(hash), e)), -// Outcome::Complete(w) => -// (Ok(Weight::from_ref_time(w)), Event::Success(Some(hash))), -// // As far as the caller is concerned, this was dispatched without error, so -// // we just report the weight used. -// Outcome::Incomplete(w, e) => -// (Ok(Weight::from_ref_time(w)), Event::Fail(Some(hash), e)), -// } -// }, -// Err(()) => (Err(XcmError::UnhandledXcmVersion), Event::BadVersion(Some(hash))), -// }; -// Self::deposit_event(event); -// result -// } -// } - -// impl XcmpMessageHandler for Pallet { -// fn handle_xcmp_messages<'a, I: Iterator>( -// iter: I, -// max_weight: Weight, -// ) -> Weight { -// for (sender, sent_at, data) in iter { -// let mut data_ref = data; -// let _ = XcmpMessageFormat::decode(&mut data_ref) -// .expect("Simulator encodes with versioned xcm format; qed"); - -// let mut remaining_fragments = &data_ref[..]; -// while !remaining_fragments.is_empty() { -// if let Ok(xcm) = -// VersionedXcm::::decode(&mut remaining_fragments) -// { -// let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); -// } else { -// debug_assert!(false, "Invalid incoming XCMP message data"); -// } -// } -// } -// max_weight -// } -// } - -// impl DmpMessageHandler for Pallet { -// fn handle_dmp_messages( -// iter: impl Iterator)>, -// limit: Weight, -// ) -> Weight { -// for (_i, (_sent_at, data)) in iter.enumerate() { -// let id = sp_io::hashing::blake2_256(&data[..]); -// let maybe_msg = VersionedXcm::::decode(&mut &data[..]) -// .map(Xcm::::try_from); -// match maybe_msg { -// Err(_) => { -// Self::deposit_event(Event::InvalidFormat(id)); -// }, -// Ok(Err(())) => { -// Self::deposit_event(Event::UnsupportedVersion(id)); -// }, -// Ok(Ok(x)) => { -// let outcome = -// T::XcmExecutor::execute_xcm(Parent, x.clone(), limit.ref_time()); -// >::append(x); -// Self::deposit_event(Event::ExecutedDownward(id, outcome)); -// }, -// } -// } -// limit -// } -// } -// } - -// impl mock_msg_queue::Config for Runtime { -// type RuntimeEvent = RuntimeEvent; -// type XcmExecutor = XcmExecutor; -// } - -// pub type LocalOriginToLocation = SignedToAccountId32; - -// impl pallet_xcm::Config for Runtime { -// type RuntimeEvent = RuntimeEvent; -// type SendXcmOrigin = EnsureXcmOrigin; -// type XcmRouter = XcmRouter; -// type ExecuteXcmOrigin = EnsureXcmOrigin; -// type XcmExecuteFilter = Everything; -// type XcmExecutor = XcmExecutor; -// type XcmTeleportFilter = Nothing; -// type XcmReserveTransferFilter = Everything; -// type Weigher = FixedWeightBounds; -// type LocationInverter = LocationInverter; -// type RuntimeOrigin = RuntimeOrigin; -// type RuntimeCall = RuntimeCall; -// const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; -// type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; -// } - -// type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -// type Block = frame_system::mocking::MockBlock; - -// construct_runtime!( -// pub enum Runtime where -// Block = Block, -// NodeBlock = Block, -// UncheckedExtrinsic = UncheckedExtrinsic, -// { -// System: frame_system::{Pallet, Call, Storage, Config, Event}, -// Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, -// MsgQueue: mock_msg_queue::{Pallet, Storage, Event}, -// PolkadotXcm: pallet_xcm::{Pallet, Call, Event, Origin}, -// } -// ); diff --git a/runtime/integration-tests/pendulum/src/relay_chain.rs b/runtime/integration-tests/pendulum/src/relay_chain.rs deleted file mode 100644 index 11dd8b74a..000000000 --- a/runtime/integration-tests/pendulum/src/relay_chain.rs +++ /dev/null @@ -1,174 +0,0 @@ -// use frame_support::{ -// construct_runtime, parameter_types, -// traits::{Everything, Nothing}, -// }; -// use sp_core::H256; -// use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; - -// use polkadot_parachain::primitives::Id as ParaId; -// use polkadot_runtime_parachains::{configuration, origin, shared, ump}; -// use xcm::latest::prelude::*; -// use xcm_builder::{ -// AccountId32Aliases, AllowUnpaidExecutionFrom, ChildParachainAsNative, -// ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, -// CurrencyAdapter as XcmCurrencyAdapter, FixedRateOfFungible, FixedWeightBounds, IsConcrete, -// LocationInverter, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, -// }; -// use xcm_executor::{Config, XcmExecutor}; - -// pub type AccountId = AccountId32; -// pub type Balance = u128; - -// parameter_types! { -// pub const BlockHashCount: u64 = 250; -// } - -// impl frame_system::Config for Runtime { -// type RuntimeOrigin = RuntimeOrigin; -// type RuntimeCall = RuntimeCall; -// type Index = u64; -// type BlockNumber = u64; -// type Hash = H256; -// type Hashing = ::sp_runtime::traits::BlakeTwo256; -// type AccountId = AccountId; -// type Lookup = IdentityLookup; -// type Header = Header; -// type RuntimeEvent = RuntimeEvent; -// type BlockHashCount = BlockHashCount; -// type BlockWeights = (); -// type BlockLength = (); -// type Version = (); -// type PalletInfo = PalletInfo; -// type AccountData = pallet_balances::AccountData; -// type OnNewAccount = (); -// type OnKilledAccount = (); -// type DbWeight = (); -// type BaseCallFilter = Everything; -// type SystemWeightInfo = (); -// type SS58Prefix = (); -// type OnSetCode = (); -// type MaxConsumers = frame_support::traits::ConstU32<16>; -// } - -// parameter_types! { -// pub ExistentialDeposit: Balance = 1; -// pub const MaxLocks: u32 = 50; -// pub const MaxReserves: u32 = 50; -// } - -// impl pallet_balances::Config for Runtime { -// type MaxLocks = MaxLocks; -// type Balance = Balance; -// type RuntimeEvent = RuntimeEvent; -// type DustRemoval = (); -// type ExistentialDeposit = ExistentialDeposit; -// type AccountStore = System; -// type WeightInfo = (); -// type MaxReserves = MaxReserves; -// type ReserveIdentifier = [u8; 8]; -// } - -// impl shared::Config for Runtime {} - -// impl configuration::Config for Runtime { -// type WeightInfo = configuration::TestWeightInfo; -// } - -// parameter_types! { -// pub const KsmLocation: MultiLocation = Here.into(); -// pub const KusamaNetwork: NetworkId = NetworkId::Kusama; -// pub const AnyNetwork: NetworkId = NetworkId::Any; -// pub Ancestry: MultiLocation = Here.into(); -// pub UnitWeightCost: u64 = 1_000; -// } - -// pub type SovereignAccountOf = -// (ChildParachainConvertsVia, AccountId32Aliases); - -// pub type LocalAssetTransactor = -// XcmCurrencyAdapter, SovereignAccountOf, AccountId, ()>; - -// type LocalOriginConverter = ( -// SovereignSignedViaLocation, -// ChildParachainAsNative, -// SignedAccountId32AsNative, -// ChildSystemParachainAsSuperuser, -// ); - -// parameter_types! { -// pub const BaseXcmWeight: u64 = 1_000; -// pub KsmPerSecond: (AssetId, u128) = (Concrete(KsmLocation::get()), 1); -// pub const MaxInstructions: u32 = 100; -// } - -// pub type XcmRouter = super::RelayChainXcmRouter; -// pub type Barrier = AllowUnpaidExecutionFrom; - -// pub struct XcmConfig; -// impl Config for XcmConfig { -// type RuntimeCall = RuntimeCall; -// type XcmSender = XcmRouter; -// type AssetTransactor = LocalAssetTransactor; -// type OriginConverter = LocalOriginConverter; -// type IsReserve = (); -// type IsTeleporter = (); -// type LocationInverter = LocationInverter; -// type Barrier = Barrier; -// type Weigher = FixedWeightBounds; -// type Trader = FixedRateOfFungible; -// type ResponseHandler = (); -// type AssetTrap = (); -// type AssetClaims = (); -// type SubscriptionService = (); -// } - -// pub type LocalOriginToLocation = SignedToAccountId32; - -// impl pallet_xcm::Config for Runtime { -// type RuntimeEvent = RuntimeEvent; -// type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; -// type XcmRouter = XcmRouter; -// // Anyone can execute XCM messages locally... -// type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; -// type XcmExecuteFilter = Nothing; -// type XcmExecutor = XcmExecutor; -// type XcmTeleportFilter = Everything; -// type XcmReserveTransferFilter = Everything; -// type Weigher = FixedWeightBounds; -// type LocationInverter = LocationInverter; -// type RuntimeOrigin = RuntimeOrigin; -// type RuntimeCall = RuntimeCall; -// const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; -// type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; -// } - -// parameter_types! { -// pub const FirstMessageFactorPercent: u64 = 100; -// } - -// impl ump::Config for Runtime { -// type RuntimeEvent = RuntimeEvent; -// type UmpSink = ump::XcmSink, Runtime>; -// type FirstMessageFactorPercent = FirstMessageFactorPercent; -// type ExecuteOverweightOrigin = frame_system::EnsureRoot; -// type WeightInfo = ump::TestWeightInfo; -// } - -// impl origin::Config for Runtime {} - -// type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -// type Block = frame_system::mocking::MockBlock; - -// construct_runtime!( -// pub enum Runtime where -// Block = Block, -// NodeBlock = Block, -// UncheckedExtrinsic = UncheckedExtrinsic, -// { -// System: frame_system::{Pallet, Call, Storage, Config, Event}, -// Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, -// ParasOrigin: origin::{Pallet, Origin}, -// ParasUmp: ump::{Pallet, Call, Storage, Event}, -// XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event, Origin}, -// } -// ); From 54fa5ddf3d06f917597b08cd5defedc1d7da6abc Mon Sep 17 00:00:00 2001 From: cr4pt0 Date: Mon, 3 Apr 2023 15:26:50 +0100 Subject: [PATCH 10/18] added test for transfer polkadot_from_pendulum_to_relay_chain --- Cargo.lock | 1 + runtime/integration-tests/pendulum/Cargo.toml | 2 +- runtime/integration-tests/pendulum/src/lib.rs | 80 ++++++++++++++++--- 3 files changed, 69 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9b624f1cb..2931e95d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14440,6 +14440,7 @@ dependencies = [ "frame-support", "frame-system", "orml-tokens 0.4.1-dev (git+https://github.com/open-web3-stack/open-runtime-module-library.git?branch=polkadot-v0.9.37)", + "orml-xtokens", "pallet-balances", "pallet-xcm", "parachain-info", diff --git a/runtime/integration-tests/pendulum/Cargo.toml b/runtime/integration-tests/pendulum/Cargo.toml index c71aa24f0..cc513ffa9 100644 --- a/runtime/integration-tests/pendulum/Cargo.toml +++ b/runtime/integration-tests/pendulum/Cargo.toml @@ -34,5 +34,5 @@ xcm-emulator = { git = "https://github.com/shaunxw/xcm-simulator", rev = "6847a5 orml-tokens = {git = "https://github.com/open-web3-stack/open-runtime-module-library.git", default-features = false, branch = "polkadot-v0.9.37" } cumulus-pallet-dmp-queue = {git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.37"} - +orml-xtokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.37" } pendulum-runtime = { path = "../../pendulum"} diff --git a/runtime/integration-tests/pendulum/src/lib.rs b/runtime/integration-tests/pendulum/src/lib.rs index 6096376d1..ac9c745b9 100644 --- a/runtime/integration-tests/pendulum/src/lib.rs +++ b/runtime/integration-tests/pendulum/src/lib.rs @@ -62,6 +62,7 @@ pub fn relay_ext() -> sp_io::TestExternalities { pallet_balances::GenesisConfig:: { balances: vec![ (AccountId::from(ALICE), dot(100000)), + (AccountId::from(BOB), dot(100)), (ParaId::from(2094).into_account_truncating(), 10 * dot(100000)), ], } @@ -112,7 +113,16 @@ impl ExtBuilderPendulum { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); // let native_currency_id = Pendulum_runtime::Native::get(); pallet_balances::GenesisConfig:: { - balances: vec![(AccountId::from(ALICE), INITIAL_BALANCE)], + balances: vec![ + (AccountId::from(ALICE), INITIAL_BALANCE), + (AccountId::from(BOB), INITIAL_BALANCE), + ], + } + .assimilate_storage(&mut t) + .unwrap(); + + orml_tokens::GenesisConfig:: { + balances: vec![(AccountId::from(BOB), PendulumCurrencyId::XCM(0), dot(100))], } .assimilate_storage(&mut t) .unwrap(); @@ -241,21 +251,26 @@ fn transfer_polkadot_from_relay_chain_to_pendulum() { orml_tokens_before + transfer_amount - DOT_FEE ); }); +} + +#[test] +fn transfer_polkadot_from_pendulum_to_relay_chain() { + MockNet::reset(); + + let transfer_dot_amount: Balance = dot(10); + let FEE = 421434140; - return - //TODO move to another test. - //TODO rewrite the test with correct assert statements Relay::execute_with(|| { - let before_bob_free_balance = polkadot_runtime::Balances::free_balance(&BOB.into()); - println!("BOB DOT BEFORE balance on relay chain {} ", before_bob_free_balance); - assert_eq!(before_bob_free_balance, 0); + let after_bob_free_balance = polkadot_runtime::Balances::free_balance(&BOB.into()); + // println!("BOB DOT BEFORE balance on relay chain {} ", after_bob_free_balance); + assert_eq!(after_bob_free_balance, dot(100)); }); PendulumParachain::execute_with(|| { assert_ok!(pendulum_runtime::XTokens::transfer( - pendulum_runtime::RuntimeOrigin::signed(ALICE.into()), + pendulum_runtime::RuntimeOrigin::signed(BOB.into()), pendulum_runtime::PendulumCurrencyId::XCM(0), - dot(1), + transfer_dot_amount, Box::new( MultiLocation::new( 1, @@ -266,11 +281,50 @@ fn transfer_polkadot_from_relay_chain_to_pendulum() { WeightLimit::Limited(4_000_000_000), )); }); - //h horozin rmp hrmp - // ump dmp + + PendulumParachain::execute_with(|| { + use pendulum_runtime::{RuntimeEvent, System}; + // for i in System::events().iter() { + // println!(" Pendulum_runtime {:?}", i); + // } + + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::Tokens(orml_tokens::Event::Withdrawn { .. }) + ))); + + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::XTokens(orml_xtokens::Event::TransferredMultiAssets { .. }) + ))); + }); + + Relay::execute_with(|| { + use polkadot_runtime::{RuntimeEvent, System}; + + // for i in System::events().iter() { + // println!("polkadot_runtime {:?}", i); + // } + + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::Balances(pallet_balances::Event::Withdraw { .. }) + ))); + + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::Balances(pallet_balances::Event::Deposit { .. }) + ))); + + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::Ump(polkadot_runtime_parachains::ump::Event::ExecutedUpward { .. }) + ))); + }); + Relay::execute_with(|| { let after_bob_free_balance = polkadot_runtime::Balances::free_balance(&BOB.into()); - println!("BOB DOT AFTER balance on relay chain {} ", after_bob_free_balance); - assert_eq!(after_bob_free_balance, 999988476752); + // println!("BOB DOT AFTER balance on relay chain {} ", after_bob_free_balance); + assert_eq!(after_bob_free_balance, dot(100) + transfer_dot_amount - FEE); }); } From 75b0c811d0b4d30e5bc13be3ee9809802a4103c6 Mon Sep 17 00:00:00 2001 From: Rust Ninja <102041955+RustNinja@users.noreply.github.com> Date: Tue, 4 Apr 2023 15:34:37 +0100 Subject: [PATCH 11/18] Statemint integration tests to cover USDT bidirectional reserve transfer Pendulum <-> Statemint (#196) * add statemint-runtime to integration tests * add Statemint to RelayNet as system chain 1000 * add statemine_transfer_asset_to_pendulum unit tests * check BOB balance in statemine_transfer_asset_to_pendulum test * add statemine_transfer_asset_to_statemint * rename statemine to statemint. because this is tests for polkadot net * add statemint_transfer_incorrect_asset_to_pendulum_fails * move pendulum and statemint configuration from lib.rs to setup.rs * move test from lib.rs to test.rs * move polkadot net configuration to polkadot_test_net * split tests, setup and polkadot_test_net to different files * remove unused import in all files * rename to pendulum-runtime-integration-tests * Revert "rename to pendulum-runtime-integration-tests" This reverts commit 2f18be69312712afbe64875988c7674429ca12ca. --- Cargo.lock | 136 +++++++ runtime/integration-tests/pendulum/Cargo.toml | 4 + runtime/integration-tests/pendulum/src/lib.rs | 334 +---------------- .../pendulum/src/polkadot_test_net.rs | 129 +++++++ .../integration-tests/pendulum/src/setup.rs | 113 ++++++ .../integration-tests/pendulum/src/tests.rs | 352 ++++++++++++++++++ 6 files changed, 738 insertions(+), 330 deletions(-) create mode 100644 runtime/integration-tests/pendulum/src/polkadot_test_net.rs create mode 100644 runtime/integration-tests/pendulum/src/setup.rs create mode 100644 runtime/integration-tests/pendulum/src/tests.rs diff --git a/Cargo.lock b/Cargo.lock index 2931e95d5..07104e149 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6068,6 +6068,39 @@ dependencies = [ "libm 0.1.4", ] +[[package]] +name = "pallet-asset-tx-payment" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.37#f38bd6671d460293c93062cc1e4fe9e9e490cb29" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "pallet-transaction-payment", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-assets" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.37#f38bd6671d460293c93062cc1e4fe9e9e490cb29" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-aura" version = "4.0.0-dev" @@ -7010,6 +7043,21 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-uniques" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.37#f38bd6671d460293c93062cc1e4fe9e9e490cb29" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-utility" version = "4.0.0-dev" @@ -7128,6 +7176,32 @@ dependencies = [ "sp-std", ] +[[package]] +name = "parachains-common" +version = "1.0.0" +source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.37#09418fc04c2608b123f36ca80f16df3d2096753b" +dependencies = [ + "cumulus-primitives-utility", + "frame-support", + "frame-system", + "pallet-asset-tx-payment", + "pallet-assets", + "pallet-authorship", + "pallet-balances", + "pallet-collator-selection", + "parity-scale-codec", + "polkadot-primitives", + "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.4.6" @@ -12049,6 +12123,66 @@ dependencies = [ "spacewalk-primitives", ] +[[package]] +name = "statemint-runtime" +version = "1.0.0" +source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.37#09418fc04c2608b123f36ca80f16df3d2096753b" +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-primitives-core", + "cumulus-primitives-timestamp", + "cumulus-primitives-utility", + "frame-executive", + "frame-support", + "frame-system", + "frame-system-rpc-runtime-api", + "log", + "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-core-primitives", + "polkadot-parachain", + "polkadot-runtime-common", + "polkadot-runtime-constants", + "scale-info", + "smallvec", + "sp-api", + "sp-block-builder", + "sp-consensus-aura", + "sp-core", + "sp-inherents", + "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" @@ -14437,6 +14571,7 @@ name = "xcm-simulator-example" version = "0.1.0" dependencies = [ "cumulus-pallet-dmp-queue", + "cumulus-pallet-xcmp-queue", "frame-support", "frame-system", "orml-tokens 0.4.1-dev (git+https://github.com/open-web3-stack/open-runtime-module-library.git?branch=polkadot-v0.9.37)", @@ -14457,6 +14592,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std", + "statemint-runtime", "xcm", "xcm-builder", "xcm-emulator", diff --git a/runtime/integration-tests/pendulum/Cargo.toml b/runtime/integration-tests/pendulum/Cargo.toml index cc513ffa9..ae634aa70 100644 --- a/runtime/integration-tests/pendulum/Cargo.toml +++ b/runtime/integration-tests/pendulum/Cargo.toml @@ -36,3 +36,7 @@ orml-tokens = {git = "https://github.com/open-web3-stack/open-runtime-module-lib cumulus-pallet-dmp-queue = {git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.37"} orml-xtokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.37" } pendulum-runtime = { path = "../../pendulum"} + +statemint-runtime = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" } + +cumulus-pallet-xcmp-queue = {git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.37"} diff --git a/runtime/integration-tests/pendulum/src/lib.rs b/runtime/integration-tests/pendulum/src/lib.rs index ac9c745b9..552378512 100644 --- a/runtime/integration-tests/pendulum/src/lib.rs +++ b/runtime/integration-tests/pendulum/src/lib.rs @@ -1,330 +1,4 @@ -use frame_support::{ - assert_ok, - traits::{fungibles::Inspect, GenesisBuild}, -}; -use pendulum_runtime::{Balances, PendulumCurrencyId, Runtime, System, Tokens}; -use polkadot_core_primitives::{AccountId, Balance, BlockNumber}; -use polkadot_parachain::primitives::Id as ParaId; -use polkadot_primitives::v2::{MAX_CODE_SIZE, MAX_POV_SIZE}; -use polkadot_runtime_parachains::configuration::HostConfiguration; -use sp_runtime::traits::AccountIdConversion; -use xcm::{ - latest::{ - AssetId, Fungibility, Junction, Junction::*, Junctions::*, MultiAsset, MultiLocation, - NetworkId, WeightLimit, - }, - v2::{Instruction::WithdrawAsset, Xcm}, - VersionedMultiLocation, -}; -const DOT_FEE: Balance = 3200000000; -use xcm_emulator::{ - decl_test_network, decl_test_parachain, decl_test_relay_chain, Junctions, TestExt, Weight, -}; - -pub const ALICE: [u8; 32] = [4u8; 32]; -pub const BOB: [u8; 32] = [5u8; 32]; -pub const INITIAL_BALANCE: u128 = 1_000_000_000; - -decl_test_relay_chain! { - pub struct Relay { - Runtime = polkadot_runtime::Runtime, - XcmConfig = polkadot_runtime::xcm_config::XcmConfig, - new_ext = relay_ext(), - } -} - -decl_test_parachain! { - pub struct PendulumParachain { - Runtime = pendulum_runtime::Runtime, - RuntimeOrigin = pendulum_runtime::RuntimeOrigin, - XcmpMessageHandler = pendulum_runtime::XcmpQueue, - DmpMessageHandler = pendulum_runtime::DmpQueue, - new_ext = para_ext_pendulum(2094), - } -} - -decl_test_network! { - pub struct MockNet { - relay_chain = Relay, - parachains = vec![ - (2094, PendulumParachain), - ], - } -} - -pub fn para_account_id(id: u32) -> polkadot_core_primitives::AccountId { - ParaId::from(id).into_account_truncating() -} - -pub fn relay_ext() -> sp_io::TestExternalities { - use polkadot_runtime::{Runtime, System}; - let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - pallet_balances::GenesisConfig:: { - balances: vec![ - (AccountId::from(ALICE), dot(100000)), - (AccountId::from(BOB), dot(100)), - (ParaId::from(2094).into_account_truncating(), 10 * dot(100000)), - ], - } - .assimilate_storage(&mut t) - .unwrap(); - polkadot_runtime_parachains::configuration::GenesisConfig:: { - config: default_parachains_host_configuration(), - } - .assimilate_storage(&mut t) - .unwrap(); - >::assimilate_storage( - &pallet_xcm::GenesisConfig { safe_xcm_version: Some(2) }, - &mut t, - ) - .unwrap(); - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); - ext -} - -pub struct ExtBuilderPendulum { - balances: Vec<(AccountId, PendulumCurrencyId, Balance)>, - parachain_id: u32, -} -impl Default for ExtBuilderPendulum { - fn default() -> Self { - Self { balances: vec![], parachain_id: 2094 } - } -} - -pub fn para_ext_pendulum(parachain_id: u32) -> sp_io::TestExternalities { - ExtBuilderPendulum::default() - .balances(vec![]) - .parachain_id(parachain_id) - .build() -} - -impl ExtBuilderPendulum { - pub fn balances(mut self, balances: Vec<(AccountId, PendulumCurrencyId, Balance)>) -> Self { - self.balances = balances; - self - } - pub fn parachain_id(mut self, parachain_id: u32) -> Self { - self.parachain_id = parachain_id; - self - } - pub fn build(self) -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - // let native_currency_id = Pendulum_runtime::Native::get(); - pallet_balances::GenesisConfig:: { - balances: vec![ - (AccountId::from(ALICE), INITIAL_BALANCE), - (AccountId::from(BOB), INITIAL_BALANCE), - ], - } - .assimilate_storage(&mut t) - .unwrap(); - - orml_tokens::GenesisConfig:: { - balances: vec![(AccountId::from(BOB), PendulumCurrencyId::XCM(0), dot(100))], - } - .assimilate_storage(&mut t) - .unwrap(); - >::assimilate_storage( - ¶chain_info::GenesisConfig { parachain_id: self.parachain_id.into() }, - &mut t, - ) - .unwrap(); - >::assimilate_storage( - &pallet_xcm::GenesisConfig { safe_xcm_version: Some(2) }, - &mut t, - ) - .unwrap(); - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); - ext - } -} - -fn default_parachains_host_configuration() -> HostConfiguration { - HostConfiguration { - minimum_validation_upgrade_delay: 5, - validation_upgrade_cooldown: 5u32, - validation_upgrade_delay: 5, - code_retention_period: 1200, - max_code_size: MAX_CODE_SIZE, - max_pov_size: MAX_POV_SIZE, - max_head_data_size: 32 * 1024, - group_rotation_frequency: 20, - chain_availability_period: 4, - thread_availability_period: 4, - max_upward_queue_count: 8, - max_upward_queue_size: 1024 * 1024, - max_downward_message_size: 1024, - ump_service_total_weight: Weight::from_ref_time(4 * 1_000_000_000), - max_upward_message_size: 50 * 1024, - max_upward_message_num_per_candidate: 5, - hrmp_sender_deposit: 0, - hrmp_recipient_deposit: 0, - hrmp_channel_max_capacity: 8, - hrmp_channel_max_total_size: 8 * 1024, - hrmp_max_parachain_inbound_channels: 4, - hrmp_max_parathread_inbound_channels: 4, - hrmp_channel_max_message_size: 1024 * 1024, - hrmp_max_parachain_outbound_channels: 4, - hrmp_max_parathread_outbound_channels: 4, - hrmp_max_message_num_per_candidate: 5, - dispute_period: 6, - no_show_slots: 2, - n_delay_tranches: 25, - needed_approvals: 2, - relay_vrf_modulo_samples: 2, - zeroth_delay_tranche_width: 0, - ..Default::default() - } -} - -pub fn dot(amount: Balance) -> Balance { - amount * one(9) -} - -pub fn one(decimals: u32) -> Balance { - 10u128.saturating_pow(decimals.into()) -} - -#[test] -fn transfer_polkadot_from_relay_chain_to_pendulum() { - MockNet::reset(); - - let transfer_amount: Balance = dot(20); - println!("transfer DOT amount : {} ", transfer_amount); - let mut balance_before = 0; - let mut orml_tokens_before = 0; - PendulumParachain::execute_with(|| { - balance_before = Balances::free_balance(&ALICE.into()); - println!("Alice balance_before {}", balance_before); - let orml_tokens_before = pendulum_runtime::Tokens::balance( - pendulum_runtime::PendulumCurrencyId::XCM(0), - &ALICE.into(), - ); - println!("Alice orml tokens DOT before {}", orml_tokens_before); - }); - - Relay::execute_with(|| { - assert_ok!(polkadot_runtime::XcmPallet::reserve_transfer_assets( - polkadot_runtime::RuntimeOrigin::signed(ALICE.into()), - Box::new(Parachain(2094).into().into()), - Box::new(Junction::AccountId32 { network: NetworkId::Any, id: ALICE }.into().into()), - Box::new((Here, transfer_amount).into()), - 0 - )); - }); - - Relay::execute_with(|| { - use polkadot_runtime::{RuntimeEvent, System}; - for i in System::events().iter() { - println!("polkadot_runtime {:?}", i); - } - }); - - println!("____________________________________________________"); - - PendulumParachain::execute_with(|| { - use pendulum_runtime::{RuntimeEvent, System, Tokens}; - for i in System::events().iter() { - println!(" Pendulum_runtime {:?}", i); - } - - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::Tokens(orml_tokens::Event::Deposited { .. }) - ))); - - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::DmpQueue(cumulus_pallet_dmp_queue::Event::ExecutedDownward { .. }) - ))); - }); - - PendulumParachain::execute_with(|| { - assert_eq!( - pendulum_runtime::Tokens::balance( - pendulum_runtime::PendulumCurrencyId::XCM(0), - &ALICE.into() - ), - orml_tokens_before + transfer_amount - DOT_FEE - ); - }); -} - -#[test] -fn transfer_polkadot_from_pendulum_to_relay_chain() { - MockNet::reset(); - - let transfer_dot_amount: Balance = dot(10); - let FEE = 421434140; - - Relay::execute_with(|| { - let after_bob_free_balance = polkadot_runtime::Balances::free_balance(&BOB.into()); - // println!("BOB DOT BEFORE balance on relay chain {} ", after_bob_free_balance); - assert_eq!(after_bob_free_balance, dot(100)); - }); - - PendulumParachain::execute_with(|| { - assert_ok!(pendulum_runtime::XTokens::transfer( - pendulum_runtime::RuntimeOrigin::signed(BOB.into()), - pendulum_runtime::PendulumCurrencyId::XCM(0), - transfer_dot_amount, - Box::new( - MultiLocation::new( - 1, - Junctions::X1(Junction::AccountId32 { id: BOB, network: NetworkId::Any }) - ) - .into() - ), - WeightLimit::Limited(4_000_000_000), - )); - }); - - PendulumParachain::execute_with(|| { - use pendulum_runtime::{RuntimeEvent, System}; - // for i in System::events().iter() { - // println!(" Pendulum_runtime {:?}", i); - // } - - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::Tokens(orml_tokens::Event::Withdrawn { .. }) - ))); - - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::XTokens(orml_xtokens::Event::TransferredMultiAssets { .. }) - ))); - }); - - Relay::execute_with(|| { - use polkadot_runtime::{RuntimeEvent, System}; - - // for i in System::events().iter() { - // println!("polkadot_runtime {:?}", i); - // } - - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::Balances(pallet_balances::Event::Withdraw { .. }) - ))); - - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::Balances(pallet_balances::Event::Deposit { .. }) - ))); - - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::Ump(polkadot_runtime_parachains::ump::Event::ExecutedUpward { .. }) - ))); - }); - - Relay::execute_with(|| { - let after_bob_free_balance = polkadot_runtime::Balances::free_balance(&BOB.into()); - // println!("BOB DOT AFTER balance on relay chain {} ", after_bob_free_balance); - assert_eq!(after_bob_free_balance, dot(100) + transfer_dot_amount - FEE); - }); -} +#![cfg(test)] +mod polkadot_test_net; +mod setup; +mod tests; diff --git a/runtime/integration-tests/pendulum/src/polkadot_test_net.rs b/runtime/integration-tests/pendulum/src/polkadot_test_net.rs new file mode 100644 index 000000000..bba21cf92 --- /dev/null +++ b/runtime/integration-tests/pendulum/src/polkadot_test_net.rs @@ -0,0 +1,129 @@ +use crate::setup::{dot, ExtBuilderPendulum, ExtStatemintBuilder, ALICE, BOB}; +use frame_support::traits::GenesisBuild; +use polkadot_core_primitives::{AccountId, BlockNumber}; +use polkadot_parachain::primitives::Id as ParaId; +use polkadot_primitives::v2::{MAX_CODE_SIZE, MAX_POV_SIZE}; +use polkadot_runtime_parachains::configuration::HostConfiguration; +use sp_runtime::traits::AccountIdConversion; +use xcm_emulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, Weight}; + +decl_test_relay_chain! { + pub struct Relay { + Runtime = polkadot_runtime::Runtime, + XcmConfig = polkadot_runtime::xcm_config::XcmConfig, + new_ext = relay_ext(), + } +} + +decl_test_parachain! { + pub struct PendulumParachain { + Runtime = pendulum_runtime::Runtime, + RuntimeOrigin = pendulum_runtime::RuntimeOrigin, + XcmpMessageHandler = pendulum_runtime::XcmpQueue, + DmpMessageHandler = pendulum_runtime::DmpQueue, + new_ext = para_ext_pendulum(2094), + } +} + +decl_test_parachain! { + pub struct Statemint { + Runtime = statemint_runtime::Runtime, + RuntimeOrigin = statemint_runtime::RuntimeOrigin, + XcmpMessageHandler = statemint_runtime::XcmpQueue, + DmpMessageHandler = statemint_runtime::DmpQueue, + new_ext = para_ext_statemint(1000), + } +} + +decl_test_network! { + pub struct MockNet { + relay_chain = Relay, + parachains = vec![ + (1000, Statemint), + (2094, PendulumParachain), + ], + } +} + +pub fn para_account_id(id: u32) -> polkadot_core_primitives::AccountId { + ParaId::from(id).into_account_truncating() +} + +pub fn relay_ext() -> sp_io::TestExternalities { + use polkadot_runtime::{Runtime, System}; + let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + pallet_balances::GenesisConfig:: { + balances: vec![ + (AccountId::from(ALICE), dot(100000)), + (AccountId::from(BOB), dot(100)), + (para_account_id(2094), 10 * dot(100000)), + ], + } + .assimilate_storage(&mut t) + .unwrap(); + polkadot_runtime_parachains::configuration::GenesisConfig:: { + config: default_parachains_host_configuration(), + } + .assimilate_storage(&mut t) + .unwrap(); + >::assimilate_storage( + &pallet_xcm::GenesisConfig { safe_xcm_version: Some(2) }, + &mut t, + ) + .unwrap(); + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext +} + +fn default_parachains_host_configuration() -> HostConfiguration { + HostConfiguration { + minimum_validation_upgrade_delay: 5, + validation_upgrade_cooldown: 5u32, + validation_upgrade_delay: 5, + code_retention_period: 1200, + max_code_size: MAX_CODE_SIZE, + max_pov_size: MAX_POV_SIZE, + max_head_data_size: 32 * 1024, + group_rotation_frequency: 20, + chain_availability_period: 4, + thread_availability_period: 4, + max_upward_queue_count: 8, + max_upward_queue_size: 1024 * 1024, + max_downward_message_size: 1024, + ump_service_total_weight: Weight::from_ref_time(4 * 1_000_000_000), + max_upward_message_size: 50 * 1024, + max_upward_message_num_per_candidate: 5, + hrmp_sender_deposit: 0, + hrmp_recipient_deposit: 0, + hrmp_channel_max_capacity: 8, + hrmp_channel_max_total_size: 8 * 1024, + hrmp_max_parachain_inbound_channels: 4, + hrmp_max_parathread_inbound_channels: 4, + hrmp_channel_max_message_size: 1024 * 1024, + hrmp_max_parachain_outbound_channels: 4, + hrmp_max_parathread_outbound_channels: 4, + hrmp_max_message_num_per_candidate: 5, + dispute_period: 6, + no_show_slots: 2, + n_delay_tranches: 25, + needed_approvals: 2, + relay_vrf_modulo_samples: 2, + zeroth_delay_tranche_width: 0, + ..Default::default() + } +} + +pub fn para_ext_pendulum(parachain_id: u32) -> sp_io::TestExternalities { + ExtBuilderPendulum::default() + .balances(vec![]) + .parachain_id(parachain_id) + .build() +} + +pub fn para_ext_statemint(parachain_id: u32) -> sp_io::TestExternalities { + ExtStatemintBuilder::default() + .balances(vec![]) + .parachain_id(parachain_id) + .build() +} diff --git a/runtime/integration-tests/pendulum/src/setup.rs b/runtime/integration-tests/pendulum/src/setup.rs new file mode 100644 index 000000000..4ecec011c --- /dev/null +++ b/runtime/integration-tests/pendulum/src/setup.rs @@ -0,0 +1,113 @@ +use frame_support::traits::GenesisBuild; +use pendulum_runtime::{PendulumCurrencyId, Runtime, System}; +use polkadot_core_primitives::{AccountId, Balance}; + +pub fn dot(amount: Balance) -> Balance { + amount * 10u128.saturating_pow(9) +} +pub const ALICE: [u8; 32] = [4u8; 32]; +pub const BOB: [u8; 32] = [5u8; 32]; +pub const INITIAL_BALANCE: u128 = 1_000_000_000; + +pub struct ExtBuilderPendulum { + balances: Vec<(AccountId, PendulumCurrencyId, Balance)>, + parachain_id: u32, +} +impl Default for ExtBuilderPendulum { + fn default() -> Self { + Self { balances: vec![], parachain_id: 2094 } + } +} + +impl ExtBuilderPendulum { + pub fn balances(mut self, balances: Vec<(AccountId, PendulumCurrencyId, Balance)>) -> Self { + self.balances = balances; + self + } + pub fn parachain_id(mut self, parachain_id: u32) -> Self { + self.parachain_id = parachain_id; + self + } + pub fn build(self) -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + pallet_balances::GenesisConfig:: { + balances: vec![ + (AccountId::from(ALICE), INITIAL_BALANCE), + (AccountId::from(BOB), INITIAL_BALANCE), + ], + } + .assimilate_storage(&mut t) + .unwrap(); + + orml_tokens::GenesisConfig:: { + balances: vec![(AccountId::from(BOB), PendulumCurrencyId::XCM(0), dot(100))], + } + .assimilate_storage(&mut t) + .unwrap(); + >::assimilate_storage( + ¶chain_info::GenesisConfig { parachain_id: self.parachain_id.into() }, + &mut t, + ) + .unwrap(); + >::assimilate_storage( + &pallet_xcm::GenesisConfig { safe_xcm_version: Some(2) }, + &mut t, + ) + .unwrap(); + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext + } +} + +pub struct ExtStatemintBuilder { + balances: Vec<(AccountId, u128, Balance)>, + parachain_id: u32, +} + +impl Default for ExtStatemintBuilder { + fn default() -> Self { + Self { balances: vec![], parachain_id: 1000 } + } +} + +impl ExtStatemintBuilder { + pub fn balances(mut self, balances: Vec<(AccountId, u128, Balance)>) -> Self { + self.balances = balances; + self + } + + #[allow(dead_code)] + pub fn parachain_id(mut self, parachain_id: u32) -> Self { + self.parachain_id = parachain_id; + self + } + + pub fn build(self) -> sp_io::TestExternalities { + use statemint_runtime::Runtime as StatemintRuntime; + + let mut t = frame_system::GenesisConfig::default() + .build_storage::() + .unwrap(); + + pallet_balances::GenesisConfig:: { balances: vec![] } + .assimilate_storage(&mut t) + .unwrap(); + + >::assimilate_storage( + ¶chain_info::GenesisConfig { parachain_id: self.parachain_id.into() }, + &mut t, + ) + .unwrap(); + + >::assimilate_storage( + &pallet_xcm::GenesisConfig { safe_xcm_version: Some(2) }, + &mut t, + ) + .unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext + } +} diff --git a/runtime/integration-tests/pendulum/src/tests.rs b/runtime/integration-tests/pendulum/src/tests.rs new file mode 100644 index 000000000..2037fcee8 --- /dev/null +++ b/runtime/integration-tests/pendulum/src/tests.rs @@ -0,0 +1,352 @@ +use crate::{polkadot_test_net::*, setup::*}; +use frame_support::{ + assert_ok, + traits::{fungible::Mutate, fungibles::Inspect, Currency}, +}; +use pendulum_runtime::{Balances, PendulumCurrencyId, RuntimeOrigin, Tokens, XTokens}; +use sp_runtime::{traits::AccountIdConversion, MultiAddress}; +use xcm::latest::{Junction, Junction::*, Junctions::*, MultiLocation, NetworkId, WeightLimit}; +use xcm_emulator::{Junctions, TestExt}; + +use polkadot_core_primitives::{AccountId, Balance}; +use polkadot_parachain::primitives::Sibling; + +const DOT_FEE: Balance = 3200000000; +const ASSET_ID: u32 = 1984; //Real USDT Asset ID from Statemint +const INCORRECT_ASSET_ID: u32 = 0; +pub const UNIT: Balance = 1_000_000_000_000; +pub const TEN: Balance = 10_000_000_000_000; +const FEE: u128 = 421434140; + +#[test] +fn transfer_polkadot_from_relay_chain_to_pendulum() { + MockNet::reset(); + + let transfer_amount: Balance = dot(20); + let mut orml_tokens_before = 0; + PendulumParachain::execute_with(|| { + orml_tokens_before = pendulum_runtime::Tokens::balance( + pendulum_runtime::PendulumCurrencyId::XCM(0), + &ALICE.into(), + ); + }); + + Relay::execute_with(|| { + assert_ok!(polkadot_runtime::XcmPallet::reserve_transfer_assets( + polkadot_runtime::RuntimeOrigin::signed(ALICE.into()), + Box::new(Parachain(2094).into().into()), + Box::new(Junction::AccountId32 { network: NetworkId::Any, id: ALICE }.into().into()), + Box::new((Here, transfer_amount).into()), + 0 + )); + }); + + PendulumParachain::execute_with(|| { + use pendulum_runtime::{RuntimeEvent, System}; + + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::Tokens(orml_tokens::Event::Deposited { .. }) + ))); + + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::DmpQueue(cumulus_pallet_dmp_queue::Event::ExecutedDownward { .. }) + ))); + }); + + PendulumParachain::execute_with(|| { + assert_eq!( + pendulum_runtime::Tokens::balance( + pendulum_runtime::PendulumCurrencyId::XCM(0), + &ALICE.into() + ), + orml_tokens_before + transfer_amount - DOT_FEE + ); + }); +} + +#[test] +fn transfer_polkadot_from_pendulum_to_relay_chain() { + MockNet::reset(); + + let transfer_dot_amount: Balance = dot(10); + + Relay::execute_with(|| { + let after_bob_free_balance = polkadot_runtime::Balances::free_balance(&BOB.into()); + assert_eq!(after_bob_free_balance, dot(100)); + }); + + PendulumParachain::execute_with(|| { + assert_ok!(pendulum_runtime::XTokens::transfer( + pendulum_runtime::RuntimeOrigin::signed(BOB.into()), + pendulum_runtime::PendulumCurrencyId::XCM(0), + transfer_dot_amount, + Box::new( + MultiLocation::new( + 1, + Junctions::X1(Junction::AccountId32 { id: BOB, network: NetworkId::Any }) + ) + .into() + ), + WeightLimit::Limited(4_000_000_000), + )); + }); + + PendulumParachain::execute_with(|| { + use pendulum_runtime::{RuntimeEvent, System}; + + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::Tokens(orml_tokens::Event::Withdrawn { .. }) + ))); + + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::XTokens(orml_xtokens::Event::TransferredMultiAssets { .. }) + ))); + }); + + Relay::execute_with(|| { + use polkadot_runtime::{RuntimeEvent, System}; + + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::Balances(pallet_balances::Event::Withdraw { .. }) + ))); + + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::Balances(pallet_balances::Event::Deposit { .. }) + ))); + + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::Ump(polkadot_runtime_parachains::ump::Event::ExecutedUpward { .. }) + ))); + }); + + Relay::execute_with(|| { + let after_bob_free_balance = polkadot_runtime::Balances::free_balance(&BOB.into()); + assert_eq!(after_bob_free_balance, dot(100) + transfer_dot_amount - FEE); + }); +} + +#[test] +fn statemint_transfer_incorrect_asset_to_pendulum_fails() { + let para_2094: AccountId = Sibling::from(2094).into_account_truncating(); + + PendulumParachain::execute_with(|| { + assert_eq!( + pendulum_runtime::Tokens::balance( + pendulum_runtime::PendulumCurrencyId::XCM(1), + &BOB.into() + ), + 0 + ); + }); + + Statemint::execute_with(|| { + use statemint_runtime::*; + + let origin = RuntimeOrigin::signed(ALICE.into()); + Balances::make_free_balance_be(&ALICE.into(), TEN); + Balances::make_free_balance_be(&BOB.into(), UNIT); + + // If using non root, create custom asset cost 0.1 Dot + // We're using force_create here to make sure asset is sufficient. + assert_ok!(Assets::force_create( + RuntimeOrigin::root(), + INCORRECT_ASSET_ID.into(), + MultiAddress::Id(ALICE.into()), + true, + UNIT / 100 + )); + + assert_ok!(Assets::mint( + origin.clone(), + INCORRECT_ASSET_ID.into(), + MultiAddress::Id(ALICE.into()), + 1000 * UNIT + )); + + // need to have some DOT to be able to receive user assets + Balances::make_free_balance_be(¶_2094, UNIT); + + assert_ok!(PolkadotXcm::limited_reserve_transfer_assets( + origin.clone(), + Box::new(MultiLocation::new(1, X1(Parachain(2094))).into()), + Box::new(Junction::AccountId32 { id: BOB, network: NetworkId::Any }.into().into()), + Box::new( + (X2(PalletInstance(50), GeneralIndex(INCORRECT_ASSET_ID as u128)), TEN).into() + ), + 0, + WeightLimit::Unlimited + )); + + assert_eq!(990 * UNIT, Assets::balance(INCORRECT_ASSET_ID, &AccountId::from(ALICE))); + assert_eq!(0, Assets::balance(INCORRECT_ASSET_ID, &AccountId::from(BOB))); + + assert_eq!(TEN, Assets::balance(INCORRECT_ASSET_ID, ¶_2094)); + // the DOT balance of sibling parachain sovereign account is not changed + assert_eq!(UNIT, Balances::free_balance(¶_2094)); + }); + + // Rerun the Statemint::execute to actually send the egress message via XCM + Statemint::execute_with(|| {}); + + PendulumParachain::execute_with(|| { + use pendulum_runtime::{RuntimeEvent, System}; + + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Fail { + message_hash: _, + error: xcm::v2::Error::FailedToTransactAsset(..), + weight: _ + }) + ))); + }); +} + +#[test] +fn statemint_transfer_asset_to_pendulum() { + let para_2094: AccountId = Sibling::from(2094).into_account_truncating(); + + PendulumParachain::execute_with(|| { + assert_eq!( + pendulum_runtime::Tokens::balance( + pendulum_runtime::PendulumCurrencyId::XCM(1), + &BOB.into() + ), + 0 + ); + }); + + Statemint::execute_with(|| { + use statemint_runtime::*; + + let origin = RuntimeOrigin::signed(ALICE.into()); + Balances::make_free_balance_be(&ALICE.into(), TEN); + Balances::make_free_balance_be(&BOB.into(), UNIT); + + // If using non root, create custom asset cost 0.1 Dot + // We're using force_create here to make sure asset is sufficient. + assert_ok!(Assets::force_create( + RuntimeOrigin::root(), + ASSET_ID.into(), + MultiAddress::Id(ALICE.into()), + true, + UNIT / 100 + )); + + assert_ok!(Assets::mint( + origin.clone(), + ASSET_ID.into(), + MultiAddress::Id(ALICE.into()), + 1000 * UNIT + )); + + // need to have some DOT to be able to receive user assets + Balances::make_free_balance_be(¶_2094, UNIT); + + assert_ok!(PolkadotXcm::limited_reserve_transfer_assets( + origin.clone(), + Box::new(MultiLocation::new(1, X1(Parachain(2094))).into()), + Box::new(Junction::AccountId32 { id: BOB, network: NetworkId::Any }.into().into()), + Box::new((X2(PalletInstance(50), GeneralIndex(ASSET_ID as u128)), TEN).into()), + 0, + WeightLimit::Unlimited + )); + + assert_eq!(990 * UNIT, Assets::balance(ASSET_ID, &AccountId::from(ALICE))); + assert_eq!(0, Assets::balance(ASSET_ID, &AccountId::from(BOB))); + + assert_eq!(TEN, Assets::balance(ASSET_ID, ¶_2094)); + // the DOT balance of sibling parachain sovereign account is not changed + assert_eq!(UNIT, Balances::free_balance(¶_2094)); + }); + + // Rerun the Statemint::execute to actually send the egress message via XCM + Statemint::execute_with(|| {}); + + PendulumParachain::execute_with(|| { + use pendulum_runtime::{RuntimeEvent, System}; + for i in System::events().iter() { + println!(" Pendulum_runtime {:?}", i); + } + + assert!(System::events() + .iter() + .any(|r| matches!(r.event, RuntimeEvent::Tokens(orml_tokens::Event::Endowed { .. })))); + + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::Tokens(orml_tokens::Event::Deposited { .. }) + ))); + + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { .. }) + ))); + + assert_eq!( + pendulum_runtime::Tokens::balance( + pendulum_runtime::PendulumCurrencyId::XCM(1), + &BOB.into() + ), + TEN + ); + }); +} + +#[test] +fn statemint_transfer_asset_to_statemint() { + statemint_transfer_asset_to_pendulum(); + + Statemint::execute_with(|| {}); + + PendulumParachain::execute_with(|| { + assert_eq!(TEN, Tokens::balance(PendulumCurrencyId::XCM(1), &AccountId::from(BOB))); + // ensure sender has enough PEN balance to be charged as fee + assert_ok!(Balances::mint_into(&AccountId::from(BOB), TEN)); + + assert_ok!(XTokens::transfer( + RuntimeOrigin::signed(BOB.into()), + PendulumCurrencyId::XCM(1), + UNIT * 1, + Box::new( + MultiLocation::new( + 1, + X2( + Parachain(1000), + Junction::AccountId32 { network: NetworkId::Any, id: BOB.into() } + ) + ) + .into() + ), + WeightLimit::Limited(10_000_000_000), + )); + + assert_eq!( + TEN - 1 * UNIT, //inital balance - one unit + Tokens::balance(PendulumCurrencyId::XCM(1), &AccountId::from(BOB)) + ); + + use pendulum_runtime::{RuntimeEvent, System}; + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) + ))); + + // assert_eq!(TEN - ksm_fee_amount, Tokens::free_balance(KSM, &AccountId::from(BOB))); + }); + + Statemint::execute_with(|| { + use statemint_runtime::*; + + // https://github.com/paritytech/cumulus/pull/1278 support using self sufficient asset + // for paying xcm execution fee on Statemint. + assert_eq!(990_000_000_000, Assets::balance(ASSET_ID, &AccountId::from(BOB))); + }); +} From c41a3824202b298194c3a8a68f1dd0177ee1f786 Mon Sep 17 00:00:00 2001 From: cr4pt0 Date: Tue, 4 Apr 2023 15:55:09 +0100 Subject: [PATCH 12/18] rename to runtime-integration-tests --- Cargo.lock | 68 +++++++++---------- runtime/integration-tests/pendulum/Cargo.toml | 4 +- .../integration-tests/pendulum/src/tests.rs | 2 - 3 files changed, 36 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 07104e149..277bf0390 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9657,6 +9657,40 @@ dependencies = [ "spacewalk-primitives", ] +[[package]] +name = "runtime-integration-tests" +version = "0.1.0" +dependencies = [ + "cumulus-pallet-dmp-queue", + "cumulus-pallet-xcmp-queue", + "frame-support", + "frame-system", + "orml-tokens 0.4.1-dev (git+https://github.com/open-web3-stack/open-runtime-module-library.git?branch=polkadot-v0.9.37)", + "orml-xtokens", + "pallet-balances", + "pallet-xcm", + "parachain-info", + "parity-scale-codec", + "pendulum-runtime", + "polkadot-core-primitives", + "polkadot-parachain", + "polkadot-primitives", + "polkadot-runtime", + "polkadot-runtime-common", + "polkadot-runtime-parachains", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "statemint-runtime", + "xcm", + "xcm-builder", + "xcm-emulator", + "xcm-executor", + "xcm-simulator", +] + [[package]] name = "rustc-demangle" version = "0.1.22" @@ -14566,40 +14600,6 @@ dependencies = [ "xcm-executor", ] -[[package]] -name = "xcm-simulator-example" -version = "0.1.0" -dependencies = [ - "cumulus-pallet-dmp-queue", - "cumulus-pallet-xcmp-queue", - "frame-support", - "frame-system", - "orml-tokens 0.4.1-dev (git+https://github.com/open-web3-stack/open-runtime-module-library.git?branch=polkadot-v0.9.37)", - "orml-xtokens", - "pallet-balances", - "pallet-xcm", - "parachain-info", - "parity-scale-codec", - "pendulum-runtime", - "polkadot-core-primitives", - "polkadot-parachain", - "polkadot-primitives", - "polkadot-runtime", - "polkadot-runtime-common", - "polkadot-runtime-parachains", - "scale-info", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std", - "statemint-runtime", - "xcm", - "xcm-builder", - "xcm-emulator", - "xcm-executor", - "xcm-simulator", -] - [[package]] name = "yamux" version = "0.10.2" diff --git a/runtime/integration-tests/pendulum/Cargo.toml b/runtime/integration-tests/pendulum/Cargo.toml index ae634aa70..02c1b14bc 100644 --- a/runtime/integration-tests/pendulum/Cargo.toml +++ b/runtime/integration-tests/pendulum/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "xcm-simulator-example" -description = "Examples of xcm-simulator usage." +name = "runtime-integration-tests" +description = "Pendulum runtime integration tests" authors = ["Pendulum"] edition = "2021" version = "0.1.0" diff --git a/runtime/integration-tests/pendulum/src/tests.rs b/runtime/integration-tests/pendulum/src/tests.rs index 2037fcee8..875db6504 100644 --- a/runtime/integration-tests/pendulum/src/tests.rs +++ b/runtime/integration-tests/pendulum/src/tests.rs @@ -338,8 +338,6 @@ fn statemint_transfer_asset_to_statemint() { r.event, RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) ))); - - // assert_eq!(TEN - ksm_fee_amount, Tokens::free_balance(KSM, &AccountId::from(BOB))); }); Statemint::execute_with(|| { From 741ae7d5c8eb8cc403228dc8abcda74cc38a3395 Mon Sep 17 00:00:00 2001 From: Rust Ninja <102041955+RustNinja@users.noreply.github.com> Date: Wed, 5 Apr 2023 14:00:28 +0100 Subject: [PATCH 13/18] Final refactor xcm integration tests (#198) * rename dot function ot one * refactor setup rs file * add #[cfg(test)] attribute for all modules * add comments about fees and rename TEN to TEN_UNITS * update comment and constants name to show what is it * wrap Parachain into X1 to have the same approach everywhere * update transfer_dot_from_pendulum_to_relay_chain assert statement * add. comment statemint_transfer_incorrect_asset_to_pendulum_should_fails * add comment statemint_transfer_asset_to_statemint * move use pendulum_runtime::{RuntimeEvent, System}; to top of the file --- runtime/integration-tests/pendulum/src/lib.rs | 6 +- .../pendulum/src/polkadot_test_net.rs | 8 +- .../integration-tests/pendulum/src/setup.rs | 8 +- .../integration-tests/pendulum/src/tests.rs | 80 +++++++++++-------- 4 files changed, 62 insertions(+), 40 deletions(-) diff --git a/runtime/integration-tests/pendulum/src/lib.rs b/runtime/integration-tests/pendulum/src/lib.rs index 552378512..c41ea7300 100644 --- a/runtime/integration-tests/pendulum/src/lib.rs +++ b/runtime/integration-tests/pendulum/src/lib.rs @@ -1,4 +1,8 @@ -#![cfg(test)] +#[cfg(test)] mod polkadot_test_net; + +#[cfg(test)] mod setup; + +#[cfg(test)] mod tests; diff --git a/runtime/integration-tests/pendulum/src/polkadot_test_net.rs b/runtime/integration-tests/pendulum/src/polkadot_test_net.rs index bba21cf92..60529a4c4 100644 --- a/runtime/integration-tests/pendulum/src/polkadot_test_net.rs +++ b/runtime/integration-tests/pendulum/src/polkadot_test_net.rs @@ -1,4 +1,4 @@ -use crate::setup::{dot, ExtBuilderPendulum, ExtStatemintBuilder, ALICE, BOB}; +use crate::setup::{one, ExtBuilderPendulum, ExtStatemintBuilder, ALICE, BOB}; use frame_support::traits::GenesisBuild; use polkadot_core_primitives::{AccountId, BlockNumber}; use polkadot_parachain::primitives::Id as ParaId; @@ -54,9 +54,9 @@ pub fn relay_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); pallet_balances::GenesisConfig:: { balances: vec![ - (AccountId::from(ALICE), dot(100000)), - (AccountId::from(BOB), dot(100)), - (para_account_id(2094), 10 * dot(100000)), + (AccountId::from(ALICE), one(100000)), + (AccountId::from(BOB), one(100)), + (para_account_id(2094), 10 * one(100000)), ], } .assimilate_storage(&mut t) diff --git a/runtime/integration-tests/pendulum/src/setup.rs b/runtime/integration-tests/pendulum/src/setup.rs index 4ecec011c..7eb1fe79e 100644 --- a/runtime/integration-tests/pendulum/src/setup.rs +++ b/runtime/integration-tests/pendulum/src/setup.rs @@ -2,9 +2,10 @@ use frame_support::traits::GenesisBuild; use pendulum_runtime::{PendulumCurrencyId, Runtime, System}; use polkadot_core_primitives::{AccountId, Balance}; -pub fn dot(amount: Balance) -> Balance { +pub fn one(amount: Balance) -> Balance { amount * 10u128.saturating_pow(9) } + pub const ALICE: [u8; 32] = [4u8; 32]; pub const BOB: [u8; 32] = [5u8; 32]; pub const INITIAL_BALANCE: u128 = 1_000_000_000; @@ -13,6 +14,7 @@ pub struct ExtBuilderPendulum { balances: Vec<(AccountId, PendulumCurrencyId, Balance)>, parachain_id: u32, } + impl Default for ExtBuilderPendulum { fn default() -> Self { Self { balances: vec![], parachain_id: 2094 } @@ -24,10 +26,12 @@ impl ExtBuilderPendulum { self.balances = balances; self } + pub fn parachain_id(mut self, parachain_id: u32) -> Self { self.parachain_id = parachain_id; self } + pub fn build(self) -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); pallet_balances::GenesisConfig:: { @@ -40,7 +44,7 @@ impl ExtBuilderPendulum { .unwrap(); orml_tokens::GenesisConfig:: { - balances: vec![(AccountId::from(BOB), PendulumCurrencyId::XCM(0), dot(100))], + balances: vec![(AccountId::from(BOB), PendulumCurrencyId::XCM(0), one(100))], } .assimilate_storage(&mut t) .unwrap(); diff --git a/runtime/integration-tests/pendulum/src/tests.rs b/runtime/integration-tests/pendulum/src/tests.rs index 875db6504..79b716d7a 100644 --- a/runtime/integration-tests/pendulum/src/tests.rs +++ b/runtime/integration-tests/pendulum/src/tests.rs @@ -8,21 +8,22 @@ use sp_runtime::{traits::AccountIdConversion, MultiAddress}; use xcm::latest::{Junction, Junction::*, Junctions::*, MultiLocation, NetworkId, WeightLimit}; use xcm_emulator::{Junctions, TestExt}; +use pendulum_runtime::{RuntimeEvent, System}; use polkadot_core_primitives::{AccountId, Balance}; use polkadot_parachain::primitives::Sibling; -const DOT_FEE: Balance = 3200000000; +const DOT_FEE_WHEN_TRANSFER_TO_PARACHAIN: Balance = 3200000000; //The fees that relay chain will charge when transfer DOT to parachain. sovereign account of some parachain will receive transfer_amount - DOT_FEE const ASSET_ID: u32 = 1984; //Real USDT Asset ID from Statemint -const INCORRECT_ASSET_ID: u32 = 0; +const INCORRECT_ASSET_ID: u32 = 0; //Incorrect asset id that pendulum is not supporting pendulum_runtime xcm_config pub const UNIT: Balance = 1_000_000_000_000; -pub const TEN: Balance = 10_000_000_000_000; -const FEE: u128 = 421434140; +pub const TEN_UNITS: Balance = 10_000_000_000_000; +const DOT_FEE_WHEN_TRANSFER_TO_RELAY: u128 = 421434140; //This fee will taken to transfer assets(Polkadot) from sovereign parachain account to destination user account; #[test] -fn transfer_polkadot_from_relay_chain_to_pendulum() { +fn transfer_dot_from_relay_chain_to_pendulum() { MockNet::reset(); - let transfer_amount: Balance = dot(20); + let transfer_amount: Balance = one(20); let mut orml_tokens_before = 0; PendulumParachain::execute_with(|| { orml_tokens_before = pendulum_runtime::Tokens::balance( @@ -34,7 +35,7 @@ fn transfer_polkadot_from_relay_chain_to_pendulum() { Relay::execute_with(|| { assert_ok!(polkadot_runtime::XcmPallet::reserve_transfer_assets( polkadot_runtime::RuntimeOrigin::signed(ALICE.into()), - Box::new(Parachain(2094).into().into()), + Box::new(X1(Parachain(2094)).into().into()), Box::new(Junction::AccountId32 { network: NetworkId::Any, id: ALICE }.into().into()), Box::new((Here, transfer_amount).into()), 0 @@ -42,8 +43,6 @@ fn transfer_polkadot_from_relay_chain_to_pendulum() { }); PendulumParachain::execute_with(|| { - use pendulum_runtime::{RuntimeEvent, System}; - assert!(System::events().iter().any(|r| matches!( r.event, RuntimeEvent::Tokens(orml_tokens::Event::Deposited { .. }) @@ -61,20 +60,21 @@ fn transfer_polkadot_from_relay_chain_to_pendulum() { pendulum_runtime::PendulumCurrencyId::XCM(0), &ALICE.into() ), - orml_tokens_before + transfer_amount - DOT_FEE + orml_tokens_before + transfer_amount - DOT_FEE_WHEN_TRANSFER_TO_PARACHAIN ); }); } #[test] -fn transfer_polkadot_from_pendulum_to_relay_chain() { +fn transfer_dot_from_pendulum_to_relay_chain() { MockNet::reset(); - let transfer_dot_amount: Balance = dot(10); + let transfer_dot_amount: Balance = one(10); + let expected_base_balance = one(100); Relay::execute_with(|| { - let after_bob_free_balance = polkadot_runtime::Balances::free_balance(&BOB.into()); - assert_eq!(after_bob_free_balance, dot(100)); + let before_bob_free_balance = polkadot_runtime::Balances::free_balance(&BOB.into()); + assert_eq!(before_bob_free_balance, expected_base_balance); }); PendulumParachain::execute_with(|| { @@ -94,8 +94,6 @@ fn transfer_polkadot_from_pendulum_to_relay_chain() { }); PendulumParachain::execute_with(|| { - use pendulum_runtime::{RuntimeEvent, System}; - assert!(System::events().iter().any(|r| matches!( r.event, RuntimeEvent::Tokens(orml_tokens::Event::Withdrawn { .. }) @@ -128,21 +126,29 @@ fn transfer_polkadot_from_pendulum_to_relay_chain() { Relay::execute_with(|| { let after_bob_free_balance = polkadot_runtime::Balances::free_balance(&BOB.into()); - assert_eq!(after_bob_free_balance, dot(100) + transfer_dot_amount - FEE); + assert_eq!( + after_bob_free_balance, + expected_base_balance + transfer_dot_amount - DOT_FEE_WHEN_TRANSFER_TO_RELAY + ); }); } #[test] -fn statemint_transfer_incorrect_asset_to_pendulum_fails() { +fn statemint_transfer_incorrect_asset_to_pendulum_should_fails() { let para_2094: AccountId = Sibling::from(2094).into_account_truncating(); + //pendulum_runtime::PendulumCurrencyId::XCM(1) is the representation of USDT from Statemint on Pendulum chain. + //The asset id for USDT on Statemint is 1984. and pendulum support only this asset id to recive it on chain. + //we are going to execute XCM call to sent incorrect Asset Id and expect to see cumulus_pallet_xcmp_queue::Event::Fail event with an error FailedToTransactAsset. + //we what to be sure that the initial USDT balance for BOB is the same after XCM call from statemint when we tried to send wrong ASSET_ID from system parachain. + let extected_base_usdt_balance = 0; PendulumParachain::execute_with(|| { assert_eq!( pendulum_runtime::Tokens::balance( pendulum_runtime::PendulumCurrencyId::XCM(1), &BOB.into() ), - 0 + extected_base_usdt_balance ); }); @@ -150,7 +156,7 @@ fn statemint_transfer_incorrect_asset_to_pendulum_fails() { use statemint_runtime::*; let origin = RuntimeOrigin::signed(ALICE.into()); - Balances::make_free_balance_be(&ALICE.into(), TEN); + Balances::make_free_balance_be(&ALICE.into(), TEN_UNITS); Balances::make_free_balance_be(&BOB.into(), UNIT); // If using non root, create custom asset cost 0.1 Dot @@ -178,7 +184,8 @@ fn statemint_transfer_incorrect_asset_to_pendulum_fails() { Box::new(MultiLocation::new(1, X1(Parachain(2094))).into()), Box::new(Junction::AccountId32 { id: BOB, network: NetworkId::Any }.into().into()), Box::new( - (X2(PalletInstance(50), GeneralIndex(INCORRECT_ASSET_ID as u128)), TEN).into() + (X2(PalletInstance(50), GeneralIndex(INCORRECT_ASSET_ID as u128)), TEN_UNITS) + .into() ), 0, WeightLimit::Unlimited @@ -187,7 +194,7 @@ fn statemint_transfer_incorrect_asset_to_pendulum_fails() { assert_eq!(990 * UNIT, Assets::balance(INCORRECT_ASSET_ID, &AccountId::from(ALICE))); assert_eq!(0, Assets::balance(INCORRECT_ASSET_ID, &AccountId::from(BOB))); - assert_eq!(TEN, Assets::balance(INCORRECT_ASSET_ID, ¶_2094)); + assert_eq!(TEN_UNITS, Assets::balance(INCORRECT_ASSET_ID, ¶_2094)); // the DOT balance of sibling parachain sovereign account is not changed assert_eq!(UNIT, Balances::free_balance(¶_2094)); }); @@ -196,8 +203,6 @@ fn statemint_transfer_incorrect_asset_to_pendulum_fails() { Statemint::execute_with(|| {}); PendulumParachain::execute_with(|| { - use pendulum_runtime::{RuntimeEvent, System}; - assert!(System::events().iter().any(|r| matches!( r.event, RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Fail { @@ -207,6 +212,16 @@ fn statemint_transfer_incorrect_asset_to_pendulum_fails() { }) ))); }); + + PendulumParachain::execute_with(|| { + assert_eq!( + pendulum_runtime::Tokens::balance( + pendulum_runtime::PendulumCurrencyId::XCM(1), + &BOB.into() + ), + extected_base_usdt_balance + ); + }); } #[test] @@ -227,7 +242,7 @@ fn statemint_transfer_asset_to_pendulum() { use statemint_runtime::*; let origin = RuntimeOrigin::signed(ALICE.into()); - Balances::make_free_balance_be(&ALICE.into(), TEN); + Balances::make_free_balance_be(&ALICE.into(), TEN_UNITS); Balances::make_free_balance_be(&BOB.into(), UNIT); // If using non root, create custom asset cost 0.1 Dot @@ -254,7 +269,7 @@ fn statemint_transfer_asset_to_pendulum() { origin.clone(), Box::new(MultiLocation::new(1, X1(Parachain(2094))).into()), Box::new(Junction::AccountId32 { id: BOB, network: NetworkId::Any }.into().into()), - Box::new((X2(PalletInstance(50), GeneralIndex(ASSET_ID as u128)), TEN).into()), + Box::new((X2(PalletInstance(50), GeneralIndex(ASSET_ID as u128)), TEN_UNITS).into()), 0, WeightLimit::Unlimited )); @@ -262,7 +277,7 @@ fn statemint_transfer_asset_to_pendulum() { assert_eq!(990 * UNIT, Assets::balance(ASSET_ID, &AccountId::from(ALICE))); assert_eq!(0, Assets::balance(ASSET_ID, &AccountId::from(BOB))); - assert_eq!(TEN, Assets::balance(ASSET_ID, ¶_2094)); + assert_eq!(TEN_UNITS, Assets::balance(ASSET_ID, ¶_2094)); // the DOT balance of sibling parachain sovereign account is not changed assert_eq!(UNIT, Balances::free_balance(¶_2094)); }); @@ -271,7 +286,6 @@ fn statemint_transfer_asset_to_pendulum() { Statemint::execute_with(|| {}); PendulumParachain::execute_with(|| { - use pendulum_runtime::{RuntimeEvent, System}; for i in System::events().iter() { println!(" Pendulum_runtime {:?}", i); } @@ -295,21 +309,22 @@ fn statemint_transfer_asset_to_pendulum() { pendulum_runtime::PendulumCurrencyId::XCM(1), &BOB.into() ), - TEN + TEN_UNITS ); }); } #[test] fn statemint_transfer_asset_to_statemint() { + //first we need to set up USDT balance on pendulum chain before to start transfer it back. statemint_transfer_asset_to_pendulum(); Statemint::execute_with(|| {}); PendulumParachain::execute_with(|| { - assert_eq!(TEN, Tokens::balance(PendulumCurrencyId::XCM(1), &AccountId::from(BOB))); + assert_eq!(TEN_UNITS, Tokens::balance(PendulumCurrencyId::XCM(1), &AccountId::from(BOB))); // ensure sender has enough PEN balance to be charged as fee - assert_ok!(Balances::mint_into(&AccountId::from(BOB), TEN)); + assert_ok!(Balances::mint_into(&AccountId::from(BOB), TEN_UNITS)); assert_ok!(XTokens::transfer( RuntimeOrigin::signed(BOB.into()), @@ -329,11 +344,10 @@ fn statemint_transfer_asset_to_statemint() { )); assert_eq!( - TEN - 1 * UNIT, //inital balance - one unit + TEN_UNITS - 1 * UNIT, //inital balance - one unit Tokens::balance(PendulumCurrencyId::XCM(1), &AccountId::from(BOB)) ); - use pendulum_runtime::{RuntimeEvent, System}; assert!(System::events().iter().any(|r| matches!( r.event, RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) From 039bdbdc7d54019c095788bba904ffb511772c6a Mon Sep 17 00:00:00 2001 From: cr4pt0 Date: Thu, 6 Apr 2023 11:20:14 +0100 Subject: [PATCH 14/18] move comment up function statemint_transfer_incorrect_asset_to_pendulum --- runtime/integration-tests/pendulum/src/tests.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/integration-tests/pendulum/src/tests.rs b/runtime/integration-tests/pendulum/src/tests.rs index 79b716d7a..602a2dbbd 100644 --- a/runtime/integration-tests/pendulum/src/tests.rs +++ b/runtime/integration-tests/pendulum/src/tests.rs @@ -133,14 +133,14 @@ fn transfer_dot_from_pendulum_to_relay_chain() { }); } +//pendulum_runtime::PendulumCurrencyId::XCM(1) is the representation of USDT from Statemint on Pendulum chain. +//The asset id for USDT on Statemint is 1984. and pendulum support only this asset id to recive it on chain. +//we are going to execute XCM call to sent incorrect Asset Id and expect to see cumulus_pallet_xcmp_queue::Event::Fail event with an error FailedToTransactAsset. +//we what to be sure that the initial USDT balance for BOB is the same after XCM call from statemint when we tried to send wrong ASSET_ID from system parachain. #[test] fn statemint_transfer_incorrect_asset_to_pendulum_should_fails() { let para_2094: AccountId = Sibling::from(2094).into_account_truncating(); - //pendulum_runtime::PendulumCurrencyId::XCM(1) is the representation of USDT from Statemint on Pendulum chain. - //The asset id for USDT on Statemint is 1984. and pendulum support only this asset id to recive it on chain. - //we are going to execute XCM call to sent incorrect Asset Id and expect to see cumulus_pallet_xcmp_queue::Event::Fail event with an error FailedToTransactAsset. - //we what to be sure that the initial USDT balance for BOB is the same after XCM call from statemint when we tried to send wrong ASSET_ID from system parachain. let extected_base_usdt_balance = 0; PendulumParachain::execute_with(|| { assert_eq!( From 79a7c997fe93c1519da3d8770c0fea17b6701351 Mon Sep 17 00:00:00 2001 From: cr4pt0 Date: Thu, 6 Apr 2023 11:23:10 +0100 Subject: [PATCH 15/18] renamed to renamed to fn units(amount) --- .../integration-tests/pendulum/src/polkadot_test_net.rs | 8 ++++---- runtime/integration-tests/pendulum/src/setup.rs | 4 ++-- runtime/integration-tests/pendulum/src/tests.rs | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/runtime/integration-tests/pendulum/src/polkadot_test_net.rs b/runtime/integration-tests/pendulum/src/polkadot_test_net.rs index 60529a4c4..e7345cc70 100644 --- a/runtime/integration-tests/pendulum/src/polkadot_test_net.rs +++ b/runtime/integration-tests/pendulum/src/polkadot_test_net.rs @@ -1,4 +1,4 @@ -use crate::setup::{one, ExtBuilderPendulum, ExtStatemintBuilder, ALICE, BOB}; +use crate::setup::{units, ExtBuilderPendulum, ExtStatemintBuilder, ALICE, BOB}; use frame_support::traits::GenesisBuild; use polkadot_core_primitives::{AccountId, BlockNumber}; use polkadot_parachain::primitives::Id as ParaId; @@ -54,9 +54,9 @@ pub fn relay_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); pallet_balances::GenesisConfig:: { balances: vec![ - (AccountId::from(ALICE), one(100000)), - (AccountId::from(BOB), one(100)), - (para_account_id(2094), 10 * one(100000)), + (AccountId::from(ALICE), units(100000)), + (AccountId::from(BOB), units(100)), + (para_account_id(2094), 10 * units(100000)), ], } .assimilate_storage(&mut t) diff --git a/runtime/integration-tests/pendulum/src/setup.rs b/runtime/integration-tests/pendulum/src/setup.rs index 7eb1fe79e..db54f539c 100644 --- a/runtime/integration-tests/pendulum/src/setup.rs +++ b/runtime/integration-tests/pendulum/src/setup.rs @@ -2,7 +2,7 @@ use frame_support::traits::GenesisBuild; use pendulum_runtime::{PendulumCurrencyId, Runtime, System}; use polkadot_core_primitives::{AccountId, Balance}; -pub fn one(amount: Balance) -> Balance { +pub fn units(amount: Balance) -> Balance { amount * 10u128.saturating_pow(9) } @@ -44,7 +44,7 @@ impl ExtBuilderPendulum { .unwrap(); orml_tokens::GenesisConfig:: { - balances: vec![(AccountId::from(BOB), PendulumCurrencyId::XCM(0), one(100))], + balances: vec![(AccountId::from(BOB), PendulumCurrencyId::XCM(0), units(100))], } .assimilate_storage(&mut t) .unwrap(); diff --git a/runtime/integration-tests/pendulum/src/tests.rs b/runtime/integration-tests/pendulum/src/tests.rs index 602a2dbbd..40467512a 100644 --- a/runtime/integration-tests/pendulum/src/tests.rs +++ b/runtime/integration-tests/pendulum/src/tests.rs @@ -23,7 +23,7 @@ const DOT_FEE_WHEN_TRANSFER_TO_RELAY: u128 = 421434140; //This fee will taken to fn transfer_dot_from_relay_chain_to_pendulum() { MockNet::reset(); - let transfer_amount: Balance = one(20); + let transfer_amount: Balance = units(20); let mut orml_tokens_before = 0; PendulumParachain::execute_with(|| { orml_tokens_before = pendulum_runtime::Tokens::balance( @@ -69,9 +69,9 @@ fn transfer_dot_from_relay_chain_to_pendulum() { fn transfer_dot_from_pendulum_to_relay_chain() { MockNet::reset(); - let transfer_dot_amount: Balance = one(10); + let transfer_dot_amount: Balance = units(10); - let expected_base_balance = one(100); + let expected_base_balance = units(100); Relay::execute_with(|| { let before_bob_free_balance = polkadot_runtime::Balances::free_balance(&BOB.into()); assert_eq!(before_bob_free_balance, expected_base_balance); From 0471cadc800c58b7ed4f0d6405ed60bcddbfc889 Mon Sep 17 00:00:00 2001 From: cr4pt0 Date: Thu, 6 Apr 2023 11:26:57 +0100 Subject: [PATCH 16/18] wrap AccountId32 to X1 when call reserve_transfer_assets --- runtime/integration-tests/pendulum/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/integration-tests/pendulum/src/tests.rs b/runtime/integration-tests/pendulum/src/tests.rs index 40467512a..d57ac58e9 100644 --- a/runtime/integration-tests/pendulum/src/tests.rs +++ b/runtime/integration-tests/pendulum/src/tests.rs @@ -36,7 +36,7 @@ fn transfer_dot_from_relay_chain_to_pendulum() { assert_ok!(polkadot_runtime::XcmPallet::reserve_transfer_assets( polkadot_runtime::RuntimeOrigin::signed(ALICE.into()), Box::new(X1(Parachain(2094)).into().into()), - Box::new(Junction::AccountId32 { network: NetworkId::Any, id: ALICE }.into().into()), + Box::new(X1(Junction::AccountId32 { network: NetworkId::Any, id: ALICE }).into().into()), Box::new((Here, transfer_amount).into()), 0 )); From 63b89751aa924d997cc72d2dc63ca40bf640a6de Mon Sep 17 00:00:00 2001 From: Rust Ninja <102041955+RustNinja@users.noreply.github.com> Date: Thu, 6 Apr 2023 11:44:50 +0100 Subject: [PATCH 17/18] make Foucoco xcm config identical to pendulum runtime (#199) make foucoco xcm config identical to pendulum runtime --- runtime/foucoco/src/xcm_config.rs | 34 +++++++++++++++---- .../integration-tests/pendulum/src/tests.rs | 4 ++- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/runtime/foucoco/src/xcm_config.rs b/runtime/foucoco/src/xcm_config.rs index 7069756c6..9c76484dc 100644 --- a/runtime/foucoco/src/xcm_config.rs +++ b/runtime/foucoco/src/xcm_config.rs @@ -7,7 +7,10 @@ use frame_support::{ log, match_types, parameter_types, traits::{Everything, Nothing}, }; -use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key}; +use orml_traits::{ + location::{RelativeReserveProvider, Reserve}, + parameter_type_with_key, +}; use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; use polkadot_runtime_common::impls::ToAuthor; @@ -15,12 +18,12 @@ use sp_runtime::traits::Convert; use xcm::latest::{prelude::*, Weight as XCMWeight}; use xcm_builder::{ AccountId32Aliases, AllowUnpaidExecutionFrom, ConvertedConcreteAssetId, EnsureXcmOrigin, - FixedWeightBounds, FungiblesAdapter, LocationInverter, NativeAsset, ParentIsPreset, - RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, UsingComponents, + FixedWeightBounds, FungiblesAdapter, LocationInverter, ParentIsPreset, RelayChainAsNative, + SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, UsingComponents, }; use xcm_executor::{ - traits::{JustTry, ShouldExecute}, + traits::{FilterAssetLocation, JustTry, ShouldExecute}, XcmExecutor, }; @@ -94,6 +97,23 @@ impl xcm_executor::traits::Convert for CurrencyIdConv } } +/// A `FilterAssetLocation` implementation. Filters multi native assets whose +/// reserve is same with `origin`. +pub struct MultiNativeAsset(PhantomData); +impl FilterAssetLocation for MultiNativeAsset +where + ReserveProvider: Reserve, +{ + fn filter_asset_location(asset: &MultiAsset, origin: &MultiLocation) -> bool { + if let Some(ref reserve) = ReserveProvider::reserve(asset) { + if reserve == origin { + return true + } + } + false + } +} + /// Means for transacting the fungibles assets of ths parachain. pub type FungiblesTransactor = FungiblesAdapter< // Use this fungibles implementation @@ -220,7 +240,7 @@ impl xcm_executor::Config for XcmConfig { // How to withdraw and deposit an asset. type AssetTransactor = FungiblesTransactor; type OriginConverter = XcmOriginToTransactDispatchOrigin; - type IsReserve = NativeAsset; + type IsReserve = MultiNativeAsset; type IsTeleporter = (); // Teleporting is disabled. type LocationInverter = LocationInverter; type Barrier = Barrier; @@ -286,7 +306,7 @@ impl orml_xtokens::Config for Runtime { type MaxAssetsForTransfer = MaxAssetsForTransfer; type MinXcmFee = ParachainMinFee; //TODO to support hrmp transfer beetween parachain adjust this parameter type MultiLocationsFilter = Everything; - type ReserveProvider = AbsoluteReserveProvider; + type ReserveProvider = RelativeReserveProvider; } pub struct AccountIdToMultiLocation; diff --git a/runtime/integration-tests/pendulum/src/tests.rs b/runtime/integration-tests/pendulum/src/tests.rs index d57ac58e9..0a0fa30ca 100644 --- a/runtime/integration-tests/pendulum/src/tests.rs +++ b/runtime/integration-tests/pendulum/src/tests.rs @@ -36,7 +36,9 @@ fn transfer_dot_from_relay_chain_to_pendulum() { assert_ok!(polkadot_runtime::XcmPallet::reserve_transfer_assets( polkadot_runtime::RuntimeOrigin::signed(ALICE.into()), Box::new(X1(Parachain(2094)).into().into()), - Box::new(X1(Junction::AccountId32 { network: NetworkId::Any, id: ALICE }).into().into()), + Box::new( + X1(Junction::AccountId32 { network: NetworkId::Any, id: ALICE }).into().into() + ), Box::new((Here, transfer_amount).into()), 0 )); From 35386bc3811c5aba05420132a87c5d2e3205a791 Mon Sep 17 00:00:00 2001 From: cr4pt0 Date: Thu, 6 Apr 2023 15:14:38 +0100 Subject: [PATCH 18/18] remove duplicate of "runtime/development" --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 22848bb72..7cc81a5c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,5 @@ members = [ "runtime/foucoco", "runtime/pendulum", "runtime/development", - "runtime/development", "runtime/integration-tests/pendulum", ]