mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 19:11:02 +00:00
Make System Parachains trusted Teleporters (#1368)
Make System Parachain trusted Teleporters of each other. Migration of https://github.com/paritytech/cumulus/pull/2842 --------- Co-authored-by: command-bot <> Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! test_parachain_is_trusted_teleporter {
|
||||
( $sender_para:ty, vec![$( $receiver_para:ty ),+], ($assets:expr, $amount:expr) ) => {
|
||||
$crate::paste::paste! {
|
||||
// init Origin variables
|
||||
let sender = [<$sender_para Sender>]::get();
|
||||
let mut para_sender_balance_before =
|
||||
<$sender_para as $crate::Chain>::account_data_of(sender.clone()).free;
|
||||
let origin = <$sender_para as $crate::Chain>::RuntimeOrigin::signed(sender.clone());
|
||||
let fee_asset_item = 0;
|
||||
let weight_limit = $crate::WeightLimit::Unlimited;
|
||||
|
||||
$(
|
||||
{
|
||||
// init Destination variables
|
||||
let receiver = [<$receiver_para Receiver>]::get();
|
||||
let para_receiver_balance_before =
|
||||
<$receiver_para as $crate::Chain>::account_data_of(receiver.clone()).free;
|
||||
let para_destination =
|
||||
<$sender_para>::sibling_location_of(<$receiver_para>::para_id()).into();
|
||||
let beneficiary =
|
||||
$crate::AccountId32 { network: None, id: receiver.clone().into() }.into();
|
||||
|
||||
// Send XCM message from Origin Parachain
|
||||
// We are only testing the limited teleport version, which should be ok since success will
|
||||
// depend only on a proper `XcmConfig` at destination.
|
||||
<$sender_para>::execute_with(|| {
|
||||
assert_ok!(<$sender_para as [<$sender_para Pallet>]>::PolkadotXcm::limited_teleport_assets(
|
||||
origin.clone(),
|
||||
bx!(para_destination),
|
||||
bx!(beneficiary),
|
||||
bx!($assets.clone()),
|
||||
fee_asset_item,
|
||||
weight_limit.clone(),
|
||||
));
|
||||
|
||||
type RuntimeEvent = <$sender_para as $crate::Chain>::RuntimeEvent;
|
||||
|
||||
assert_expected_events!(
|
||||
$sender_para,
|
||||
vec![
|
||||
RuntimeEvent::PolkadotXcm(
|
||||
$crate::pallet_xcm::Event::Attempted { outcome: Outcome::Complete { .. } }
|
||||
) => {},
|
||||
RuntimeEvent::XcmpQueue(
|
||||
$crate::cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }
|
||||
) => {},
|
||||
RuntimeEvent::Balances(
|
||||
$crate::pallet_balances::Event::Withdraw { who: sender, amount }
|
||||
) => {},
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
// Receive XCM message in Destination Parachain
|
||||
<$receiver_para>::execute_with(|| {
|
||||
type RuntimeEvent = <$receiver_para as $crate::Chain>::RuntimeEvent;
|
||||
|
||||
assert_expected_events!(
|
||||
$receiver_para,
|
||||
vec![
|
||||
RuntimeEvent::Balances(
|
||||
$crate::pallet_balances::Event::Deposit { who: receiver, .. }
|
||||
) => {},
|
||||
RuntimeEvent::XcmpQueue(
|
||||
$crate::cumulus_pallet_xcmp_queue::Event::Success { .. }
|
||||
) => {},
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
// Check if balances are updated accordingly in Origin and Destination Parachains
|
||||
let para_sender_balance_after =
|
||||
<$sender_para as $crate::Chain>::account_data_of(sender.clone()).free;
|
||||
let para_receiver_balance_after =
|
||||
<$receiver_para as $crate::Chain>::account_data_of(receiver.clone()).free;
|
||||
|
||||
assert_eq!(para_sender_balance_before - $amount, para_sender_balance_after);
|
||||
assert!(para_receiver_balance_after > para_receiver_balance_before);
|
||||
|
||||
// Update sender balance
|
||||
para_sender_balance_before = <$sender_para as $crate::Chain>::account_data_of(sender.clone()).free;
|
||||
}
|
||||
)+
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user