[xcm-emulator] Chains generic over Network & Integration tests restructure (#2092)

Closes:
- #1383 
- Declared chains can be now be imported and reused in a different
crate.
- Chain declaration are now generic over a generic type `N` (the
Network)
- #1389
- Solved #1383, chains and networks declarations can be restructure to
avoid having to compile all chains when running integrations tests where
are not needed.
- Chains are now declared on its own crate (removed from
`integration-tests-common`)
- Networks are now declared on its own crate (removed from
`integration-tests-common`)
    - Integration tests will import only the relevant Network crate
- `integration-tests-common` is renamed to
`emulated-integration-tests-common`

All this is necessary to be able to implement what is described here:
https://github.com/paritytech/roadmap/issues/56#issuecomment-1777010553

---------

Co-authored-by: command-bot <>
This commit is contained in:
Ignacio Palacios
2023-11-08 16:02:03 +01:00
committed by GitHub
parent 50390950d8
commit ffa0e30e58
79 changed files with 2674 additions and 2750 deletions
+125 -109
View File
@@ -170,30 +170,21 @@ pub trait Network {
relay_parent_number: u32,
parent_head_data: HeadData,
) -> ParachainInherentData;
}
pub trait NetworkComponent {
type Network: Network;
fn send_horizontal_messages<I: Iterator<Item = (ParaId, RelayBlockNumber, Vec<u8>)>>(
to_para_id: u32,
iter: I,
) {
HORIZONTAL_MESSAGES.with(|b| {
b.borrow_mut()
.get_mut(Self::Network::name())
.get_mut(Self::name())
.unwrap()
.push_back((to_para_id, iter.collect()))
});
}
fn send_upward_message(from_para_id: u32, msg: Vec<u8>) {
UPWARD_MESSAGES.with(|b| {
b.borrow_mut()
.get_mut(Self::Network::name())
.unwrap()
.push_back((from_para_id, msg))
});
UPWARD_MESSAGES
.with(|b| b.borrow_mut().get_mut(Self::name()).unwrap().push_back((from_para_id, msg)));
}
fn send_downward_messages(
@@ -202,19 +193,19 @@ pub trait NetworkComponent {
) {
DOWNWARD_MESSAGES.with(|b| {
b.borrow_mut()
.get_mut(Self::Network::name())
.get_mut(Self::name())
.unwrap()
.push_back((to_para_id, iter.collect()))
});
}
fn send_bridged_messages(msg: BridgeMessage) {
BRIDGED_MESSAGES
.with(|b| b.borrow_mut().get_mut(Self::Network::name()).unwrap().push_back(msg));
BRIDGED_MESSAGES.with(|b| b.borrow_mut().get_mut(Self::name()).unwrap().push_back(msg));
}
}
pub trait Chain: TestExt + NetworkComponent {
pub trait Chain: TestExt {
type Network: Network;
type Runtime: SystemConfig;
type RuntimeCall;
type RuntimeOrigin;
@@ -234,6 +225,8 @@ pub trait RelayChain: Chain {
type SovereignAccountOf: ConvertLocation<AccountIdOf<Self::Runtime>>;
type MessageProcessor: ProcessMessage<Origin = ParaId> + ServiceQueues;
fn init();
fn child_location_of(id: ParaId) -> MultiLocation {
(Ancestor(0), ParachainJunction(id.into())).into()
}
@@ -348,7 +341,6 @@ macro_rules! decl_test_relay_chains {
on_init = $on_init:expr,
runtime = $runtime:ident,
core = {
MessageProcessor: $mp:path,
SovereignAccountOf: $sovereign_acc_of:path,
},
pallets = {
@@ -361,9 +353,10 @@ macro_rules! decl_test_relay_chains {
) => {
$(
#[derive(Clone)]
pub struct $name;
pub struct $name<N>($crate::PhantomData<N>);
impl $crate::Chain for $name {
impl<N: $crate::Network> $crate::Chain for $name<N> {
type Network = N;
type Runtime = $runtime::Runtime;
type RuntimeCall = $runtime::RuntimeCall;
type RuntimeOrigin = $runtime::RuntimeOrigin;
@@ -382,27 +375,35 @@ macro_rules! decl_test_relay_chains {
}
}
impl $crate::RelayChain for $name {
impl<N: $crate::Network> $crate::RelayChain for $name<N> {
type SovereignAccountOf = $sovereign_acc_of;
type MessageProcessor = $mp;
type MessageProcessor = $crate::DefaultRelayMessageProcessor<$name<N>>;
fn init() {
use $crate::TestExt;
// Initialize the thread local variable
$crate::paste::paste! {
[<LOCAL_EXT_ $name:upper>].with(|v| *v.borrow_mut() = Self::build_new_ext($genesis));
}
}
}
$crate::paste::paste! {
pub trait [<$name Pallet>] {
pub trait [<$name RelayPallet>] {
$(
type $pallet_name;
)?
}
impl [<$name Pallet>] for $name {
impl<N: $crate::Network> [<$name RelayPallet>] for $name<N> {
$(
type $pallet_name = $pallet_path;
)?
}
}
$crate::__impl_test_ext_for_relay_chain!($name, $genesis, $on_init, $api_version);
$crate::__impl_check_assertion!($name);
$crate::__impl_test_ext_for_relay_chain!($name, N, $genesis, $on_init, $api_version);
$crate::__impl_check_assertion!($name, N);
)+
};
}
@@ -410,10 +411,11 @@ macro_rules! decl_test_relay_chains {
#[macro_export]
macro_rules! __impl_test_ext_for_relay_chain {
// entry point: generate ext name
($name:ident, $genesis:expr, $on_init:expr, $api_version:tt) => {
($name:ident, $network:ident, $genesis:expr, $on_init:expr, $api_version:tt) => {
$crate::paste::paste! {
$crate::__impl_test_ext_for_relay_chain!(
@impl $name,
$network,
$genesis,
$on_init,
[<ParachainHostV $api_version>],
@@ -423,10 +425,10 @@ macro_rules! __impl_test_ext_for_relay_chain {
}
};
// impl
(@impl $name:ident, $genesis:expr, $on_init:expr, $api_version:ident, $local_ext:ident, $global_ext:ident) => {
(@impl $name:ident, $network:ident, $genesis:expr, $on_init:expr, $api_version:ident, $local_ext:ident, $global_ext:ident) => {
thread_local! {
pub static $local_ext: $crate::RefCell<$crate::TestExternalities>
= $crate::RefCell::new(<$name as $crate::TestExt>::build_new_ext($genesis));
= $crate::RefCell::new($crate::TestExternalities::new($genesis));
}
$crate::lazy_static! {
@@ -434,9 +436,9 @@ macro_rules! __impl_test_ext_for_relay_chain {
= $crate::Mutex::new($crate::RefCell::new($crate::HashMap::new()));
}
impl $crate::TestExt for $name {
impl<$network: $crate::Network> $crate::TestExt for $name<$network> {
fn build_new_ext(storage: $crate::Storage) -> $crate::TestExternalities {
use $crate::{sp_tracing, NetworkComponent, Network, Chain, TestExternalities};
use $crate::{sp_tracing, Network, Chain, TestExternalities};
let mut ext = TestExternalities::new(storage);
@@ -453,7 +455,7 @@ macro_rules! __impl_test_ext_for_relay_chain {
}
fn new_ext() -> $crate::TestExternalities {
<$name>::build_new_ext($genesis)
Self::build_new_ext($genesis)
}
fn move_ext_out(id: &'static str) {
@@ -504,13 +506,13 @@ macro_rules! __impl_test_ext_for_relay_chain {
}
fn reset_ext() {
$local_ext.with(|v| *v.borrow_mut() = <$name>::build_new_ext($genesis));
$local_ext.with(|v| *v.borrow_mut() = Self::build_new_ext($genesis));
}
fn execute_with<R>(execute: impl FnOnce() -> R) -> R {
use $crate::{Chain, NetworkComponent, Network};
use $crate::{Chain, Network};
// Make sure the Network is initialized
<$name as NetworkComponent>::Network::init();
<$network>::init();
// Execute
let r = $local_ext.with(|v| v.borrow_mut().execute_with(execute));
@@ -521,7 +523,7 @@ macro_rules! __impl_test_ext_for_relay_chain {
use $crate::polkadot_primitives::runtime_api::runtime_decl_for_parachain_host::$api_version;
//TODO: mark sent count & filter out sent msg
for para_id in<$name as NetworkComponent>::Network::para_ids() {
for para_id in <$network>::para_ids() {
// downward messages
let downward_messages = <Self as $crate::Chain>::Runtime::dmq_contents(para_id.into())
.into_iter()
@@ -529,7 +531,7 @@ macro_rules! __impl_test_ext_for_relay_chain {
if downward_messages.len() == 0 {
continue;
}
<$name>::send_downward_messages(para_id, downward_messages.into_iter());
<$network>::send_downward_messages(para_id, downward_messages.into_iter());
// Note: no need to handle horizontal messages, as the
// simulator directly sends them to dest (not relayed).
@@ -545,7 +547,7 @@ macro_rules! __impl_test_ext_for_relay_chain {
})
});
<$name as NetworkComponent>::Network::process_messages();
<$network>::process_messages();
r
}
@@ -574,7 +576,7 @@ macro_rules! decl_test_parachains {
XcmpMessageHandler: $xcmp_message_handler:path,
LocationToAccountId: $location_to_account:path,
ParachainInfo: $parachain_info:path,
MessageProcessor: $message_processor:path,
// MessageProcessor: $message_processor:path,
},
pallets = {
$($pallet_name:ident: $pallet_path:path,)*
@@ -586,14 +588,15 @@ macro_rules! decl_test_parachains {
) => {
$(
#[derive(Clone)]
pub struct $name;
pub struct $name<N>($crate::PhantomData<N>);
impl $crate::Chain for $name {
impl<N: $crate::Network> $crate::Chain for $name<N> {
type Runtime = $runtime::Runtime;
type RuntimeCall = $runtime::RuntimeCall;
type RuntimeOrigin = $runtime::RuntimeOrigin;
type RuntimeEvent = $runtime::RuntimeEvent;
type System = $crate::SystemPallet::<Self::Runtime>;
type Network = N;
fn account_data_of(account: $crate::AccountIdOf<Self::Runtime>) -> $crate::AccountData<$crate::Balance> {
<Self as $crate::TestExt>::ext_wrapper(|| $crate::SystemPallet::<Self::Runtime>::account(account).data.into())
@@ -607,17 +610,21 @@ macro_rules! decl_test_parachains {
}
}
impl $crate::Parachain for $name {
impl<N: $crate::Network> $crate::Parachain for $name<N> {
type XcmpMessageHandler = $xcmp_message_handler;
type LocationToAccountId = $location_to_account;
type ParachainSystem = $crate::ParachainSystemPallet<<Self as $crate::Chain>::Runtime>;
type ParachainInfo = $parachain_info;
type MessageProcessor = $message_processor;
type MessageProcessor = $crate::DefaultParaMessageProcessor<$name<N>>;
// We run an empty block during initialisation to open HRMP channels
// and have them ready for the next block
fn init() {
use $crate::{Chain, HeadData, Network, NetworkComponent, Hooks, Encode, Parachain, TestExt};
use $crate::{Chain, HeadData, Network, Hooks, Encode, Parachain, TestExt};
// Initialize the thread local variable
$crate::paste::paste! {
[<LOCAL_EXT_ $name:upper>].with(|v| *v.borrow_mut() = Self::build_new_ext($genesis));
}
// Set the last block head for later use in the next block
Self::set_last_head();
// Initialize a new block
@@ -627,21 +634,21 @@ macro_rules! decl_test_parachains {
}
fn new_block() {
use $crate::{Chain, HeadData, Network, NetworkComponent, Hooks, Encode, Parachain, TestExt};
use $crate::{Chain, HeadData, Network, Hooks, Encode, Parachain, TestExt};
let para_id = Self::para_id().into();
Self::ext_wrapper(|| {
// Increase Relay Chain block number
let mut relay_block_number = <$name as NetworkComponent>::Network::relay_block_number();
let mut relay_block_number = N::relay_block_number();
relay_block_number += 1;
<$name as NetworkComponent>::Network::set_relay_block_number(relay_block_number);
N::set_relay_block_number(relay_block_number);
// Initialize a new Parachain block
let mut block_number = <Self as Chain>::System::block_number();
block_number += 1;
let parent_head_data = $crate::LAST_HEAD.with(|b| b.borrow_mut()
.get_mut(<Self as NetworkComponent>::Network::name())
.get_mut(N::name())
.expect("network not initialized?")
.get(&para_id)
.expect("network not initialized?")
@@ -652,13 +659,13 @@ macro_rules! decl_test_parachains {
let _ = <Self as Parachain>::ParachainSystem::set_validation_data(
<Self as Chain>::RuntimeOrigin::none(),
<$name as NetworkComponent>::Network::hrmp_channel_parachain_inherent_data(para_id, relay_block_number, parent_head_data),
N::hrmp_channel_parachain_inherent_data(para_id, relay_block_number, parent_head_data),
);
});
}
fn finalize_block() {
use $crate::{Chain, Encode, Hooks, Network, NetworkComponent, Parachain, TestExt};
use $crate::{Chain, Encode, Hooks, Network, Parachain, TestExt};
Self::ext_wrapper(|| {
let block_number = <Self as Chain>::System::block_number();
@@ -670,7 +677,7 @@ macro_rules! decl_test_parachains {
fn set_last_head() {
use $crate::{Chain, Encode, HeadData, Network, NetworkComponent, Parachain, TestExt};
use $crate::{Chain, Encode, HeadData, Network, Parachain, TestExt};
let para_id = Self::para_id().into();
@@ -678,7 +685,7 @@ macro_rules! decl_test_parachains {
// Store parent head data for use later.
let created_header = <Self as Chain>::System::finalize();
$crate::LAST_HEAD.with(|b| b.borrow_mut()
.get_mut(<Self as NetworkComponent>::Network::name())
.get_mut(N::name())
.expect("network not initialized?")
.insert(para_id, HeadData(created_header.encode()))
);
@@ -687,21 +694,21 @@ macro_rules! decl_test_parachains {
}
$crate::paste::paste! {
pub trait [<$name Pallet>] {
pub trait [<$name ParaPallet>] {
$(
type $pallet_name;
)*
}
impl [<$name Pallet>] for $name {
impl<N: $crate::Network> [<$name ParaPallet>] for $name<N> {
$(
type $pallet_name = $pallet_path;
)*
}
}
$crate::__impl_test_ext_for_parachain!($name, $genesis, $on_init);
$crate::__impl_check_assertion!($name);
$crate::__impl_test_ext_for_parachain!($name, N, $genesis, $on_init);
$crate::__impl_check_assertion!($name, N);
)+
};
}
@@ -709,16 +716,16 @@ macro_rules! decl_test_parachains {
#[macro_export]
macro_rules! __impl_test_ext_for_parachain {
// entry point: generate ext name
($name:ident, $genesis:expr, $on_init:expr) => {
($name:ident, $network:ident, $genesis:expr, $on_init:expr) => {
$crate::paste::paste! {
$crate::__impl_test_ext_for_parachain!(@impl $name, $genesis, $on_init, [<LOCAL_EXT_ $name:upper>], [<GLOBAL_EXT_ $name:upper>]);
$crate::__impl_test_ext_for_parachain!(@impl $name, $network, $genesis, $on_init, [<LOCAL_EXT_ $name:upper>], [<GLOBAL_EXT_ $name:upper>]);
}
};
// impl
(@impl $name:ident, $genesis:expr, $on_init:expr, $local_ext:ident, $global_ext:ident) => {
(@impl $name:ident, $network:ident, $genesis:expr, $on_init:expr, $local_ext:ident, $global_ext:ident) => {
thread_local! {
pub static $local_ext: $crate::RefCell<$crate::TestExternalities>
= $crate::RefCell::new(<$name as $crate::TestExt>::build_new_ext($genesis));
= $crate::RefCell::new($crate::TestExternalities::new($genesis));
}
$crate::lazy_static! {
@@ -726,7 +733,7 @@ macro_rules! __impl_test_ext_for_parachain {
= $crate::Mutex::new($crate::RefCell::new($crate::HashMap::new()));
}
impl $crate::TestExt for $name {
impl<$network: $crate::Network> $crate::TestExt for $name<$network> {
fn build_new_ext(storage: $crate::Storage) -> $crate::TestExternalities {
let mut ext = $crate::TestExternalities::new(storage);
@@ -743,7 +750,7 @@ macro_rules! __impl_test_ext_for_parachain {
}
fn new_ext() -> $crate::TestExternalities {
<$name>::build_new_ext($genesis)
Self::build_new_ext($genesis)
}
fn move_ext_out(id: &'static str) {
@@ -794,14 +801,14 @@ macro_rules! __impl_test_ext_for_parachain {
}
fn reset_ext() {
$local_ext.with(|v| *v.borrow_mut() = <$name>::build_new_ext($genesis));
$local_ext.with(|v| *v.borrow_mut() = Self::build_new_ext($genesis));
}
fn execute_with<R>(execute: impl FnOnce() -> R) -> R {
use $crate::{Chain, Get, Hooks, NetworkComponent, Network, Parachain, Encode};
use $crate::{Chain, Get, Hooks, Network, Parachain, Encode};
// Make sure the Network is initialized
<$name as NetworkComponent>::Network::init();
<$network>::init();
// Initialize a new block
Self::new_block();
@@ -812,7 +819,7 @@ macro_rules! __impl_test_ext_for_parachain {
// Finalize the block
Self::finalize_block();
let para_id = <$name>::para_id().into();
let para_id = Self::para_id().into();
// Send messages if needed
$local_ext.with(|v| {
@@ -828,27 +835,27 @@ macro_rules! __impl_test_ext_for_parachain {
let collation_info = <Self as Parachain>::ParachainSystem::collect_collation_info(&mock_header);
// send upward messages
let relay_block_number = <$name as NetworkComponent>::Network::relay_block_number();
let relay_block_number = <$network>::relay_block_number();
for msg in collation_info.upward_messages.clone() {
<$name>::send_upward_message(para_id, msg);
<$network>::send_upward_message(para_id, msg);
}
// send horizontal messages
for msg in collation_info.horizontal_messages {
<$name>::send_horizontal_messages(
<$network>::send_horizontal_messages(
msg.recipient.into(),
vec![(para_id.into(), relay_block_number, msg.data)].into_iter(),
);
}
// get bridge messages
type NetworkBridge = <<$name as NetworkComponent>::Network as $crate::Network>::Bridge;
type NetworkBridge<$network> = <$network as $crate::Network>::Bridge;
let bridge_messages = <<NetworkBridge as $crate::Bridge>::Handler as $crate::BridgeMessageHandler>::get_source_outbound_messages();
let bridge_messages = <<NetworkBridge<$network> as $crate::Bridge>::Handler as $crate::BridgeMessageHandler>::get_source_outbound_messages();
// send bridged messages
for msg in bridge_messages {
<$name>::send_bridged_messages(msg);
<$network>::send_bridged_messages(msg);
}
// log events
@@ -864,7 +871,7 @@ macro_rules! __impl_test_ext_for_parachain {
// provide inbound DMP/HRMP messages through a side-channel.
// normally this would come through the `set_validation_data`,
// but we go around that.
<$name as NetworkComponent>::Network::process_messages();
<$network>::process_messages();
r
}
@@ -886,8 +893,8 @@ macro_rules! decl_test_networks {
(
$(
pub struct $name:ident {
relay_chain = $relay_chain:ty,
parachains = vec![ $( $parachain:ty, )* ],
relay_chain = $relay_chain:ident,
parachains = vec![ $( $parachain:ident, )* ],
bridge = $bridge:ty
}
),
@@ -895,10 +902,11 @@ macro_rules! decl_test_networks {
$(,)?
) => {
$(
#[derive(Clone)]
pub struct $name;
impl $crate::Network for $name {
type Relay = $relay_chain;
type Relay = $relay_chain<Self>;
type Bridge = $bridge;
fn name() -> &'static str {
@@ -916,8 +924,8 @@ macro_rules! decl_test_networks {
$crate::BRIDGED_MESSAGES.with(|b| b.borrow_mut().remove(Self::name()));
$crate::LAST_HEAD.with(|b| b.borrow_mut().remove(Self::name()));
<$relay_chain>::reset_ext();
$( <$parachain>::reset_ext(); )*
<$relay_chain<Self>>::reset_ext();
$( <$parachain<Self>>::reset_ext(); )*
}
fn init() {
@@ -932,13 +940,14 @@ macro_rules! decl_test_networks {
$crate::PARA_IDS.with(|b| b.borrow_mut().insert(Self::name().to_string(), Self::para_ids()));
$crate::LAST_HEAD.with(|b| b.borrow_mut().insert(Self::name().to_string(), $crate::HashMap::new()));
$( <$parachain as $crate::Parachain>::init(); )*
<$relay_chain<Self> as $crate::RelayChain>::init();
$( <$parachain<Self> as $crate::Parachain>::init(); )*
}
}
fn para_ids() -> Vec<u32> {
vec![$(
<$parachain as $crate::Parachain>::para_id().into(),
<$parachain<Self> as $crate::Parachain>::para_id().into(),
)*]
}
@@ -976,7 +985,7 @@ macro_rules! decl_test_networks {
while let Some((to_para_id, messages))
= $crate::DOWNWARD_MESSAGES.with(|b| b.borrow_mut().get_mut(Self::name()).unwrap().pop_front()) {
$(
let para_id: u32 = <$parachain>::para_id().into();
let para_id: u32 = <$parachain<Self>>::para_id().into();
if $crate::PARA_IDS.with(|b| b.borrow_mut().get_mut(Self::name()).unwrap().contains(&to_para_id)) && para_id == to_para_id {
let mut msg_dedup: Vec<(RelayChainBlockNumber, Vec<u8>)> = Vec::new();
@@ -986,21 +995,21 @@ macro_rules! decl_test_networks {
msg_dedup.dedup();
let msgs = msg_dedup.clone().into_iter().filter(|m| {
!$crate::DMP_DONE.with(|b| b.borrow().get(stringify!($name))
!$crate::DMP_DONE.with(|b| b.borrow().get(Self::name())
.unwrap_or(&mut $crate::VecDeque::new())
.contains(&(to_para_id, m.0, m.1.clone()))
)
}).collect::<Vec<(RelayChainBlockNumber, Vec<u8>)>>();
use $crate::{ProcessMessage, CumulusAggregateMessageOrigin, BoundedSlice, WeightMeter, TestExt};
use $crate::{ProcessMessage, CumulusAggregateMessageOrigin, BoundedSlice, WeightMeter};
for (block, msg) in msgs.clone().into_iter() {
let mut weight_meter = WeightMeter::new();
<$parachain>::ext_wrapper(|| {
let _ = <$parachain as Parachain>::MessageProcessor::process_message(
<$parachain<Self>>::ext_wrapper(|| {
let _ = <$parachain<Self> as Parachain>::MessageProcessor::process_message(
&msg[..],
$crate::CumulusAggregateMessageOrigin::Parent,
&mut weight_meter,
&mut msg.using_encoded(sp_core::blake2_256),
&mut msg.using_encoded($crate::blake2_256),
);
});
$crate::log::debug!(target: concat!("dmp::", stringify!($name)) , "DMP messages processed {:?} to para_id {:?}", msgs.clone(), &to_para_id);
@@ -1012,19 +1021,19 @@ macro_rules! decl_test_networks {
}
fn process_horizontal_messages() {
use $crate::{XcmpMessageHandler, ServiceQueues, Bounded};
use $crate::{XcmpMessageHandler, ServiceQueues, Bounded, Parachain, TestExt};
while let Some((to_para_id, messages))
= $crate::HORIZONTAL_MESSAGES.with(|b| b.borrow_mut().get_mut(Self::name()).unwrap().pop_front()) {
let iter = messages.iter().map(|(p, b, m)| (*p, *b, &m[..])).collect::<Vec<_>>().into_iter();
$(
let para_id: u32 = <$parachain>::para_id().into();
let para_id: u32 = <$parachain<Self>>::para_id().into();
if $crate::PARA_IDS.with(|b| b.borrow_mut().get_mut(Self::name()).unwrap().contains(&to_para_id)) && para_id == to_para_id {
<$parachain>::ext_wrapper(|| {
<$parachain as Parachain>::XcmpMessageHandler::handle_xcmp_messages(iter.clone(), $crate::Weight::MAX);
<$parachain<Self>>::ext_wrapper(|| {
<$parachain<Self> as Parachain>::XcmpMessageHandler::handle_xcmp_messages(iter.clone(), $crate::Weight::MAX);
// Nudge the MQ pallet to process immediately instead of in the next block.
let _ = <$parachain as Parachain>::MessageProcessor::service_queues($crate::Weight::MAX);
let _ = <$parachain<Self> as Parachain>::MessageProcessor::service_queues($crate::Weight::MAX);
});
$crate::log::debug!(target: concat!("hrmp::", stringify!($name)) , "HRMP messages processed {:?} to para_id {:?}", &messages, &to_para_id);
}
@@ -1037,8 +1046,8 @@ macro_rules! decl_test_networks {
while let Some((from_para_id, msg)) = $crate::UPWARD_MESSAGES.with(|b| b.borrow_mut().get_mut(Self::name()).unwrap().pop_front()) {
let mut weight_meter = WeightMeter::new();
<$relay_chain>::ext_wrapper(|| {
let _ = <$relay_chain as $crate::RelayChain>::MessageProcessor::process_message(
<$relay_chain<Self>>::ext_wrapper(|| {
let _ = <$relay_chain<Self> as $crate::RelayChain>::MessageProcessor::process_message(
&msg[..],
from_para_id.into(),
&mut weight_meter,
@@ -1121,13 +1130,13 @@ macro_rules! decl_test_networks {
}
}
impl $crate::NetworkComponent for $relay_chain {
type Network = $name;
$crate::paste::paste! {
pub type [<$relay_chain Relay>] = $relay_chain<$name>;
}
$(
impl $crate::NetworkComponent for $parachain {
type Network = $name;
$crate::paste::paste! {
pub type [<$parachain Para>] = $parachain<$name>;
}
)*
)+
@@ -1139,9 +1148,9 @@ macro_rules! decl_test_bridges {
(
$(
pub struct $name:ident {
source = $source:ty,
target = $target:ty,
handler = $handler:ty
source = $source:ident,
target = $target:ident,
handler = $handler:ident
}
),
+
@@ -1157,10 +1166,10 @@ macro_rules! decl_test_bridges {
type Handler = $handler;
fn init() {
use $crate::{NetworkComponent, Network};
use $crate::{Network, Parachain};
// Make sure source and target `Network` have been initialized
<$source as NetworkComponent>::Network::init();
<$target as NetworkComponent>::Network::init();
<$source as Chain>::Network::init();
<$target as Chain>::Network::init();
}
}
)+
@@ -1169,10 +1178,11 @@ macro_rules! decl_test_bridges {
#[macro_export]
macro_rules! __impl_check_assertion {
($chain:ident) => {
impl<Origin, Destination, Hops, Args>
$crate::CheckAssertion<Origin, Destination, Hops, Args> for $chain
($chain:ident, $network:ident) => {
impl<$network, Origin, Destination, Hops, Args>
$crate::CheckAssertion<Origin, Destination, Hops, Args> for $chain<$network>
where
$network: $crate::Network,
Origin: $crate::Chain + Clone,
Destination: $crate::Chain + Clone,
Origin::RuntimeOrigin:
@@ -1185,9 +1195,9 @@ macro_rules! __impl_check_assertion {
fn check_assertion(test: $crate::Test<Origin, Destination, Hops, Args>) {
use $crate::TestExt;
let chain_name = std::any::type_name::<$chain>();
let chain_name = std::any::type_name::<$chain<$network>>();
<$chain>::execute_with(|| {
<$chain<$network>>::execute_with(|| {
if let Some(dispatchable) = test.hops_dispatchable.get(chain_name) {
$crate::assert_ok!(dispatchable(test.clone()));
}
@@ -1213,7 +1223,6 @@ macro_rules! assert_expected_events {
let mut event_message: Vec<String> = Vec::new();
for (index, event) in events.iter().enumerate() {
$crate::log::debug!(target: concat!("events::", stringify!($chain)), "{:?}", event);
// Have to reset the variable to override a previous partial match
meet_conditions = true;
match event {
@@ -1259,7 +1268,14 @@ macro_rules! assert_expected_events {
)
);
} else if !event_received {
message.push(format!("\n\n{}::\x1b[31m{}\x1b[0m was never received. All events:\n{:#?}", stringify!($chain), stringify!($event_pat), <$chain>::events()));
message.push(
format!(
"\n\n{}::\x1b[31m{}\x1b[0m was never received. All events:\n{:#?}",
stringify!($chain),
stringify!($event_pat),
<$chain as $crate::Chain>::events(),
)
);
} else {
// If we find a perfect match we remove the event to avoid being potentially assessed multiple times
events.remove(index_match);