Skip to content

Commit

Permalink
xcm-emulator: fix bridge-hub-westend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
acatangiu committed Nov 7, 2023
1 parent 2c21851 commit ecfe059
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 60 deletions.
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
@@ -1,10 +1,10 @@
[package]
name = "bridge-hub-rococo-integration-tests"
name = "bridge-hub-westend-integration-tests"
version = "1.0.0"
authors.workspace = true
edition.workspace = true
license = "Apache-2.0"
description = "Bridge Hub Rococo runtime integration tests with xcm-emulator"
description = "Bridge Hub Westend runtime integration tests with xcm-emulator"
publish = false

[dependencies]
Expand Down Expand Up @@ -34,7 +34,7 @@ cumulus-pallet-xcmp-queue = { path = "../../../../../pallets/xcmp-queue", defaul
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-rococo-runtime = { path = "../../../../../parachains/runtimes/bridge-hubs/bridge-hub-rococo", 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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ pub use bp_messages::LaneId;
pub use frame_support::assert_ok;
pub use integration_tests_common::{
constants::{
bridge_hub_rococo::ED as BRIDGE_HUB_ROCOCO_ED, rococo::ED as ROCOCO_ED,
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, AssetHubRococoReceiver, AssetHubWococo, BridgeHubRococo, BridgeHubRococoPallet,
BridgeHubRococoSender, BridgeHubWococo, PenpalRococoA, Rococo, RococoPallet,
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, Wococo as WococoId},
NetworkId::{Rococo as RococoId, Westend as WestendId},
},
};
pub use xcm_emulator::{
Expand All @@ -42,17 +42,17 @@ pub const ASSET_ID: u32 = 1;
pub const ASSET_MIN_BALANCE: u128 = 1000;
pub const ASSETS_PALLET_ID: u8 = 50;

pub type RelayToSystemParaTest = Test<Rococo, AssetHubRococo>;
pub type SystemParaToRelayTest = Test<AssetHubRococo, Rococo>;
pub type SystemParaToParaTest = Test<AssetHubRococo, PenpalRococoA>;
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: Rococo::child_location_of(AssetHubRococo::para_id()),
dest: Westend::child_location_of(AssetHubWestend::para_id()),
beneficiary: AccountId32Junction {
network: None,
id: AssetHubRococoReceiver::get().into(),
id: AssetHubWestendReceiver::get().into(),
}
.into(),
amount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use crate::*;
fn example() {
// Init tests variables
// XcmPallet send arguments
let sudo_origin = <Rococo as Chain>::RuntimeOrigin::root();
let destination = Rococo::child_location_of(BridgeHubRococo::para_id()).into();
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;

Expand All @@ -29,72 +29,46 @@ fn example() {
let xcm = VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit, check_origin },
ExportMessage {
network: WococoId,
destination: X1(Parachain(AssetHubWococo::para_id().into())),
network: RococoId,
destination: X1(Parachain(AssetHubRococo::para_id().into())),
xcm: remote_xcm,
},
]));

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

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

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

assert_expected_events!(
BridgeHubRococo,
BridgeHubWestend,
vec![
RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed {
success: true,
..
}) => {},
RuntimeEvent::BridgeWococoMessages(pallet_bridge_messages::Event::MessageAccepted {
lane_id: LaneId([0, 0, 0, 1]),
RuntimeEvent::BridgeRococoMessages(pallet_bridge_messages::Event::MessageAccepted {
lane_id: LaneId([0, 0, 0, 2]),
nonce: 1,
}) => {},
]
);
});

// Wococo GLobal Consensus
// Receive XCM message in Bridge Hub target Parachain
BridgeHubWococo::execute_with(|| {
type RuntimeEvent = <BridgeHubWococo as Chain>::RuntimeEvent;

assert_expected_events!(
BridgeHubWococo,
vec![
RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {},
]
);
});
// Receive embeded XCM message within `ExportMessage` in Parachain destination
AssetHubWococo::execute_with(|| {
type RuntimeEvent = <AssetHubWococo as Chain>::RuntimeEvent;

assert_expected_events!(
AssetHubWococo,
vec![
RuntimeEvent::MessageQueue(pallet_message_queue::Event::ProcessingFailed {
..
}) => {},
]
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
// limitations under the License.

use crate::*;
use bridge_hub_rococo_runtime::xcm_config::XcmConfig;
use bridge_hub_westend_runtime::xcm_config::XcmConfig;

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

test_parachain_is_trusted_teleporter!(
BridgeHubRococo, // Origin
XcmConfig, // XCM configuration
vec![AssetHubRococo], // Destinations
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!"),
)
}
}
27 changes: 25 additions & 2 deletions cumulus/parachains/integration-tests/emulated/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub mod xcm_helpers;

use constants::{
accounts::{ALICE, BOB},
asset_hub_rococo, asset_hub_westend, asset_hub_wococo, bridge_hub_rococo, penpal, rococo,
westend,
asset_hub_rococo, asset_hub_westend, asset_hub_wococo, bridge_hub_rococo, bridge_hub_westend,
penpal, rococo, westend,
};
use impls::{RococoWococoMessageHandler, WococoRococoMessageHandler};
pub use paste;
Expand Down Expand Up @@ -118,6 +118,23 @@ decl_test_parachains! {
AssetConversion: asset_hub_westend_runtime::AssetConversion,
}
},
pub struct BridgeHubWestend {
genesis = bridge_hub_westend::genesis(),
on_init = {
bridge_hub_westend_runtime::AuraExt::on_initialize(1);
},
runtime = bridge_hub_westend_runtime,
core = {
XcmpMessageHandler: bridge_hub_westend_runtime::XcmpQueue,
LocationToAccountId: bridge_hub_westend_runtime::xcm_config::LocationToAccountId,
ParachainInfo: bridge_hub_westend_runtime::ParachainInfo,
MessageProcessor: DefaultParaMessageProcessor<BridgeHubWestend>,
},
pallets = {
PolkadotXcm: bridge_hub_westend_runtime::PolkadotXcm,
Balances: bridge_hub_westend_runtime::Balances,
}
},
pub struct PenpalWestendA {
genesis = penpal::genesis(penpal::PARA_ID_A),
on_init = {
Expand Down Expand Up @@ -257,6 +274,7 @@ decl_test_networks! {
relay_chain = Westend,
parachains = vec![
AssetHubWestend,
BridgeHubWestend,
PenpalWestendA,
],
bridge = ()
Expand Down Expand Up @@ -323,6 +341,10 @@ impl_assert_events_helpers_for_parachain!(AssetHubRococo);
// PenpalWestendA implementation
impl_assert_events_helpers_for_parachain!(PenpalWestendA);

// BridgeHubWestend implementation
impl_accounts_helpers_for_parachain!(BridgeHubWestend);
impl_assert_events_helpers_for_parachain!(BridgeHubWestend);

// BridgeHubRococo implementation
impl_accounts_helpers_for_parachain!(BridgeHubRococo);
impl_assert_events_helpers_for_parachain!(BridgeHubRococo);
Expand All @@ -343,6 +365,7 @@ decl_test_sender_receiver_accounts_parameter_types! {
// Bridged Hubs
BridgeHubRococo { sender: ALICE, receiver: BOB },
BridgeHubWococo { sender: ALICE, receiver: BOB },
BridgeHubWestend { sender: ALICE, receiver: BOB },
// Penpals
PenpalWestendA { sender: ALICE, receiver: BOB },
PenpalRococoA { sender: ALICE, receiver: BOB },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pallet-aura = { path = "../../../../../substrate/frame/aura", default-features =
pallet-authorship = { path = "../../../../../substrate/frame/authorship", default-features = false}
pallet-balances = { path = "../../../../../substrate/frame/balances", default-features = false}
pallet-session = { path = "../../../../../substrate/frame/session", default-features = false}
pallet-message-queue = { path = "../../../../../substrate/frame/message-queue", default-features = false }
pallet-multisig = { path = "../../../../../substrate/frame/multisig", default-features = false}
pallet-timestamp = { path = "../../../../../substrate/frame/timestamp", default-features = false}
pallet-transaction-payment = { path = "../../../../../substrate/frame/transaction-payment", default-features = false}
Expand Down Expand Up @@ -62,7 +63,6 @@ xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkad

# Cumulus
cumulus-pallet-aura-ext = { path = "../../../../pallets/aura-ext", default-features = false }
pallet-message-queue = { path = "../../../../../substrate/frame/message-queue", default-features = false }
cumulus-pallet-dmp-queue = { path = "../../../../pallets/dmp-queue", default-features = false }
cumulus-pallet-parachain-system = { path = "../../../../pallets/parachain-system", default-features = false, features = ["parameterized-consensus-hook",] }
cumulus-pallet-session-benchmarking = { path = "../../../../pallets/session-benchmarking", default-features = false}
Expand Down

0 comments on commit ecfe059

Please sign in to comment.