pub use paste;
pub use frame_support::{pallet_prelude::Weight, weights::WeightToFee};
pub use pallet_assets;
pub use pallet_balances;
pub use pallet_message_queue;
pub use pallet_xcm;
pub use xcm::{
prelude::{
AccountId32, All, Asset, AssetId, BuyExecution, DepositAsset, ExpectTransactStatus,
Fungible, Here, Location, MaybeErrorCode, OriginKind, RefundSurplus, Transact, Unlimited,
VersionedXcm, WeightLimit, WithdrawAsset, Xcm,
},
v3::Location as V3Location,
};
pub use asset_test_utils;
pub use cumulus_pallet_xcmp_queue;
pub use parachains_common::AccountId;
pub use xcm_emulator::Chain;
#[macro_export]
macro_rules! test_parachain_is_trusted_teleporter {
( $sender_para:ty, $sender_xcm_config:ty, vec![$( $receiver_para:ty ),+], ($assets:expr, $amount:expr) ) => {
$crate::macros::paste::paste! {
let sender = [<$sender_para Sender>]::get();
let mut para_sender_balance_before =
<$sender_para as $crate::macros::Chain>::account_data_of(sender.clone()).free;
let origin = <$sender_para as $crate::macros::Chain>::RuntimeOrigin::signed(sender.clone());
let fee_asset_item = 0;
let weight_limit = $crate::macros::WeightLimit::Unlimited;
$(
{
let receiver = [<$receiver_para Receiver>]::get();
let para_receiver_balance_before =
<$receiver_para as $crate::macros::Chain>::account_data_of(receiver.clone()).free;
let para_destination =
<$sender_para>::sibling_location_of(<$receiver_para>::para_id());
let beneficiary: Location =
$crate::macros::AccountId32 { network: None, id: receiver.clone().into() }.into();
<$sender_para>::execute_with(|| {
assert_ok!(<$sender_para as [<$sender_para Pallet>]>::PolkadotXcm::limited_teleport_assets(
origin.clone(),
bx!(para_destination.clone().into()),
bx!(beneficiary.clone().into()),
bx!($assets.clone().into()),
fee_asset_item,
weight_limit.clone(),
));
type RuntimeEvent = <$sender_para as $crate::macros::Chain>::RuntimeEvent;
assert_expected_events!(
$sender_para,
vec![
RuntimeEvent::PolkadotXcm(
$crate::macros::pallet_xcm::Event::Attempted { outcome: Outcome::Complete { .. } }
) => {},
RuntimeEvent::XcmpQueue(
$crate::macros::cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }
) => {},
RuntimeEvent::Balances(
$crate::macros::pallet_balances::Event::Burned { who: sender, amount }
) => {},
]
);
});
<$receiver_para>::execute_with(|| {
type RuntimeEvent = <$receiver_para as $crate::macros::Chain>::RuntimeEvent;
assert_expected_events!(
$receiver_para,
vec![
RuntimeEvent::Balances(
$crate::macros::pallet_balances::Event::Minted { who: receiver, .. }
) => {},
RuntimeEvent::MessageQueue(
$crate::macros::pallet_message_queue::Event::Processed { success: true, .. }
) => {},
]
);
});
let para_sender_balance_after =
<$sender_para as $crate::macros::Chain>::account_data_of(sender.clone()).free;
let para_receiver_balance_after =
<$receiver_para as $crate::macros::Chain>::account_data_of(receiver.clone()).free;
let delivery_fees = <$sender_para>::execute_with(|| {
$crate::macros::asset_test_utils::xcm_helpers::teleport_assets_delivery_fees::<
<$sender_xcm_config as xcm_executor::Config>::XcmSender,
>($assets.clone(), fee_asset_item, weight_limit.clone(), beneficiary, para_destination)
});
assert_eq!(para_sender_balance_before - $amount - delivery_fees, para_sender_balance_after);
assert!(para_receiver_balance_after > para_receiver_balance_before);
para_sender_balance_before = <$sender_para as $crate::macros::Chain>::account_data_of(sender.clone()).free;
}
)+
}
};
}