Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Make xcm-emulator test pass for new consensus hook #2722

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions parachains/integration-tests/emulated/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ decl_test_relay_chains! {
MessageQueue: polkadot_runtime::MessageQueue,
XcmConfig: polkadot_runtime::xcm_config::XcmConfig,
SovereignAccountOf: polkadot_runtime::xcm_config::SovereignAccountOf,
AllPallets: polkadot_runtime::AllPalletsWithSystem,
System: polkadot_runtime::System,
Balances: polkadot_runtime::Balances,
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
},
Expand All @@ -45,6 +46,7 @@ decl_test_relay_chains! {
MessageQueue: kusama_runtime::MessageQueue,
XcmConfig: kusama_runtime::xcm_config::XcmConfig,
SovereignAccountOf: kusama_runtime::xcm_config::SovereignAccountOf,
AllPallets: kusama_runtime::AllPalletsWithSystem,
System: kusama_runtime::System,
Balances: kusama_runtime::Balances,
},
Expand All @@ -67,6 +69,7 @@ decl_test_parachains! {
XcmpMessageHandler: statemint_runtime::XcmpQueue,
DmpMessageHandler: statemint_runtime::DmpQueue,
LocationToAccountId: statemint_runtime::xcm_config::LocationToAccountId,
AllPallets: statemint_runtime::AllPalletsWithSystem,
System: statemint_runtime::System,
Balances: statemint_runtime::Balances,
ParachainSystem: statemint_runtime::ParachainSystem,
Expand All @@ -88,6 +91,7 @@ decl_test_parachains! {
XcmpMessageHandler: penpal_runtime::XcmpQueue,
DmpMessageHandler: penpal_runtime::DmpQueue,
LocationToAccountId: penpal_runtime::xcm_config::LocationToAccountId,
AllPallets: penpal_runtime::AllPalletsWithSystem,
System: penpal_runtime::System,
Balances: penpal_runtime::Balances,
ParachainSystem: penpal_runtime::ParachainSystem,
Expand All @@ -110,6 +114,7 @@ decl_test_parachains! {
XcmpMessageHandler: statemine_runtime::XcmpQueue,
DmpMessageHandler: statemine_runtime::DmpQueue,
LocationToAccountId: statemine_runtime::xcm_config::LocationToAccountId,
AllPallets: statemine_runtime::AllPalletsWithSystem,
System: statemine_runtime::System,
Balances: statemine_runtime::Balances,
ParachainSystem: statemine_runtime::ParachainSystem,
Expand All @@ -132,6 +137,7 @@ decl_test_parachains! {
XcmpMessageHandler: penpal_runtime::XcmpQueue,
DmpMessageHandler: penpal_runtime::DmpQueue,
LocationToAccountId: penpal_runtime::xcm_config::LocationToAccountId,
AllPallets: penpal_runtime::AllPalletsWithSystem,
System: penpal_runtime::System,
Balances: penpal_runtime::Balances,
ParachainSystem: penpal_runtime::ParachainSystem,
Expand All @@ -153,6 +159,7 @@ decl_test_parachains! {
XcmpMessageHandler: collectives_polkadot_runtime::XcmpQueue,
DmpMessageHandler: collectives_polkadot_runtime::DmpQueue,
LocationToAccountId: collectives_polkadot_runtime::xcm_config::LocationToAccountId,
AllPallets: collectives_polkadot_runtime::AllPalletsWithSystem,
System: collectives_polkadot_runtime::System,
Balances: collectives_polkadot_runtime::Balances,
ParachainSystem: collectives_polkadot_runtime::ParachainSystem,
Expand All @@ -173,6 +180,7 @@ decl_test_parachains! {
XcmpMessageHandler: bridge_hub_kusama_runtime::XcmpQueue,
DmpMessageHandler: bridge_hub_kusama_runtime::DmpQueue,
LocationToAccountId: bridge_hub_kusama_runtime::xcm_config::LocationToAccountId,
AllPallets: bridge_hub_kusama_runtime::AllPalletsWithSystem,
System: bridge_hub_kusama_runtime::System,
Balances: bridge_hub_kusama_runtime::Balances,
ParachainSystem: bridge_hub_kusama_runtime::ParachainSystem,
Expand All @@ -193,6 +201,7 @@ decl_test_parachains! {
XcmpMessageHandler: bridge_hub_polkadot_runtime::XcmpQueue,
DmpMessageHandler: bridge_hub_polkadot_runtime::DmpQueue,
LocationToAccountId: bridge_hub_polkadot_runtime::xcm_config::LocationToAccountId,
AllPallets: bridge_hub_polkadot_runtime::AllPalletsWithSystem,
System: bridge_hub_polkadot_runtime::System,
Balances: bridge_hub_polkadot_runtime::Balances,
ParachainSystem: bridge_hub_polkadot_runtime::ParachainSystem,
Expand Down
40 changes: 30 additions & 10 deletions xcm/xcm-emulator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub use casey::pascal;
pub use codec::Encode;
pub use frame_support::{
sp_runtime::BuildStorage,
traits::{EnqueueMessage, Get, Hooks, ProcessMessage, ProcessMessageError, ServiceQueues},
traits::{EnqueueMessage, Get, Hooks, OnInitialize, ProcessMessage, ProcessMessageError, ServiceQueues},
weights::{Weight, WeightMeter},
};
pub use frame_system::AccountInfo;
Expand Down Expand Up @@ -206,6 +206,7 @@ macro_rules! decl_test_relay_chains {
MessageQueue: $mq:path,
XcmConfig: $xcm_config:path,
SovereignAccountOf: $sovereign_acc_of:path,
AllPallets: $all_pallets:path,
System: $system:path,
Balances: $balances:path,
},
Expand Down Expand Up @@ -280,21 +281,21 @@ macro_rules! decl_test_relay_chains {
}
}

$crate::__impl_test_ext_for_relay_chain!($name, $genesis, $on_init);
$crate::__impl_test_ext_for_relay_chain!($name, $genesis, $on_init, $all_pallets);
)+
};
}

#[macro_export]
macro_rules! __impl_test_ext_for_relay_chain {
// entry point: generate ext name
($name:ident, $genesis:expr, $on_init:expr) => {
($name:ident, $genesis:expr, $on_init:expr, $all_pallets:path) => {
$crate::paste::paste! {
$crate::__impl_test_ext_for_relay_chain!(@impl $name, $genesis, $on_init, [<EXT_ $name:upper>]);
$crate::__impl_test_ext_for_relay_chain!(@impl $name, $genesis, $on_init, $all_pallets, [<EXT_ $name:upper>]);
}
};
// impl
(@impl $name:ident, $genesis:expr, $on_init:expr, $ext_name:ident) => {
(@impl $name:ident, $genesis:expr, $on_init:expr, $all_pallets:path, $ext_name:ident) => {
thread_local! {
pub static $ext_name: $crate::RefCell<$crate::sp_io::TestExternalities>
= $crate::RefCell::new(<$name>::build_new_ext($genesis));
Expand Down Expand Up @@ -325,6 +326,14 @@ macro_rules! __impl_test_ext_for_relay_chain {
// Make sure the Network is initialized
<$name>::init();

// Make sure pallets hooks are executed
$ext_name.with(|v| {
v.borrow_mut().execute_with(|| {
let relay_block_number = <$name>::relay_block_number();
<$all_pallets as $crate::OnInitialize<u32>>::on_initialize(relay_block_number);
})
});

let r = $ext_name.with(|v| v.borrow_mut().execute_with(execute));

// send messages if needed
Expand Down Expand Up @@ -429,6 +438,7 @@ macro_rules! decl_test_parachains {
XcmpMessageHandler: $xcmp_message_handler:path,
DmpMessageHandler: $dmp_message_handler:path,
LocationToAccountId: $location_to_account:path,
AllPallets: $all_pallets:path,
System: $system:path,
Balances: $balances_pallet:path,
ParachainSystem: $parachain_system:path,
Expand Down Expand Up @@ -473,7 +483,7 @@ macro_rules! decl_test_parachains {
}

$crate::__impl_xcm_handlers_for_parachain!($name);
$crate::__impl_test_ext_for_parachain!($name, $genesis, $on_init);
$crate::__impl_test_ext_for_parachain!($name, $genesis, $on_init, $all_pallets);
)+
};
}
Expand Down Expand Up @@ -515,13 +525,13 @@ macro_rules! __impl_xcm_handlers_for_parachain {
#[macro_export]
macro_rules! __impl_test_ext_for_parachain {
// entry point: generate ext name
($name:ident, $genesis:expr, $on_init:expr) => {
($name:ident, $genesis:expr, $on_init:expr, $all_pallets:path) => {
$crate::paste::paste! {
$crate::__impl_test_ext_for_parachain!(@impl $name, $genesis, $on_init, [<EXT_ $name:upper>]);
$crate::__impl_test_ext_for_parachain!(@impl $name, $genesis, $on_init, $all_pallets, [<EXT_ $name:upper>]);
}
};
// impl
(@impl $name:ident, $genesis:expr, $on_init:expr, $ext_name:ident) => {
(@impl $name:ident, $genesis:expr, $on_init:expr, $all_pallets:path, $ext_name:ident) => {
thread_local! {
pub static $ext_name: $crate::RefCell<$crate::sp_io::TestExternalities>
= $crate::RefCell::new(<$name>::build_new_ext($genesis));
Expand Down Expand Up @@ -553,16 +563,26 @@ macro_rules! __impl_test_ext_for_parachain {
// Make sure the Network is initialized
<$name>::init();

// Set new relay block number
let mut relay_block_number = <$name>::relay_block_number();
relay_block_number += 1;
<$name>::set_relay_block_number(relay_block_number);
relay_block_number = <$name>::relay_block_number();

// Make sure pallets hooks are executed
$ext_name.with(|v| {
v.borrow_mut().execute_with(|| {
let relay_block_number = <$name>::relay_block_number();
<$all_pallets as $crate::OnInitialize<u32>>::on_initialize(relay_block_number);
})
});

let para_id = <$name>::para_id().into();

$ext_name.with(|v| {
v.borrow_mut().execute_with(|| {
// Make sure it has been recorded properly
let relay_block_number = <$name>::relay_block_number();
// let relay_block_number = <$name>::relay_block_number();
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
let _ = <Self as Parachain>::ParachainSystem::set_validation_data(
<Self as Parachain>::RuntimeOrigin::none(),
<$name>::hrmp_channel_parachain_inherent_data(para_id, relay_block_number),
Expand Down