Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Make System Parachains trusted Teleporters #2842

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ members = [
"parachains/integration-tests/emulated/assets/asset-hub-kusama",
"parachains/integration-tests/emulated/assets/asset-hub-polkadot",
"parachains/integration-tests/emulated/assets/asset-hub-westend",
"parachains/integration-tests/emulated/assets/asset-hub-rococo",
"parachains/integration-tests/emulated/collectives/collectives-polkadot",
"parachains/integration-tests/emulated/collectives/collectives-westend",
"parachains/integration-tests/emulated/bridges/bridge-hub-rococo",
"test/client",
"test/relay-sproof-builder",
Expand Down
54 changes: 53 additions & 1 deletion parachains/common/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,61 @@ impl<Location: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
for ConcreteNativeAssetFrom<Location>
{
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
log::trace!(target: "xcm::filter_asset_location",
log::trace!(target: "xcm::contains",
"ConcreteNativeAsset asset: {:?}, origin: {:?}, location: {:?}",
asset, origin, Location::get());
matches!(asset.id, Concrete(ref id) if id == origin && origin == &Location::get())
}
}

/// Accepts an asset if it is a native asset from a System Parachain.
pub struct NativeAssetFromSiblingSystemParachain;
impl ContainsPair<MultiAsset, MultiLocation> for NativeAssetFromSiblingSystemParachain {
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
log::trace!(target: "xcm::contains", "NativeAssetFromSiblingSystemParachain asset: {:?}, origin: {:?}", asset, origin);
let is_system_para = match origin {
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
MultiLocation { parents: 1, interior: X1(Parachain(id)) } if *id < 2000 => true,
_ => false,
};
let parent = MultiLocation::parent();
matches!(asset.id, Concrete(id) if id == parent && is_system_para)
}
}

#[cfg(test)]
mod tests {
use super::{
ContainsPair, Here, MultiAsset, MultiLocation, NativeAssetFromSiblingSystemParachain,
Parachain, Parent,
};

#[test]
fn native_asset_from_sibling_system_para_works() {
let expected_asset: MultiAsset = (Parent, 1000000).into();
let expected_origin: MultiLocation = (Parent, Parachain(1000)).into();

assert!(NativeAssetFromSiblingSystemParachain::contains(&expected_asset, &expected_origin));
}

#[test]
fn native_asset_from_sibling_system_para_fails_for_wrong_asset() {
let unexpected_asset: MultiAsset = (Here, 1000000).into();
let expected_origin: MultiLocation = (Parent, Parachain(1000)).into();
NachoPal marked this conversation as resolved.
Show resolved Hide resolved

assert!(!NativeAssetFromSiblingSystemParachain::contains(
&unexpected_asset,
&expected_origin
));
}

#[test]
fn native_asset_from_sibling_system_para_fails_for_wrong_origin() {
let expected_asset: MultiAsset = (Parent, 1000000).into();
let unexpected_origin: MultiLocation = (Parent, Parachain(2000)).into();

assert!(!NativeAssetFromSiblingSystemParachain::contains(
&expected_asset,
&unexpected_origin
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@

// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

pub use codec::Encode;
pub use frame_support::{
assert_ok, instances::Instance1, pallet_prelude::Weight, traits::fungibles::Inspect,
};
pub use integration_tests_common::{
constants::{
accounts::{ALICE, BOB},
asset_hub_kusama::ED as ASSET_HUB_KUSAMA_ED,
bridge_hub_kusama::ED as BRIDGE_HUB_KUSAMA_ED,
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
kusama::ED as KUSAMA_ED,
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
},
AccountId, AssetHubKusama, AssetHubKusamaPallet, AssetHubKusamaReceiver, AssetHubKusamaSender,
BridgeHubKusama, BridgeHubKusamaPallet, BridgeHubKusamaReceiver, BridgeHubKusamaSender,
BridgeHubPolkadot, BridgeHubPolkadotPallet, BridgeHubPolkadotReceiver, BridgeHubPolkadotSender,
Collectives, CollectivesPallet, CollectivesReceiver, CollectivesSender, Kusama, KusamaMockNet,
KusamaPallet, KusamaReceiver, KusamaSender, PenpalKusama, PenpalKusamaReceiver,
test_parachain_is_trusted_teleporter, AccountId, AssetHubKusama, AssetHubKusamaPallet,
AssetHubKusamaReceiver, AssetHubKusamaSender, BridgeHubKusama, BridgeHubKusamaPallet,
BridgeHubKusamaReceiver, BridgeHubKusamaSender, BridgeHubPolkadot, BridgeHubPolkadotPallet,
BridgeHubPolkadotReceiver, BridgeHubPolkadotSender, Kusama, KusamaMockNet, KusamaPallet,
KusamaReceiver, KusamaSender, PenpalKusama, PenpalKusamaPallet, PenpalKusamaReceiver,
PenpalKusamaSender, PenpalPolkadot, PenpalPolkadotReceiver, PenpalPolkadotSender, Polkadot,
PolkadotMockNet, PolkadotPallet, PolkadotReceiver, PolkadotSender,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,16 @@ fn teleport_native_assets_from_relay_to_assets_para() {
assert_eq!(relay_sender_balance_before - amount, relay_sender_balance_after);
assert!(para_sender_balance_after > para_receiver_balance_before);
}

#[test]
fn teleport_to_other_system_parachains() {
let amount = ASSET_HUB_KUSAMA_ED * 100;
let expected_asset: VersionedMultiAssets = (Parent, amount).into();

// Works for the right origin and asset
test_parachain_is_trusted_teleporter!(
AssetHubKusama, // Origin
vec![BridgeHubKusama], // Destinations
(expected_asset, amount)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ pub use frame_support::{
pub use integration_tests_common::{
constants::{
accounts::{ALICE, BOB},
asset_hub_polkadot::ED as ASSET_HUB_POLKADOT_ED,
polkadot::ED as POLKADOT_ED,
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
},
AccountId, AssetHubKusama, AssetHubKusamaPallet, AssetHubKusamaReceiver, AssetHubKusamaSender,
AssetHubPolkadot, AssetHubPolkadotPallet, AssetHubPolkadotReceiver, AssetHubPolkadotSender,
BridgeHubKusama, BridgeHubKusamaPallet, BridgeHubKusamaReceiver, BridgeHubKusamaSender,
BridgeHubPolkadot, BridgeHubPolkadotPallet, BridgeHubPolkadotReceiver, BridgeHubPolkadotSender,
Collectives, CollectivesPallet, CollectivesReceiver, CollectivesSender, Kusama, KusamaMockNet,
KusamaPallet, KusamaReceiver, KusamaSender, PenpalKusama, PenpalKusamaReceiver,
test_parachain_is_trusted_teleporter, AccountId, AssetHubKusama, AssetHubKusamaPallet,
AssetHubKusamaReceiver, AssetHubKusamaSender, AssetHubPolkadot, AssetHubPolkadotPallet,
AssetHubPolkadotReceiver, AssetHubPolkadotSender, BridgeHubKusama, BridgeHubKusamaPallet,
BridgeHubKusamaReceiver, BridgeHubKusamaSender, BridgeHubPolkadot, BridgeHubPolkadotPallet,
BridgeHubPolkadotReceiver, BridgeHubPolkadotSender, CollectivesPolkadot,
CollectivesPolkadotPallet, CollectivesPolkadotReceiver, CollectivesPolkadotSender, Kusama,
KusamaMockNet, KusamaPallet, KusamaReceiver, KusamaSender, PenpalKusama, PenpalKusamaReceiver,
PenpalKusamaSender, PenpalPolkadot, PenpalPolkadotReceiver, PenpalPolkadotSender, Polkadot,
PolkadotMockNet, PolkadotPallet, PolkadotReceiver, PolkadotSender,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,15 @@ fn teleport_native_assets_from_relay_to_assets_para() {
assert_eq!(relay_sender_balance_before - amount, relay_sender_balance_after);
assert!(para_sender_balance_after > para_receiver_balance_before);
}

#[test]
fn teleport_to_other_system_parachains() {
let amount = ASSET_HUB_POLKADOT_ED * 100;
let native_asset: VersionedMultiAssets = (Parent, amount).into();

test_parachain_is_trusted_teleporter!(
AssetHubPolkadot, // Origin
vec![CollectivesPolkadot, BridgeHubPolkadot], // Destinations
(native_asset, amount)
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "asset-hub-rococo-integration-tests"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
description = "Asset Hub Rococo parachain runtime integration tests based on xcm-emulator"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false }

# Substrate
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
sp-weights = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-assets = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-core-fellowship = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-salary = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }

# Polkadot
polkadot-core-primitives = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-parachain = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "master" }
xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }
xcm-executor = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }
pallet-xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }

# Cumulus
parachains-common = { path = "../../../../common" }
cumulus-pallet-xcmp-queue = { default-features = false, path = "../../../../../pallets/xcmp-queue" }
asset-hub-polkadot-runtime = { path = "../../../../runtimes/assets/asset-hub-polkadot" }

# Local
xcm-emulator = { default-features = false, path = "../../../../../xcm/xcm-emulator" }
integration-tests-common = { default-features = false, path = "../../common" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright Parity Technologies (UK) Ltd.
// This file is part of Cumulus.

// 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/>.

//! Collectives Parachain integration tests based on xcm-emulator.

pub use frame_support::assert_ok;
pub use integration_tests_common::{
constants::asset_hub_polkadot::ED as ASSET_HUB_ROCOCO_ED, test_parachain_is_trusted_teleporter,
AccountId, AssetHubRococo, AssetHubRococoPallet, AssetHubRococoSender, BridgeHubRococo,
BridgeHubRococoReceiver,
};
pub use xcm::prelude::*;
pub use xcm_emulator::{assert_expected_events, bx, Parachain, TestExt};

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright Parity Technologies (UK) Ltd.
// This file is part of Cumulus.

// 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/>.

mod teleport;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright Parity Technologies (UK) Ltd.
// This file is part of Cumulus.

// 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/>.

use crate::*;

#[test]
fn teleport_to_other_system_parachains() {
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)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ pub use frame_support::{
pub use integration_tests_common::{
constants::{
accounts::{ALICE, BOB},
asset_hub_westend::ED as ASSET_HUB_WESTEND_ED,
polkadot::ED as POLKADOT_ED,
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
},
AccountId, AssetHubWestend, AssetHubWestendPallet, AssetHubWestendReceiver,
AssetHubWestendSender, Collectives, CollectivesPallet, CollectivesReceiver, CollectivesSender,
PenpalWestend, PenpalWestendPallet, PenpalWestendReceiver, PenpalWestendSender, Westend,
WestendPallet, WestendReceiver, WestendSender,
test_parachain_is_trusted_teleporter, AccountId, AssetHubWestend, AssetHubWestendPallet,
AssetHubWestendReceiver, AssetHubWestendSender, CollectivesWestend, CollectivesWestendPallet,
CollectivesWestendReceiver, CollectivesWestendSender, PenpalWestend, PenpalWestendPallet,
PenpalWestendReceiver, PenpalWestendSender, Westend, WestendPallet, WestendReceiver,
WestendSender,
};
pub use polkadot_core_primitives::InboundDownwardMessage;
pub use xcm::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,15 @@ fn teleport_native_assets_from_relay_to_assets_para() {
assert_eq!(relay_sender_balance_before - amount, relay_sender_balance_after);
assert!(para_sender_balance_after > para_receiver_balance_before);
}

#[test]
fn teleport_to_other_system_parachains() {
let amount = ASSET_HUB_WESTEND_ED * 100;
let native_asset: VersionedMultiAssets = (Parent, amount).into();

test_parachain_is_trusted_teleporter!(
AssetHubWestend, // Origin
vec![CollectivesWestend], // Destinations
(native_asset, amount)
);
}
Loading