Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[testnets][xcm-emulator] add bridge-hub-westend and hook it up to emulator #2204

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 30 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ members = [
"cumulus/parachains/integration-tests/emulated/assets/asset-hub-rococo",
"cumulus/parachains/integration-tests/emulated/assets/asset-hub-westend",
"cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo",
"cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-westend",
"cumulus/parachains/integration-tests/emulated/common",
"cumulus/parachains/pallets/collective-content",
"cumulus/parachains/pallets/parachain-info",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[package]
name = "bridge-hub-westend-integration-tests"
version = "1.0.0"
authors.workspace = true
edition.workspace = true
license = "Apache-2.0"
description = "Bridge Hub Westend 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}
frame-system = { path = "../../../../../../substrate/frame/system", default-features = false}
sp-core = { path = "../../../../../../substrate/primitives/core", default-features = false}
sp-weights = { path = "../../../../../../substrate/primitives/weights", default-features = false}
pallet-balances = { path = "../../../../../../substrate/frame/balances", default-features = false}
pallet-assets = { path = "../../../../../../substrate/frame/assets", default-features = false}
pallet-message-queue = { path = "../../../../../../substrate/frame/message-queue", default-features = false }

# Polkadot
polkadot-core-primitives = { path = "../../../../../../polkadot/core-primitives", default-features = false}
polkadot-parachain-primitives = { path = "../../../../../../polkadot/parachain", default-features = false}
polkadot-runtime-parachains = { path = "../../../../../../polkadot/runtime/parachains" }
xcm = { package = "staging-xcm", path = "../../../../../../polkadot/xcm", default-features = false}
pallet-xcm = { path = "../../../../../../polkadot/xcm/pallet-xcm", default-features = false}
xcm-executor = { package = "staging-xcm-executor", path = "../../../../../../polkadot/xcm/xcm-executor", default-features = false}

# Cumulus
asset-test-utils = { path = "../../../../../parachains/runtimes/assets/test-utils", default-features = false }
parachains-common = { path = "../../../../common" }
cumulus-pallet-xcmp-queue = { path = "../../../../../pallets/xcmp-queue", default-features = false}
cumulus-pallet-dmp-queue = { path = "../../../../../pallets/dmp-queue", default-features = false}
pallet-bridge-messages = { path = "../../../../../../bridges/modules/messages", default-features = false}
bp-messages = { path = "../../../../../../bridges/primitives/messages", default-features = false}
bridge-hub-westend-runtime = { path = "../../../../../parachains/runtimes/bridge-hubs/bridge-hub-westend", default-features = false }

# Local
xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false}
integration-tests-common = { path = "../../common", default-features = false}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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 bp_messages::LaneId;
pub use frame_support::assert_ok;
pub use integration_tests_common::{
constants::{
bridge_hub_westend::ED as BRIDGE_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},
AssetHubRococo, AssetHubWestend, AssetHubWestendReceiver, BridgeHubRococo, BridgeHubWestend,
BridgeHubWestendPallet, BridgeHubWestendSender, PenpalWestendA, Westend, WestendPallet,
};
pub use parachains_common::{AccountId, Balance};
pub use xcm::{
prelude::{AccountId32 as AccountId32Junction, *},
v3::{
Error,
NetworkId::{Rococo as RococoId, Westend as WestendId},
},
};
pub use xcm_emulator::{
assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para,
RelayChain as Relay, Test, TestArgs, TestContext, TestExt,
};

pub const ASSET_ID: u32 = 1;
pub const ASSET_MIN_BALANCE: u128 = 1000;
pub const ASSETS_PALLET_ID: u8 = 50;

pub type RelayToSystemParaTest = Test<Westend, AssetHubWestend>;
pub type SystemParaToRelayTest = Test<AssetHubWestend, Westend>;
pub type SystemParaToParaTest = Test<AssetHubWestend, PenpalWestendA>;

/// Returns a `TestArgs` instance to de used for the Relay Chain accross integraton tests
pub fn relay_test_args(amount: Balance) -> TestArgs {
TestArgs {
dest: Westend::child_location_of(AssetHubWestend::para_id()),
beneficiary: AccountId32Junction {
network: None,
id: AssetHubWestendReceiver::get().into(),
}
.into(),
amount,
assets: (Here, amount).into(),
asset_id: None,
fee_asset_item: 0,
weight_limit: WeightLimit::Unlimited,
}
}

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// 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 example() {
// Init tests variables
// XcmPallet send arguments
let sudo_origin = <Westend as Chain>::RuntimeOrigin::root();
let destination = Westend::child_location_of(BridgeHubWestend::para_id()).into();
let weight_limit = WeightLimit::Unlimited;
let check_origin = None;

let remote_xcm = Xcm(vec![ClearOrigin]);

let xcm = VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit, check_origin },
ExportMessage {
network: RococoId,
destination: X1(Parachain(AssetHubRococo::para_id().into())),
xcm: remote_xcm,
},
]));

// Westend Global Consensus
// Send XCM message from Relay Chain to Bridge Hub source Parachain
Westend::execute_with(|| {
assert_ok!(<Westend as WestendPallet>::XcmPallet::send(
sudo_origin,
bx!(destination),
bx!(xcm),
));

type RuntimeEvent = <Westend as Chain>::RuntimeEvent;

assert_expected_events!(
Westend,
vec![
RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {},
]
);
});
// Receive XCM message in Bridge Hub source Parachain
BridgeHubWestend::execute_with(|| {
type RuntimeEvent = <BridgeHubWestend as Chain>::RuntimeEvent;

assert_expected_events!(
BridgeHubWestend,
vec![
RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed {
success: true,
..
}) => {},
RuntimeEvent::BridgeRococoMessages(pallet_bridge_messages::Event::MessageAccepted {
lane_id: LaneId([0, 0, 0, 2]),
nonce: 1,
}) => {},
]
);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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 example;
mod teleport;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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::*;
use bridge_hub_westend_runtime::xcm_config::XcmConfig;

#[test]
fn teleport_to_other_system_parachains_works() {
let amount = BRIDGE_HUB_WESTEND_ED * 100;
let native_asset: MultiAssets = (Parent, amount).into();

test_parachain_is_trusted_teleporter!(
BridgeHubWestend, // Origin
XcmConfig, // XCM configuration
vec![AssetHubWestend], // Destinations
(native_asset, amount)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ collectives-polkadot-runtime = { path = "../../../runtimes/collectives/collectiv
bridge-hub-kusama-runtime = { path = "../../../runtimes/bridge-hubs/bridge-hub-kusama" }
bridge-hub-polkadot-runtime = { path = "../../../runtimes/bridge-hubs/bridge-hub-polkadot" }
bridge-hub-rococo-runtime = { path = "../../../runtimes/bridge-hubs/bridge-hub-rococo" }
bridge-hub-westend-runtime = { path = "../../../runtimes/bridge-hubs/bridge-hub-westend" }
xcm-emulator = { default-features = false, path = "../../../../xcm/xcm-emulator" }
cumulus-pallet-xcmp-queue = { default-features = false, path = "../../../../pallets/xcmp-queue" }
cumulus-pallet-parachain-system = { path = "../../../../pallets/parachain-system" }
Expand All @@ -68,6 +69,7 @@ runtime-benchmarks = [
"bridge-hub-kusama-runtime/runtime-benchmarks",
"bridge-hub-polkadot-runtime/runtime-benchmarks",
"bridge-hub-rococo-runtime/runtime-benchmarks",
"bridge-hub-westend-runtime/runtime-benchmarks",
"bridge-runtime-common/runtime-benchmarks",
"collectives-polkadot-runtime/runtime-benchmarks",
"cumulus-pallet-parachain-system/runtime-benchmarks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1160,3 +1160,60 @@ pub mod bridge_hub_rococo {
}
}
}

// Bridge Hub Westend
pub mod bridge_hub_westend {
use super::*;
pub const PARA_ID: u32 = 1013;
pub const ED: Balance = parachains_common::westend::currency::EXISTENTIAL_DEPOSIT;

pub fn genesis() -> Storage {
let genesis_config = serde_json::json!({
"balances": {
"balances": accounts::init_balances()
.iter()
.cloned()
.map(|k| (k, ED * 4096))
.collect::<Vec<_>>(),
},
"parachainInfo": {
"parachainId": cumulus_primitives_core::ParaId::from(PARA_ID),
},
"collatorSelection": {
"invulnerables": collators::invulnerables()
.iter()
.cloned()
.map(|(acc, _)| acc)
.collect::<Vec<_>>(),
"candidacyBond": ED * 16,
},
"session": {
"keys": collators::invulnerables()
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
bridge_hub_westend_runtime::SessionKeys { aura }, // session keys
)
})
.collect::<Vec<_>>(),
},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
},
"bridgeRococoGrandpa": {
"owner": Some(get_account_id_from_seed::<sr25519::Public>(accounts::BOB)),
},
"bridgeRococoMessages": {
"owner": Some(get_account_id_from_seed::<sr25519::Public>(accounts::BOB)),
}
});

build_genesis_storage(
genesis_config,
bridge_hub_westend_runtime::WASM_BINARY
.expect("WASM binary was not built, please build it!"),
)
}
}
Loading
Loading