From befd98d6e8e77d1f1b349d588f1f423b0ccf93e0 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Wed, 9 Aug 2023 13:34:29 +1200 Subject: [PATCH 1/9] improve macros to accept trailing comma --- xcm/xcm-emulator/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xcm/xcm-emulator/src/lib.rs b/xcm/xcm-emulator/src/lib.rs index 115a32ebf24..179a27a6ddf 100644 --- a/xcm/xcm-emulator/src/lib.rs +++ b/xcm/xcm-emulator/src/lib.rs @@ -289,6 +289,7 @@ macro_rules! decl_test_relay_chains { } ), + + $(,)? ) => { $( pub struct $name; @@ -516,6 +517,7 @@ macro_rules! decl_test_parachains { } ), + + $(,)? ) => { $( pub struct $name; @@ -803,6 +805,7 @@ macro_rules! decl_test_networks { } ), + + $(,)? ) => { $( pub struct $name; @@ -1027,6 +1030,7 @@ macro_rules! decl_test_bridges { } ), + + $(,)? ) => { $( #[derive(Debug)] From d3693f571124cd2f36fcec27d09838fe2c88be94 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Wed, 9 Aug 2023 13:59:28 +1200 Subject: [PATCH 2/9] improve hygiene --- parachains/integration-tests/emulated/common/src/lib.rs | 2 +- xcm/xcm-emulator/src/lib.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/parachains/integration-tests/emulated/common/src/lib.rs b/parachains/integration-tests/emulated/common/src/lib.rs index 23b05a54c72..2571dae85aa 100644 --- a/parachains/integration-tests/emulated/common/src/lib.rs +++ b/parachains/integration-tests/emulated/common/src/lib.rs @@ -396,7 +396,7 @@ decl_test_parachains! { pallets_extra = { PolkadotXcm: asset_hub_polkadot_runtime::PolkadotXcm, Assets: asset_hub_polkadot_runtime::Assets, - } + }` } } diff --git a/xcm/xcm-emulator/src/lib.rs b/xcm/xcm-emulator/src/lib.rs index 179a27a6ddf..5344bc59210 100644 --- a/xcm/xcm-emulator/src/lib.rs +++ b/xcm/xcm-emulator/src/lib.rs @@ -294,7 +294,7 @@ macro_rules! decl_test_relay_chains { $( pub struct $name; - impl RelayChain for $name { + impl $crate::RelayChain for $name { type Runtime = $runtime; type RuntimeOrigin = $runtime_origin; type RuntimeCall = $runtime_call; @@ -375,7 +375,7 @@ macro_rules! __impl_test_ext_for_relay_chain { = $crate::RefCell::new(<$name>::build_new_ext($genesis)); } - impl TestExt for $name { + impl $crate::TestExt for $name { fn build_new_ext(storage: $crate::Storage) -> $crate::sp_io::TestExternalities { let mut ext = sp_io::TestExternalities::new(storage); ext.execute_with(|| { @@ -522,7 +522,7 @@ macro_rules! decl_test_parachains { $( pub struct $name; - impl Parachain for $name { + impl $crate::Parachain for $name { type Runtime = $runtime; type RuntimeOrigin = $runtime_origin; type RuntimeCall = $runtime_call; From baf0edaf14c68106261245142493d1d265ee6292 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Wed, 9 Aug 2023 14:04:01 +1200 Subject: [PATCH 3/9] improve hygiene --- Cargo.lock | 1 + xcm/xcm-emulator/Cargo.toml | 1 + xcm/xcm-emulator/src/lib.rs | 5 +++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 44e700e552c..1dd3f97ce21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15677,6 +15677,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std", + "sp-tracing", "sp-trie", "xcm", ] diff --git a/xcm/xcm-emulator/Cargo.toml b/xcm/xcm-emulator/Cargo.toml index 3a1402109e2..e5175969e6f 100644 --- a/xcm/xcm-emulator/Cargo.toml +++ b/xcm/xcm-emulator/Cargo.toml @@ -21,6 +21,7 @@ sp-std = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" } pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master" } pallet-message-queue = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/xcm/xcm-emulator/src/lib.rs b/xcm/xcm-emulator/src/lib.rs index 5344bc59210..3248ce3731f 100644 --- a/xcm/xcm-emulator/src/lib.rs +++ b/xcm/xcm-emulator/src/lib.rs @@ -51,6 +51,7 @@ pub use polkadot_runtime_parachains::{ dmp, inclusion::{AggregateMessageOrigin, UmpQueueId}, }; +pub use sp_tracing; // Polkadot pub use xcm::v3::prelude::*; @@ -381,7 +382,7 @@ macro_rules! __impl_test_ext_for_relay_chain { ext.execute_with(|| { #[allow(clippy::no_effect)] $on_init; - sp_tracing::try_init_simple(); + $crate::sp_tracing::try_init_simple(); ::System::set_block_number(1); }); ext @@ -611,7 +612,7 @@ macro_rules! __impl_test_ext_for_parachain { ext.execute_with(|| { #[allow(clippy::no_effect)] $on_init; - sp_tracing::try_init_simple(); + $crate::sp_tracing::try_init_simple(); ::System::set_block_number(1); }); ext From 6f1128881582c7be41c433f6b6b6fa0494cd196b Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Wed, 9 Aug 2023 14:05:13 +1200 Subject: [PATCH 4/9] improve hygiene --- xcm/xcm-emulator/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xcm/xcm-emulator/src/lib.rs b/xcm/xcm-emulator/src/lib.rs index 3248ce3731f..fae8b9a3122 100644 --- a/xcm/xcm-emulator/src/lib.rs +++ b/xcm/xcm-emulator/src/lib.rs @@ -947,14 +947,14 @@ macro_rules! decl_test_networks { while let Some(msg) = $crate::BRIDGED_MESSAGES.with(|b| b.borrow_mut().get_mut(stringify!($name)).unwrap().pop_front()) { let dispatch_result = <::Target as TestExt>::ext_wrapper(|| { - <::Handler as BridgeMessageHandler>::dispatch_target_inbound_message(msg.clone()) + <::Handler as $crate::BridgeMessageHandler>::dispatch_target_inbound_message(msg.clone()) }); match dispatch_result { Err(e) => panic!("Error {:?} processing bridged message: {:?}", e, msg.clone()), Ok(()) => { <::Source as TestExt>::ext_wrapper(|| { - <::Handler as BridgeMessageHandler>::notify_source_message_delivery(msg.id); + <::Handler as $crate::BridgeMessageHandler>::notify_source_message_delivery(msg.id); }); $crate::log::debug!(target: concat!("bridge::", stringify!($name)) , "Bridged message processed {:?}", msg.clone()); } From f093d91e397c9787b35912d9b08af5d2a7cc79a1 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Wed, 9 Aug 2023 14:10:48 +1200 Subject: [PATCH 5/9] woops --- parachains/integration-tests/emulated/common/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parachains/integration-tests/emulated/common/src/lib.rs b/parachains/integration-tests/emulated/common/src/lib.rs index 2571dae85aa..23b05a54c72 100644 --- a/parachains/integration-tests/emulated/common/src/lib.rs +++ b/parachains/integration-tests/emulated/common/src/lib.rs @@ -396,7 +396,7 @@ decl_test_parachains! { pallets_extra = { PolkadotXcm: asset_hub_polkadot_runtime::PolkadotXcm, Assets: asset_hub_polkadot_runtime::Assets, - }` + } } } From 3d0f97abb0cb8021216777d1ff0c4557c8ebe29e Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Wed, 9 Aug 2023 15:33:41 +1200 Subject: [PATCH 6/9] cleanup --- Cargo.lock | 1 + .../assets/asset-hub-kusama/src/lib.rs | 2 +- .../assets/asset-hub-polkadot/src/lib.rs | 2 +- .../assets/asset-hub-westend/src/lib.rs | 2 +- .../bridges/bridge-hub-rococo/src/lib.rs | 2 +- .../collectives-polkadot/src/lib.rs | 3 +- .../emulated/common/src/lib.rs | 8 +- xcm/xcm-emulator/Cargo.toml | 1 + xcm/xcm-emulator/src/lib.rs | 116 ++++++++++-------- 9 files changed, 72 insertions(+), 65 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1dd3f97ce21..2b1904c1277 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15680,6 +15680,7 @@ dependencies = [ "sp-tracing", "sp-trie", "xcm", + "xcm-executor", ] [[package]] diff --git a/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs b/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs index b090432fa7c..fbf7eb192ce 100644 --- a/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs +++ b/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs @@ -24,7 +24,7 @@ pub use integration_tests_common::{ kusama::ED as KUSAMA_ED, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, }, - AccountId, AssetHubKusama, AssetHubKusamaPallet, AssetHubKusamaReceiver, AssetHubKusamaSender, + AssetHubKusama, AssetHubKusamaPallet, AssetHubKusamaReceiver, AssetHubKusamaSender, BridgeHubKusama, BridgeHubKusamaPallet, BridgeHubKusamaReceiver, BridgeHubKusamaSender, BridgeHubPolkadot, BridgeHubPolkadotPallet, BridgeHubPolkadotReceiver, BridgeHubPolkadotSender, Collectives, CollectivesPallet, CollectivesReceiver, CollectivesSender, Kusama, KusamaMockNet, diff --git a/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs b/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs index 70506d98cbc..b33fa232a6d 100644 --- a/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs +++ b/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs @@ -24,7 +24,7 @@ pub use integration_tests_common::{ polkadot::ED as POLKADOT_ED, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, }, - AccountId, AssetHubKusama, AssetHubKusamaPallet, AssetHubKusamaReceiver, AssetHubKusamaSender, + AssetHubKusama, AssetHubKusamaPallet, AssetHubKusamaReceiver, AssetHubKusamaSender, AssetHubPolkadot, AssetHubPolkadotPallet, AssetHubPolkadotReceiver, AssetHubPolkadotSender, BridgeHubKusama, BridgeHubKusamaPallet, BridgeHubKusamaReceiver, BridgeHubKusamaSender, BridgeHubPolkadot, BridgeHubPolkadotPallet, BridgeHubPolkadotReceiver, BridgeHubPolkadotSender, diff --git a/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs b/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs index e3d33dabaa2..b4608f35456 100644 --- a/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs +++ b/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs @@ -24,7 +24,7 @@ pub use integration_tests_common::{ polkadot::ED as POLKADOT_ED, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, }, - AccountId, AssetHubWestend, AssetHubWestendPallet, AssetHubWestendReceiver, + AssetHubWestend, AssetHubWestendPallet, AssetHubWestendReceiver, AssetHubWestendSender, Collectives, CollectivesPallet, CollectivesReceiver, CollectivesSender, PenpalWestend, PenpalWestendPallet, PenpalWestendReceiver, PenpalWestendSender, Westend, WestendPallet, WestendReceiver, WestendSender, diff --git a/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/lib.rs b/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/lib.rs index 105212b1907..68d23bf8888 100644 --- a/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/lib.rs +++ b/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/lib.rs @@ -23,7 +23,7 @@ pub use integration_tests_common::{ rococo::{ED as ROCOCO_ED, ED as WOCOCO_ED}, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, }, - AccountId, AssetHubWococo, BridgeHubPolkadot, BridgeHubPolkadotPallet, + AssetHubWococo, BridgeHubPolkadot, BridgeHubPolkadotPallet, BridgeHubPolkadotReceiver, BridgeHubPolkadotSender, BridgeHubRococo, BridgeHubRococoPallet, BridgeHubRococoReceiver, BridgeHubRococoSender, BridgeHubWococo, Collectives, CollectivesPallet, CollectivesReceiver, CollectivesSender, Kusama, KusamaPallet, diff --git a/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/lib.rs b/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/lib.rs index d83ddfffd99..bdd1e3be973 100644 --- a/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/lib.rs +++ b/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/lib.rs @@ -19,8 +19,9 @@ #![cfg(test)] pub use frame_support::assert_ok; +pub use parachains_common::AccountId; pub use integration_tests_common::{ - constants::accounts::ALICE, AccountId, AssetHubPolkadot as AssetHub, + constants::accounts::ALICE, AssetHubPolkadot as AssetHub, AssetHubPolkadotPallet as AssetHubPallet, Collectives, CollectivesPallet, Polkadot, PolkadotMockNet, }; diff --git a/parachains/integration-tests/emulated/common/src/lib.rs b/parachains/integration-tests/emulated/common/src/lib.rs index 23b05a54c72..e66bc2e5e87 100644 --- a/parachains/integration-tests/emulated/common/src/lib.rs +++ b/parachains/integration-tests/emulated/common/src/lib.rs @@ -8,16 +8,10 @@ pub use constants::{ }; pub use impls::{RococoWococoMessageHandler, WococoRococoMessageHandler}; -use frame_support::{parameter_types, sp_io, sp_tracing}; -pub use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId, Balance, BlockNumber}; -pub use sp_core::{sr25519, storage::Storage, Get}; -use xcm::prelude::*; use xcm_emulator::{ decl_test_bridges, decl_test_networks, decl_test_parachains, decl_test_relay_chains, - decl_test_sender_receiver_accounts_parameter_types, BridgeMessageHandler, Parachain, - RelayChain, TestExt, + decl_test_sender_receiver_accounts_parameter_types }; -use xcm_executor::traits::ConvertLocation; decl_test_relay_chains! { #[api_version(5)] diff --git a/xcm/xcm-emulator/Cargo.toml b/xcm/xcm-emulator/Cargo.toml index e5175969e6f..7baa782a953 100644 --- a/xcm/xcm-emulator/Cargo.toml +++ b/xcm/xcm-emulator/Cargo.toml @@ -37,5 +37,6 @@ parachains-common = { path = "../../parachains/common" } # Polkadot xcm = { git = "https://github.com/paritytech/polkadot", branch = "master" } +xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "master" } polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "master" } polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "master" } diff --git a/xcm/xcm-emulator/src/lib.rs b/xcm/xcm-emulator/src/lib.rs index fae8b9a3122..3a57ca1a996 100644 --- a/xcm/xcm-emulator/src/lib.rs +++ b/xcm/xcm-emulator/src/lib.rs @@ -28,7 +28,7 @@ pub use frame_support::{ pub use frame_system::AccountInfo; pub use pallet_balances::AccountData; pub use sp_arithmetic::traits::Bounded; -pub use sp_core::{storage::Storage, Pair, H256}; +pub use sp_core::{storage::Storage, Pair, H256, sr25519, parameter_types}; pub use sp_io; pub use sp_std::{cell::RefCell, collections::vec_deque::VecDeque, fmt::Debug}; pub use sp_trie::StorageProof; @@ -45,7 +45,7 @@ pub use cumulus_primitives_parachain_inherent::ParachainInherentData; pub use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; pub use pallet_message_queue; pub use parachain_info; -pub use parachains_common::{AccountId, BlockNumber}; +pub use parachains_common::{AccountId, BlockNumber, Balance}; pub use polkadot_primitives; pub use polkadot_runtime_parachains::{ dmp, @@ -54,7 +54,9 @@ pub use polkadot_runtime_parachains::{ pub use sp_tracing; // Polkadot +pub use xcm::v3::prelude as xcm_prelude; pub use xcm::v3::prelude::*; +pub use xcm_executor::traits::ConvertLocation; thread_local! { /// Downward messages, each message is: `(to_para_id, [(relay_block_number, msg)])` @@ -327,9 +329,9 @@ macro_rules! decl_test_relay_chains { msg: &[u8], para: Self::Origin, meter: &mut $crate::WeightMeter, - _id: &mut XcmHash + _id: &mut $crate::XcmHash ) -> Result { - use $crate::{Weight, AggregateMessageOrigin, UmpQueueId, ServiceQueues, EnqueueMessage}; + use $crate::{Weight, AggregateMessageOrigin, UmpQueueId, ServiceQueues, EnqueueMessage, TestExt}; use $mq as message_queue; use $runtime_event as runtime_event; @@ -373,17 +375,17 @@ macro_rules! __impl_test_ext_for_relay_chain { (@impl $name:ident, $genesis:expr, $on_init:expr, $api_version:ident, $ext_name:ident) => { thread_local! { pub static $ext_name: $crate::RefCell<$crate::sp_io::TestExternalities> - = $crate::RefCell::new(<$name>::build_new_ext($genesis)); + = $crate::RefCell::new(<$name as $crate::TestExt>::build_new_ext($genesis)); } impl $crate::TestExt for $name { fn build_new_ext(storage: $crate::Storage) -> $crate::sp_io::TestExternalities { - let mut ext = sp_io::TestExternalities::new(storage); + let mut ext = $crate::sp_io::TestExternalities::new(storage); ext.execute_with(|| { #[allow(clippy::no_effect)] $on_init; $crate::sp_tracing::try_init_simple(); - ::System::set_block_number(1); + ::System::set_block_number(1); }); ext } @@ -411,7 +413,7 @@ macro_rules! __impl_test_ext_for_relay_chain { //TODO: mark sent count & filter out sent msg for para_id in<$name as NetworkComponent>::Network::para_ids() { // downward messages - let downward_messages = ::Runtime::dmq_contents(para_id.into()) + let downward_messages = ::Runtime::dmq_contents(para_id.into()) .into_iter() .map(|inbound| (inbound.sent_at, inbound.msg)); if downward_messages.len() == 0 { @@ -453,27 +455,29 @@ macro_rules! __impl_relay { } impl $relay_chain { - pub fn child_location_of(id: $crate::ParaId) -> MultiLocation { + pub fn child_location_of(id: $crate::ParaId) -> $crate::MultiLocation { + use $crate::xcm_prelude::*; + (Ancestor(0), Parachain(id.into())).into() } pub fn account_id_of(seed: &str) -> $crate::AccountId { - $crate::get_account_id_from_seed::(seed) + $crate::get_account_id_from_seed::<$crate::sr25519::Public>(seed) } - pub fn account_data_of(account: AccountId) -> $crate::AccountData { - Self::ext_wrapper(|| ::System::account(account).data) + pub fn account_data_of(account: $crate::AccountId) -> $crate::AccountData<$crate::Balance> { + ::ext_wrapper(|| ::System::account(account).data) } pub fn sovereign_account_id_of(location: $crate::MultiLocation) -> $crate::AccountId { - ::SovereignAccountOf::convert_location(&location).unwrap() + <::SovereignAccountOf as $crate::ConvertLocation<$crate::AccountId>>::convert_location(&location).unwrap() } - pub fn fund_accounts(accounts: Vec<(AccountId, Balance)>) { - Self::ext_wrapper(|| { + pub fn fund_accounts(accounts: Vec<($crate::AccountId, $crate::Balance)>) { + ::ext_wrapper(|| { for account in accounts { - let _ = ::Balances::force_set_balance( - ::RuntimeOrigin::root(), + let _ = ::Balances::force_set_balance( + ::RuntimeOrigin::root(), account.0.into(), account.1.into(), ); @@ -481,8 +485,8 @@ macro_rules! __impl_relay { }); } - pub fn events() -> Vec<::RuntimeEvent> { - ::System::events() + pub fn events() -> Vec<::RuntimeEvent> { + ::System::events() .iter() .map(|record| record.event.clone()) .collect() @@ -570,8 +574,8 @@ macro_rules! __impl_xcm_handlers_for_parachain { ) -> $crate::Weight { use $crate::{TestExt, XcmpMessageHandler}; - $name::ext_wrapper(|| { - ::XcmpMessageHandler::handle_xcmp_messages(iter, max_weight) + <$name as $crate::TestExt>::ext_wrapper(|| { + ::XcmpMessageHandler::handle_xcmp_messages(iter, max_weight) }) } } @@ -583,8 +587,8 @@ macro_rules! __impl_xcm_handlers_for_parachain { ) -> $crate::Weight { use $crate::{DmpMessageHandler, TestExt}; - $name::ext_wrapper(|| { - ::DmpMessageHandler::handle_dmp_messages(iter, max_weight) + <$name as $crate::TestExt>::ext_wrapper(|| { + ::DmpMessageHandler::handle_dmp_messages(iter, max_weight) }) } } @@ -603,17 +607,17 @@ macro_rules! __impl_test_ext_for_parachain { (@impl $name:ident, $genesis:expr, $on_init:expr, $ext_name:ident) => { thread_local! { pub static $ext_name: $crate::RefCell<$crate::sp_io::TestExternalities> - = $crate::RefCell::new(<$name>::build_new_ext($genesis)); + = $crate::RefCell::new(<$name as $crate::TestExt>::build_new_ext($genesis)); } - impl TestExt for $name { + impl $crate::TestExt for $name { fn build_new_ext(storage: $crate::Storage) -> $crate::sp_io::TestExternalities { - let mut ext = sp_io::TestExternalities::new(storage); + let mut ext = $crate::sp_io::TestExternalities::new(storage); ext.execute_with(|| { #[allow(clippy::no_effect)] $on_init; $crate::sp_tracing::try_init_simple(); - ::System::set_block_number(1); + ::System::set_block_number(1); }); ext } @@ -642,8 +646,8 @@ macro_rules! __impl_test_ext_for_parachain { v.borrow_mut().execute_with(|| { // Make sure it has been recorded properly let relay_block_number = <$name as NetworkComponent>::Network::relay_block_number(); - let _ = ::ParachainSystem::set_validation_data( - ::RuntimeOrigin::none(), + let _ = ::ParachainSystem::set_validation_data( + ::RuntimeOrigin::none(), <$name as NetworkComponent>::Network::hrmp_channel_parachain_inherent_data(para_id, relay_block_number), ); }) @@ -657,7 +661,7 @@ macro_rules! __impl_test_ext_for_parachain { v.borrow_mut().execute_with(|| { use sp_runtime::traits::Header as HeaderT; - let block_number = ::System::block_number(); + let block_number = ::System::block_number(); let mock_header = HeaderT::new( 0, Default::default(), @@ -667,8 +671,8 @@ macro_rules! __impl_test_ext_for_parachain { ); // get xcmp messages - ::ParachainSystem::on_finalize(block_number); - let collation_info = ::ParachainSystem::collect_collation_info(&mock_header); + ::ParachainSystem::on_finalize(block_number); + let collation_info = ::ParachainSystem::collect_collation_info(&mock_header); // send upward messages let relay_block_number = <$name as NetworkComponent>::Network::relay_block_number(); @@ -687,7 +691,7 @@ macro_rules! __impl_test_ext_for_parachain { // get bridge messages type NetworkBridge = <<$name as NetworkComponent>::Network as Network>::Bridge; - let bridge_messages = ::Handler::get_source_outbound_messages(); + let bridge_messages = <::Handler as $crate::BridgeMessageHandler>::get_source_outbound_messages(); // send bridged messages for msg in bridge_messages { @@ -695,7 +699,7 @@ macro_rules! __impl_test_ext_for_parachain { } // clean messages - ::ParachainSystem::on_initialize(block_number); + ::ParachainSystem::on_initialize(block_number); }) }); @@ -728,34 +732,40 @@ macro_rules! __impl_parachain { impl $parachain { pub fn para_id() -> $crate::ParaId { - Self::ext_wrapper(|| ::ParachainInfo::get()) + use $crate::Get; + + ::ext_wrapper(|| ::ParachainInfo::get()) } pub fn parent_location() -> $crate::MultiLocation { + use $crate::xcm_prelude::*; + (Parent).into() } pub fn sibling_location_of(para_id: $crate::ParaId) -> $crate::MultiLocation { + use $crate::xcm_prelude::*; + (Parent, X1(Parachain(para_id.into()))).into() } pub fn account_id_of(seed: &str) -> $crate::AccountId { - $crate::get_account_id_from_seed::(seed) + $crate::get_account_id_from_seed::<$crate::sr25519::Public>(seed) } - pub fn account_data_of(account: AccountId) -> $crate::AccountData { - Self::ext_wrapper(|| ::System::account(account).data) + pub fn account_data_of(account: $crate::AccountId) -> $crate::AccountData<$crate::Balance> { + ::ext_wrapper(|| ::System::account(account).data) } pub fn sovereign_account_id_of(location: $crate::MultiLocation) -> $crate::AccountId { - ::LocationToAccountId::convert_location(&location).unwrap() + <::LocationToAccountId as $crate::ConvertLocation<$crate::AccountId>>::convert_location(&location).unwrap() } - pub fn fund_accounts(accounts: Vec<(AccountId, Balance)>) { - Self::ext_wrapper(|| { + pub fn fund_accounts(accounts: Vec<($crate::AccountId, $crate::Balance)>) { + ::ext_wrapper(|| { for account in accounts { - let _ = ::Balances::force_set_balance( - ::RuntimeOrigin::root(), + let _ = ::Balances::force_set_balance( + ::RuntimeOrigin::root(), account.0.into(), account.1.into(), ); @@ -763,8 +773,8 @@ macro_rules! __impl_parachain { }); } - pub fn events() -> Vec<::RuntimeEvent> { - ::System::events() + pub fn events() -> Vec<::RuntimeEvent> { + ::System::events() .iter() .map(|record| record.event.clone()) .collect() @@ -774,20 +784,20 @@ macro_rules! __impl_parachain { use $crate::{Network, NetworkComponent}; let para_id = Self::para_id(); - ::ext_wrapper(|| { + ::ext_wrapper(|| { use $crate::{Get, Hooks}; - let block_number = ::System::block_number(); + let block_number = ::System::block_number(); - let _ = ::ParachainSystem::set_validation_data( - ::RuntimeOrigin::none(), + let _ = ::ParachainSystem::set_validation_data( + ::RuntimeOrigin::none(), ::Network::hrmp_channel_parachain_inherent_data( para_id.into(), 1, ), ); // set `AnnouncedHrmpMessagesPerCandidate` - ::ParachainSystem::on_initialize(block_number); + ::ParachainSystem::on_initialize(block_number); }); } } @@ -946,14 +956,14 @@ macro_rules! decl_test_networks { ::init(); while let Some(msg) = $crate::BRIDGED_MESSAGES.with(|b| b.borrow_mut().get_mut(stringify!($name)).unwrap().pop_front()) { - let dispatch_result = <::Target as TestExt>::ext_wrapper(|| { + let dispatch_result = <::Target as $crate::TestExt>::ext_wrapper(|| { <::Handler as $crate::BridgeMessageHandler>::dispatch_target_inbound_message(msg.clone()) }); match dispatch_result { Err(e) => panic!("Error {:?} processing bridged message: {:?}", e, msg.clone()), Ok(()) => { - <::Source as TestExt>::ext_wrapper(|| { + <::Source as $crate::TestExt>::ext_wrapper(|| { <::Handler as $crate::BridgeMessageHandler>::notify_source_message_delivery(msg.id); }); $crate::log::debug!(target: concat!("bridge::", stringify!($name)) , "Bridged message processed {:?}", msg.clone()); @@ -1102,7 +1112,7 @@ macro_rules! bx { macro_rules! decl_test_sender_receiver_accounts_parameter_types { ( $( $chain:ident { sender: $sender:expr, receiver: $receiver:expr }),+ ) => { $crate::paste::paste! { - parameter_types! { + $crate::parameter_types! { $( pub [<$chain Sender>]: $crate::AccountId = <$chain>::account_id_of($sender); pub [<$chain Receiver>]: $crate::AccountId = <$chain>::account_id_of($receiver); From b088b686a7b6a45bdaa3ab2d1748690f12a43aae Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Wed, 9 Aug 2023 15:39:46 +1200 Subject: [PATCH 7/9] fmt --- .../assets/asset-hub-westend/src/lib.rs | 8 ++-- .../bridges/bridge-hub-rococo/src/lib.rs | 13 +++--- .../collectives-polkadot/src/lib.rs | 2 +- .../emulated/common/src/lib.rs | 2 +- xcm/xcm-emulator/src/lib.rs | 45 +++++++++++++------ 5 files changed, 44 insertions(+), 26 deletions(-) diff --git a/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs b/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs index b4608f35456..5fade25a668 100644 --- a/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs +++ b/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs @@ -24,10 +24,10 @@ pub use integration_tests_common::{ polkadot::ED as POLKADOT_ED, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, }, - AssetHubWestend, AssetHubWestendPallet, AssetHubWestendReceiver, - AssetHubWestendSender, Collectives, CollectivesPallet, CollectivesReceiver, CollectivesSender, - PenpalWestend, PenpalWestendPallet, PenpalWestendReceiver, PenpalWestendSender, Westend, - WestendPallet, WestendReceiver, WestendSender, + AssetHubWestend, AssetHubWestendPallet, AssetHubWestendReceiver, AssetHubWestendSender, + Collectives, CollectivesPallet, CollectivesReceiver, CollectivesSender, PenpalWestend, + PenpalWestendPallet, PenpalWestendReceiver, PenpalWestendSender, Westend, WestendPallet, + WestendReceiver, WestendSender, }; pub use polkadot_core_primitives::InboundDownwardMessage; pub use xcm::{ diff --git a/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/lib.rs b/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/lib.rs index 68d23bf8888..b751bf09488 100644 --- a/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/lib.rs +++ b/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/lib.rs @@ -23,13 +23,12 @@ pub use integration_tests_common::{ rococo::{ED as ROCOCO_ED, ED as WOCOCO_ED}, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, }, - AssetHubWococo, BridgeHubPolkadot, BridgeHubPolkadotPallet, - BridgeHubPolkadotReceiver, BridgeHubPolkadotSender, BridgeHubRococo, BridgeHubRococoPallet, - BridgeHubRococoReceiver, BridgeHubRococoSender, BridgeHubWococo, Collectives, - CollectivesPallet, CollectivesReceiver, CollectivesSender, Kusama, KusamaPallet, - PenpalPolkadot, PenpalPolkadotReceiver, PenpalPolkadotSender, Polkadot, PolkadotMockNet, - PolkadotPallet, PolkadotReceiver, PolkadotSender, Rococo, RococoMockNet, RococoPallet, - RococoReceiver, RococoSender, + AssetHubWococo, BridgeHubPolkadot, BridgeHubPolkadotPallet, BridgeHubPolkadotReceiver, + BridgeHubPolkadotSender, BridgeHubRococo, BridgeHubRococoPallet, BridgeHubRococoReceiver, + BridgeHubRococoSender, BridgeHubWococo, Collectives, CollectivesPallet, CollectivesReceiver, + CollectivesSender, Kusama, KusamaPallet, PenpalPolkadot, PenpalPolkadotReceiver, + PenpalPolkadotSender, Polkadot, PolkadotMockNet, PolkadotPallet, PolkadotReceiver, + PolkadotSender, Rococo, RococoMockNet, RococoPallet, RococoReceiver, RococoSender, }; // pub use polkadot_core_primitives::InboundDownwardMessage; pub use xcm::{ diff --git a/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/lib.rs b/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/lib.rs index bdd1e3be973..7aee7e643eb 100644 --- a/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/lib.rs +++ b/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/lib.rs @@ -19,12 +19,12 @@ #![cfg(test)] pub use frame_support::assert_ok; -pub use parachains_common::AccountId; pub use integration_tests_common::{ constants::accounts::ALICE, AssetHubPolkadot as AssetHub, AssetHubPolkadotPallet as AssetHubPallet, Collectives, CollectivesPallet, Polkadot, PolkadotMockNet, }; +pub use parachains_common::AccountId; pub use xcm::prelude::*; pub use xcm_emulator::{assert_expected_events, Parachain}; diff --git a/parachains/integration-tests/emulated/common/src/lib.rs b/parachains/integration-tests/emulated/common/src/lib.rs index e66bc2e5e87..2a50daee22b 100644 --- a/parachains/integration-tests/emulated/common/src/lib.rs +++ b/parachains/integration-tests/emulated/common/src/lib.rs @@ -10,7 +10,7 @@ pub use impls::{RococoWococoMessageHandler, WococoRococoMessageHandler}; use xcm_emulator::{ decl_test_bridges, decl_test_networks, decl_test_parachains, decl_test_relay_chains, - decl_test_sender_receiver_accounts_parameter_types + decl_test_sender_receiver_accounts_parameter_types, }; decl_test_relay_chains! { diff --git a/xcm/xcm-emulator/src/lib.rs b/xcm/xcm-emulator/src/lib.rs index 3a57ca1a996..91e6079e105 100644 --- a/xcm/xcm-emulator/src/lib.rs +++ b/xcm/xcm-emulator/src/lib.rs @@ -28,7 +28,7 @@ pub use frame_support::{ pub use frame_system::AccountInfo; pub use pallet_balances::AccountData; pub use sp_arithmetic::traits::Bounded; -pub use sp_core::{storage::Storage, Pair, H256, sr25519, parameter_types}; +pub use sp_core::{parameter_types, sr25519, storage::Storage, Pair, H256}; pub use sp_io; pub use sp_std::{cell::RefCell, collections::vec_deque::VecDeque, fmt::Debug}; pub use sp_trie::StorageProof; @@ -45,7 +45,7 @@ pub use cumulus_primitives_parachain_inherent::ParachainInherentData; pub use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; pub use pallet_message_queue; pub use parachain_info; -pub use parachains_common::{AccountId, BlockNumber, Balance}; +pub use parachains_common::{AccountId, Balance, BlockNumber}; pub use polkadot_primitives; pub use polkadot_runtime_parachains::{ dmp, @@ -54,8 +54,7 @@ pub use polkadot_runtime_parachains::{ pub use sp_tracing; // Polkadot -pub use xcm::v3::prelude as xcm_prelude; -pub use xcm::v3::prelude::*; +pub use xcm::v3::{prelude as xcm_prelude, prelude::*}; pub use xcm_executor::traits::ConvertLocation; thread_local! { @@ -465,12 +464,19 @@ macro_rules! __impl_relay { $crate::get_account_id_from_seed::<$crate::sr25519::Public>(seed) } - pub fn account_data_of(account: $crate::AccountId) -> $crate::AccountData<$crate::Balance> { - ::ext_wrapper(|| ::System::account(account).data) + pub fn account_data_of( + account: $crate::AccountId, + ) -> $crate::AccountData<$crate::Balance> { + ::ext_wrapper(|| { + ::System::account(account).data + }) } pub fn sovereign_account_id_of(location: $crate::MultiLocation) -> $crate::AccountId { - <::SovereignAccountOf as $crate::ConvertLocation<$crate::AccountId>>::convert_location(&location).unwrap() + <::SovereignAccountOf as $crate::ConvertLocation< + $crate::AccountId, + >>::convert_location(&location) + .unwrap() } pub fn fund_accounts(accounts: Vec<($crate::AccountId, $crate::Balance)>) { @@ -575,7 +581,9 @@ macro_rules! __impl_xcm_handlers_for_parachain { use $crate::{TestExt, XcmpMessageHandler}; <$name as $crate::TestExt>::ext_wrapper(|| { - ::XcmpMessageHandler::handle_xcmp_messages(iter, max_weight) + ::XcmpMessageHandler::handle_xcmp_messages( + iter, max_weight, + ) }) } } @@ -588,7 +596,9 @@ macro_rules! __impl_xcm_handlers_for_parachain { use $crate::{DmpMessageHandler, TestExt}; <$name as $crate::TestExt>::ext_wrapper(|| { - ::DmpMessageHandler::handle_dmp_messages(iter, max_weight) + ::DmpMessageHandler::handle_dmp_messages( + iter, max_weight, + ) }) } } @@ -734,7 +744,9 @@ macro_rules! __impl_parachain { pub fn para_id() -> $crate::ParaId { use $crate::Get; - ::ext_wrapper(|| ::ParachainInfo::get()) + ::ext_wrapper(|| { + ::ParachainInfo::get() + }) } pub fn parent_location() -> $crate::MultiLocation { @@ -753,12 +765,19 @@ macro_rules! __impl_parachain { $crate::get_account_id_from_seed::<$crate::sr25519::Public>(seed) } - pub fn account_data_of(account: $crate::AccountId) -> $crate::AccountData<$crate::Balance> { - ::ext_wrapper(|| ::System::account(account).data) + pub fn account_data_of( + account: $crate::AccountId, + ) -> $crate::AccountData<$crate::Balance> { + ::ext_wrapper(|| { + ::System::account(account).data + }) } pub fn sovereign_account_id_of(location: $crate::MultiLocation) -> $crate::AccountId { - <::LocationToAccountId as $crate::ConvertLocation<$crate::AccountId>>::convert_location(&location).unwrap() + <::LocationToAccountId as $crate::ConvertLocation< + $crate::AccountId, + >>::convert_location(&location) + .unwrap() } pub fn fund_accounts(accounts: Vec<($crate::AccountId, $crate::Balance)>) { From 1da3636f37615a28750761e0f289535500a1209a Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Wed, 16 Aug 2023 17:06:46 +1200 Subject: [PATCH 8/9] fix --- Cargo.lock | 1 + parachains/integration-tests/emulated/common/src/lib.rs | 2 +- xcm/xcm-emulator/Cargo.toml | 1 + xcm/xcm-emulator/src/lib.rs | 4 ++-- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b6d01bb2ca9..ac2735b0da5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15929,6 +15929,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std", + "sp-tracing", "sp-trie", "xcm", "xcm-executor", diff --git a/parachains/integration-tests/emulated/common/src/lib.rs b/parachains/integration-tests/emulated/common/src/lib.rs index 7ef57027c45..1604eb1e7f3 100644 --- a/parachains/integration-tests/emulated/common/src/lib.rs +++ b/parachains/integration-tests/emulated/common/src/lib.rs @@ -10,7 +10,7 @@ pub use constants::{ PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, }; use frame_support::{ - assert_ok, instances::Instance1, parameter_types, sp_tracing, traits::fungibles::Inspect, + assert_ok, instances::Instance1, traits::fungibles::Inspect, }; pub use impls::{RococoWococoMessageHandler, WococoRococoMessageHandler}; pub use parachains_common::{AccountId, Balance}; diff --git a/xcm/xcm-emulator/Cargo.toml b/xcm/xcm-emulator/Cargo.toml index 9a88eaf286a..1eb234eca4e 100644 --- a/xcm/xcm-emulator/Cargo.toml +++ b/xcm/xcm-emulator/Cargo.toml @@ -21,6 +21,7 @@ sp-std = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" } pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master" } pallet-message-queue = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/xcm/xcm-emulator/src/lib.rs b/xcm/xcm-emulator/src/lib.rs index 37a4e017be1..065b93ae52d 100644 --- a/xcm/xcm-emulator/src/lib.rs +++ b/xcm/xcm-emulator/src/lib.rs @@ -445,7 +445,7 @@ macro_rules! __impl_test_ext_for_relay_chain { ext.execute_with(|| { #[allow(clippy::no_effect)] $on_init; - sp_tracing::try_init_simple(); + $crate::sp_tracing::try_init_simple(); let mut block_number = ::System::block_number(); block_number = std::cmp::max(1, block_number); @@ -687,7 +687,7 @@ macro_rules! __impl_test_ext_for_parachain { ext.execute_with(|| { #[allow(clippy::no_effect)] $on_init; - sp_tracing::try_init_simple(); + $crate::sp_tracing::try_init_simple(); let mut block_number = ::System::block_number(); block_number = std::cmp::max(1, block_number); From 235fca592400bca937dda84b0ca79e78756e5b5a Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Wed, 16 Aug 2023 17:15:42 +1200 Subject: [PATCH 9/9] fix some --- .../assets/asset-hub-kusama/src/lib.rs | 1 - .../assets/asset-hub-polkadot/src/lib.rs | 1 - .../assets/asset-hub-westend/src/lib.rs | 1 - .../bridges/bridge-hub-rococo/src/lib.rs | 1 - .../collectives-polkadot/src/lib.rs | 1 - .../emulated/common/src/impls.rs | 33 ++++++++++--------- .../emulated/common/src/lib.rs | 23 +------------ 7 files changed, 19 insertions(+), 42 deletions(-) diff --git a/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs b/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs index 4282e91c499..19689d41f66 100644 --- a/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs +++ b/parachains/integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs @@ -17,7 +17,6 @@ pub use codec::Encode; pub use frame_support::{ assert_err, assert_ok, - instances::Instance1, pallet_prelude::Weight, sp_runtime::{AccountId32, DispatchError, DispatchResult, MultiAddress}, traits::{fungibles::Inspect, OriginTrait}, diff --git a/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs b/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs index 9d87458f876..62e744c87e7 100644 --- a/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs +++ b/parachains/integration-tests/emulated/assets/asset-hub-polkadot/src/lib.rs @@ -17,7 +17,6 @@ pub use codec::Encode; pub use frame_support::{ assert_err, assert_ok, - instances::Instance1, pallet_prelude::Weight, sp_runtime::{AccountId32, DispatchError, DispatchResult, MultiAddress}, traits::{fungibles::Inspect, OriginTrait}, diff --git a/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs b/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs index b7f064e7d6e..a78dad75a3b 100644 --- a/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs +++ b/parachains/integration-tests/emulated/assets/asset-hub-westend/src/lib.rs @@ -17,7 +17,6 @@ pub use codec::Encode; pub use frame_support::{ assert_err, assert_ok, - instances::{Instance1, Instance2}, pallet_prelude::Weight, sp_runtime::{AccountId32, DispatchError, DispatchResult, ModuleError, MultiAddress}, traits::{fungibles::Inspect, OriginTrait}, diff --git a/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/lib.rs b/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/lib.rs index 2a4927d857c..bc44f070a09 100644 --- a/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/lib.rs +++ b/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/lib.rs @@ -18,7 +18,6 @@ pub use bp_messages::LaneId; pub use codec::Encode; pub use frame_support::{ assert_err, assert_ok, - instances::Instance1, pallet_prelude::Weight, sp_runtime::{AccountId32, DispatchError, DispatchResult, MultiAddress}, traits::{fungibles::Inspect, OriginTrait}, diff --git a/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/lib.rs b/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/lib.rs index b71ee65a222..c83578b234e 100644 --- a/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/lib.rs +++ b/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/lib.rs @@ -17,7 +17,6 @@ pub use codec::Encode; pub use frame_support::{ assert_err, assert_ok, - instances::Instance1, pallet_prelude::Weight, sp_runtime::{AccountId32, DispatchError, DispatchResult, MultiAddress}, traits::{fungibles::Inspect, OriginTrait}, diff --git a/parachains/integration-tests/emulated/common/src/impls.rs b/parachains/integration-tests/emulated/common/src/impls.rs index 92c68f4dd61..b7da17b5398 100644 --- a/parachains/integration-tests/emulated/common/src/impls.rs +++ b/parachains/integration-tests/emulated/common/src/impls.rs @@ -11,6 +11,9 @@ use pallet_bridge_messages::{Config, Instance1, Instance2, OutboundLanes, Pallet use sp_core::Get; use xcm_emulator::{BridgeMessage, BridgeMessageDispatchError, BridgeMessageHandler, Chain}; +pub use paste; +pub use parachains_common::{AccountId, Balance}; + pub struct BridgeHubMessageHandler { _marker: std::marker::PhantomData<(S, T, I)>, } @@ -129,10 +132,10 @@ where #[macro_export] macro_rules! impl_accounts_helpers_for_relay_chain { ( $chain:ident ) => { - $crate::paste::paste! { + $crate::impls::paste::paste! { impl $chain { /// Fund a set of accounts with a balance - pub fn fund_accounts(accounts: Vec<(AccountId, Balance)>) { + pub fn fund_accounts(accounts: Vec<($crate::impls::AccountId, $crate::impls::Balance)>) { Self::execute_with(|| { for account in accounts { assert_ok!(]>::Balances::force_set_balance( @@ -144,7 +147,7 @@ macro_rules! impl_accounts_helpers_for_relay_chain { }); } /// Fund a sovereign account based on its Parachain Id - pub fn fund_para_sovereign(amount: Balance, para_id: ParaId) -> sp_runtime::AccountId32 { + pub fn fund_para_sovereign(amount: $crate::impls::Balance, para_id: ParaId) -> sp_runtime::AccountId32 { let sovereign_account = Self::sovereign_account_id_of_child_para(para_id); Self::fund_accounts(vec![(sovereign_account.clone(), amount)]); sovereign_account @@ -157,7 +160,7 @@ macro_rules! impl_accounts_helpers_for_relay_chain { #[macro_export] macro_rules! impl_assert_events_helpers_for_relay_chain { ( $chain:ident ) => { - $crate::paste::paste! { + $crate::impls::paste::paste! { type [<$chain RuntimeEvent>] = <$chain as Chain>::RuntimeEvent; impl $chain { @@ -247,7 +250,7 @@ macro_rules! impl_assert_events_helpers_for_relay_chain { #[macro_export] macro_rules! impl_hrmp_channels_helpers_for_relay_chain { ( $chain:ident ) => { - $crate::paste::paste! { + $crate::impls::paste::paste! { impl $chain { /// Init open channel request with another Parachain pub fn init_open_channel_call( @@ -305,10 +308,10 @@ macro_rules! impl_hrmp_channels_helpers_for_relay_chain { #[macro_export] macro_rules! impl_accounts_helpers_for_parachain { ( $chain:ident ) => { - $crate::paste::paste! { + $crate::impls::paste::paste! { impl $chain { /// Fund a set of accounts with a balance - pub fn fund_accounts(accounts: Vec<(AccountId, Balance)>) { + pub fn fund_accounts(accounts: Vec<($crate::impls::AccountId, $crate::impls::Balance)>) { Self::execute_with(|| { for account in accounts { assert_ok!(]>::Balances::force_set_balance( @@ -327,7 +330,7 @@ macro_rules! impl_accounts_helpers_for_parachain { #[macro_export] macro_rules! impl_assert_events_helpers_for_parachain { ( $chain:ident ) => { - $crate::paste::paste! { + $crate::impls::paste::paste! { type [<$chain RuntimeEvent>] = <$chain as Chain>::RuntimeEvent; impl $chain { @@ -474,14 +477,14 @@ macro_rules! impl_assert_events_helpers_for_parachain { #[macro_export] macro_rules! impl_assets_helpers_for_parachain { ( $chain:ident, $relay_chain:ident ) => { - $crate::paste::paste! { + $crate::impls::paste::paste! { impl $chain { /// Returns the encoded call for `force_create` from the assets pallet pub fn force_create_asset_call( asset_id: u32, - owner: AccountId, + owner: $crate::impls::AccountId, is_sufficient: bool, - min_balance: Balance, + min_balance: $crate::impls::Balance, ) -> DoubleEncoded<()> { ::RuntimeCall::Assets(pallet_assets::Call::< ::Runtime, @@ -500,9 +503,9 @@ macro_rules! impl_assets_helpers_for_parachain { pub fn force_create_asset_xcm( origin_kind: OriginKind, asset_id: u32, - owner: AccountId, + owner: $crate::impls::AccountId, is_sufficient: bool, - min_balance: Balance, + min_balance: $crate::impls::Balance, ) -> VersionedXcm<()> { let call = Self::force_create_asset_call(asset_id, owner, is_sufficient, min_balance); xcm_transact_unpaid_execution(call, origin_kind) @@ -512,7 +515,7 @@ macro_rules! impl_assets_helpers_for_parachain { pub fn mint_asset( signed_origin: ::RuntimeOrigin, id: u32, - beneficiary: AccountId, + beneficiary: $crate::impls::AccountId, amount_to_mint: u128, ) { Self::execute_with(|| { @@ -543,7 +546,7 @@ macro_rules! impl_assets_helpers_for_parachain { id: u32, min_balance: u128, is_sufficient: bool, - asset_owner: AccountId, + asset_owner: $crate::impls::AccountId, amount_to_mint: u128, ) { // Init values for Relay Chain diff --git a/parachains/integration-tests/emulated/common/src/lib.rs b/parachains/integration-tests/emulated/common/src/lib.rs index 1604eb1e7f3..40f3ef91332 100644 --- a/parachains/integration-tests/emulated/common/src/lib.rs +++ b/parachains/integration-tests/emulated/common/src/lib.rs @@ -2,37 +2,16 @@ pub use lazy_static; pub mod constants; pub mod impls; -pub use codec::Encode; pub use constants::{ accounts::{ALICE, BOB}, asset_hub_kusama, asset_hub_polkadot, asset_hub_westend, bridge_hub_kusama, bridge_hub_polkadot, bridge_hub_rococo, collectives, kusama, penpal, polkadot, rococo, westend, - PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, -}; -use frame_support::{ - assert_ok, instances::Instance1, traits::fungibles::Inspect, }; +use frame_support::traits::fungibles::Inspect; pub use impls::{RococoWococoMessageHandler, WococoRococoMessageHandler}; -pub use parachains_common::{AccountId, Balance}; -pub use paste; -use polkadot_parachain::primitives::HrmpChannelId; -pub use polkadot_runtime_parachains::inclusion::{AggregateMessageOrigin, UmpQueueId}; -pub use sp_core::{sr25519, storage::Storage, Get}; use xcm_emulator::{ assert_expected_events, bx, decl_test_bridges, decl_test_networks, decl_test_parachains, decl_test_relay_chains, decl_test_sender_receiver_accounts_parameter_types, - helpers::weight_within_threshold, BridgeMessageHandler, Chain, DefaultMessageProcessor, ParaId, - Parachain, RelayChain, TestExt, -}; - -pub use xcm::{ - prelude::{ - AccountId32, All, BuyExecution, DepositAsset, MultiAsset, MultiAssets, MultiLocation, - OriginKind, Outcome, RefundSurplus, Transact, UnpaidExecution, VersionedXcm, Weight, - WeightLimit, WithdrawAsset, Xcm, X1, - }, - v3::Error, - DoubleEncoded, }; decl_test_relay_chains! {