mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-06 23:07:22 +00:00
[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:
@@ -17,41 +17,22 @@ pub use codec::{Decode, Encode};
|
||||
pub use paste;
|
||||
|
||||
pub use crate::{
|
||||
constants::{PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD},
|
||||
xcm_helpers::xcm_transact_unpaid_execution,
|
||||
BridgeHubRococo, BridgeHubWococo,
|
||||
xcm_helpers::xcm_transact_unpaid_execution, PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD,
|
||||
};
|
||||
|
||||
// Substrate
|
||||
pub use frame_support::{
|
||||
assert_ok,
|
||||
sp_runtime::AccountId32,
|
||||
traits::fungibles::Inspect,
|
||||
weights::{Weight, WeightMeter},
|
||||
};
|
||||
pub use pallet_assets;
|
||||
pub use pallet_message_queue;
|
||||
pub use pallet_xcm;
|
||||
use sp_core::Get;
|
||||
|
||||
// Cumulus
|
||||
use bp_messages::{
|
||||
target_chain::{DispatchMessage, DispatchMessageData, MessageDispatch},
|
||||
LaneId, MessageKey, OutboundLaneData,
|
||||
};
|
||||
use bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatchResult;
|
||||
pub use cumulus_pallet_parachain_system;
|
||||
pub use cumulus_pallet_xcmp_queue;
|
||||
pub use cumulus_primitives_core::{
|
||||
relay_chain::HrmpChannelId, DmpMessageHandler, ParaId, XcmpMessageHandler,
|
||||
};
|
||||
use pallet_bridge_messages::{Config, Instance1, Instance2, OutboundLanes, Pallet};
|
||||
pub use parachains_common::{AccountId, Balance};
|
||||
pub use xcm_emulator::{
|
||||
assert_expected_events, bx, helpers::weight_within_threshold, BridgeMessage,
|
||||
BridgeMessageDispatchError, BridgeMessageHandler, Chain, Parachain, RelayChain, TestExt,
|
||||
};
|
||||
|
||||
// Polkadot
|
||||
pub use pallet_xcm;
|
||||
pub use polkadot_runtime_parachains::{
|
||||
dmp, hrmp,
|
||||
inclusion::{AggregateMessageOrigin, UmpQueueId},
|
||||
@@ -62,6 +43,28 @@ pub use xcm::{
|
||||
DoubleEncoded,
|
||||
};
|
||||
|
||||
// Cumulus
|
||||
pub use cumulus_pallet_parachain_system;
|
||||
pub use cumulus_pallet_xcmp_queue;
|
||||
pub use cumulus_primitives_core::{
|
||||
relay_chain::HrmpChannelId, DmpMessageHandler, ParaId, XcmpMessageHandler,
|
||||
};
|
||||
pub use parachains_common::{AccountId, Balance};
|
||||
pub use xcm_emulator::{
|
||||
assert_expected_events, bx, helpers::weight_within_threshold, BridgeMessage,
|
||||
BridgeMessageDispatchError, BridgeMessageHandler, Chain, Network, Parachain, RelayChain,
|
||||
TestExt,
|
||||
};
|
||||
|
||||
// Bridges
|
||||
use bp_messages::{
|
||||
target_chain::{DispatchMessage, DispatchMessageData, MessageDispatch},
|
||||
LaneId, MessageKey, OutboundLaneData,
|
||||
};
|
||||
use bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatchResult;
|
||||
pub use pallet_bridge_messages::Instance2 as BridgeMessagesInstance2;
|
||||
use pallet_bridge_messages::{Config, Instance1, OutboundLanes, Pallet};
|
||||
|
||||
pub struct BridgeHubMessageHandler<S, T, I> {
|
||||
_marker: std::marker::PhantomData<(S, T, I)>,
|
||||
}
|
||||
@@ -80,14 +83,6 @@ impl From<u32> for LaneIdWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
type BridgeHubRococoRuntime = <BridgeHubRococo as Chain>::Runtime;
|
||||
type BridgeHubWococoRuntime = <BridgeHubWococo as Chain>::Runtime;
|
||||
|
||||
pub type RococoWococoMessageHandler =
|
||||
BridgeHubMessageHandler<BridgeHubRococoRuntime, BridgeHubWococoRuntime, Instance2>;
|
||||
pub type WococoRococoMessageHandler =
|
||||
BridgeHubMessageHandler<BridgeHubWococoRuntime, BridgeHubRococoRuntime, Instance2>;
|
||||
|
||||
impl<S, T, I> BridgeMessageHandler for BridgeHubMessageHandler<S, T, I>
|
||||
where
|
||||
S: Config<Instance1>,
|
||||
@@ -171,12 +166,12 @@ where
|
||||
macro_rules! impl_accounts_helpers_for_relay_chain {
|
||||
( $chain:ident ) => {
|
||||
$crate::impls::paste::paste! {
|
||||
impl $chain {
|
||||
impl<N: $crate::impls::Network> $chain<N> {
|
||||
/// Fund a set of accounts with a balance
|
||||
pub fn fund_accounts(accounts: Vec<($crate::impls::AccountId, $crate::impls::Balance)>) {
|
||||
<Self as $crate::impls::TestExt>::execute_with(|| {
|
||||
for account in accounts {
|
||||
$crate::impls::assert_ok!(<Self as [<$chain Pallet>]>::Balances::force_set_balance(
|
||||
$crate::impls::assert_ok!(<Self as [<$chain RelayPallet>]>::Balances::force_set_balance(
|
||||
<Self as $crate::impls::Chain>::RuntimeOrigin::root(),
|
||||
account.0.into(),
|
||||
account.1,
|
||||
@@ -185,7 +180,7 @@ macro_rules! impl_accounts_helpers_for_relay_chain {
|
||||
});
|
||||
}
|
||||
/// Fund a sovereign account based on its Parachain Id
|
||||
pub fn fund_para_sovereign(amount: $crate::impls::Balance, para_id: $crate::impls::ParaId) -> sp_runtime::AccountId32 {
|
||||
pub fn fund_para_sovereign(amount: $crate::impls::Balance, para_id: $crate::impls::ParaId) -> $crate::impls::AccountId32 {
|
||||
let sovereign_account = <Self as $crate::impls::RelayChain>::sovereign_account_id_of_child_para(para_id);
|
||||
Self::fund_accounts(vec![(sovereign_account.clone(), amount)]);
|
||||
sovereign_account
|
||||
@@ -199,15 +194,15 @@ macro_rules! impl_accounts_helpers_for_relay_chain {
|
||||
macro_rules! impl_assert_events_helpers_for_relay_chain {
|
||||
( $chain:ident ) => {
|
||||
$crate::impls::paste::paste! {
|
||||
type [<$chain RuntimeEvent>] = <$chain as $crate::impls::Chain>::RuntimeEvent;
|
||||
type [<$chain RuntimeEvent>]<N> = <$chain<N> as $crate::impls::Chain>::RuntimeEvent;
|
||||
|
||||
impl $chain {
|
||||
impl<N: $crate::impls::Network> $chain<N> {
|
||||
/// Asserts a dispatchable is completely executed and XCM sent
|
||||
pub fn assert_xcm_pallet_attempted_complete(expected_weight: Option<$crate::impls::Weight>) {
|
||||
$crate::impls::assert_expected_events!(
|
||||
Self,
|
||||
vec![
|
||||
[<$chain RuntimeEvent>]::XcmPallet(
|
||||
[<$chain RuntimeEvent>]::<N>::XcmPallet(
|
||||
$crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Complete(weight) }
|
||||
) => {
|
||||
weight: $crate::impls::weight_within_threshold(
|
||||
@@ -229,7 +224,7 @@ macro_rules! impl_assert_events_helpers_for_relay_chain {
|
||||
Self,
|
||||
vec![
|
||||
// Dispatchable is properly executed and XCM message sent
|
||||
[<$chain RuntimeEvent>]::XcmPallet(
|
||||
[<$chain RuntimeEvent>]::<N>::XcmPallet(
|
||||
$crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Incomplete(weight, error) }
|
||||
) => {
|
||||
weight: $crate::impls::weight_within_threshold(
|
||||
@@ -248,7 +243,7 @@ macro_rules! impl_assert_events_helpers_for_relay_chain {
|
||||
$crate::impls::assert_expected_events!(
|
||||
Self,
|
||||
vec![
|
||||
[<$chain RuntimeEvent>]::XcmPallet($crate::impls::pallet_xcm::Event::Sent { .. }) => {},
|
||||
[<$chain RuntimeEvent>]::<N>::XcmPallet($crate::impls::pallet_xcm::Event::Sent { .. }) => {},
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -263,7 +258,7 @@ macro_rules! impl_assert_events_helpers_for_relay_chain {
|
||||
Self,
|
||||
vec![
|
||||
// XCM is succesfully received and proccessed
|
||||
[<$chain RuntimeEvent>]::MessageQueue($crate::impls::pallet_message_queue::Event::Processed {
|
||||
[<$chain RuntimeEvent>]::<N>::MessageQueue($crate::impls::pallet_message_queue::Event::Processed {
|
||||
origin: $crate::impls::AggregateMessageOrigin::Ump($crate::impls::UmpQueueId::Para(id)),
|
||||
weight_used,
|
||||
success,
|
||||
@@ -289,7 +284,7 @@ macro_rules! impl_assert_events_helpers_for_relay_chain {
|
||||
macro_rules! impl_hrmp_channels_helpers_for_relay_chain {
|
||||
( $chain:ident ) => {
|
||||
$crate::impls::paste::paste! {
|
||||
impl $chain {
|
||||
impl<N: $crate::impls::Network> $chain<N> {
|
||||
/// Init open channel request with another Parachain
|
||||
pub fn init_open_channel_call(
|
||||
recipient_para_id: $crate::impls::ParaId,
|
||||
@@ -329,7 +324,7 @@ macro_rules! impl_hrmp_channels_helpers_for_relay_chain {
|
||||
let relay_root_origin = <Self as Chain>::RuntimeOrigin::root();
|
||||
|
||||
// Force process HRMP open channel requests without waiting for the next session
|
||||
$crate::impls::assert_ok!(<Self as [<$chain Pallet>]>::Hrmp::force_process_hrmp_open(
|
||||
$crate::impls::assert_ok!(<Self as [<$chain RelayPallet>]>::Hrmp::force_process_hrmp_open(
|
||||
relay_root_origin,
|
||||
0
|
||||
));
|
||||
@@ -353,7 +348,7 @@ macro_rules! impl_hrmp_channels_helpers_for_relay_chain {
|
||||
macro_rules! impl_send_transact_helpers_for_relay_chain {
|
||||
( $chain:ident ) => {
|
||||
$crate::impls::paste::paste! {
|
||||
impl $chain {
|
||||
impl<N: $crate::impls::Network> $chain<N> {
|
||||
/// A root origin (as governance) sends `xcm::Transact` with `UnpaidExecution` and encoded `call` to child parachain.
|
||||
pub fn send_unpaid_transact_to_parachain_as_root(
|
||||
recipient: $crate::impls::ParaId,
|
||||
@@ -367,7 +362,7 @@ macro_rules! impl_send_transact_helpers_for_relay_chain {
|
||||
let xcm = $crate::impls::xcm_transact_unpaid_execution(call, $crate::impls::OriginKind::Superuser);
|
||||
|
||||
// Send XCM `Transact`
|
||||
$crate::impls::assert_ok!(<Self as [<$chain Pallet>]>::XcmPallet::send(
|
||||
$crate::impls::assert_ok!(<Self as [<$chain RelayPallet>]>::XcmPallet::send(
|
||||
root_origin,
|
||||
bx!(destination.into()),
|
||||
bx!(xcm),
|
||||
@@ -384,12 +379,12 @@ macro_rules! impl_send_transact_helpers_for_relay_chain {
|
||||
macro_rules! impl_accounts_helpers_for_parachain {
|
||||
( $chain:ident ) => {
|
||||
$crate::impls::paste::paste! {
|
||||
impl $chain {
|
||||
impl<N: $crate::impls::Network> $chain<N> {
|
||||
/// Fund a set of accounts with a balance
|
||||
pub fn fund_accounts(accounts: Vec<($crate::impls::AccountId, $crate::impls::Balance)>) {
|
||||
<Self as $crate::impls::TestExt>::execute_with(|| {
|
||||
for account in accounts {
|
||||
$crate::impls::assert_ok!(<Self as [<$chain Pallet>]>::Balances::force_set_balance(
|
||||
$crate::impls::assert_ok!(<Self as [<$chain ParaPallet>]>::Balances::force_set_balance(
|
||||
<Self as $crate::impls::Chain>::RuntimeOrigin::root(),
|
||||
account.0.into(),
|
||||
account.1,
|
||||
@@ -406,15 +401,15 @@ macro_rules! impl_accounts_helpers_for_parachain {
|
||||
macro_rules! impl_assert_events_helpers_for_parachain {
|
||||
( $chain:ident ) => {
|
||||
$crate::impls::paste::paste! {
|
||||
type [<$chain RuntimeEvent>] = <$chain as $crate::impls::Chain>::RuntimeEvent;
|
||||
type [<$chain RuntimeEvent>]<N> = <$chain<N> as $crate::impls::Chain>::RuntimeEvent;
|
||||
|
||||
impl $chain {
|
||||
impl<N: $crate::impls::Network> $chain<N> {
|
||||
/// Asserts a dispatchable is completely executed and XCM sent
|
||||
pub fn assert_xcm_pallet_attempted_complete(expected_weight: Option<$crate::impls::Weight>) {
|
||||
$crate::impls::assert_expected_events!(
|
||||
Self,
|
||||
vec![
|
||||
[<$chain RuntimeEvent>]::PolkadotXcm(
|
||||
[<$chain RuntimeEvent>]::<N>::PolkadotXcm(
|
||||
$crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Complete(weight) }
|
||||
) => {
|
||||
weight: $crate::impls::weight_within_threshold(
|
||||
@@ -436,7 +431,7 @@ macro_rules! impl_assert_events_helpers_for_parachain {
|
||||
Self,
|
||||
vec![
|
||||
// Dispatchable is properly executed and XCM message sent
|
||||
[<$chain RuntimeEvent>]::PolkadotXcm(
|
||||
[<$chain RuntimeEvent>]::<N>::PolkadotXcm(
|
||||
$crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Incomplete(weight, error) }
|
||||
) => {
|
||||
weight: $crate::impls::weight_within_threshold(
|
||||
@@ -456,7 +451,7 @@ macro_rules! impl_assert_events_helpers_for_parachain {
|
||||
Self,
|
||||
vec![
|
||||
// Execution fails in the origin with `Barrier`
|
||||
[<$chain RuntimeEvent>]::PolkadotXcm(
|
||||
[<$chain RuntimeEvent>]::<N>::PolkadotXcm(
|
||||
$crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Error(error) }
|
||||
) => {
|
||||
error: *error == expected_error.unwrap_or(*error),
|
||||
@@ -470,7 +465,7 @@ macro_rules! impl_assert_events_helpers_for_parachain {
|
||||
$crate::impls::assert_expected_events!(
|
||||
Self,
|
||||
vec![
|
||||
[<$chain RuntimeEvent>]::PolkadotXcm($crate::impls::pallet_xcm::Event::Sent { .. }) => {},
|
||||
[<$chain RuntimeEvent>]::<N>::PolkadotXcm($crate::impls::pallet_xcm::Event::Sent { .. }) => {},
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -480,7 +475,7 @@ macro_rules! impl_assert_events_helpers_for_parachain {
|
||||
$crate::impls::assert_expected_events!(
|
||||
Self,
|
||||
vec![
|
||||
[<$chain RuntimeEvent>]::ParachainSystem(
|
||||
[<$chain RuntimeEvent>]::<N>::ParachainSystem(
|
||||
$crate::impls::cumulus_pallet_parachain_system::Event::UpwardMessageSent { .. }
|
||||
) => {},
|
||||
]
|
||||
@@ -492,7 +487,7 @@ macro_rules! impl_assert_events_helpers_for_parachain {
|
||||
$crate::impls::assert_expected_events!(
|
||||
Self,
|
||||
vec![
|
||||
[<$chain RuntimeEvent>]::MessageQueue(pallet_message_queue::Event::Processed {
|
||||
[<$chain RuntimeEvent>]::<N>::MessageQueue($crate::impls::pallet_message_queue::Event::Processed {
|
||||
success: true, weight_used: weight, ..
|
||||
}) => {
|
||||
weight: $crate::impls::weight_within_threshold(
|
||||
@@ -512,7 +507,7 @@ macro_rules! impl_assert_events_helpers_for_parachain {
|
||||
$crate::impls::assert_expected_events!(
|
||||
Self,
|
||||
vec![
|
||||
[<$chain RuntimeEvent>]::MessageQueue(pallet_message_queue::Event::Processed {
|
||||
[<$chain RuntimeEvent>]::<N>::MessageQueue($crate::impls::pallet_message_queue::Event::Processed {
|
||||
success: false, weight_used: weight, ..
|
||||
}) => {
|
||||
weight: $crate::impls::weight_within_threshold(
|
||||
@@ -530,7 +525,7 @@ macro_rules! impl_assert_events_helpers_for_parachain {
|
||||
$crate::impls::assert_expected_events!(
|
||||
Self,
|
||||
vec![
|
||||
[<$chain RuntimeEvent>]::MessageQueue($crate::impls::pallet_message_queue::Event::ProcessingFailed {
|
||||
[<$chain RuntimeEvent>]::<N>::MessageQueue($crate::impls::pallet_message_queue::Event::ProcessingFailed {
|
||||
..
|
||||
}) => {
|
||||
|
||||
@@ -544,7 +539,7 @@ macro_rules! impl_assert_events_helpers_for_parachain {
|
||||
$crate::impls::assert_expected_events!(
|
||||
Self,
|
||||
vec![
|
||||
[<$chain RuntimeEvent>]::MessageQueue(pallet_message_queue::Event::Processed { success: true, weight_used: weight, .. }
|
||||
[<$chain RuntimeEvent>]::<N>::MessageQueue($crate::impls::pallet_message_queue::Event::Processed { success: true, weight_used: weight, .. }
|
||||
) => {
|
||||
weight: $crate::impls::weight_within_threshold(
|
||||
($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD),
|
||||
@@ -561,10 +556,10 @@ macro_rules! impl_assert_events_helpers_for_parachain {
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! impl_assets_helpers_for_parachain {
|
||||
macro_rules! impl_assets_helpers_for_system_parachain {
|
||||
( $chain:ident, $relay_chain:ident ) => {
|
||||
$crate::impls::paste::paste! {
|
||||
impl $chain {
|
||||
impl<N: $crate::impls::Network> $chain<N> {
|
||||
/// Returns the encoded call for `force_create` from the assets pallet
|
||||
pub fn force_create_asset_call(
|
||||
asset_id: u32,
|
||||
@@ -607,19 +602,19 @@ macro_rules! impl_assets_helpers_for_parachain {
|
||||
amount_to_mint: u128,
|
||||
) {
|
||||
<Self as $crate::impls::TestExt>::execute_with(|| {
|
||||
$crate::impls::assert_ok!(<Self as [<$chain Pallet>]>::Assets::mint(
|
||||
$crate::impls::assert_ok!(<Self as [<$chain ParaPallet>]>::Assets::mint(
|
||||
signed_origin,
|
||||
id.into(),
|
||||
beneficiary.clone().into(),
|
||||
amount_to_mint
|
||||
));
|
||||
|
||||
type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent;
|
||||
type RuntimeEvent<N> = <$chain<N> as $crate::impls::Chain>::RuntimeEvent;
|
||||
|
||||
$crate::impls::assert_expected_events!(
|
||||
Self,
|
||||
vec![
|
||||
RuntimeEvent::Assets($crate::impls::pallet_assets::Event::Issued { asset_id, owner, amount }) => {
|
||||
RuntimeEvent::<N>::Assets($crate::impls::pallet_assets::Event::Issued { asset_id, owner, amount }) => {
|
||||
asset_id: *asset_id == id,
|
||||
owner: *owner == beneficiary.clone().into(),
|
||||
amount: *amount == amount_to_mint,
|
||||
@@ -664,28 +659,28 @@ macro_rules! impl_assets_helpers_for_parachain {
|
||||
) {
|
||||
use $crate::impls::{Parachain, Inspect, TestExt};
|
||||
|
||||
<$relay_chain>::send_unpaid_transact_to_parachain_as_root(
|
||||
<$relay_chain<N>>::send_unpaid_transact_to_parachain_as_root(
|
||||
Self::para_id(),
|
||||
Self::force_create_asset_call(id, asset_owner.clone(), is_sufficient, min_balance),
|
||||
);
|
||||
|
||||
// Receive XCM message in Assets Parachain
|
||||
Self::execute_with(|| {
|
||||
type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent;
|
||||
type RuntimeEvent<N> = <$chain<N> as $crate::impls::Chain>::RuntimeEvent;
|
||||
|
||||
Self::assert_dmp_queue_complete(dmp_weight_threshold);
|
||||
|
||||
$crate::impls::assert_expected_events!(
|
||||
Self,
|
||||
vec![
|
||||
RuntimeEvent::Assets($crate::impls::pallet_assets::Event::ForceCreated { asset_id, owner }) => {
|
||||
RuntimeEvent::<N>::Assets($crate::impls::pallet_assets::Event::ForceCreated { asset_id, owner }) => {
|
||||
asset_id: *asset_id == id,
|
||||
owner: *owner == asset_owner,
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
assert!(<Self as [<$chain Pallet>]>::Assets::asset_exists(id.into()));
|
||||
assert!(<Self as [<$chain ParaPallet>]>::Assets::asset_exists(id.into()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user