Skip to content

Commit ba4c74d

Browse files
acatangiuordian
authored andcommitted
[testnets][xcm-emulator] add bridge-hub-westend and hook it up to emulator (#2204)
`bridge-hub-westend-runtime` was added to cumulus/parachains, but wasn't hooked up to xcm-emulator to run tests against it. This commit addresses that ^. Signed-off-by: Adrian Catangiu <[email protected]>
1 parent 0d350b6 commit ba4c74d

File tree

11 files changed

+345
-3
lines changed

11 files changed

+345
-3
lines changed

Cargo.lock

Lines changed: 30 additions & 0 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
@@ -68,6 +68,7 @@ members = [
6868
"cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo",
6969
"cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend",
7070
"cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo",
71+
"cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-westend",
7172
"cumulus/parachains/integration-tests/emulated/common",
7273
"cumulus/parachains/pallets/collective-content",
7374
"cumulus/parachains/pallets/parachain-info",
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[package]
2+
name = "bridge-hub-westend-integration-tests"
3+
version = "1.0.0"
4+
authors.workspace = true
5+
edition.workspace = true
6+
license = "Apache-2.0"
7+
description = "Bridge Hub Westend runtime integration tests with xcm-emulator"
8+
publish = false
9+
10+
[dependencies]
11+
codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false }
12+
13+
# Substrate
14+
frame-support = { path = "../../../../../../substrate/frame/support", default-features = false}
15+
frame-system = { path = "../../../../../../substrate/frame/system", default-features = false}
16+
sp-core = { path = "../../../../../../substrate/primitives/core", default-features = false}
17+
sp-weights = { path = "../../../../../../substrate/primitives/weights", default-features = false}
18+
pallet-balances = { path = "../../../../../../substrate/frame/balances", default-features = false}
19+
pallet-assets = { path = "../../../../../../substrate/frame/assets", default-features = false}
20+
pallet-message-queue = { path = "../../../../../../substrate/frame/message-queue", default-features = false }
21+
22+
# Polkadot
23+
polkadot-core-primitives = { path = "../../../../../../polkadot/core-primitives", default-features = false}
24+
polkadot-parachain-primitives = { path = "../../../../../../polkadot/parachain", default-features = false}
25+
polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" }
26+
xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false}
27+
pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false}
28+
xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../polkadot/xcm/xcm-executor", default-features = false}
29+
30+
# Cumulus
31+
asset-test-utils = { path = "../../../../../parachains/runtimes/assets/test-utils", default-features = false }
32+
parachains-common = { path = "../../../../common" }
33+
cumulus-pallet-xcmp-queue = { path = "../../../../../pallets/xcmp-queue", default-features = false}
34+
cumulus-pallet-dmp-queue = { path = "../../../../../pallets/dmp-queue", default-features = false}
35+
pallet-bridge-messages = { path = "../../../../../../bridges/modules/messages", default-features = false}
36+
bp-messages = { path = "../../../../../../bridges/primitives/messages", default-features = false}
37+
bridge-hub-westend-runtime = { path = "../../../../../parachains/runtimes/bridge-hubs/bridge-hub-westend", default-features = false }
38+
39+
# Local
40+
xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false}
41+
integration-tests-common = { path = "../../common", default-features = false}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 bp_messages::LaneId;
17+
pub use frame_support::assert_ok;
18+
pub use integration_tests_common::{
19+
constants::{
20+
bridge_hub_westend::ED as BRIDGE_HUB_WESTEND_ED, westend::ED as WESTEND_ED,
21+
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
22+
},
23+
test_parachain_is_trusted_teleporter,
24+
xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution},
25+
AssetHubRococo, AssetHubWestend, AssetHubWestendReceiver, BridgeHubRococo, BridgeHubWestend,
26+
BridgeHubWestendPallet, BridgeHubWestendSender, PenpalWestendA, Westend, WestendPallet,
27+
};
28+
pub use parachains_common::{AccountId, Balance};
29+
pub use xcm::{
30+
prelude::{AccountId32 as AccountId32Junction, *},
31+
v3::{
32+
Error,
33+
NetworkId::{Rococo as RococoId, Westend as WestendId},
34+
},
35+
};
36+
pub use xcm_emulator::{
37+
assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para,
38+
RelayChain as Relay, Test, TestArgs, TestContext, TestExt,
39+
};
40+
41+
pub const ASSET_ID: u32 = 1;
42+
pub const ASSET_MIN_BALANCE: u128 = 1000;
43+
pub const ASSETS_PALLET_ID: u8 = 50;
44+
45+
pub type RelayToSystemParaTest = Test<Westend, AssetHubWestend>;
46+
pub type SystemParaToRelayTest = Test<AssetHubWestend, Westend>;
47+
pub type SystemParaToParaTest = Test<AssetHubWestend, PenpalWestendA>;
48+
49+
/// Returns a `TestArgs` instance to de used for the Relay Chain accross integraton tests
50+
pub fn relay_test_args(amount: Balance) -> TestArgs {
51+
TestArgs {
52+
dest: Westend::child_location_of(AssetHubWestend::para_id()),
53+
beneficiary: AccountId32Junction {
54+
network: None,
55+
id: AssetHubWestendReceiver::get().into(),
56+
}
57+
.into(),
58+
amount,
59+
assets: (Here, amount).into(),
60+
asset_id: None,
61+
fee_asset_item: 0,
62+
weight_limit: WeightLimit::Unlimited,
63+
}
64+
}
65+
66+
#[cfg(test)]
67+
mod tests;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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 example() {
20+
// Init tests variables
21+
// XcmPallet send arguments
22+
let sudo_origin = <Westend as Chain>::RuntimeOrigin::root();
23+
let destination = Westend::child_location_of(BridgeHubWestend::para_id()).into();
24+
let weight_limit = WeightLimit::Unlimited;
25+
let check_origin = None;
26+
27+
let remote_xcm = Xcm(vec![ClearOrigin]);
28+
29+
let xcm = VersionedXcm::from(Xcm(vec![
30+
UnpaidExecution { weight_limit, check_origin },
31+
ExportMessage {
32+
network: RococoId,
33+
destination: X1(Parachain(AssetHubRococo::para_id().into())),
34+
xcm: remote_xcm,
35+
},
36+
]));
37+
38+
// Westend Global Consensus
39+
// Send XCM message from Relay Chain to Bridge Hub source Parachain
40+
Westend::execute_with(|| {
41+
assert_ok!(<Westend as WestendPallet>::XcmPallet::send(
42+
sudo_origin,
43+
bx!(destination),
44+
bx!(xcm),
45+
));
46+
47+
type RuntimeEvent = <Westend as Chain>::RuntimeEvent;
48+
49+
assert_expected_events!(
50+
Westend,
51+
vec![
52+
RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {},
53+
]
54+
);
55+
});
56+
// Receive XCM message in Bridge Hub source Parachain
57+
BridgeHubWestend::execute_with(|| {
58+
type RuntimeEvent = <BridgeHubWestend as Chain>::RuntimeEvent;
59+
60+
assert_expected_events!(
61+
BridgeHubWestend,
62+
vec![
63+
RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed {
64+
success: true,
65+
..
66+
}) => {},
67+
RuntimeEvent::BridgeRococoMessages(pallet_bridge_messages::Event::MessageAccepted {
68+
lane_id: LaneId([0, 0, 0, 2]),
69+
nonce: 1,
70+
}) => {},
71+
]
72+
);
73+
});
74+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 example;
17+
mod teleport;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
use bridge_hub_westend_runtime::xcm_config::XcmConfig;
18+
19+
#[test]
20+
fn teleport_to_other_system_parachains_works() {
21+
let amount = BRIDGE_HUB_WESTEND_ED * 100;
22+
let native_asset: MultiAssets = (Parent, amount).into();
23+
24+
test_parachain_is_trusted_teleporter!(
25+
BridgeHubWestend, // Origin
26+
XcmConfig, // XCM configuration
27+
vec![AssetHubWestend], // Destinations
28+
(native_asset, amount)
29+
);
30+
}

cumulus/parachains/integration-tests/emulated/common/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ collectives-polkadot-runtime = { path = "../../../runtimes/collectives/collectiv
5252
bridge-hub-kusama-runtime = { path = "../../../runtimes/bridge-hubs/bridge-hub-kusama" }
5353
bridge-hub-polkadot-runtime = { path = "../../../runtimes/bridge-hubs/bridge-hub-polkadot" }
5454
bridge-hub-rococo-runtime = { path = "../../../runtimes/bridge-hubs/bridge-hub-rococo" }
55+
bridge-hub-westend-runtime = { path = "../../../runtimes/bridge-hubs/bridge-hub-westend" }
5556
xcm-emulator = { default-features = false, path = "../../../../xcm/xcm-emulator" }
5657
cumulus-pallet-xcmp-queue = { default-features = false, path = "../../../../pallets/xcmp-queue" }
5758
cumulus-pallet-parachain-system = { path = "../../../../pallets/parachain-system" }
@@ -68,6 +69,7 @@ runtime-benchmarks = [
6869
"bridge-hub-kusama-runtime/runtime-benchmarks",
6970
"bridge-hub-polkadot-runtime/runtime-benchmarks",
7071
"bridge-hub-rococo-runtime/runtime-benchmarks",
72+
"bridge-hub-westend-runtime/runtime-benchmarks",
7173
"bridge-runtime-common/runtime-benchmarks",
7274
"collectives-polkadot-runtime/runtime-benchmarks",
7375
"cumulus-pallet-parachain-system/runtime-benchmarks",

cumulus/parachains/integration-tests/emulated/common/src/constants.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,3 +1160,60 @@ pub mod bridge_hub_rococo {
11601160
}
11611161
}
11621162
}
1163+
1164+
// Bridge Hub Westend
1165+
pub mod bridge_hub_westend {
1166+
use super::*;
1167+
pub const PARA_ID: u32 = 1013;
1168+
pub const ED: Balance = parachains_common::westend::currency::EXISTENTIAL_DEPOSIT;
1169+
1170+
pub fn genesis() -> Storage {
1171+
let genesis_config = serde_json::json!({
1172+
"balances": {
1173+
"balances": accounts::init_balances()
1174+
.iter()
1175+
.cloned()
1176+
.map(|k| (k, ED * 4096))
1177+
.collect::<Vec<_>>(),
1178+
},
1179+
"parachainInfo": {
1180+
"parachainId": cumulus_primitives_core::ParaId::from(PARA_ID),
1181+
},
1182+
"collatorSelection": {
1183+
"invulnerables": collators::invulnerables()
1184+
.iter()
1185+
.cloned()
1186+
.map(|(acc, _)| acc)
1187+
.collect::<Vec<_>>(),
1188+
"candidacyBond": ED * 16,
1189+
},
1190+
"session": {
1191+
"keys": collators::invulnerables()
1192+
.into_iter()
1193+
.map(|(acc, aura)| {
1194+
(
1195+
acc.clone(), // account id
1196+
acc, // validator id
1197+
bridge_hub_westend_runtime::SessionKeys { aura }, // session keys
1198+
)
1199+
})
1200+
.collect::<Vec<_>>(),
1201+
},
1202+
"polkadotXcm": {
1203+
"safeXcmVersion": Some(SAFE_XCM_VERSION),
1204+
},
1205+
"bridgeRococoGrandpa": {
1206+
"owner": Some(get_account_id_from_seed::<sr25519::Public>(accounts::BOB)),
1207+
},
1208+
"bridgeRococoMessages": {
1209+
"owner": Some(get_account_id_from_seed::<sr25519::Public>(accounts::BOB)),
1210+
}
1211+
});
1212+
1213+
build_genesis_storage(
1214+
genesis_config,
1215+
bridge_hub_westend_runtime::WASM_BINARY
1216+
.expect("WASM binary was not built, please build it!"),
1217+
)
1218+
}
1219+
}

0 commit comments

Comments
 (0)