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:
Ignacio Palacios
2023-10-16 19:52:33 +02:00
committed by GitHub
parent 4145902f1c
commit e0065cb81b
24 changed files with 465 additions and 84 deletions
@@ -0,0 +1,24 @@
[package]
name = "asset-hub-rococo-integration-tests"
version = "1.0.0"
authors.workspace = true
edition.workspace = true
description = "Asset Hub Rococo runtime integration tests with xcm-emulator"
publish = false
[dependencies]
codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false }
# Substrate
frame-support = { path = "../../../../../../substrate/frame/support", default-features = false}
xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false}
# Local
xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false}
integration-tests-common = { path = "../../common", default-features = false}
[features]
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"integration-tests-common/runtime-benchmarks",
]
@@ -0,0 +1,26 @@
// 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.
pub use frame_support::assert_ok;
pub use integration_tests_common::{
constants::asset_hub_rococo::ED as ASSET_HUB_ROCOCO_ED, test_parachain_is_trusted_teleporter,
AssetHubRococo, AssetHubRococoPallet, AssetHubRococoSender, BridgeHubRococo,
BridgeHubRococoReceiver,
};
pub use xcm::prelude::*;
pub use xcm_emulator::{assert_expected_events, bx, Chain, Parachain, TestExt};
#[cfg(test)]
mod tests;
@@ -0,0 +1,16 @@
// 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.
mod teleport;
@@ -0,0 +1,28 @@
// 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.
use crate::*;
#[test]
fn teleport_to_other_system_parachains_works() {
let amount = ASSET_HUB_ROCOCO_ED * 100;
let native_asset: VersionedMultiAssets = (Parent, amount).into();
test_parachain_is_trusted_teleporter!(
AssetHubRococo, // Origin
vec![BridgeHubRococo], // Destinations
(native_asset, amount)
);
}
@@ -27,6 +27,7 @@ pub use integration_tests_common::{
asset_hub_westend::ED as ASSET_HUB_WESTEND_ED, westend::ED as WESTEND_ED,
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
},
test_parachain_is_trusted_teleporter,
xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution},
AssetHubWestend, AssetHubWestendPallet, AssetHubWestendReceiver, AssetHubWestendSender,
PenpalWestendA, PenpalWestendAPallet, PenpalWestendAReceiver, PenpalWestendASender, Westend,
@@ -88,5 +89,4 @@ pub fn system_para_test_args(
}
#[cfg(test)]
#[cfg(not(feature = "runtime-benchmarks"))]
mod tests;
@@ -357,3 +357,17 @@ fn teleport_native_assets_from_system_para_to_relay_fails() {
// Receiver's balance does not change
assert_eq!(receiver_balance_after, receiver_balance_before);
}
// TODO: uncomment when CollectivesWestend and BridgeHubWestend are implemented
// https://github.com/paritytech/polkadot-sdk/pull/1737 (CollectivesWestend)
// #[test]
// fn teleport_to_other_system_parachains_works() {
// let amount = ASSET_HUB_WESTEND_ED * 100;
// let native_asset: VersionedMultiAssets = (Parent, amount).into();
// test_parachain_is_trusted_teleporter!(
// AssetHubWestend, // Origin
// vec![CollectivesWestend, BridgeHubWestend], // Destinations
// (native_asset, amount)
// );
// }
@@ -17,12 +17,13 @@ pub use bp_messages::LaneId;
pub use frame_support::assert_ok;
pub use integration_tests_common::{
constants::{
asset_hub_rococo::ED as ASSET_HUB_ROCOCO_ED, rococo::ED as ROCOCO_ED, PROOF_SIZE_THRESHOLD,
REF_TIME_THRESHOLD, XCM_V3,
bridge_hub_rococo::ED as BRIDGE_HUB_ROCOCO_ED, rococo::ED as ROCOCO_ED,
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
},
test_parachain_is_trusted_teleporter,
xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution},
AssetHubRococo, AssetHubRococoReceiver, AssetHubWococo, BridgeHubRococo, BridgeHubWococo,
PenpalRococoA, Rococo, RococoPallet,
AssetHubRococo, AssetHubRococoReceiver, AssetHubWococo, BridgeHubRococo, BridgeHubRococoPallet,
BridgeHubRococoSender, BridgeHubWococo, PenpalRococoA, Rococo, RococoPallet,
};
pub use parachains_common::{AccountId, Balance};
pub use xcm::{
@@ -63,5 +64,4 @@ pub fn relay_test_args(amount: Balance) -> TestArgs {
}
#[cfg(test)]
#[cfg(not(feature = "runtime-benchmarks"))]
mod tests;
@@ -14,3 +14,4 @@
// limitations under the License.
mod example;
mod teleport;
@@ -0,0 +1,28 @@
// 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.
use crate::*;
#[test]
fn teleport_to_other_system_parachains_works() {
let amount = BRIDGE_HUB_ROCOCO_ED * 100;
let native_asset: VersionedMultiAssets = (Parent, amount).into();
test_parachain_is_trusted_teleporter!(
BridgeHubRococo, // Origin
vec![AssetHubRococo], // Destinations
(native_asset, amount)
);
}
@@ -19,6 +19,7 @@ frame-support = { path = "../../../../../substrate/frame/support", default-featu
sp-core = { path = "../../../../../substrate/primitives/core", default-features = false}
sp-consensus-babe = { path = "../../../../../substrate/primitives/consensus/babe", default-features = false}
pallet-assets = { path = "../../../../../substrate/frame/assets", default-features = false}
pallet-balances = { path = "../../../../../substrate/frame/balances", default-features = false}
pallet-staking = { path = "../../../../../substrate/frame/staking", default-features = false}
pallet-message-queue = { path = "../../../../../substrate/frame/message-queue", default-features = false}
pallet-im-online = { path = "../../../../../substrate/frame/im-online", default-features = false}
@@ -70,6 +71,7 @@ runtime-benchmarks = [
"cumulus-pallet-xcmp-queue/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-bridge-messages/runtime-benchmarks",
"pallet-im-online/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
@@ -15,6 +15,7 @@
pub mod constants;
pub mod impls;
pub mod macros;
pub mod xcm_helpers;
use constants::{
@@ -22,16 +23,24 @@ use constants::{
asset_hub_rococo, asset_hub_westend, bridge_hub_rococo, penpal, rococo, westend,
};
use impls::{RococoWococoMessageHandler, WococoRococoMessageHandler};
pub use paste;
// Substrate
use frame_support::traits::OnInitialize;
pub use pallet_balances;
// Cumulus
pub use cumulus_pallet_xcmp_queue;
pub use xcm_emulator::Chain;
use xcm_emulator::{
decl_test_bridges, decl_test_networks, decl_test_parachains, decl_test_relay_chains,
decl_test_sender_receiver_accounts_parameter_types, DefaultMessageProcessor,
};
// Polkadot
pub use pallet_xcm;
pub use xcm::prelude::{AccountId32, WeightLimit};
decl_test_relay_chains! {
#[api_version(8)]
pub struct Westend {
@@ -120,6 +129,7 @@ decl_test_parachains! {
pallets = {
PolkadotXcm: penpal_runtime::PolkadotXcm,
Assets: penpal_runtime::Assets,
Balances: penpal_runtime::Balances,
}
},
// Rococo Parachains
@@ -156,6 +166,7 @@ decl_test_parachains! {
pallets = {
PolkadotXcm: asset_hub_kusama_runtime::PolkadotXcm,
Assets: asset_hub_kusama_runtime::Assets,
Balances: asset_hub_kusama_runtime::Balances,
}
},
// Wococo Parachains
@@ -190,6 +201,7 @@ decl_test_parachains! {
pallets = {
PolkadotXcm: asset_hub_polkadot_runtime::PolkadotXcm,
Assets: asset_hub_polkadot_runtime::Assets,
Balances: asset_hub_polkadot_runtime::Balances,
}
},
pub struct PenpalRococoA {
@@ -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;
}
)+
}
};
}
@@ -1,18 +1,17 @@
// Copyright Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Cumulus 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.
// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
// 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.
use parachains_common::AccountId;
use xcm::{