diff --git a/runtime/dancebox/src/tests/common/xcm/core_buyer.rs b/runtime/dancebox/src/tests/common/xcm/core_buyer.rs index 1cdb011c7..9e7cc0d1f 100644 --- a/runtime/dancebox/src/tests/common/xcm/core_buyer.rs +++ b/runtime/dancebox/src/tests/common/xcm/core_buyer.rs @@ -16,7 +16,6 @@ use { crate::{ - assert_expected_events, tests::common::xcm::{ core_buyer_common::*, mocknets::{DanceboxRococoPara as Dancebox, RococoRelay as Rococo, RococoRelayPallet}, @@ -26,7 +25,7 @@ use { polkadot_runtime_parachains::on_demand as parachains_assigner_on_demand, staging_xcm::latest::{MaybeErrorCode, Response}, tp_traits::ParaId, - xcm_emulator::Chain, + xcm_emulator::{Chain, assert_expected_events}, }; const PARATHREAD_ID: u32 = 3333; diff --git a/runtime/dancebox/src/tests/common/xcm/core_buyer_common.rs b/runtime/dancebox/src/tests/common/xcm/core_buyer_common.rs index 8562b5784..ccd622861 100644 --- a/runtime/dancebox/src/tests/common/xcm/core_buyer_common.rs +++ b/runtime/dancebox/src/tests/common/xcm/core_buyer_common.rs @@ -16,7 +16,6 @@ use { crate::{ - assert_expected_events, tests::common::{ empty_genesis_data, run_to_session, set_dummy_boot_node, start_block, xcm::{ @@ -42,7 +41,7 @@ use { staging_xcm::v3::QueryId, staging_xcm_executor::traits::ConvertLocation, tp_traits::{ParaId, SlotFrequency}, - xcm_emulator::{Chain, RelayChain}, + xcm_emulator::{assert_expected_events, Chain, RelayChain}, }; pub const PARATHREAD_ID: u32 = 3333; diff --git a/runtime/dancebox/src/tests/common/xcm/delivery_fees.rs b/runtime/dancebox/src/tests/common/xcm/delivery_fees.rs index e4688730f..00f506f78 100644 --- a/runtime/dancebox/src/tests/common/xcm/delivery_fees.rs +++ b/runtime/dancebox/src/tests/common/xcm/delivery_fees.rs @@ -16,7 +16,6 @@ use { crate::{ - assert_expected_events, tests::common::xcm::{ mocknets::{ DanceboxPara as Dancebox, DanceboxParaPallet, DanceboxSender, @@ -33,7 +32,7 @@ use { latest::prelude::{Junctions::X1, *}, VersionedLocation, VersionedXcm, }, - xcm_emulator::Chain, + xcm_emulator::{Chain, assert_expected_events}, }; #[test] diff --git a/runtime/dancebox/src/tests/common/xcm/expected_event_checker.rs b/runtime/dancebox/src/tests/common/xcm/expected_event_checker.rs deleted file mode 100644 index 8d387aef7..000000000 --- a/runtime/dancebox/src/tests/common/xcm/expected_event_checker.rs +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (C) Moondance Labs Ltd. -// This file is part of Tanssi. - -// Tanssi is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Tanssi is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Tanssi. If not, see - -#[macro_export] -macro_rules! assert_expected_events { - ( $chain:ident, vec![$( $event_pat:pat => { $($attr:ident : $condition:expr, )* }, )*] ) => { - let mut message: Vec = Vec::new(); - let mut events = <$chain as xcm_emulator::Chain>::events(); - - $( - let mut event_received = false; - let mut meet_conditions = true; - let mut index_match = 0; - let mut event_message: Vec = Vec::new(); - - for (index, event) in events.iter().enumerate() { - // Variable to record current event's meet conditions - #[allow(unused_mut)] // To suppress warning in case no conditions are declared - let mut current_event_meet_conditions = true; - match event { - $event_pat => { - event_received = true; - - #[allow(unused_mut)] // To suppress warning in case no conditions are declared - let mut conditions_message: Vec = Vec::new(); - - $( - // We only want to record condition error messages in case it did not happened before - // Only the first partial match is recorded - if !$condition && event_message.is_empty() { - conditions_message.push( - format!( - " - The attribute {:?} = {:?} did not met the condition {:?}\n", - stringify!($attr), - $attr, - stringify!($condition) - ) - ); - } - current_event_meet_conditions &= $condition; - )* - - // Set the variable to latest matched event's condition evaluation result - meet_conditions = current_event_meet_conditions; - - // Set the index where we found a perfect match - if event_received && meet_conditions { - index_match = index; - break; - } else { - event_message.extend(conditions_message); - } - }, - _ => {} - } - } - - if event_received && !meet_conditions { - message.push( - format!( - "\n\n{}::\x1b[31m{}\x1b[0m was received but some of its attributes did not meet the conditions:\n{}", - stringify!($chain), - stringify!($event_pat), - event_message.concat() - ) - ); - } 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 as xcm_emulator::Chain>::events(), - ) - ); - } else { - // If we find a perfect match we remove the event to avoid being potentially assessed multiple times - events.remove(index_match); - } - )* - - if !message.is_empty() { - // Log events as they will not be logged after the panic - <$chain as xcm_emulator::Chain>::events().iter().for_each(|event| { - log::debug!(target: concat!("events::", stringify!($chain)), "{:?}", event); - }); - panic!("{}", message.concat()) - } - } -} diff --git a/runtime/dancebox/src/tests/common/xcm/force_core_buyer.rs b/runtime/dancebox/src/tests/common/xcm/force_core_buyer.rs index e0c10e39f..c2d944ce5 100644 --- a/runtime/dancebox/src/tests/common/xcm/force_core_buyer.rs +++ b/runtime/dancebox/src/tests/common/xcm/force_core_buyer.rs @@ -16,7 +16,6 @@ use { crate::{ - assert_expected_events, tests::common::xcm::{ core_buyer_common::*, mocknets::{DanceboxRococoPara as Dancebox, RococoRelay as Rococo, RococoRelayPallet}, @@ -26,7 +25,7 @@ use { polkadot_runtime_parachains::on_demand as parachains_assigner_on_demand, staging_xcm::latest::{MaybeErrorCode, Response}, tp_traits::ParaId, - xcm_emulator::Chain, + xcm_emulator::{Chain, assert_expected_events}, }; #[test] diff --git a/runtime/dancebox/src/tests/common/xcm/foreign_signed_based_sovereign.rs b/runtime/dancebox/src/tests/common/xcm/foreign_signed_based_sovereign.rs index 05f4252d0..e730a1bdf 100644 --- a/runtime/dancebox/src/tests/common/xcm/foreign_signed_based_sovereign.rs +++ b/runtime/dancebox/src/tests/common/xcm/foreign_signed_based_sovereign.rs @@ -16,7 +16,6 @@ use { crate::{ - assert_expected_events, tests::common::xcm::{ mocknets::{ DanceboxEmptyReceiver, DanceboxPara as Dancebox, DanceboxParaPallet, @@ -38,7 +37,7 @@ use { VersionedLocation, VersionedXcm, }, staging_xcm_executor::traits::ConvertLocation, - xcm_emulator::Chain, + xcm_emulator::{Chain, assert_expected_events}, }; #[test] diff --git a/runtime/dancebox/src/tests/common/xcm/foreign_sovereigns.rs b/runtime/dancebox/src/tests/common/xcm/foreign_sovereigns.rs index 5fd08df6f..df6b8a746 100644 --- a/runtime/dancebox/src/tests/common/xcm/foreign_sovereigns.rs +++ b/runtime/dancebox/src/tests/common/xcm/foreign_sovereigns.rs @@ -16,7 +16,6 @@ use { crate::{ - assert_expected_events, tests::common::xcm::{ mocknets::{ DanceboxPara as Dancebox, DanceboxParaPallet, EthereumEmptyReceiver, @@ -38,7 +37,7 @@ use { }, staging_xcm_executor::traits::ConvertLocation, westend_runtime_constants::currency::UNITS as WND, - xcm_emulator::Chain, + xcm_emulator::{Chain, assert_expected_events}, }; #[test] diff --git a/runtime/dancebox/src/tests/common/xcm/mod.rs b/runtime/dancebox/src/tests/common/xcm/mod.rs index f83881475..d105c8d76 100644 --- a/runtime/dancebox/src/tests/common/xcm/mod.rs +++ b/runtime/dancebox/src/tests/common/xcm/mod.rs @@ -32,9 +32,6 @@ mod token_derivative_reception_relay_simple_container; mod transact; mod trap; -#[macro_use] -mod expected_event_checker; - pub use { paste, xcm_emulator::{bx, Parachain as Para, RelayChain as Relay, TestExt}, diff --git a/runtime/dancebox/src/tests/common/xcm/reserver_transfers_polkadot_xcm.rs b/runtime/dancebox/src/tests/common/xcm/reserver_transfers_polkadot_xcm.rs index 7a8fac12d..0391513ed 100644 --- a/runtime/dancebox/src/tests/common/xcm/reserver_transfers_polkadot_xcm.rs +++ b/runtime/dancebox/src/tests/common/xcm/reserver_transfers_polkadot_xcm.rs @@ -15,17 +15,14 @@ // along with Tanssi. If not, see use { - crate::{ - assert_expected_events, - tests::common::xcm::{ - mocknets::{ - DanceboxPara as Dancebox, DanceboxParaPallet, DanceboxSender, - SimpleTemplateEmptyReceiver, SimpleTemplatePara as SimpleTemplate, - SimpleTemplateParaPallet, SimpleTemplateSender, WestendRelay as Westend, - WestendRelayPallet, WestendSender, - }, - *, + crate::tests::common::xcm::{ + mocknets::{ + DanceboxPara as Dancebox, DanceboxParaPallet, DanceboxSender, + SimpleTemplateEmptyReceiver, SimpleTemplatePara as SimpleTemplate, + SimpleTemplateParaPallet, SimpleTemplateSender, WestendRelay as Westend, + WestendRelayPallet, WestendSender, }, + *, }, frame_support::{ assert_noop, assert_ok, @@ -37,7 +34,7 @@ use { latest::prelude::{Junctions::*, *}, VersionedLocation, }, - xcm_emulator::Chain, + xcm_emulator::{assert_expected_events, Chain}, }; #[allow(unused_assignments)] diff --git a/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_container_dancebox.rs b/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_container_dancebox.rs index 00f7506b2..71fd6a916 100644 --- a/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_container_dancebox.rs +++ b/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_container_dancebox.rs @@ -16,7 +16,6 @@ use { crate::{ - assert_expected_events, tests::common::xcm::{ mocknets::{ DanceboxPara as Dancebox, DanceboxParaPallet, DanceboxReceiver, @@ -36,7 +35,7 @@ use { latest::prelude::{Junctions::*, *}, VersionedLocation, }, - xcm_emulator::Chain, + xcm_emulator::{Chain, assert_expected_events}, }; #[allow(unused_assignments)] diff --git a/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_dancebox_frontier_container.rs b/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_dancebox_frontier_container.rs index 11db2ac5a..356a4fcf3 100644 --- a/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_dancebox_frontier_container.rs +++ b/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_dancebox_frontier_container.rs @@ -15,15 +15,12 @@ // along with Tanssi. If not, see use { - crate::{ - assert_expected_events, - tests::common::xcm::{ - mocknets::{ - DanceboxPara as Dancebox, DanceboxParaPallet, DanceboxSender, EthereumReceiver, - FrontierTemplatePara as FrontierTemplate, FrontierTemplateParaPallet, - }, - *, + crate::tests::common::xcm::{ + mocknets::{ + DanceboxPara as Dancebox, DanceboxParaPallet, DanceboxSender, EthereumReceiver, + FrontierTemplatePara as FrontierTemplate, FrontierTemplateParaPallet, }, + *, }, frame_support::{ assert_ok, @@ -35,7 +32,7 @@ use { latest::prelude::{Junctions::*, *}, VersionedLocation, }, - xcm_emulator::Chain, + xcm_emulator::{assert_expected_events, Chain}, }; #[allow(unused_assignments)] diff --git a/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_dancebox_simple_container.rs b/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_dancebox_simple_container.rs index ee78f1344..88113ef6c 100644 --- a/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_dancebox_simple_container.rs +++ b/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_dancebox_simple_container.rs @@ -16,7 +16,6 @@ use { crate::{ - assert_expected_events, tests::common::xcm::{ mocknets::{ DanceboxPara as Dancebox, DanceboxParaPallet, DanceboxSender, @@ -36,7 +35,7 @@ use { latest::prelude::{Junctions::*, *}, VersionedLocation, }, - xcm_emulator::Chain, + xcm_emulator::{Chain, assert_expected_events}, }; #[allow(unused_assignments)] diff --git a/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_relay_dancebox.rs b/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_relay_dancebox.rs index ff6e7a9b5..5fe47a165 100644 --- a/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_relay_dancebox.rs +++ b/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_relay_dancebox.rs @@ -16,7 +16,6 @@ use { crate::{ - assert_expected_events, tests::common::xcm::{ mocknets::{ DanceboxPara as Dancebox, DanceboxParaPallet, DanceboxReceiver, @@ -34,7 +33,7 @@ use { latest::prelude::{Junctions::*, *}, VersionedLocation, }, - xcm_emulator::Chain, + xcm_emulator::{Chain, assert_expected_events}, }; #[allow(unused_assignments)] diff --git a/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_relay_frontier_container.rs b/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_relay_frontier_container.rs index 4ddc7b1f9..e889dead2 100644 --- a/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_relay_frontier_container.rs +++ b/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_relay_frontier_container.rs @@ -16,7 +16,6 @@ use { crate::{ - assert_expected_events, tests::common::xcm::{ mocknets::{ EthereumReceiver, FrontierTemplatePara as FrontierTemplate, @@ -36,7 +35,7 @@ use { latest::prelude::{Junctions::*, *}, VersionedLocation, }, - xcm_emulator::Chain, + xcm_emulator::{Chain, assert_expected_events}, }; #[allow(unused_assignments)] diff --git a/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_relay_simple_container.rs b/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_relay_simple_container.rs index 53e61ed38..2573f7c60 100644 --- a/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_relay_simple_container.rs +++ b/runtime/dancebox/src/tests/common/xcm/token_derivative_reception_relay_simple_container.rs @@ -16,7 +16,6 @@ use { crate::{ - assert_expected_events, tests::common::xcm::{ mocknets::{ SimpleTemplatePara as SimpleTemplate, SimpleTemplateParaPallet, @@ -34,7 +33,7 @@ use { latest::prelude::{Junctions::*, *}, VersionedLocation, }, - xcm_emulator::Chain, + xcm_emulator::{Chain, assert_expected_events}, }; #[allow(unused_assignments)] diff --git a/runtime/dancebox/src/tests/common/xcm/transact.rs b/runtime/dancebox/src/tests/common/xcm/transact.rs index 2f86f17e5..c9d5cdf74 100644 --- a/runtime/dancebox/src/tests/common/xcm/transact.rs +++ b/runtime/dancebox/src/tests/common/xcm/transact.rs @@ -18,7 +18,6 @@ use crate::tests::common::xcm::*; use { crate::{ - assert_expected_events, tests::common::xcm::mocknets::{ DanceboxPara as Dancebox, FrontierTemplatePara as FrontierTemplate, FrontierTemplateParaPallet, SimpleTemplatePara as SimpleTemplate, @@ -36,7 +35,7 @@ use { }, staging_xcm_builder::{ParentIsPreset, SiblingParachainConvertsVia}, staging_xcm_executor::traits::ConvertLocation, - xcm_emulator::Chain, + xcm_emulator::{Chain, assert_expected_events}, }; #[test] diff --git a/runtime/dancebox/src/tests/common/xcm/trap.rs b/runtime/dancebox/src/tests/common/xcm/trap.rs index dbee80210..01fc7ea6e 100644 --- a/runtime/dancebox/src/tests/common/xcm/trap.rs +++ b/runtime/dancebox/src/tests/common/xcm/trap.rs @@ -17,18 +17,15 @@ use crate::tests::common::xcm::*; use { - crate::{ - assert_expected_events, - tests::common::xcm::mocknets::{ - DanceboxPara as Dancebox, WestendRelay as Westend, WestendRelayPallet, - }, + crate::tests::common::xcm::mocknets::{ + DanceboxPara as Dancebox, WestendRelay as Westend, WestendRelayPallet, }, frame_support::{ assert_ok, weights::{Weight, WeightToFee}, }, staging_xcm::{latest::prelude::*, VersionedLocation, VersionedXcm}, - xcm_emulator::Chain, + xcm_emulator::{assert_expected_events, Chain}, }; #[test] diff --git a/solo-chains/runtime/dancelight/src/tests/common/xcm/expected_event_checker.rs b/solo-chains/runtime/dancelight/src/tests/common/xcm/expected_event_checker.rs deleted file mode 100644 index 8d387aef7..000000000 --- a/solo-chains/runtime/dancelight/src/tests/common/xcm/expected_event_checker.rs +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (C) Moondance Labs Ltd. -// This file is part of Tanssi. - -// Tanssi is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Tanssi is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Tanssi. If not, see - -#[macro_export] -macro_rules! assert_expected_events { - ( $chain:ident, vec![$( $event_pat:pat => { $($attr:ident : $condition:expr, )* }, )*] ) => { - let mut message: Vec = Vec::new(); - let mut events = <$chain as xcm_emulator::Chain>::events(); - - $( - let mut event_received = false; - let mut meet_conditions = true; - let mut index_match = 0; - let mut event_message: Vec = Vec::new(); - - for (index, event) in events.iter().enumerate() { - // Variable to record current event's meet conditions - #[allow(unused_mut)] // To suppress warning in case no conditions are declared - let mut current_event_meet_conditions = true; - match event { - $event_pat => { - event_received = true; - - #[allow(unused_mut)] // To suppress warning in case no conditions are declared - let mut conditions_message: Vec = Vec::new(); - - $( - // We only want to record condition error messages in case it did not happened before - // Only the first partial match is recorded - if !$condition && event_message.is_empty() { - conditions_message.push( - format!( - " - The attribute {:?} = {:?} did not met the condition {:?}\n", - stringify!($attr), - $attr, - stringify!($condition) - ) - ); - } - current_event_meet_conditions &= $condition; - )* - - // Set the variable to latest matched event's condition evaluation result - meet_conditions = current_event_meet_conditions; - - // Set the index where we found a perfect match - if event_received && meet_conditions { - index_match = index; - break; - } else { - event_message.extend(conditions_message); - } - }, - _ => {} - } - } - - if event_received && !meet_conditions { - message.push( - format!( - "\n\n{}::\x1b[31m{}\x1b[0m was received but some of its attributes did not meet the conditions:\n{}", - stringify!($chain), - stringify!($event_pat), - event_message.concat() - ) - ); - } 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 as xcm_emulator::Chain>::events(), - ) - ); - } else { - // If we find a perfect match we remove the event to avoid being potentially assessed multiple times - events.remove(index_match); - } - )* - - if !message.is_empty() { - // Log events as they will not be logged after the panic - <$chain as xcm_emulator::Chain>::events().iter().for_each(|event| { - log::debug!(target: concat!("events::", stringify!($chain)), "{:?}", event); - }); - panic!("{}", message.concat()) - } - } -} diff --git a/solo-chains/runtime/dancelight/src/tests/common/xcm/mod.rs b/solo-chains/runtime/dancelight/src/tests/common/xcm/mod.rs index 803d03416..f19b25444 100644 --- a/solo-chains/runtime/dancelight/src/tests/common/xcm/mod.rs +++ b/solo-chains/runtime/dancelight/src/tests/common/xcm/mod.rs @@ -17,8 +17,4 @@ mod constants; mod mocknets; mod reserver_transfers_polkadot_xcm; - -#[macro_use] -mod expected_event_checker; - pub use xcm_emulator::{bx, TestExt}; diff --git a/solo-chains/runtime/dancelight/src/tests/common/xcm/reserver_transfers_polkadot_xcm.rs b/solo-chains/runtime/dancelight/src/tests/common/xcm/reserver_transfers_polkadot_xcm.rs index 47fe49bed..fe98c8670 100644 --- a/solo-chains/runtime/dancelight/src/tests/common/xcm/reserver_transfers_polkadot_xcm.rs +++ b/solo-chains/runtime/dancelight/src/tests/common/xcm/reserver_transfers_polkadot_xcm.rs @@ -15,16 +15,13 @@ // along with Tanssi. If not, see use { - crate::{ - assert_expected_events, - tests::common::xcm::{ - mocknets::{ - DancelightRelay as Dancelight, DancelightSender, - SimpleTemplateDancelightEmptyReceiver as SimpleTemplateEmptyReceiver, - SimpleTemplateDancelightPara as SimpleTemplateDancelight, - }, - *, + crate::tests::common::xcm::{ + mocknets::{ + DancelightRelay as Dancelight, DancelightSender, + SimpleTemplateDancelightEmptyReceiver as SimpleTemplateEmptyReceiver, + SimpleTemplateDancelightPara as SimpleTemplateDancelight, }, + *, }, frame_support::{ assert_ok, @@ -36,7 +33,7 @@ use { latest::prelude::{Junctions::*, *}, VersionedLocation, }, - xcm_emulator::Chain, + xcm_emulator::{assert_expected_events, Chain}, }; #[allow(unused_assignments)]