From efff7559ef18a128629a545e6663d65184eef771 Mon Sep 17 00:00:00 2001 From: ron Date: Thu, 2 Nov 2023 11:36:19 +0800 Subject: [PATCH 1/2] Fix tests --- .../bridge-hub-rococo/src/tests/snowbridge.rs | 46 +++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/snowbridge.rs b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/snowbridge.rs index fa494fbac3c6..15caa305a659 100644 --- a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/snowbridge.rs +++ b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/snowbridge.rs @@ -19,11 +19,19 @@ use snowbridge_control; #[test] fn create_agent() { + BridgeHubRococo::fund_accounts(vec![( + BridgeHubRococo::sovereign_account_id_of(MultiLocation { + parents: 1, + interior: X1(Parachain(1000)), + }), + 5_000_000 * ROCOCO_ED, + )]); + let sudo_origin = ::RuntimeOrigin::root(); let destination = Rococo::child_location_of(BridgeHubRococo::para_id()).into(); let remote_xcm = VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: WeightLimit::Unlimited, check_origin: None }, + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, DescendOrigin(X1(Parachain(1000))), Transact { require_weight_at_most: 3000000000.into(), @@ -71,30 +79,50 @@ fn create_agent() { #[test] fn create_channel() { + let source_location = MultiLocation { parents: 1, interior: X1(Parachain(1000)) }; + + BridgeHubRococo::fund_accounts(vec![( + BridgeHubRococo::sovereign_account_id_of(source_location), + 5_000_000 * ROCOCO_ED, + )]); + let sudo_origin = ::RuntimeOrigin::root(); - let destination = Rococo::child_location_of(BridgeHubRococo::para_id()).into(); + let destination: VersionedMultiLocation = + Rococo::child_location_of(BridgeHubRococo::para_id()).into(); - let remote_xcm = VersionedXcm::from(Xcm(vec![ + let create_agent_xcm = VersionedXcm::from(Xcm(vec![ UnpaidExecution { weight_limit: WeightLimit::Unlimited, check_origin: None }, DescendOrigin(X1(Parachain(1000))), Transact { - require_weight_at_most: 8000000000.into(), + require_weight_at_most: 3000000000.into(), origin_kind: OriginKind::Xcm, - call: vec![51, 2].into(), + call: vec![51, 1].into(), }, ])); - //BridgeHubRococo::execute_with(|| { // TODO Create agent in storage - // ::EthereumControl::create_agent(sudo_origin); - //}); + let create_channel_xcm = VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + DescendOrigin(X1(Parachain(1000))), + Transact { + require_weight_at_most: 3000000000.into(), + origin_kind: OriginKind::Xcm, + call: vec![51, 2].into(), + }, + ])); //Rococo Global Consensus // Send XCM message from Relay Chain to Bridge Hub source Parachain Rococo::execute_with(|| { + assert_ok!(::XcmPallet::send( + sudo_origin.clone(), + bx!(destination.clone()), + bx!(create_agent_xcm), + )); + assert_ok!(::XcmPallet::send( sudo_origin, bx!(destination), - bx!(remote_xcm), + bx!(create_channel_xcm), )); type RuntimeEvent = ::RuntimeEvent; From 0ccbcbfe5cab6333be12f615c3b2ed04ebd8da56 Mon Sep 17 00:00:00 2001 From: ron Date: Thu, 2 Nov 2023 17:16:27 +0800 Subject: [PATCH 2/2] Improve integration tests --- Cargo.lock | 6 ++ .../bridges/bridge-hub-rococo/Cargo.toml | 35 +++++++----- .../bridge-hub-rococo/src/tests/snowbridge.rs | 55 ++++++++++++++++++- .../emulated/common/src/lib.rs | 1 + 4 files changed, 83 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 576e3836c943..ce3793856e3d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2022,7 +2022,10 @@ dependencies = [ "cumulus-pallet-dmp-queue", "cumulus-pallet-xcmp-queue", "frame-support", + "hex", + "hex-literal", "integration-tests-common", + "pallet-assets", "pallet-bridge-messages", "pallet-xcm", "parachains-common", @@ -2031,6 +2034,9 @@ dependencies = [ "polkadot-parachain-primitives", "polkadot-runtime-parachains", "snowbridge-control", + "snowbridge-core", + "snowbridge-inbound-queue", + "snowbridge-router-primitives", "staging-xcm", "staging-xcm-executor", "xcm-emulator", diff --git a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/Cargo.toml index 29499034fba5..90eb7738876a 100644 --- a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/Cargo.toml @@ -7,32 +7,41 @@ license = "Apache-2.0" description = "Bridge Hub Rococo runtime integration tests with xcm-emulator" publish = false +[lib] +doctest = false + [dependencies] codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false } +hex = "0.4.3" +hex-literal = "0.4.1" # Substrate -frame-support = { path = "../../../../../../substrate/frame/support", default-features = false} +frame-support = { path = "../../../../../../substrate/frame/support", default-features = false } +pallet-assets = { path = "../../../../../../substrate/frame/assets", default-features = false } # Polkadot -polkadot-core-primitives = { path = "../../../../../../polkadot/core-primitives", default-features = false} -polkadot-parachain-primitives = { path = "../../../../../../polkadot/parachain", default-features = false} +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} +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} +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-rococo-runtime = { path = "../../../../../parachains/runtimes/bridge-hubs/bridge-hub-rococo", default-features = false } # Local -xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false} -integration-tests-common = { path = "../../common", default-features = false} +xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false } +integration-tests-common = { path = "../../common", default-features = false } # Snowbridge -snowbridge-control = { path = "../../../../../../../parachain/pallets/control" } +snowbridge-core = { path = "../../../../../../../parachain/primitives/core", default-features = false } +snowbridge-router-primitives = { path = "../../../../../../../parachain/primitives/router", default-features = false } +snowbridge-control = { path = "../../../../../../../parachain/pallets/control", default-features = false } +snowbridge-inbound-queue = { path = "../../../../../../../parachain/pallets/inbound-queue", default-features = false } diff --git a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/snowbridge.rs b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/snowbridge.rs index 15caa305a659..35f9c7e06de9 100644 --- a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/snowbridge.rs +++ b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/snowbridge.rs @@ -14,8 +14,10 @@ // limitations under the License. use crate::*; +use hex_literal::hex; use integration_tests_common::BridgeHubRococoPallet; use snowbridge_control; +use snowbridge_router_primitives::inbound::{Command, MessageV1, VersionedMessage}; #[test] fn create_agent() { @@ -91,7 +93,7 @@ fn create_channel() { Rococo::child_location_of(BridgeHubRococo::para_id()).into(); let create_agent_xcm = VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit: WeightLimit::Unlimited, check_origin: None }, + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, DescendOrigin(X1(Parachain(1000))), Transact { require_weight_at_most: 3000000000.into(), @@ -152,3 +154,54 @@ fn create_channel() { ); }); } + +#[test] +fn register_token() { + BridgeHubRococo::fund_accounts(vec![( + BridgeHubRococo::sovereign_account_id_of(MultiLocation { + parents: 1, + interior: X1(Parachain(1000)), + }), + 5_000_000 * ROCOCO_ED, + )]); + + // Fund gateway sovereign in asset hub + AssetHubRococo::fund_accounts(vec![( + hex!("c9794dd8013efb2ad83f668845c62b373c16ad33971745731408058e4d0c6ff5").into(), + 5_000_000_000_000 * ROCOCO_ED, + )]); + + BridgeHubRococo::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + type EthereumInboundQueue = + ::EthereumInboundQueue; + let message = VersionedMessage::V1(MessageV1 { + chain_id: 15, + command: Command::RegisterToken { + gateway: hex!("EDa338E4dC46038493b885327842fD3E301CaB39").into(), + token: hex!("87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d").into(), + }, + }); + let xcm = EthereumInboundQueue::do_convert(message).unwrap(); + let _ = EthereumInboundQueue::send_xcm(xcm, 1000.into()).unwrap(); + + assert_expected_events!( + BridgeHubRococo, + vec![ + RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {}, + ] + ); + }); + + AssetHubRococo::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + AssetHubRococo, + vec![ + RuntimeEvent::ForeignAssets(pallet_assets::Event::Created { .. }) => {}, + RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { .. }) => {}, + ] + ); + }); +} diff --git a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs index 3317ba2950e5..c87e406247be 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs @@ -151,6 +151,7 @@ decl_test_parachains! { PolkadotXcm: bridge_hub_rococo_runtime::PolkadotXcm, Balances: bridge_hub_rococo_runtime::Balances, EthereumControl: bridge_hub_rococo_runtime::EthereumControl, + EthereumInboundQueue: bridge_hub_rococo_runtime::EthereumInboundQueue, } }, // AssetHubRococo