Skip to content

Commit e0065cb

Browse files
Make System Parachains trusted Teleporters (#1368)
Make System Parachain trusted Teleporters of each other. Migration of paritytech/cumulus#2842 --------- Co-authored-by: command-bot <> Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
1 parent 4145902 commit e0065cb

24 files changed

Lines changed: 465 additions & 84 deletions

File tree

Cargo.lock

Lines changed: 33 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ members = [
6060
"cumulus/parachain-template/pallets/template",
6161
"cumulus/parachain-template/runtime",
6262
"cumulus/parachains/common",
63+
"cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo",
6364
"cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend",
6465
"cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo",
6566
"cumulus/parachains/integration-tests/emulated/common",

cumulus/parachains/common/src/xcm_config.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use crate::impls::AccountIdOf;
1717
use core::marker::PhantomData;
18+
use cumulus_primitives_core::{IsSystem, ParaId};
1819
use frame_support::{
1920
traits::{fungibles::Inspect, tokens::ConversionToAssetBalance, ContainsPair},
2021
weights::Weight,
@@ -78,3 +79,85 @@ impl<Location: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
7879
matches!(asset.id, Concrete(ref id) if id == origin && origin == &Location::get())
7980
}
8081
}
82+
83+
/// Accepts an asset if it is a concrete asset from the system (Relay Chain or system parachain).
84+
pub struct ConcreteAssetFromSystem<AssetLocation>(PhantomData<AssetLocation>);
85+
impl<AssetLocation: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
86+
for ConcreteAssetFromSystem<AssetLocation>
87+
{
88+
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
89+
log::trace!(target: "xcm::contains", "ConcreteAssetFromSystem asset: {:?}, origin: {:?}", asset, origin);
90+
let is_system = match origin {
91+
// The Relay Chain
92+
MultiLocation { parents: 1, interior: Here } => true,
93+
// System parachain
94+
MultiLocation { parents: 1, interior: X1(Parachain(id)) } =>
95+
ParaId::from(*id).is_system(),
96+
// Others
97+
_ => false,
98+
};
99+
matches!(asset.id, Concrete(id) if id == AssetLocation::get()) && is_system
100+
}
101+
}
102+
103+
#[cfg(test)]
104+
mod tests {
105+
use frame_support::parameter_types;
106+
107+
use super::{
108+
ConcreteAssetFromSystem, ContainsPair, GeneralIndex, Here, MultiAsset, MultiLocation,
109+
PalletInstance, Parachain, Parent,
110+
};
111+
112+
parameter_types! {
113+
pub const RelayLocation: MultiLocation = MultiLocation::parent();
114+
}
115+
116+
#[test]
117+
fn concrete_asset_from_relay_works() {
118+
let expected_asset: MultiAsset = (Parent, 1000000).into();
119+
let expected_origin: MultiLocation = (Parent, Here).into();
120+
121+
assert!(<ConcreteAssetFromSystem<RelayLocation>>::contains(
122+
&expected_asset,
123+
&expected_origin
124+
));
125+
}
126+
127+
#[test]
128+
fn concrete_asset_from_sibling_system_para_fails_for_wrong_asset() {
129+
let unexpected_assets: Vec<MultiAsset> = vec![
130+
(Here, 1000000).into(),
131+
((PalletInstance(50), GeneralIndex(1)), 1000000).into(),
132+
((Parent, Parachain(1000), PalletInstance(50), GeneralIndex(1)), 1000000).into(),
133+
];
134+
let expected_origin: MultiLocation = (Parent, Parachain(1000)).into();
135+
136+
unexpected_assets.iter().for_each(|asset| {
137+
assert!(!<ConcreteAssetFromSystem<RelayLocation>>::contains(asset, &expected_origin));
138+
});
139+
}
140+
141+
#[test]
142+
fn concrete_asset_from_sibling_system_para_works_for_correct_asset() {
143+
// (para_id, expected_result)
144+
let test_data = vec![
145+
(0, true),
146+
(1, true),
147+
(1000, true),
148+
(1999, true),
149+
(2000, false), // Not a System Parachain
150+
(2001, false), // Not a System Parachain
151+
];
152+
153+
let expected_asset: MultiAsset = (Parent, 1000000).into();
154+
155+
for (para_id, expected_result) in test_data {
156+
let origin: MultiLocation = (Parent, Parachain(para_id)).into();
157+
assert_eq!(
158+
expected_result,
159+
<ConcreteAssetFromSystem<RelayLocation>>::contains(&expected_asset, &origin)
160+
);
161+
}
162+
}
163+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "asset-hub-rococo-integration-tests"
3+
version = "1.0.0"
4+
authors.workspace = true
5+
edition.workspace = true
6+
description = "Asset Hub Rococo runtime integration tests with xcm-emulator"
7+
publish = false
8+
9+
[dependencies]
10+
codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false }
11+
12+
# Substrate
13+
frame-support = { path = "../../../../../../substrate/frame/support", default-features = false}
14+
xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false}
15+
16+
# Local
17+
xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false}
18+
integration-tests-common = { path = "../../common", default-features = false}
19+
20+
[features]
21+
runtime-benchmarks = [
22+
"frame-support/runtime-benchmarks",
23+
"integration-tests-common/runtime-benchmarks",
24+
]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (C) Parity Technologies (UK) Ltd.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
pub use frame_support::assert_ok;
17+
pub use integration_tests_common::{
18+
constants::asset_hub_rococo::ED as ASSET_HUB_ROCOCO_ED, test_parachain_is_trusted_teleporter,
19+
AssetHubRococo, AssetHubRococoPallet, AssetHubRococoSender, BridgeHubRococo,
20+
BridgeHubRococoReceiver,
21+
};
22+
pub use xcm::prelude::*;
23+
pub use xcm_emulator::{assert_expected_events, bx, Chain, Parachain, TestExt};
24+
25+
#[cfg(test)]
26+
mod tests;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (C) Parity Technologies (UK) Ltd.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
mod teleport;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (C) Parity Technologies (UK) Ltd.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
use crate::*;
17+
18+
#[test]
19+
fn teleport_to_other_system_parachains_works() {
20+
let amount = ASSET_HUB_ROCOCO_ED * 100;
21+
let native_asset: VersionedMultiAssets = (Parent, amount).into();
22+
23+
test_parachain_is_trusted_teleporter!(
24+
AssetHubRococo, // Origin
25+
vec![BridgeHubRococo], // Destinations
26+
(native_asset, amount)
27+
);
28+
}

0 commit comments

Comments
 (0)