From c228db2e48e0b2e1b4b6249d2baf1938f147e31c Mon Sep 17 00:00:00 2001 From: Adrian Catangiu Date: Thu, 9 Nov 2023 14:32:32 +0200 Subject: [PATCH 1/9] xcm-emulator: switch from Rococo<>Wococo to Rococo<>Westend bridge and make bidirectional tests --- Cargo.lock | 12 ++-- Cargo.toml | 2 +- .../emulated/common/src/impls.rs | 45 +++++++------- .../Cargo.toml | 10 ++-- .../src/lib.rs | 60 ++++++++++--------- .../bridges/bridge-hub-rococo/Cargo.toml | 2 +- .../bridges/bridge-hub-rococo/src/lib.rs | 8 +-- .../bridge-hub-rococo/src/tests/example.rs | 26 ++++---- .../bridges/bridge-hub-westend/Cargo.toml | 2 +- .../bridges/bridge-hub-westend/src/lib.rs | 13 ++-- .../bridge-hub-westend/src/tests/example.rs | 28 ++++++++- 11 files changed, 121 insertions(+), 87 deletions(-) rename cumulus/parachains/integration-tests/emulated/networks/{rococo-wococo-system => rococo-westend-system}/Cargo.toml (57%) rename cumulus/parachains/integration-tests/emulated/networks/{rococo-wococo-system => rococo-westend-system}/src/lib.rs (57%) diff --git a/Cargo.lock b/Cargo.lock index 54fa7c6485bb..7e5f91fda128 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2205,7 +2205,7 @@ dependencies = [ "pallet-xcm", "parachains-common", "parity-scale-codec", - "rococo-wococo-system-emulated-network", + "rococo-westend-system-emulated-network", "staging-xcm", "staging-xcm-executor", ] @@ -2373,9 +2373,9 @@ dependencies = [ "pallet-xcm", "parachains-common", "parity-scale-codec", + "rococo-westend-system-emulated-network", "staging-xcm", "staging-xcm-executor", - "westend-system-emulated-network", ] [[package]] @@ -14550,16 +14550,16 @@ dependencies = [ ] [[package]] -name = "rococo-wococo-system-emulated-network" +name = "rococo-westend-system-emulated-network" version = "0.0.0" dependencies = [ "asset-hub-rococo-emulated-chain", - "asset-hub-wococo-emulated-chain", + "asset-hub-westend-emulated-chain", "bridge-hub-rococo-emulated-chain", - "bridge-hub-wococo-emulated-chain", + "bridge-hub-westend-emulated-chain", "emulated-integration-tests-common", "rococo-emulated-chain", - "wococo-emulated-chain", + "westend-emulated-chain", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 3b3469e5483e..027605b7ab5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -80,7 +80,7 @@ members = [ "cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend", "cumulus/parachains/integration-tests/emulated/networks/rococo-system", "cumulus/parachains/integration-tests/emulated/networks/wococo-system", - "cumulus/parachains/integration-tests/emulated/networks/rococo-wococo-system", + "cumulus/parachains/integration-tests/emulated/networks/rococo-westend-system", "cumulus/parachains/integration-tests/emulated/networks/westend-system", "cumulus/parachains/pallets/collective-content", "cumulus/parachains/pallets/parachain-info", diff --git a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs index 6c99c1614db9..7e06c2750446 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs @@ -62,11 +62,14 @@ use bp_messages::{ LaneId, MessageKey, OutboundLaneData, }; use bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatchResult; -pub use pallet_bridge_messages::Instance2 as BridgeMessagesInstance2; -use pallet_bridge_messages::{Config, Instance1, OutboundLanes, Pallet}; +use pallet_bridge_messages::{Config, OutboundLanes, Pallet}; +pub use pallet_bridge_messages::{ + Instance1 as BridgeMessagesInstance1, Instance2 as BridgeMessagesInstance2, + Instance3 as BridgeMessagesInstance3, +}; -pub struct BridgeHubMessageHandler { - _marker: std::marker::PhantomData<(S, T, I)>, +pub struct BridgeHubMessageHandler { + _marker: std::marker::PhantomData<(S, SI, T, TI)>, } struct LaneIdWrapper(LaneId); @@ -83,13 +86,14 @@ impl From for LaneIdWrapper { } } -impl BridgeMessageHandler for BridgeHubMessageHandler +impl BridgeMessageHandler for BridgeHubMessageHandler where - S: Config, - T: Config, - I: 'static, - >::InboundPayload: From>, - >::MessageDispatch: + S: Config, + SI: 'static, + T: Config, + TI: 'static, + >::InboundPayload: From>, + >::MessageDispatch: MessageDispatch, { fn get_source_outbound_messages() -> Vec { @@ -100,16 +104,13 @@ where // collect messages from `OutboundMessages` for each active outbound lane in the source for lane in active_lanes { - let latest_generated_nonce = - OutboundLanes::::get(lane).latest_generated_nonce; - let latest_received_nonce = - OutboundLanes::::get(lane).latest_received_nonce; + let latest_generated_nonce = OutboundLanes::::get(lane).latest_generated_nonce; + let latest_received_nonce = OutboundLanes::::get(lane).latest_received_nonce; (latest_received_nonce + 1..=latest_generated_nonce).for_each(|nonce| { - let encoded_payload: Vec = - Pallet::::outbound_message_data(*lane, nonce) - .expect("Bridge message does not exist") - .into(); + let encoded_payload: Vec = Pallet::::outbound_message_data(*lane, nonce) + .expect("Bridge message does not exist") + .into(); let payload = Vec::::decode(&mut &encoded_payload[..]) .expect("Decodign XCM message failed"); let id: u32 = LaneIdWrapper(*lane).into(); @@ -133,9 +134,9 @@ where // Directly dispatch outbound messages assuming everything is correct // and bypassing the `Relayers` and `InboundLane` logic - let dispatch_result = TargetMessageDispatch::::dispatch(DispatchMessage { + let dispatch_result = TargetMessageDispatch::::dispatch(DispatchMessage { key: MessageKey { lane_id, nonce }, - data: DispatchMessageData::> { payload }, + data: DispatchMessageData::> { payload }, }); let result = match dispatch_result.dispatch_level_result { @@ -151,14 +152,14 @@ where } fn notify_source_message_delivery(lane_id: u32) { - let data = OutboundLanes::::get(LaneIdWrapper::from(lane_id).0); + let data = OutboundLanes::::get(LaneIdWrapper::from(lane_id).0); let new_data = OutboundLaneData { oldest_unpruned_nonce: data.oldest_unpruned_nonce + 1, latest_received_nonce: data.latest_received_nonce + 1, ..data }; - OutboundLanes::::insert(LaneIdWrapper::from(lane_id).0, new_data); + OutboundLanes::::insert(LaneIdWrapper::from(lane_id).0, new_data); } } diff --git a/cumulus/parachains/integration-tests/emulated/networks/rococo-wococo-system/Cargo.toml b/cumulus/parachains/integration-tests/emulated/networks/rococo-westend-system/Cargo.toml similarity index 57% rename from cumulus/parachains/integration-tests/emulated/networks/rococo-wococo-system/Cargo.toml rename to cumulus/parachains/integration-tests/emulated/networks/rococo-westend-system/Cargo.toml index 53a6f0840a5b..34713f5b48e9 100644 --- a/cumulus/parachains/integration-tests/emulated/networks/rococo-wococo-system/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/networks/rococo-westend-system/Cargo.toml @@ -1,18 +1,18 @@ [package] -name = "rococo-wococo-system-emulated-network" +name = "rococo-westend-system-emulated-network" version = "0.0.0" authors.workspace = true edition.workspace = true license = "Apache-2.0" -description = "Rococo<>Wococo emulated bridged network" +description = "Rococo<>Westend emulated bridged network" publish = false [dependencies] # Cumulus emulated-integration-tests-common = { path = "../../common", default-features = false } rococo-emulated-chain = { path = "../../chains/relays/rococo" } -wococo-emulated-chain = { path = "../../chains/relays/wococo" } +westend-emulated-chain = { path = "../../chains/relays/westend" } asset-hub-rococo-emulated-chain = { path = "../../chains/parachains/assets/asset-hub-rococo" } -asset-hub-wococo-emulated-chain = { path = "../../chains/parachains/assets/asset-hub-wococo" } +asset-hub-westend-emulated-chain = { path = "../../chains/parachains/assets/asset-hub-westend" } bridge-hub-rococo-emulated-chain = { path = "../../chains/parachains/bridges/bridge-hub-rococo" } -bridge-hub-wococo-emulated-chain = { path = "../../chains/parachains/bridges/bridge-hub-wococo" } +bridge-hub-westend-emulated-chain = { path = "../../chains/parachains/bridges/bridge-hub-westend" } diff --git a/cumulus/parachains/integration-tests/emulated/networks/rococo-wococo-system/src/lib.rs b/cumulus/parachains/integration-tests/emulated/networks/rococo-westend-system/src/lib.rs similarity index 57% rename from cumulus/parachains/integration-tests/emulated/networks/rococo-wococo-system/src/lib.rs rename to cumulus/parachains/integration-tests/emulated/networks/rococo-westend-system/src/lib.rs index e20dcfa6b32c..b03ff692b952 100644 --- a/cumulus/parachains/integration-tests/emulated/networks/rococo-wococo-system/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/networks/rococo-westend-system/src/lib.rs @@ -14,23 +14,23 @@ // limitations under the License. pub use asset_hub_rococo_emulated_chain; -pub use asset_hub_wococo_emulated_chain; +pub use asset_hub_westend_emulated_chain; pub use bridge_hub_rococo_emulated_chain; -pub use bridge_hub_wococo_emulated_chain; +pub use bridge_hub_westend_emulated_chain; pub use rococo_emulated_chain; -pub use wococo_emulated_chain; +pub use westend_emulated_chain; use asset_hub_rococo_emulated_chain::AssetHubRococo; -use asset_hub_wococo_emulated_chain::AssetHubWococo; +use asset_hub_westend_emulated_chain::AssetHubWestend; use bridge_hub_rococo_emulated_chain::BridgeHubRococo; -use bridge_hub_wococo_emulated_chain::BridgeHubWococo; +use bridge_hub_westend_emulated_chain::BridgeHubWestend; use rococo_emulated_chain::Rococo; -use wococo_emulated_chain::Wococo; +use westend_emulated_chain::Westend; // Cumulus use emulated_integration_tests_common::{ accounts::{ALICE, BOB}, - impls::{BridgeHubMessageHandler, BridgeMessagesInstance2}, + impls::{BridgeHubMessageHandler, BridgeMessagesInstance1, BridgeMessagesInstance3}, xcm_emulator::{ decl_test_bridges, decl_test_networks, decl_test_sender_receiver_accounts_parameter_types, Chain, @@ -44,51 +44,53 @@ decl_test_networks! { AssetHubRococo, BridgeHubRococo, ], - bridge = RococoWococoMockBridge + bridge = RococoWestendMockBridge }, - pub struct WococoMockNet { - relay_chain = Wococo, + pub struct WestendMockNet { + relay_chain = Westend, parachains = vec![ - AssetHubWococo, - BridgeHubWococo, + AssetHubWestend, + BridgeHubWestend, ], - bridge = WococoRococoMockBridge + bridge = WestendRococoMockBridge }, } decl_test_bridges! { - pub struct RococoWococoMockBridge { + pub struct RococoWestendMockBridge { source = BridgeHubRococoPara, - target = BridgeHubWococoPara, - handler = RococoWococoMessageHandler + target = BridgeHubWestendPara, + handler = RococoWestendMessageHandler }, - pub struct WococoRococoMockBridge { - source = BridgeHubWococoPara, + pub struct WestendRococoMockBridge { + source = BridgeHubWestendPara, target = BridgeHubRococoPara, - handler = WococoRococoMessageHandler + handler = WestendRococoMessageHandler } } type BridgeHubRococoRuntime = ::Runtime; -type BridgeHubWococoRuntime = ::Runtime; +type BridgeHubWestendRuntime = ::Runtime; -pub type RococoWococoMessageHandler = BridgeHubMessageHandler< +pub type RococoWestendMessageHandler = BridgeHubMessageHandler< BridgeHubRococoRuntime, - BridgeHubWococoRuntime, - BridgeMessagesInstance2, + BridgeMessagesInstance3, + BridgeHubWestendRuntime, + BridgeMessagesInstance1, >; -pub type WococoRococoMessageHandler = BridgeHubMessageHandler< - BridgeHubWococoRuntime, +pub type WestendRococoMessageHandler = BridgeHubMessageHandler< + BridgeHubWestendRuntime, + BridgeMessagesInstance1, BridgeHubRococoRuntime, - BridgeMessagesInstance2, + BridgeMessagesInstance3, >; decl_test_sender_receiver_accounts_parameter_types! { RococoRelay { sender: ALICE, receiver: BOB }, AssetHubRococoPara { sender: ALICE, receiver: BOB }, BridgeHubRococoPara { sender: ALICE, receiver: BOB }, - WococoRelay { sender: ALICE, receiver: BOB }, - AssetHubWococoPara { sender: ALICE, receiver: BOB }, - BridgeHubWococoPara { sender: ALICE, receiver: BOB } + WestendRelay { sender: ALICE, receiver: BOB }, + AssetHubWestendPara { sender: ALICE, receiver: BOB }, + BridgeHubWestendPara { sender: ALICE, receiver: BOB } } diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml index 035d9c107933..584a074c8abe 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml @@ -30,4 +30,4 @@ cumulus-pallet-xcmp-queue = { path = "../../../../../../pallets/xcmp-queue", def cumulus-pallet-dmp-queue = { path = "../../../../../../pallets/dmp-queue", default-features = false} bridge-hub-rococo-runtime = { path = "../../../../../../parachains/runtimes/bridge-hubs/bridge-hub-rococo", default-features = false } emulated-integration-tests-common = { path = "../../../common", default-features = false} -rococo-wococo-system-emulated-network ={ path = "../../../networks/rococo-wococo-system" } +rococo-westend-system-emulated-network = { path = "../../../networks/rococo-westend-system" } diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs index 19e10d23bbba..72f8b490f310 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs @@ -21,7 +21,7 @@ pub use xcm::{ prelude::{AccountId32 as AccountId32Junction, *}, v3::{ Error, - NetworkId::{Rococo as RococoId, Wococo as WococoId}, + NetworkId::{Rococo as RococoId, Westend as WestendId}, }, }; @@ -39,15 +39,15 @@ pub use emulated_integration_tests_common::{ PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, }; pub use parachains_common::{AccountId, Balance}; -pub use rococo_wococo_system_emulated_network::{ +pub use rococo_westend_system_emulated_network::{ bridge_hub_rococo_emulated_chain::{ genesis::ED as BRIDGE_HUB_ROCOCO_ED, BridgeHubRococoParaPallet as BridgeHubRococoPallet, }, rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet}, AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver, - AssetHubRococoParaSender as AssetHubRococoSender, AssetHubWococoPara as AssetHubWococo, + AssetHubRococoParaSender as AssetHubRococoSender, AssetHubWestendPara as AssetHubWestend, BridgeHubRococoPara as BridgeHubRococo, BridgeHubRococoParaReceiver as BridgeHubRococoReceiver, - BridgeHubRococoParaSender as BridgeHubRococoSender, BridgeHubWococoPara as BridgeHubWococo, + BridgeHubRococoParaSender as BridgeHubRococoSender, BridgeHubWestendPara as BridgeHubWestend, RococoRelay as Rococo, RococoRelayReceiver as RococoReceiver, RococoRelaySender as RococoSender, }; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/example.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/example.rs index 35cfa394174c..66979d31cea8 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/example.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/example.rs @@ -29,13 +29,13 @@ fn example() { let xcm = VersionedXcm::from(Xcm(vec![ UnpaidExecution { weight_limit, check_origin }, ExportMessage { - network: WococoId, - destination: X1(Parachain(AssetHubWococo::para_id().into())), + network: WestendId, + destination: X1(Parachain(AssetHubWestend::para_id().into())), xcm: remote_xcm, }, ])); - //Rococo Global Consensus + // Rococo Global Consensus // Send XCM message from Relay Chain to Bridge Hub source Parachain Rococo::execute_with(|| { assert_ok!(::XcmPallet::send( @@ -64,32 +64,32 @@ fn example() { success: true, .. }) => {}, - RuntimeEvent::BridgeWococoMessages(pallet_bridge_messages::Event::MessageAccepted { - lane_id: LaneId([0, 0, 0, 1]), + RuntimeEvent::BridgeWestendMessages(pallet_bridge_messages::Event::MessageAccepted { + lane_id: LaneId([0, 0, 0, 2]), nonce: 1, }) => {}, ] ); }); - // Wococo GLobal Consensus + // Westend Global Consensus // Receive XCM message in Bridge Hub target Parachain - BridgeHubWococo::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; + BridgeHubWestend::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; assert_expected_events!( - BridgeHubWococo, + BridgeHubWestend, vec![ RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {}, ] ); }); - // Receive embeded XCM message within `ExportMessage` in Parachain destination - AssetHubWococo::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; + // Receive embedded XCM message within `ExportMessage` in Parachain destination + AssetHubWestend::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; assert_expected_events!( - AssetHubWococo, + AssetHubWestend, vec![ RuntimeEvent::MessageQueue(pallet_message_queue::Event::ProcessingFailed { .. diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/Cargo.toml index 62b969b682f4..42a21c7dc8e4 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/Cargo.toml @@ -30,4 +30,4 @@ cumulus-pallet-xcmp-queue = { path = "../../../../../../pallets/xcmp-queue", def cumulus-pallet-dmp-queue = { path = "../../../../../../pallets/dmp-queue", default-features = false} bridge-hub-westend-runtime = { path = "../../../../../../parachains/runtimes/bridge-hubs/bridge-hub-westend", default-features = false } emulated-integration-tests-common = { path = "../../../common", default-features = false} -westend-system-emulated-network ={ path = "../../../networks/westend-system" } +rococo-westend-system-emulated-network = { path = "../../../networks/rococo-westend-system" } diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs index f406a73d18d5..30b215782d9b 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs @@ -19,7 +19,10 @@ pub use frame_support::assert_ok; // Polkadot pub use xcm::{ prelude::{AccountId32 as AccountId32Junction, *}, - v3::{Error, NetworkId::Rococo as RococoId}, + v3::{ + Error, + NetworkId::{Rococo as RococoId, Westend as WestendId}, + }, }; // Bridges @@ -36,13 +39,15 @@ pub use emulated_integration_tests_common::{ PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, }; pub use parachains_common::{AccountId, Balance}; -pub use westend_system_emulated_network::{ +pub use rococo_westend_system_emulated_network::{ bridge_hub_westend_emulated_chain::{ genesis::ED as BRIDGE_HUB_ROCOCO_ED, BridgeHubWestendParaPallet as BridgeHubWestendPallet, }, westend_emulated_chain::{genesis::ED as ROCOCO_ED, WestendRelayPallet as WestendPallet}, - AssetHubWestendPara as AssetHubWestend, AssetHubWestendParaReceiver as AssetHubWestendReceiver, - AssetHubWestendParaSender as AssetHubWestendSender, BridgeHubWestendPara as BridgeHubWestend, + AssetHubRococoPara as AssetHubRococo, AssetHubWestendPara as AssetHubWestend, + AssetHubWestendParaReceiver as AssetHubWestendReceiver, + AssetHubWestendParaSender as AssetHubWestendSender, BridgeHubRococoPara as BridgeHubRococo, + BridgeHubWestendPara as BridgeHubWestend, BridgeHubWestendParaReceiver as BridgeHubWestendReceiver, BridgeHubWestendParaSender as BridgeHubWestendSender, WestendRelay as Westend, WestendRelayReceiver as WestendReceiver, WestendRelaySender as WestendSender, diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/example.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/example.rs index 1fdd9441e483..195fa9493f5b 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/example.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/example.rs @@ -30,7 +30,7 @@ fn example() { UnpaidExecution { weight_limit, check_origin }, ExportMessage { network: RococoId, - destination: X1(Parachain(AssetHubWestend::para_id().into())), + destination: X1(Parachain(AssetHubRococo::para_id().into())), xcm: remote_xcm, }, ])); @@ -71,4 +71,30 @@ fn example() { ] ); }); + + // Rococo Global Consensus + // Receive XCM message in Bridge Hub target Parachain + BridgeHubRococo::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + BridgeHubRococo, + vec![ + RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {}, + ] + ); + }); + // Receive embedded XCM message within `ExportMessage` in Parachain destination + AssetHubRococo::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + AssetHubRococo, + vec![ + RuntimeEvent::MessageQueue(pallet_message_queue::Event::ProcessingFailed { + .. + }) => {}, + ] + ); + }); } From c5265e785d0aca195dbcce85fbed48b90ee52424 Mon Sep 17 00:00:00 2001 From: Adrian Catangiu Date: Thu, 9 Nov 2023 14:44:07 +0200 Subject: [PATCH 2/9] xcm-emulator: remove wococo chains --- Cargo.lock | 62 ------------------- Cargo.toml | 3 - .../assets/asset-hub-wococo/Cargo.toml | 26 -------- .../assets/asset-hub-wococo/src/lib.rs | 53 ---------------- .../bridges/bridge-hub-wococo/Cargo.toml | 25 -------- .../bridges/bridge-hub-wococo/src/lib.rs | 47 -------------- .../emulated/chains/relays/wococo/Cargo.toml | 30 --------- .../emulated/chains/relays/wococo/src/lib.rs | 46 -------------- .../networks/wococo-system/Cargo.toml | 16 ----- .../networks/wococo-system/src/lib.rs | 50 --------------- 10 files changed, 358 deletions(-) delete mode 100644 cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-wococo/Cargo.toml delete mode 100644 cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-wococo/src/lib.rs delete mode 100644 cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-wococo/Cargo.toml delete mode 100644 cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-wococo/src/lib.rs delete mode 100644 cumulus/parachains/integration-tests/emulated/chains/relays/wococo/Cargo.toml delete mode 100644 cumulus/parachains/integration-tests/emulated/chains/relays/wococo/src/lib.rs delete mode 100644 cumulus/parachains/integration-tests/emulated/networks/wococo-system/Cargo.toml delete mode 100644 cumulus/parachains/integration-tests/emulated/networks/wococo-system/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 7e5f91fda128..7cf280a8b146 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1117,22 +1117,6 @@ dependencies = [ "westend-runtime-constants", ] -[[package]] -name = "asset-hub-wococo-emulated-chain" -version = "0.0.0" -dependencies = [ - "asset-hub-rococo-emulated-chain", - "asset-hub-rococo-runtime", - "cumulus-primitives-core", - "emulated-integration-tests-common", - "frame-support", - "parachains-common", - "serde_json", - "sp-core", - "sp-runtime", - "wococo-emulated-chain", -] - [[package]] name = "asset-test-utils" version = "1.0.0" @@ -2461,21 +2445,6 @@ dependencies = [ "westend-runtime-constants", ] -[[package]] -name = "bridge-hub-wococo-emulated-chain" -version = "0.0.0" -dependencies = [ - "bridge-hub-rococo-emulated-chain", - "bridge-hub-rococo-runtime", - "cumulus-primitives-core", - "emulated-integration-tests-common", - "frame-support", - "parachains-common", - "serde_json", - "sp-core", - "sp-runtime", -] - [[package]] name = "bridge-runtime-common" version = "0.1.0" @@ -21206,37 +21175,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "wococo-emulated-chain" -version = "0.0.0" -dependencies = [ - "emulated-integration-tests-common", - "pallet-im-online", - "parachains-common", - "polkadot-primitives", - "rococo-emulated-chain", - "rococo-runtime", - "rococo-runtime-constants", - "sc-consensus-grandpa", - "serde_json", - "sp-authority-discovery", - "sp-consensus-babe", - "sp-consensus-beefy", - "sp-core", - "sp-runtime", -] - -[[package]] -name = "wococo-system-emulated-network" -version = "0.0.0" -dependencies = [ - "asset-hub-wococo-emulated-chain", - "bridge-hub-wococo-emulated-chain", - "emulated-integration-tests-common", - "penpal-emulated-chain", - "wococo-emulated-chain", -] - [[package]] name = "wyz" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 027605b7ab5e..9435cc09025a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,15 +71,12 @@ members = [ "cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend", "cumulus/parachains/integration-tests/emulated/common", "cumulus/parachains/integration-tests/emulated/chains/relays/rococo", - "cumulus/parachains/integration-tests/emulated/chains/relays/wococo", "cumulus/parachains/integration-tests/emulated/chains/relays/westend", "cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo", - "cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-wococo", "cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend", "cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo", "cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend", "cumulus/parachains/integration-tests/emulated/networks/rococo-system", - "cumulus/parachains/integration-tests/emulated/networks/wococo-system", "cumulus/parachains/integration-tests/emulated/networks/rococo-westend-system", "cumulus/parachains/integration-tests/emulated/networks/westend-system", "cumulus/parachains/pallets/collective-content", diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-wococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-wococo/Cargo.toml deleted file mode 100644 index 0f212c159996..000000000000 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-wococo/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name = "asset-hub-wococo-emulated-chain" -version = "0.0.0" -authors.workspace = true -edition.workspace = true -license = "Apache-2.0" -description = "Asset Hub Wococo emulated chain" -publish = false - -[dependencies] -serde_json = "1.0.104" - -# Substrate -sp-core = { path = "../../../../../../../../substrate/primitives/core", default-features = false } -sp-runtime = { path = "../../../../../../../../substrate/primitives/runtime", default-features = false } -frame-support = { path = "../../../../../../../../substrate/frame/support", default-features = false } - -# Polakadot -parachains-common = { path = "../../../../../../../parachains/common" } - -# Cumulus -cumulus-primitives-core = { path = "../../../../../../../primitives/core", default-features = false } -emulated-integration-tests-common = { path = "../../../../common", default-features = false } -asset-hub-rococo-runtime = { path = "../../../../../../runtimes/assets/asset-hub-rococo" } -wococo-emulated-chain = { path = "../../../relays/wococo" } -asset-hub-rococo-emulated-chain = { path = "../asset-hub-rococo" } diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-wococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-wococo/src/lib.rs deleted file mode 100644 index 677ca1763cfd..000000000000 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-wococo/src/lib.rs +++ /dev/null @@ -1,53 +0,0 @@ -// 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. - -// Substrate -use frame_support::traits::OnInitialize; - -// Cumulus -use emulated_integration_tests_common::{ - impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, - impl_assets_helpers_for_system_parachain, xcm_emulator::decl_test_parachains, -}; -use wococo_emulated_chain::Wococo; - -// AssetHubWococo Parachain declaration -decl_test_parachains! { - pub struct AssetHubWococo { - genesis = asset_hub_rococo_emulated_chain::genesis::genesis(), - on_init = { - asset_hub_rococo_runtime::AuraExt::on_initialize(1); - }, - runtime = asset_hub_rococo_runtime, - core = { - XcmpMessageHandler: asset_hub_rococo_runtime::XcmpQueue, - LocationToAccountId: asset_hub_rococo_runtime::xcm_config::LocationToAccountId, - ParachainInfo: asset_hub_rococo_runtime::ParachainInfo, - }, - pallets = { - PolkadotXcm: asset_hub_rococo_runtime::PolkadotXcm, - Assets: asset_hub_rococo_runtime::Assets, - ForeignAssets: asset_hub_rococo_runtime::ForeignAssets, - PoolAssets: asset_hub_rococo_runtime::PoolAssets, - AssetConversion: asset_hub_rococo_runtime::AssetConversion, - Balances: asset_hub_rococo_runtime::Balances, - } - }, -} - -// AssetHubWococo implementation -impl_accounts_helpers_for_parachain!(AssetHubWococo); -impl_assert_events_helpers_for_parachain!(AssetHubWococo); -impl_assets_helpers_for_system_parachain!(AssetHubWococo, Wococo); diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-wococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-wococo/Cargo.toml deleted file mode 100644 index 0b02730a50c6..000000000000 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-wococo/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "bridge-hub-wococo-emulated-chain" -version = "0.0.0" -authors.workspace = true -edition.workspace = true -license = "Apache-2.0" -description = "Bridge Hub Wococo emulated chain" -publish = false - -[dependencies] -serde_json = "1.0.104" - -# Substrate -sp-core = { path = "../../../../../../../../substrate/primitives/core", default-features = false } -sp-runtime = { path = "../../../../../../../../substrate/primitives/runtime", default-features = false } -frame-support = { path = "../../../../../../../../substrate/frame/support", default-features = false } - -# Polakadot -parachains-common = { path = "../../../../../../../parachains/common" } - -# Cumulus -cumulus-primitives-core = { path = "../../../../../../../primitives/core", default-features = false } -emulated-integration-tests-common = { path = "../../../../common", default-features = false } -bridge-hub-rococo-runtime = { path = "../../../../../../runtimes/bridge-hubs/bridge-hub-rococo" } -bridge-hub-rococo-emulated-chain = { path = "../bridge-hub-rococo" } diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-wococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-wococo/src/lib.rs deleted file mode 100644 index 6807a2ab8c80..000000000000 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-wococo/src/lib.rs +++ /dev/null @@ -1,47 +0,0 @@ -// 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. - -// Substrate -use frame_support::traits::OnInitialize; - -// Cumulus -use emulated_integration_tests_common::{ - impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, - xcm_emulator::decl_test_parachains, -}; - -// BridgeHubWococo Parachain declaration -decl_test_parachains! { - pub struct BridgeHubWococo { - genesis = bridge_hub_rococo_emulated_chain::genesis::genesis(), - on_init = { - bridge_hub_rococo_runtime::AuraExt::on_initialize(1); - }, - runtime = bridge_hub_rococo_runtime, - core = { - XcmpMessageHandler: bridge_hub_rococo_runtime::XcmpQueue, - LocationToAccountId: bridge_hub_rococo_runtime::xcm_config::LocationToAccountId, - ParachainInfo: bridge_hub_rococo_runtime::ParachainInfo, - }, - pallets = { - PolkadotXcm: bridge_hub_rococo_runtime::PolkadotXcm, - Balances: bridge_hub_rococo_runtime::Balances, - } - }, -} - -// BridgeHubWococo implementation -impl_accounts_helpers_for_parachain!(BridgeHubWococo); -impl_assert_events_helpers_for_parachain!(BridgeHubWococo); diff --git a/cumulus/parachains/integration-tests/emulated/chains/relays/wococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/chains/relays/wococo/Cargo.toml deleted file mode 100644 index 51a87954b8c0..000000000000 --- a/cumulus/parachains/integration-tests/emulated/chains/relays/wococo/Cargo.toml +++ /dev/null @@ -1,30 +0,0 @@ -[package] -name = "wococo-emulated-chain" -version = "0.0.0" -authors.workspace = true -edition.workspace = true -license = "Apache-2.0" -description = "Wococo emulated chain" -publish = false - -[dependencies] -serde_json = "1.0.104" - -# Substrate -sp-core = { path = "../../../../../../../substrate/primitives/core", default-features = false } -sp-runtime = { path = "../../../../../../../substrate/primitives/runtime", default-features = false } -sp-authority-discovery = { path = "../../../../../../../substrate/primitives/authority-discovery", default-features = false } -sp-consensus-babe = { path = "../../../../../../../substrate/primitives/consensus/babe", default-features = false } -beefy-primitives = { package = "sp-consensus-beefy", path = "../../../../../../../substrate/primitives/consensus/beefy" } -grandpa = { package = "sc-consensus-grandpa", path = "../../../../../../../substrate/client/consensus/grandpa", default-features = false } -pallet-im-online = { path = "../../../../../../../substrate/frame/im-online", default-features = false } - -# Polkadot -polkadot-primitives = { path = "../../../../../../../polkadot/primitives", default-features = false } -rococo-runtime-constants = { path = "../../../../../../../polkadot/runtime/rococo/constants", default-features = false } -rococo-runtime = { path = "../../../../../../../polkadot/runtime/rococo" } - -# Cumulus -parachains-common = { path = "../../../../../../parachains/common" } -emulated-integration-tests-common = { path = "../../../common", default-features = false } -rococo-emulated-chain = { path = "../rococo" } diff --git a/cumulus/parachains/integration-tests/emulated/chains/relays/wococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/relays/wococo/src/lib.rs deleted file mode 100644 index a04deee330f7..000000000000 --- a/cumulus/parachains/integration-tests/emulated/chains/relays/wococo/src/lib.rs +++ /dev/null @@ -1,46 +0,0 @@ -// 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. - -// Cumulus -use emulated_integration_tests_common::{ - impl_accounts_helpers_for_relay_chain, impl_assert_events_helpers_for_relay_chain, - impl_hrmp_channels_helpers_for_relay_chain, impl_send_transact_helpers_for_relay_chain, - xcm_emulator::decl_test_relay_chains, -}; - -// Wococo declaration -decl_test_relay_chains! { - #[api_version(8)] - pub struct Wococo { - genesis = rococo_emulated_chain::genesis::genesis(), - on_init = (), - runtime = rococo_runtime, - core = { - SovereignAccountOf: rococo_runtime::xcm_config::LocationConverter, - }, - pallets = { - XcmPallet: rococo_runtime::XcmPallet, - Sudo: rococo_runtime::Sudo, - Balances: rococo_runtime::Balances, - Hrmp: rococo_runtime::Hrmp, - } - }, -} - -// Wococo implementation -impl_accounts_helpers_for_relay_chain!(Wococo); -impl_assert_events_helpers_for_relay_chain!(Wococo); -impl_hrmp_channels_helpers_for_relay_chain!(Wococo); -impl_send_transact_helpers_for_relay_chain!(Wococo); diff --git a/cumulus/parachains/integration-tests/emulated/networks/wococo-system/Cargo.toml b/cumulus/parachains/integration-tests/emulated/networks/wococo-system/Cargo.toml deleted file mode 100644 index a596617e82bf..000000000000 --- a/cumulus/parachains/integration-tests/emulated/networks/wococo-system/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "wococo-system-emulated-network" -version = "0.0.0" -authors.workspace = true -edition.workspace = true -license = "Apache-2.0" -description = "Wococo System emulated network" -publish = false - -[dependencies] -# Cumulus -emulated-integration-tests-common = { path = "../../common", default-features = false } -wococo-emulated-chain = { path = "../../chains/relays/wococo" } -asset-hub-wococo-emulated-chain = { path = "../../chains/parachains/assets/asset-hub-wococo" } -bridge-hub-wococo-emulated-chain = { path = "../../chains/parachains/bridges/bridge-hub-wococo" } -penpal-emulated-chain = { path = "../../chains/parachains/testing/penpal" } diff --git a/cumulus/parachains/integration-tests/emulated/networks/wococo-system/src/lib.rs b/cumulus/parachains/integration-tests/emulated/networks/wococo-system/src/lib.rs deleted file mode 100644 index 5369afe7dffe..000000000000 --- a/cumulus/parachains/integration-tests/emulated/networks/wococo-system/src/lib.rs +++ /dev/null @@ -1,50 +0,0 @@ -// 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 asset_hub_wococo_emulated_chain; -pub use bridge_hub_wococo_emulated_chain; -pub use wococo_emulated_chain; - -use asset_hub_wococo_emulated_chain::AssetHubWococo; -use bridge_hub_wococo_emulated_chain::BridgeHubWococo; -use penpal_emulated_chain::{PenpalA, PenpalB}; -use wococo_emulated_chain::Wococo; - -// Cumulus -use emulated_integration_tests_common::{ - accounts::{ALICE, BOB}, - xcm_emulator::{decl_test_networks, decl_test_sender_receiver_accounts_parameter_types}, -}; - -decl_test_networks! { - pub struct WococoMockNet { - relay_chain = Wococo, - parachains = vec![ - AssetHubWococo, - BridgeHubWococo, - PenpalA, - PenpalB, - ], - bridge = () - }, -} - -decl_test_sender_receiver_accounts_parameter_types! { - WococoRelay { sender: ALICE, receiver: BOB }, - AssetHubWococoPara { sender: ALICE, receiver: BOB }, - BridgeHubWococoPara { sender: ALICE, receiver: BOB }, - PenpalAPara { sender: ALICE, receiver: BOB }, - PenpalBPara { sender: ALICE, receiver: BOB } -} From 942092fa25069f8de7e2ccb378c640c2c17a694e Mon Sep 17 00:00:00 2001 From: Adrian Catangiu Date: Thu, 9 Nov 2023 15:09:57 +0200 Subject: [PATCH 3/9] xcm-emulator: move bridge tests under per-bridge crate --- Cargo.lock | 64 ++++------- Cargo.toml | 3 +- .../bridges/bridge-hub-rococo/Cargo.toml | 33 ------ .../bridge-hub-rococo/src/tests/example.rs | 100 ------------------ .../bridge-hub-rococo/src/tests/mod.rs | 17 --- .../bridge-hub-rococo/src/tests/teleport.rs | 30 ------ .../bridges/bridge-hub-westend/src/lib.rs | 61 ----------- .../Cargo.toml | 5 +- .../src/lib.rs | 15 ++- .../src/tests/bridge_hubs.rs} | 24 ++++- .../src/tests/mod.rs | 4 +- .../src/tests/send_xcm.rs} | 86 ++++++++++++++- 12 files changed, 144 insertions(+), 298 deletions(-) delete mode 100644 cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml delete mode 100644 cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/example.rs delete mode 100644 cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/mod.rs delete mode 100644 cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/teleport.rs delete mode 100644 cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs rename cumulus/parachains/integration-tests/emulated/tests/bridges/{bridge-hub-westend => rococo-westend}/Cargo.toml (86%) rename cumulus/parachains/integration-tests/emulated/tests/bridges/{bridge-hub-rococo => rococo-westend}/src/lib.rs (72%) rename cumulus/parachains/integration-tests/emulated/tests/bridges/{bridge-hub-westend/src/tests/teleport.rs => rococo-westend/src/tests/bridge_hubs.rs} (52%) rename cumulus/parachains/integration-tests/emulated/tests/bridges/{bridge-hub-westend => rococo-westend}/src/tests/mod.rs (95%) rename cumulus/parachains/integration-tests/emulated/tests/bridges/{bridge-hub-westend/src/tests/example.rs => rococo-westend/src/tests/send_xcm.rs} (55%) diff --git a/Cargo.lock b/Cargo.lock index 7cf280a8b146..65e64bab44bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2173,27 +2173,6 @@ dependencies = [ "sp-runtime", ] -[[package]] -name = "bridge-hub-rococo-integration-tests" -version = "1.0.0" -dependencies = [ - "asset-test-utils", - "bp-messages", - "bridge-hub-rococo-runtime", - "cumulus-pallet-dmp-queue", - "cumulus-pallet-xcmp-queue", - "emulated-integration-tests-common", - "frame-support", - "pallet-bridge-messages", - "pallet-message-queue", - "pallet-xcm", - "parachains-common", - "parity-scale-codec", - "rococo-westend-system-emulated-network", - "staging-xcm", - "staging-xcm-executor", -] - [[package]] name = "bridge-hub-rococo-runtime" version = "0.1.0" @@ -2341,27 +2320,6 @@ dependencies = [ "sp-runtime", ] -[[package]] -name = "bridge-hub-westend-integration-tests" -version = "1.0.0" -dependencies = [ - "asset-test-utils", - "bp-messages", - "bridge-hub-westend-runtime", - "cumulus-pallet-dmp-queue", - "cumulus-pallet-xcmp-queue", - "emulated-integration-tests-common", - "frame-support", - "pallet-bridge-messages", - "pallet-message-queue", - "pallet-xcm", - "parachains-common", - "parity-scale-codec", - "rococo-westend-system-emulated-network", - "staging-xcm", - "staging-xcm-executor", -] - [[package]] name = "bridge-hub-westend-runtime" version = "0.1.0" @@ -14518,6 +14476,28 @@ dependencies = [ "rococo-emulated-chain", ] +[[package]] +name = "rococo-westend-bridge-integration-tests" +version = "1.0.0" +dependencies = [ + "asset-test-utils", + "bp-messages", + "bridge-hub-rococo-runtime", + "bridge-hub-westend-runtime", + "cumulus-pallet-dmp-queue", + "cumulus-pallet-xcmp-queue", + "emulated-integration-tests-common", + "frame-support", + "pallet-bridge-messages", + "pallet-message-queue", + "pallet-xcm", + "parachains-common", + "parity-scale-codec", + "rococo-westend-system-emulated-network", + "staging-xcm", + "staging-xcm-executor", +] + [[package]] name = "rococo-westend-system-emulated-network" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index 9435cc09025a..cb682ec74627 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,8 +67,7 @@ members = [ "cumulus/parachains/common", "cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo", "cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend", - "cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo", - "cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend", + "cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend", "cumulus/parachains/integration-tests/emulated/common", "cumulus/parachains/integration-tests/emulated/chains/relays/rococo", "cumulus/parachains/integration-tests/emulated/chains/relays/westend", diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml deleted file mode 100644 index 584a074c8abe..000000000000 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml +++ /dev/null @@ -1,33 +0,0 @@ -[package] -name = "bridge-hub-rococo-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" -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} -pallet-message-queue = { path = "../../../../../../../substrate/frame/message-queue" } - -# Polkadot -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} - -# Bridges -pallet-bridge-messages = { path = "../../../../../../../bridges/modules/messages", default-features = false} -bp-messages = { path = "../../../../../../../bridges/primitives/messages", default-features = false} - -# Cumulus -asset-test-utils = { path = "../../../../../../parachains/runtimes/assets/test-utils" } -parachains-common = { path = "../../../../../../parachains/common" } -cumulus-pallet-xcmp-queue = { path = "../../../../../../pallets/xcmp-queue", default-features = false} -cumulus-pallet-dmp-queue = { path = "../../../../../../pallets/dmp-queue", default-features = false} -bridge-hub-rococo-runtime = { path = "../../../../../../parachains/runtimes/bridge-hubs/bridge-hub-rococo", default-features = false } -emulated-integration-tests-common = { path = "../../../common", default-features = false} -rococo-westend-system-emulated-network = { path = "../../../networks/rococo-westend-system" } diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/example.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/example.rs deleted file mode 100644 index 66979d31cea8..000000000000 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/example.rs +++ /dev/null @@ -1,100 +0,0 @@ -// 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 = ::RuntimeOrigin::root(); - let destination = Rococo::child_location_of(BridgeHubRococo::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: WestendId, - destination: X1(Parachain(AssetHubWestend::para_id().into())), - xcm: remote_xcm, - }, - ])); - - // Rococo Global Consensus - // Send XCM message from Relay Chain to Bridge Hub source Parachain - Rococo::execute_with(|| { - assert_ok!(::XcmPallet::send( - sudo_origin, - bx!(destination), - bx!(xcm), - )); - - type RuntimeEvent = ::RuntimeEvent; - - assert_expected_events!( - Rococo, - vec![ - RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, - ] - ); - }); - // Receive XCM message in Bridge Hub source Parachain - BridgeHubRococo::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - - assert_expected_events!( - BridgeHubRococo, - vec![ - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { - success: true, - .. - }) => {}, - RuntimeEvent::BridgeWestendMessages(pallet_bridge_messages::Event::MessageAccepted { - lane_id: LaneId([0, 0, 0, 2]), - nonce: 1, - }) => {}, - ] - ); - }); - - // Westend Global Consensus - // Receive XCM message in Bridge Hub target Parachain - BridgeHubWestend::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - - assert_expected_events!( - BridgeHubWestend, - vec![ - RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {}, - ] - ); - }); - // Receive embedded XCM message within `ExportMessage` in Parachain destination - AssetHubWestend::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - - assert_expected_events!( - AssetHubWestend, - vec![ - RuntimeEvent::MessageQueue(pallet_message_queue::Event::ProcessingFailed { - .. - }) => {}, - ] - ); - }); -} diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/mod.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/mod.rs deleted file mode 100644 index 1eef05c6b928..000000000000 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/mod.rs +++ /dev/null @@ -1,17 +0,0 @@ -// 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; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/teleport.rs deleted file mode 100644 index f00288a4d8c7..000000000000 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/teleport.rs +++ /dev/null @@ -1,30 +0,0 @@ -// 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_rococo_runtime::xcm_config::XcmConfig; - -#[test] -fn teleport_to_other_system_parachains_works() { - let amount = BRIDGE_HUB_ROCOCO_ED * 100; - let native_asset: MultiAssets = (Parent, amount).into(); - - test_parachain_is_trusted_teleporter!( - BridgeHubRococo, // Origin - XcmConfig, // XCM configuration - vec![AssetHubRococo], // Destinations - (native_asset, amount) - ); -} diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs deleted file mode 100644 index 30b215782d9b..000000000000 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs +++ /dev/null @@ -1,61 +0,0 @@ -// 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. - -// Substrate -pub use frame_support::assert_ok; - -// Polkadot -pub use xcm::{ - prelude::{AccountId32 as AccountId32Junction, *}, - v3::{ - Error, - NetworkId::{Rococo as RococoId, Westend as WestendId}, - }, -}; - -// Bridges -pub use bp_messages::LaneId; - -// Cumulus -pub use emulated_integration_tests_common::{ - test_parachain_is_trusted_teleporter, - xcm_emulator::{ - assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para, - RelayChain as Relay, Test, TestArgs, TestContext, TestExt, - }, - xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, - PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, -}; -pub use parachains_common::{AccountId, Balance}; -pub use rococo_westend_system_emulated_network::{ - bridge_hub_westend_emulated_chain::{ - genesis::ED as BRIDGE_HUB_ROCOCO_ED, BridgeHubWestendParaPallet as BridgeHubWestendPallet, - }, - westend_emulated_chain::{genesis::ED as ROCOCO_ED, WestendRelayPallet as WestendPallet}, - AssetHubRococoPara as AssetHubRococo, AssetHubWestendPara as AssetHubWestend, - AssetHubWestendParaReceiver as AssetHubWestendReceiver, - AssetHubWestendParaSender as AssetHubWestendSender, BridgeHubRococoPara as BridgeHubRococo, - BridgeHubWestendPara as BridgeHubWestend, - BridgeHubWestendParaReceiver as BridgeHubWestendReceiver, - BridgeHubWestendParaSender as BridgeHubWestendSender, WestendRelay as Westend, - WestendRelayReceiver as WestendReceiver, WestendRelaySender as WestendSender, -}; - -pub const ASSET_ID: u32 = 1; -pub const ASSET_MIN_BALANCE: u128 = 1000; -pub const ASSETS_PALLET_ID: u8 = 50; - -#[cfg(test)] -mod tests; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/Cargo.toml similarity index 86% rename from cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/Cargo.toml rename to cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/Cargo.toml index 42a21c7dc8e4..bedf83e42a71 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/Cargo.toml @@ -1,10 +1,10 @@ [package] -name = "bridge-hub-westend-integration-tests" +name = "rococo-westend-bridge-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" +description = "Rococo<>Westend bridge integration tests with xcm-emulator" publish = false [dependencies] @@ -28,6 +28,7 @@ asset-test-utils = { path = "../../../../../../parachains/runtimes/assets/test-u parachains-common = { path = "../../../../../../parachains/common" } cumulus-pallet-xcmp-queue = { path = "../../../../../../pallets/xcmp-queue", default-features = false} cumulus-pallet-dmp-queue = { path = "../../../../../../pallets/dmp-queue", 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 } emulated-integration-tests-common = { path = "../../../common", default-features = false} rococo-westend-system-emulated-network = { path = "../../../networks/rococo-westend-system" } diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/lib.rs similarity index 72% rename from cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs rename to cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/lib.rs index 72f8b490f310..9afd931e5d6a 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/lib.rs @@ -43,13 +43,22 @@ pub use rococo_westend_system_emulated_network::{ bridge_hub_rococo_emulated_chain::{ genesis::ED as BRIDGE_HUB_ROCOCO_ED, BridgeHubRococoParaPallet as BridgeHubRococoPallet, }, + bridge_hub_westend_emulated_chain::{ + genesis::ED as BRIDGE_HUB_WESTEND_ED, BridgeHubWestendParaPallet as BridgeHubWestendPallet, + }, rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet}, + westend_emulated_chain::{genesis::ED as WESTEND_ED, WestendRelayPallet as WestendPallet}, AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver, AssetHubRococoParaSender as AssetHubRococoSender, AssetHubWestendPara as AssetHubWestend, - BridgeHubRococoPara as BridgeHubRococo, BridgeHubRococoParaReceiver as BridgeHubRococoReceiver, + AssetHubWestendParaReceiver as AssetHubWestendReceiver, + AssetHubWestendParaSender as AssetHubWestendSender, BridgeHubRococoPara as BridgeHubRococo, + BridgeHubRococoParaReceiver as BridgeHubRococoReceiver, BridgeHubRococoParaSender as BridgeHubRococoSender, BridgeHubWestendPara as BridgeHubWestend, - RococoRelay as Rococo, RococoRelayReceiver as RococoReceiver, - RococoRelaySender as RococoSender, + BridgeHubWestendParaReceiver as BridgeHubWestendReceiver, + BridgeHubWestendParaSender as BridgeHubWestendSender, RococoRelay as Rococo, + RococoRelayReceiver as RococoReceiver, RococoRelaySender as RococoSender, + WestendRelay as Westend, WestendRelayReceiver as WestendReceiver, + WestendRelaySender as WestendSender, }; pub const ASSET_ID: u32 = 1; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/tests/bridge_hubs.rs similarity index 52% rename from cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/teleport.rs rename to cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/tests/bridge_hubs.rs index 32639b8614be..55de44a017c1 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/tests/bridge_hubs.rs @@ -14,17 +14,31 @@ // limitations under the License. use crate::*; -use bridge_hub_westend_runtime::xcm_config::XcmConfig; +use bridge_hub_rococo_runtime::xcm_config::XcmConfig as BridgeHubRococoXcmConfig; +use bridge_hub_westend_runtime::xcm_config::XcmConfig as BridgeHubWestendXcmConfig; #[test] -fn teleport_to_other_system_parachains_works() { +fn bridge_hub_rococo_teleport_to_other_system_parachains_works() { let amount = BRIDGE_HUB_ROCOCO_ED * 100; let native_asset: MultiAssets = (Parent, amount).into(); test_parachain_is_trusted_teleporter!( - BridgeHubWestend, // Origin - XcmConfig, // XCM configuration - vec![AssetHubWestend], // Destinations + BridgeHubRococo, // Origin + BridgeHubRococoXcmConfig, // XCM configuration + vec![AssetHubRococo], // Destinations + (native_asset, amount) + ); +} + +#[test] +fn bridge_hub_westend_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 + BridgeHubWestendXcmConfig, // XCM configuration + vec![AssetHubWestend], // Destinations (native_asset, amount) ); } diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/tests/mod.rs similarity index 95% rename from cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs rename to cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/tests/mod.rs index 1eef05c6b928..d5a359fed830 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/tests/mod.rs @@ -13,5 +13,5 @@ // See the License for the specific language governing permissions and // limitations under the License. -mod example; -mod teleport; +mod bridge_hubs; +mod send_xcm; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/example.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/tests/send_xcm.rs similarity index 55% rename from cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/example.rs rename to cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/tests/send_xcm.rs index 195fa9493f5b..ccbb2a4b4867 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/example.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/tests/send_xcm.rs @@ -16,7 +16,91 @@ use crate::*; #[test] -fn example() { +fn send_xcm_from_rococo_relay_to_westend_asset_hub() { + // Init tests variables + // XcmPallet send arguments + let sudo_origin = ::RuntimeOrigin::root(); + let destination = Rococo::child_location_of(BridgeHubRococo::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: WestendId, + destination: X1(Parachain(AssetHubWestend::para_id().into())), + xcm: remote_xcm, + }, + ])); + + // Rococo Global Consensus + // Send XCM message from Relay Chain to Bridge Hub source Parachain + Rococo::execute_with(|| { + assert_ok!(::XcmPallet::send( + sudo_origin, + bx!(destination), + bx!(xcm), + )); + + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + Rococo, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + // Receive XCM message in Bridge Hub source Parachain + BridgeHubRococo::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + BridgeHubRococo, + vec![ + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { + success: true, + .. + }) => {}, + RuntimeEvent::BridgeWestendMessages(pallet_bridge_messages::Event::MessageAccepted { + lane_id: LaneId([0, 0, 0, 2]), + nonce: 1, + }) => {}, + ] + ); + }); + + // Westend Global Consensus + // Receive XCM message in Bridge Hub target Parachain + BridgeHubWestend::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + BridgeHubWestend, + vec![ + RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {}, + ] + ); + }); + // Receive embedded XCM message within `ExportMessage` in Parachain destination + AssetHubWestend::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + AssetHubWestend, + vec![ + RuntimeEvent::MessageQueue(pallet_message_queue::Event::ProcessingFailed { + .. + }) => {}, + ] + ); + }); +} + +#[test] +fn send_xcm_from_westend_relay_to_rococo_asset_hub() { // Init tests variables // XcmPallet send arguments let sudo_origin = ::RuntimeOrigin::root(); From 3daf65c13bb2d9b41a30d3ba56c061af88d8bb91 Mon Sep 17 00:00:00 2001 From: Adrian Catangiu Date: Mon, 13 Nov 2023 16:36:05 +0200 Subject: [PATCH 4/9] Revert "xcm-emulator: move bridge tests under per-bridge crate" This reverts commit 942092fa25069f8de7e2ccb378c640c2c17a694e. --- Cargo.lock | 64 +++++++---- Cargo.toml | 3 +- .../bridges/bridge-hub-rococo/Cargo.toml | 33 ++++++ .../src/lib.rs | 15 +-- .../bridge-hub-rococo/src/tests/example.rs | 100 ++++++++++++++++++ .../src/tests/mod.rs | 4 +- .../src/tests/teleport.rs} | 24 +---- .../Cargo.toml | 5 +- .../bridges/bridge-hub-westend/src/lib.rs | 61 +++++++++++ .../src/tests/example.rs} | 86 +-------------- .../bridge-hub-westend/src/tests/mod.rs | 17 +++ .../bridge-hub-westend/src/tests/teleport.rs | 30 ++++++ 12 files changed, 298 insertions(+), 144 deletions(-) create mode 100644 cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml rename cumulus/parachains/integration-tests/emulated/tests/bridges/{rococo-westend => bridge-hub-rococo}/src/lib.rs (72%) create mode 100644 cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/example.rs rename cumulus/parachains/integration-tests/emulated/tests/bridges/{rococo-westend => bridge-hub-rococo}/src/tests/mod.rs (95%) rename cumulus/parachains/integration-tests/emulated/tests/bridges/{rococo-westend/src/tests/bridge_hubs.rs => bridge-hub-rococo/src/tests/teleport.rs} (52%) rename cumulus/parachains/integration-tests/emulated/tests/bridges/{rococo-westend => bridge-hub-westend}/Cargo.toml (86%) create mode 100644 cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs rename cumulus/parachains/integration-tests/emulated/tests/bridges/{rococo-westend/src/tests/send_xcm.rs => bridge-hub-westend/src/tests/example.rs} (55%) create mode 100644 cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs create mode 100644 cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/teleport.rs diff --git a/Cargo.lock b/Cargo.lock index 65e64bab44bc..7cf280a8b146 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2173,6 +2173,27 @@ dependencies = [ "sp-runtime", ] +[[package]] +name = "bridge-hub-rococo-integration-tests" +version = "1.0.0" +dependencies = [ + "asset-test-utils", + "bp-messages", + "bridge-hub-rococo-runtime", + "cumulus-pallet-dmp-queue", + "cumulus-pallet-xcmp-queue", + "emulated-integration-tests-common", + "frame-support", + "pallet-bridge-messages", + "pallet-message-queue", + "pallet-xcm", + "parachains-common", + "parity-scale-codec", + "rococo-westend-system-emulated-network", + "staging-xcm", + "staging-xcm-executor", +] + [[package]] name = "bridge-hub-rococo-runtime" version = "0.1.0" @@ -2320,6 +2341,27 @@ dependencies = [ "sp-runtime", ] +[[package]] +name = "bridge-hub-westend-integration-tests" +version = "1.0.0" +dependencies = [ + "asset-test-utils", + "bp-messages", + "bridge-hub-westend-runtime", + "cumulus-pallet-dmp-queue", + "cumulus-pallet-xcmp-queue", + "emulated-integration-tests-common", + "frame-support", + "pallet-bridge-messages", + "pallet-message-queue", + "pallet-xcm", + "parachains-common", + "parity-scale-codec", + "rococo-westend-system-emulated-network", + "staging-xcm", + "staging-xcm-executor", +] + [[package]] name = "bridge-hub-westend-runtime" version = "0.1.0" @@ -14476,28 +14518,6 @@ dependencies = [ "rococo-emulated-chain", ] -[[package]] -name = "rococo-westend-bridge-integration-tests" -version = "1.0.0" -dependencies = [ - "asset-test-utils", - "bp-messages", - "bridge-hub-rococo-runtime", - "bridge-hub-westend-runtime", - "cumulus-pallet-dmp-queue", - "cumulus-pallet-xcmp-queue", - "emulated-integration-tests-common", - "frame-support", - "pallet-bridge-messages", - "pallet-message-queue", - "pallet-xcm", - "parachains-common", - "parity-scale-codec", - "rococo-westend-system-emulated-network", - "staging-xcm", - "staging-xcm-executor", -] - [[package]] name = "rococo-westend-system-emulated-network" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index cb682ec74627..9435cc09025a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,7 +67,8 @@ members = [ "cumulus/parachains/common", "cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo", "cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend", - "cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend", + "cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo", + "cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend", "cumulus/parachains/integration-tests/emulated/common", "cumulus/parachains/integration-tests/emulated/chains/relays/rococo", "cumulus/parachains/integration-tests/emulated/chains/relays/westend", diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml new file mode 100644 index 000000000000..584a074c8abe --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "bridge-hub-rococo-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" +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} +pallet-message-queue = { path = "../../../../../../../substrate/frame/message-queue" } + +# Polkadot +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} + +# Bridges +pallet-bridge-messages = { path = "../../../../../../../bridges/modules/messages", default-features = false} +bp-messages = { path = "../../../../../../../bridges/primitives/messages", default-features = false} + +# Cumulus +asset-test-utils = { path = "../../../../../../parachains/runtimes/assets/test-utils" } +parachains-common = { path = "../../../../../../parachains/common" } +cumulus-pallet-xcmp-queue = { path = "../../../../../../pallets/xcmp-queue", default-features = false} +cumulus-pallet-dmp-queue = { path = "../../../../../../pallets/dmp-queue", default-features = false} +bridge-hub-rococo-runtime = { path = "../../../../../../parachains/runtimes/bridge-hubs/bridge-hub-rococo", default-features = false } +emulated-integration-tests-common = { path = "../../../common", default-features = false} +rococo-westend-system-emulated-network = { path = "../../../networks/rococo-westend-system" } diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs similarity index 72% rename from cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/lib.rs rename to cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs index 9afd931e5d6a..72f8b490f310 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs @@ -43,22 +43,13 @@ pub use rococo_westend_system_emulated_network::{ bridge_hub_rococo_emulated_chain::{ genesis::ED as BRIDGE_HUB_ROCOCO_ED, BridgeHubRococoParaPallet as BridgeHubRococoPallet, }, - bridge_hub_westend_emulated_chain::{ - genesis::ED as BRIDGE_HUB_WESTEND_ED, BridgeHubWestendParaPallet as BridgeHubWestendPallet, - }, rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet}, - westend_emulated_chain::{genesis::ED as WESTEND_ED, WestendRelayPallet as WestendPallet}, AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver, AssetHubRococoParaSender as AssetHubRococoSender, AssetHubWestendPara as AssetHubWestend, - AssetHubWestendParaReceiver as AssetHubWestendReceiver, - AssetHubWestendParaSender as AssetHubWestendSender, BridgeHubRococoPara as BridgeHubRococo, - BridgeHubRococoParaReceiver as BridgeHubRococoReceiver, + BridgeHubRococoPara as BridgeHubRococo, BridgeHubRococoParaReceiver as BridgeHubRococoReceiver, BridgeHubRococoParaSender as BridgeHubRococoSender, BridgeHubWestendPara as BridgeHubWestend, - BridgeHubWestendParaReceiver as BridgeHubWestendReceiver, - BridgeHubWestendParaSender as BridgeHubWestendSender, RococoRelay as Rococo, - RococoRelayReceiver as RococoReceiver, RococoRelaySender as RococoSender, - WestendRelay as Westend, WestendRelayReceiver as WestendReceiver, - WestendRelaySender as WestendSender, + RococoRelay as Rococo, RococoRelayReceiver as RococoReceiver, + RococoRelaySender as RococoSender, }; pub const ASSET_ID: u32 = 1; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/example.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/example.rs new file mode 100644 index 000000000000..66979d31cea8 --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/example.rs @@ -0,0 +1,100 @@ +// 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 = ::RuntimeOrigin::root(); + let destination = Rococo::child_location_of(BridgeHubRococo::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: WestendId, + destination: X1(Parachain(AssetHubWestend::para_id().into())), + xcm: remote_xcm, + }, + ])); + + // Rococo Global Consensus + // Send XCM message from Relay Chain to Bridge Hub source Parachain + Rococo::execute_with(|| { + assert_ok!(::XcmPallet::send( + sudo_origin, + bx!(destination), + bx!(xcm), + )); + + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + Rococo, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); + // Receive XCM message in Bridge Hub source Parachain + BridgeHubRococo::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + BridgeHubRococo, + vec![ + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { + success: true, + .. + }) => {}, + RuntimeEvent::BridgeWestendMessages(pallet_bridge_messages::Event::MessageAccepted { + lane_id: LaneId([0, 0, 0, 2]), + nonce: 1, + }) => {}, + ] + ); + }); + + // Westend Global Consensus + // Receive XCM message in Bridge Hub target Parachain + BridgeHubWestend::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + BridgeHubWestend, + vec![ + RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {}, + ] + ); + }); + // Receive embedded XCM message within `ExportMessage` in Parachain destination + AssetHubWestend::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + AssetHubWestend, + vec![ + RuntimeEvent::MessageQueue(pallet_message_queue::Event::ProcessingFailed { + .. + }) => {}, + ] + ); + }); +} diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/tests/mod.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/mod.rs similarity index 95% rename from cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/tests/mod.rs rename to cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/mod.rs index d5a359fed830..1eef05c6b928 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/tests/mod.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/mod.rs @@ -13,5 +13,5 @@ // See the License for the specific language governing permissions and // limitations under the License. -mod bridge_hubs; -mod send_xcm; +mod example; +mod teleport; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/tests/bridge_hubs.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/teleport.rs similarity index 52% rename from cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/tests/bridge_hubs.rs rename to cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/teleport.rs index 55de44a017c1..f00288a4d8c7 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/tests/bridge_hubs.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/teleport.rs @@ -14,31 +14,17 @@ // limitations under the License. use crate::*; -use bridge_hub_rococo_runtime::xcm_config::XcmConfig as BridgeHubRococoXcmConfig; -use bridge_hub_westend_runtime::xcm_config::XcmConfig as BridgeHubWestendXcmConfig; +use bridge_hub_rococo_runtime::xcm_config::XcmConfig; #[test] -fn bridge_hub_rococo_teleport_to_other_system_parachains_works() { +fn teleport_to_other_system_parachains_works() { let amount = BRIDGE_HUB_ROCOCO_ED * 100; let native_asset: MultiAssets = (Parent, amount).into(); test_parachain_is_trusted_teleporter!( - BridgeHubRococo, // Origin - BridgeHubRococoXcmConfig, // XCM configuration - vec![AssetHubRococo], // Destinations - (native_asset, amount) - ); -} - -#[test] -fn bridge_hub_westend_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 - BridgeHubWestendXcmConfig, // XCM configuration - vec![AssetHubWestend], // Destinations + BridgeHubRococo, // Origin + XcmConfig, // XCM configuration + vec![AssetHubRococo], // Destinations (native_asset, amount) ); } diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/Cargo.toml similarity index 86% rename from cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/Cargo.toml rename to cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/Cargo.toml index bedf83e42a71..42a21c7dc8e4 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/Cargo.toml @@ -1,10 +1,10 @@ [package] -name = "rococo-westend-bridge-integration-tests" +name = "bridge-hub-westend-integration-tests" version = "1.0.0" authors.workspace = true edition.workspace = true license = "Apache-2.0" -description = "Rococo<>Westend bridge integration tests with xcm-emulator" +description = "Bridge Hub Westend runtime integration tests with xcm-emulator" publish = false [dependencies] @@ -28,7 +28,6 @@ asset-test-utils = { path = "../../../../../../parachains/runtimes/assets/test-u parachains-common = { path = "../../../../../../parachains/common" } cumulus-pallet-xcmp-queue = { path = "../../../../../../pallets/xcmp-queue", default-features = false} cumulus-pallet-dmp-queue = { path = "../../../../../../pallets/dmp-queue", 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 } emulated-integration-tests-common = { path = "../../../common", default-features = false} rococo-westend-system-emulated-network = { path = "../../../networks/rococo-westend-system" } diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs new file mode 100644 index 000000000000..30b215782d9b --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs @@ -0,0 +1,61 @@ +// 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. + +// Substrate +pub use frame_support::assert_ok; + +// Polkadot +pub use xcm::{ + prelude::{AccountId32 as AccountId32Junction, *}, + v3::{ + Error, + NetworkId::{Rococo as RococoId, Westend as WestendId}, + }, +}; + +// Bridges +pub use bp_messages::LaneId; + +// Cumulus +pub use emulated_integration_tests_common::{ + test_parachain_is_trusted_teleporter, + xcm_emulator::{ + assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para, + RelayChain as Relay, Test, TestArgs, TestContext, TestExt, + }, + xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, + PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, +}; +pub use parachains_common::{AccountId, Balance}; +pub use rococo_westend_system_emulated_network::{ + bridge_hub_westend_emulated_chain::{ + genesis::ED as BRIDGE_HUB_ROCOCO_ED, BridgeHubWestendParaPallet as BridgeHubWestendPallet, + }, + westend_emulated_chain::{genesis::ED as ROCOCO_ED, WestendRelayPallet as WestendPallet}, + AssetHubRococoPara as AssetHubRococo, AssetHubWestendPara as AssetHubWestend, + AssetHubWestendParaReceiver as AssetHubWestendReceiver, + AssetHubWestendParaSender as AssetHubWestendSender, BridgeHubRococoPara as BridgeHubRococo, + BridgeHubWestendPara as BridgeHubWestend, + BridgeHubWestendParaReceiver as BridgeHubWestendReceiver, + BridgeHubWestendParaSender as BridgeHubWestendSender, WestendRelay as Westend, + WestendRelayReceiver as WestendReceiver, WestendRelaySender as WestendSender, +}; + +pub const ASSET_ID: u32 = 1; +pub const ASSET_MIN_BALANCE: u128 = 1000; +pub const ASSETS_PALLET_ID: u8 = 50; + +#[cfg(test)] +mod tests; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/tests/send_xcm.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/example.rs similarity index 55% rename from cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/tests/send_xcm.rs rename to cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/example.rs index ccbb2a4b4867..195fa9493f5b 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/rococo-westend/src/tests/send_xcm.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/example.rs @@ -16,91 +16,7 @@ use crate::*; #[test] -fn send_xcm_from_rococo_relay_to_westend_asset_hub() { - // Init tests variables - // XcmPallet send arguments - let sudo_origin = ::RuntimeOrigin::root(); - let destination = Rococo::child_location_of(BridgeHubRococo::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: WestendId, - destination: X1(Parachain(AssetHubWestend::para_id().into())), - xcm: remote_xcm, - }, - ])); - - // Rococo Global Consensus - // Send XCM message from Relay Chain to Bridge Hub source Parachain - Rococo::execute_with(|| { - assert_ok!(::XcmPallet::send( - sudo_origin, - bx!(destination), - bx!(xcm), - )); - - type RuntimeEvent = ::RuntimeEvent; - - assert_expected_events!( - Rococo, - vec![ - RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, - ] - ); - }); - // Receive XCM message in Bridge Hub source Parachain - BridgeHubRococo::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - - assert_expected_events!( - BridgeHubRococo, - vec![ - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { - success: true, - .. - }) => {}, - RuntimeEvent::BridgeWestendMessages(pallet_bridge_messages::Event::MessageAccepted { - lane_id: LaneId([0, 0, 0, 2]), - nonce: 1, - }) => {}, - ] - ); - }); - - // Westend Global Consensus - // Receive XCM message in Bridge Hub target Parachain - BridgeHubWestend::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - - assert_expected_events!( - BridgeHubWestend, - vec![ - RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {}, - ] - ); - }); - // Receive embedded XCM message within `ExportMessage` in Parachain destination - AssetHubWestend::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - - assert_expected_events!( - AssetHubWestend, - vec![ - RuntimeEvent::MessageQueue(pallet_message_queue::Event::ProcessingFailed { - .. - }) => {}, - ] - ); - }); -} - -#[test] -fn send_xcm_from_westend_relay_to_rococo_asset_hub() { +fn example() { // Init tests variables // XcmPallet send arguments let sudo_origin = ::RuntimeOrigin::root(); diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs new file mode 100644 index 000000000000..1eef05c6b928 --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs @@ -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; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/teleport.rs new file mode 100644 index 000000000000..32639b8614be --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/teleport.rs @@ -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_ROCOCO_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) + ); +} From 8308f7e6500475d7c1803ba193a292f31785f4cb Mon Sep 17 00:00:00 2001 From: Adrian Catangiu Date: Mon, 13 Nov 2023 17:11:35 +0200 Subject: [PATCH 5/9] xcm-emulator: add ROCs & WNDs transfers tests across R-W bridge --- Cargo.lock | 4 + .../bridges/bridge-hub-westend/src/genesis.rs | 2 +- .../bridges/bridge-hub-rococo/Cargo.toml | 4 +- .../bridges/bridge-hub-rococo/src/lib.rs | 13 +- .../src/tests/asset_transfers.rs | 155 ++++++++++++++++++ .../bridge-hub-rococo/src/tests/mod.rs | 3 +- .../src/tests/{example.rs => send_xcm.rs} | 2 +- .../bridges/bridge-hub-westend/Cargo.toml | 4 +- .../bridges/bridge-hub-westend/src/lib.rs | 20 ++- .../src/tests/asset_transfers.rs | 155 ++++++++++++++++++ .../bridge-hub-westend/src/tests/mod.rs | 3 +- .../src/tests/{example.rs => send_xcm.rs} | 2 +- .../bridge-hub-westend/src/tests/teleport.rs | 2 +- 13 files changed, 349 insertions(+), 20 deletions(-) create mode 100644 cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs rename cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/{example.rs => send_xcm.rs} (98%) create mode 100644 cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs rename cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/{example.rs => send_xcm.rs} (98%) diff --git a/Cargo.lock b/Cargo.lock index 7cf280a8b146..938c03866837 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2184,6 +2184,8 @@ dependencies = [ "cumulus-pallet-xcmp-queue", "emulated-integration-tests-common", "frame-support", + "pallet-assets", + "pallet-balances", "pallet-bridge-messages", "pallet-message-queue", "pallet-xcm", @@ -2352,6 +2354,8 @@ dependencies = [ "cumulus-pallet-xcmp-queue", "emulated-integration-tests-common", "frame-support", + "pallet-assets", + "pallet-balances", "pallet-bridge-messages", "pallet-message-queue", "pallet-xcm", diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/genesis.rs index cd578d6862f2..2eb7e0ddbd29 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/genesis.rs @@ -22,7 +22,7 @@ use emulated_integration_tests_common::{ }; use parachains_common::Balance; -pub const PARA_ID: u32 = 1013; +pub const PARA_ID: u32 = 1002; pub const ED: Balance = parachains_common::westend::currency::EXISTENTIAL_DEPOSIT; pub fn genesis() -> Storage { diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml index 584a074c8abe..00e3af2e4fff 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml @@ -11,7 +11,9 @@ publish = false codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false } # 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 } +pallet-balances = { path = "../../../../../../../substrate/frame/balances", default-features = false } pallet-message-queue = { path = "../../../../../../../substrate/frame/message-queue" } # Polkadot diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs index 72f8b490f310..e4db0fdff7a0 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs @@ -30,6 +30,8 @@ pub use bp_messages::LaneId; // Cumulus pub use emulated_integration_tests_common::{ + accounts::ALICE, + impls::Inspect, test_parachain_is_trusted_teleporter, xcm_emulator::{ assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para, @@ -40,16 +42,19 @@ pub use emulated_integration_tests_common::{ }; pub use parachains_common::{AccountId, Balance}; pub use rococo_westend_system_emulated_network::{ + asset_hub_rococo_emulated_chain::{ + genesis::ED as ASSET_HUB_ROCOCO_ED, AssetHubRococoParaPallet as AssetHubRococoPallet, + }, + asset_hub_westend_emulated_chain::AssetHubWestendParaPallet as AssetHubWestendPallet, bridge_hub_rococo_emulated_chain::{ genesis::ED as BRIDGE_HUB_ROCOCO_ED, BridgeHubRococoParaPallet as BridgeHubRococoPallet, }, - rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet}, + rococo_emulated_chain::RococoRelayPallet as RococoPallet, AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver, AssetHubRococoParaSender as AssetHubRococoSender, AssetHubWestendPara as AssetHubWestend, - BridgeHubRococoPara as BridgeHubRococo, BridgeHubRococoParaReceiver as BridgeHubRococoReceiver, + AssetHubWestendParaReceiver as AssetHubWestendReceiver, BridgeHubRococoPara as BridgeHubRococo, BridgeHubRococoParaSender as BridgeHubRococoSender, BridgeHubWestendPara as BridgeHubWestend, - RococoRelay as Rococo, RococoRelayReceiver as RococoReceiver, - RococoRelaySender as RococoSender, + RococoRelay as Rococo, }; pub const ASSET_ID: u32 = 1; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs new file mode 100644 index 000000000000..264c9b59966c --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs @@ -0,0 +1,155 @@ +// 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::*; + +fn create_roc_foreign_asset_on_asset_hub_westend() -> MultiLocation { + let sudo_origin = ::RuntimeOrigin::root(); + let alice: AccountId = AssetHubWestend::account_id_of(ALICE); + let roc_at_asset_hub_westend = + MultiLocation { parents: 2, interior: X1(GlobalConsensus(NetworkId::Rococo)) }; + + AssetHubWestend::execute_with(|| { + assert_ok!(::ForeignAssets::force_create( + sudo_origin, + roc_at_asset_hub_westend, + alice.clone().into(), + true, + ASSET_MIN_BALANCE, + )); + assert!(::ForeignAssets::asset_exists( + roc_at_asset_hub_westend + )); + type RuntimeEvent = ::RuntimeEvent; + assert_expected_events!( + AssetHubWestend, + vec![ + RuntimeEvent::ForeignAssets(pallet_assets::Event::ForceCreated { + asset_id, + .. + }) => { asset_id: *asset_id == roc_at_asset_hub_westend, }, + ] + ); + }); + roc_at_asset_hub_westend +} + +#[test] +fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() { + let roc_at_asset_hub_westend = create_roc_foreign_asset_on_asset_hub_westend(); + + let sender_balance_before = + ::account_data_of(AssetHubRococoSender::get()).free; + let receiver_rocs_before = AssetHubWestend::execute_with(|| { + type Assets = ::ForeignAssets; + >::balance(roc_at_asset_hub_westend, &AssetHubWestendReceiver::get()) + }); + + let signed_origin = + ::RuntimeOrigin::signed(AssetHubRococoSender::get().into()); + let asset_hub_westend_para_id = AssetHubWestend::para_id().into(); + let destination = MultiLocation { + parents: 2, + interior: X2(GlobalConsensus(NetworkId::Westend), Parachain(asset_hub_westend_para_id)), + }; + let beneficiary_id = AssetHubWestendReceiver::get(); + let beneficiary: MultiLocation = + AccountId32Junction { network: None, id: beneficiary_id.into() }.into(); + let amount_to_send = ASSET_HUB_ROCOCO_ED * 10; + let assets: MultiAssets = (Parent, amount_to_send).into(); + let fee_asset_item = 0; + + // fund the AHR's SA on BHR for paying bridge transport fees + let ahr_as_seen_by_bhr = BridgeHubRococo::sibling_location_of(AssetHubRococo::para_id()); + let sov_ahr_on_bhr = BridgeHubRococo::sovereign_account_id_of(ahr_as_seen_by_bhr); + BridgeHubRococo::fund_accounts(vec![(sov_ahr_on_bhr.into(), 10_000_000_000_000)]); + + AssetHubRococo::execute_with(|| { + assert_ok!( + ::PolkadotXcm::limited_reserve_transfer_assets( + signed_origin, + bx!(destination.into()), + bx!(beneficiary.into()), + bx!(assets.into()), + fee_asset_item, + WeightLimit::Unlimited, + ) + ); + }); + + BridgeHubRococo::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + assert_expected_events!( + BridgeHubRococo, + vec![ + // pay for bridge fees + RuntimeEvent::Balances(pallet_balances::Event::Withdraw { .. }) => {}, + // message exported + RuntimeEvent::BridgeWestendMessages( + pallet_bridge_messages::Event::MessageAccepted { .. } + ) => {}, + // message processed successfully + RuntimeEvent::MessageQueue( + pallet_message_queue::Event::Processed { success: true, .. } + ) => {}, + ] + ); + }); + BridgeHubWestend::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + assert_expected_events!( + BridgeHubWestend, + vec![ + // message dispatched successfully + RuntimeEvent::XcmpQueue( + cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. } + ) => {}, + ] + ); + }); + AssetHubWestend::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + assert_expected_events!( + AssetHubWestend, + vec![ + // issue ROCs on AHW + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { + asset_id, + owner, + .. + }) => { + asset_id: *asset_id == roc_at_asset_hub_westend, + owner: *owner == AssetHubWestendReceiver::get(), + }, + // message processed successfully + RuntimeEvent::MessageQueue( + pallet_message_queue::Event::Processed { success: true, .. } + ) => {}, + ] + ); + }); + + let sender_balance_after = + ::account_data_of(AssetHubRococoSender::get()).free; + let receiver_rocs_after = AssetHubWestend::execute_with(|| { + type Assets = ::ForeignAssets; + >::balance(roc_at_asset_hub_westend, &AssetHubWestendReceiver::get()) + }); + + // Sender's balance is reduced + assert!(sender_balance_before > sender_balance_after); + // Receiver's balance is increased + assert!(receiver_rocs_after > receiver_rocs_before); +} diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/mod.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/mod.rs index 1eef05c6b928..4e2ef1434fdf 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/mod.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/mod.rs @@ -13,5 +13,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -mod example; +mod asset_transfers; +mod send_xcm; mod teleport; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/example.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/send_xcm.rs similarity index 98% rename from cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/example.rs rename to cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/send_xcm.rs index 66979d31cea8..4e61f7ce0ddb 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/example.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/send_xcm.rs @@ -16,7 +16,7 @@ use crate::*; #[test] -fn example() { +fn send_xcm_from_rococo_relay_to_westend_asset_hub() { // Init tests variables // XcmPallet send arguments let sudo_origin = ::RuntimeOrigin::root(); diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/Cargo.toml index 42a21c7dc8e4..e5b1fce5f2b1 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/Cargo.toml @@ -11,7 +11,9 @@ publish = false codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false } # 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 } +pallet-balances = { path = "../../../../../../../substrate/frame/balances", default-features = false } pallet-message-queue = { path = "../../../../../../../substrate/frame/message-queue" } # Polkadot diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs index 30b215782d9b..bcec97c3c1c8 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs @@ -30,6 +30,8 @@ pub use bp_messages::LaneId; // Cumulus pub use emulated_integration_tests_common::{ + accounts::ALICE, + impls::Inspect, test_parachain_is_trusted_teleporter, xcm_emulator::{ assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para, @@ -40,17 +42,19 @@ pub use emulated_integration_tests_common::{ }; pub use parachains_common::{AccountId, Balance}; pub use rococo_westend_system_emulated_network::{ + asset_hub_rococo_emulated_chain::AssetHubRococoParaPallet as AssetHubRococoPallet, + asset_hub_westend_emulated_chain::{ + genesis::ED as ASSET_HUB_WESTEND_ED, AssetHubWestendParaPallet as AssetHubWestendPallet, + }, bridge_hub_westend_emulated_chain::{ - genesis::ED as BRIDGE_HUB_ROCOCO_ED, BridgeHubWestendParaPallet as BridgeHubWestendPallet, + genesis::ED as BRIDGE_HUB_WESTEND_ED, BridgeHubWestendParaPallet as BridgeHubWestendPallet, }, - westend_emulated_chain::{genesis::ED as ROCOCO_ED, WestendRelayPallet as WestendPallet}, - AssetHubRococoPara as AssetHubRococo, AssetHubWestendPara as AssetHubWestend, - AssetHubWestendParaReceiver as AssetHubWestendReceiver, + westend_emulated_chain::WestendRelayPallet as WestendPallet, + AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver, + AssetHubWestendPara as AssetHubWestend, AssetHubWestendParaReceiver as AssetHubWestendReceiver, AssetHubWestendParaSender as AssetHubWestendSender, BridgeHubRococoPara as BridgeHubRococo, - BridgeHubWestendPara as BridgeHubWestend, - BridgeHubWestendParaReceiver as BridgeHubWestendReceiver, - BridgeHubWestendParaSender as BridgeHubWestendSender, WestendRelay as Westend, - WestendRelayReceiver as WestendReceiver, WestendRelaySender as WestendSender, + BridgeHubWestendPara as BridgeHubWestend, BridgeHubWestendParaSender as BridgeHubWestendSender, + WestendRelay as Westend, }; pub const ASSET_ID: u32 = 1; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs new file mode 100644 index 000000000000..ee932a5d2923 --- /dev/null +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs @@ -0,0 +1,155 @@ +// 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::*; + +fn create_wnd_foreign_asset_on_asset_hub_rococo() -> MultiLocation { + let sudo_origin = ::RuntimeOrigin::root(); + let alice: AccountId = AssetHubRococo::account_id_of(ALICE); + let wnd_at_asset_hub_rococo = + MultiLocation { parents: 2, interior: X1(GlobalConsensus(NetworkId::Westend)) }; + + AssetHubRococo::execute_with(|| { + assert_ok!(::ForeignAssets::force_create( + sudo_origin, + wnd_at_asset_hub_rococo, + alice.clone().into(), + true, + ASSET_MIN_BALANCE, + )); + assert!(::ForeignAssets::asset_exists( + wnd_at_asset_hub_rococo + )); + type RuntimeEvent = ::RuntimeEvent; + assert_expected_events!( + AssetHubRococo, + vec![ + RuntimeEvent::ForeignAssets(pallet_assets::Event::ForceCreated { + asset_id, + .. + }) => { asset_id: *asset_id == wnd_at_asset_hub_rococo, }, + ] + ); + }); + wnd_at_asset_hub_rococo +} + +#[test] +fn send_wnds_from_asset_hub_westend_to_asset_hub_rococo() { + let wnd_at_asset_hub_rococo = create_wnd_foreign_asset_on_asset_hub_rococo(); + + let sender_balance_before = + ::account_data_of(AssetHubWestendSender::get()).free; + let receiver_rocs_before = AssetHubRococo::execute_with(|| { + type Assets = ::ForeignAssets; + >::balance(wnd_at_asset_hub_rococo, &AssetHubRococoReceiver::get()) + }); + + let signed_origin = + ::RuntimeOrigin::signed(AssetHubWestendSender::get().into()); + let asset_hub_rococo_para_id = AssetHubRococo::para_id().into(); + let destination = MultiLocation { + parents: 2, + interior: X2(GlobalConsensus(NetworkId::Rococo), Parachain(asset_hub_rococo_para_id)), + }; + let beneficiary_id = AssetHubRococoReceiver::get(); + let beneficiary: MultiLocation = + AccountId32Junction { network: None, id: beneficiary_id.into() }.into(); + let amount_to_send = ASSET_HUB_WESTEND_ED * 10; + let assets: MultiAssets = (Parent, amount_to_send).into(); + let fee_asset_item = 0; + + // fund the AHW's SA on BHW for paying bridge transport fees + let ahw_as_seen_by_bhw = BridgeHubWestend::sibling_location_of(AssetHubWestend::para_id()); + let sov_ahw_on_bhw = BridgeHubWestend::sovereign_account_id_of(ahw_as_seen_by_bhw); + BridgeHubWestend::fund_accounts(vec![(sov_ahw_on_bhw.into(), 10_000_000_000_000)]); + + AssetHubWestend::execute_with(|| { + assert_ok!( + ::PolkadotXcm::limited_reserve_transfer_assets( + signed_origin, + bx!(destination.into()), + bx!(beneficiary.into()), + bx!(assets.into()), + fee_asset_item, + WeightLimit::Unlimited, + ) + ); + }); + + BridgeHubWestend::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + assert_expected_events!( + BridgeHubWestend, + vec![ + // pay for bridge fees + RuntimeEvent::Balances(pallet_balances::Event::Withdraw { .. }) => {}, + // message exported + RuntimeEvent::BridgeRococoMessages( + pallet_bridge_messages::Event::MessageAccepted { .. } + ) => {}, + // message processed successfully + RuntimeEvent::MessageQueue( + pallet_message_queue::Event::Processed { success: true, .. } + ) => {}, + ] + ); + }); + BridgeHubRococo::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + assert_expected_events!( + BridgeHubRococo, + vec![ + // message dispatched successfully + RuntimeEvent::XcmpQueue( + cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. } + ) => {}, + ] + ); + }); + AssetHubRococo::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + assert_expected_events!( + AssetHubRococo, + vec![ + // issue ROCs on AHW + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { + asset_id, + owner, + .. + }) => { + asset_id: *asset_id == wnd_at_asset_hub_rococo, + owner: *owner == AssetHubRococoReceiver::get(), + }, + // message processed successfully + RuntimeEvent::MessageQueue( + pallet_message_queue::Event::Processed { success: true, .. } + ) => {}, + ] + ); + }); + + let sender_balance_after = + ::account_data_of(AssetHubWestendSender::get()).free; + let receiver_rocs_after = AssetHubRococo::execute_with(|| { + type Assets = ::ForeignAssets; + >::balance(wnd_at_asset_hub_rococo, &AssetHubRococoReceiver::get()) + }); + + // Sender's balance is reduced + assert!(sender_balance_before > sender_balance_after); + // Receiver's balance is increased + assert!(receiver_rocs_after > receiver_rocs_before); +} diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs index 1eef05c6b928..4e2ef1434fdf 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs @@ -13,5 +13,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -mod example; +mod asset_transfers; +mod send_xcm; mod teleport; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/example.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/send_xcm.rs similarity index 98% rename from cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/example.rs rename to cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/send_xcm.rs index 195fa9493f5b..4b21d758cd98 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/example.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/send_xcm.rs @@ -16,7 +16,7 @@ use crate::*; #[test] -fn example() { +fn send_xcm_from_westend_relay_to_rococo_asset_hub() { // Init tests variables // XcmPallet send arguments let sudo_origin = ::RuntimeOrigin::root(); diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/teleport.rs index 32639b8614be..8dff6c292955 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/teleport.rs @@ -18,7 +18,7 @@ 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!( From 282432016ce2815b31ea582d4d1fede4f5909494 Mon Sep 17 00:00:00 2001 From: Adrian Catangiu Date: Mon, 13 Nov 2023 17:43:17 +0200 Subject: [PATCH 6/9] fix merge damage --- .../chains/parachains/assets/asset-hub-wococo/src/lib.rs | 1 - .../chains/parachains/bridges/bridge-hub-wococo/src/lib.rs | 1 - 2 files changed, 2 deletions(-) delete mode 100644 cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-wococo/src/lib.rs delete mode 100644 cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-wococo/src/lib.rs diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-wococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-wococo/src/lib.rs deleted file mode 100644 index 8b137891791f..000000000000 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-wococo/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-wococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-wococo/src/lib.rs deleted file mode 100644 index 8b137891791f..000000000000 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-wococo/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ - From 4a595c71e052ffad24f79ccb82d4f51fee11170b Mon Sep 17 00:00:00 2001 From: Adrian Catangiu Date: Mon, 13 Nov 2023 18:45:46 +0200 Subject: [PATCH 7/9] xcm-emulator: add foreign assets helpers to emulated/common --- .../assets/asset-hub-rococo/src/lib.rs | 4 +- .../assets/asset-hub-westend/src/lib.rs | 4 +- .../emulated/common/src/impls.rs | 86 ++++++++++++++++++- .../src/tests/asset_transfers.rs | 45 +++------- .../src/tests/asset_transfers.rs | 45 +++------- 5 files changed, 115 insertions(+), 69 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs index f94c4c3d2558..689d0cd68d9a 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs @@ -21,7 +21,8 @@ use frame_support::traits::OnInitialize; // Cumulus use emulated_integration_tests_common::{ impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, - impl_assets_helpers_for_parachain, xcm_emulator::decl_test_parachains, + impl_assets_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain, + xcm_emulator::decl_test_parachains, }; use rococo_emulated_chain::Rococo; @@ -53,3 +54,4 @@ decl_test_parachains! { impl_accounts_helpers_for_parachain!(AssetHubRococo); impl_assert_events_helpers_for_parachain!(AssetHubRococo, false); impl_assets_helpers_for_parachain!(AssetHubRococo, Rococo); +impl_foreign_assets_helpers_for_parachain!(AssetHubRococo, Rococo); diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs index 73d777247a5f..f6ba92aefc8d 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs @@ -21,7 +21,8 @@ use frame_support::traits::OnInitialize; // Cumulus use emulated_integration_tests_common::{ impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, - impl_assets_helpers_for_parachain, xcm_emulator::decl_test_parachains, + impl_assets_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain, + xcm_emulator::decl_test_parachains, }; use westend_emulated_chain::Westend; @@ -53,3 +54,4 @@ decl_test_parachains! { impl_accounts_helpers_for_parachain!(AssetHubWestend); impl_assert_events_helpers_for_parachain!(AssetHubWestend, false); impl_assets_helpers_for_parachain!(AssetHubWestend, Westend); +impl_foreign_assets_helpers_for_parachain!(AssetHubWestend, Westend); diff --git a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs index 6d1a4511e1ab..a807db72876f 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs @@ -615,7 +615,9 @@ macro_rules! impl_assets_helpers_for_parachain { $crate::impls::assert_expected_events!( Self, vec![ - RuntimeEvent::::Assets($crate::impls::pallet_assets::Event::Issued { asset_id, owner, amount }) => { + RuntimeEvent::::Assets( + $crate::impls::pallet_assets::Event::Issued { asset_id, owner, amount } + ) => { asset_id: *asset_id == id, owner: *owner == beneficiary.clone().into(), amount: *amount == amount_to_mint, @@ -688,3 +690,85 @@ macro_rules! impl_assets_helpers_for_parachain { } }; } + +#[macro_export] +macro_rules! impl_foreign_assets_helpers_for_parachain { + ( $chain:ident, $relay_chain:ident ) => { + $crate::impls::paste::paste! { + impl $chain { + /// Create foreign assets using sudo `ForeignAssets::force_create()` + pub fn force_create_foreign_asset( + id: $crate::impls::MultiLocation, + owner: $crate::impls::AccountId, + is_sufficient: bool, + min_balance: u128, + prefund_accounts: Vec<($crate::impls::AccountId, u128)>, + ) { + use $crate::impls::Inspect; + let sudo_origin = <$chain as $crate::impls::Chain>::RuntimeOrigin::root(); + ::execute_with(|| { + $crate::impls::assert_ok!( + ]>::ForeignAssets::force_create( + sudo_origin, + id, + owner.clone().into(), + is_sufficient, + min_balance, + ) + ); + assert!(]>::ForeignAssets::asset_exists(id)); + type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent; + $crate::impls::assert_expected_events!( + Self, + vec![ + RuntimeEvent::::ForeignAssets( + $crate::impls::pallet_assets::Event::ForceCreated { + asset_id, + .. + } + ) => { asset_id: *asset_id == id, }, + ] + ); + }); + for (beneficiary, amount) in prefund_accounts.into_iter() { + let signed_origin = + <$chain as $crate::impls::Chain>::RuntimeOrigin::signed(owner.clone()); + Self::mint_foreign_asset(signed_origin, id, beneficiary, amount); + } + } + + /// Mint assets making use of the ForeignAssets pallet-assets instance + pub fn mint_foreign_asset( + signed_origin: ::RuntimeOrigin, + id: $crate::impls::MultiLocation, + beneficiary: $crate::impls::AccountId, + amount_to_mint: u128, + ) { + ::execute_with(|| { + $crate::impls::assert_ok!(]>::ForeignAssets::mint( + signed_origin, + id.into(), + beneficiary.clone().into(), + amount_to_mint + )); + + type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent; + + $crate::impls::assert_expected_events!( + Self, + vec![ + RuntimeEvent::::ForeignAssets( + $crate::impls::pallet_assets::Event::Issued { asset_id, owner, amount } + ) => { + asset_id: *asset_id == id, + owner: *owner == beneficiary.clone().into(), + amount: *amount == amount_to_mint, + }, + ] + ); + }); + } + } + } + }; +} diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs index 264c9b59966c..7a9de4767fac 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs @@ -15,40 +15,19 @@ use crate::*; -fn create_roc_foreign_asset_on_asset_hub_westend() -> MultiLocation { - let sudo_origin = ::RuntimeOrigin::root(); - let alice: AccountId = AssetHubWestend::account_id_of(ALICE); - let roc_at_asset_hub_westend = - MultiLocation { parents: 2, interior: X1(GlobalConsensus(NetworkId::Rococo)) }; - - AssetHubWestend::execute_with(|| { - assert_ok!(::ForeignAssets::force_create( - sudo_origin, - roc_at_asset_hub_westend, - alice.clone().into(), - true, - ASSET_MIN_BALANCE, - )); - assert!(::ForeignAssets::asset_exists( - roc_at_asset_hub_westend - )); - type RuntimeEvent = ::RuntimeEvent; - assert_expected_events!( - AssetHubWestend, - vec![ - RuntimeEvent::ForeignAssets(pallet_assets::Event::ForceCreated { - asset_id, - .. - }) => { asset_id: *asset_id == roc_at_asset_hub_westend, }, - ] - ); - }); - roc_at_asset_hub_westend -} - #[test] fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() { - let roc_at_asset_hub_westend = create_roc_foreign_asset_on_asset_hub_westend(); + let prefund_amount = 10_000_000_000_000u128; + let owner: AccountId = AssetHubWestend::account_id_of(ALICE); + let roc_at_asset_hub_westend = + MultiLocation { parents: 2, interior: X1(GlobalConsensus(NetworkId::Rococo)) }; + AssetHubWestend::force_create_foreign_asset( + roc_at_asset_hub_westend, + owner, + true, + ASSET_MIN_BALANCE, + vec![], + ); let sender_balance_before = ::account_data_of(AssetHubRococoSender::get()).free; @@ -74,7 +53,7 @@ fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() { // fund the AHR's SA on BHR for paying bridge transport fees let ahr_as_seen_by_bhr = BridgeHubRococo::sibling_location_of(AssetHubRococo::para_id()); let sov_ahr_on_bhr = BridgeHubRococo::sovereign_account_id_of(ahr_as_seen_by_bhr); - BridgeHubRococo::fund_accounts(vec![(sov_ahr_on_bhr.into(), 10_000_000_000_000)]); + BridgeHubRococo::fund_accounts(vec![(sov_ahr_on_bhr.into(), prefund_amount)]); AssetHubRococo::execute_with(|| { assert_ok!( diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs index ee932a5d2923..216344e59108 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs @@ -15,40 +15,19 @@ use crate::*; -fn create_wnd_foreign_asset_on_asset_hub_rococo() -> MultiLocation { - let sudo_origin = ::RuntimeOrigin::root(); - let alice: AccountId = AssetHubRococo::account_id_of(ALICE); - let wnd_at_asset_hub_rococo = - MultiLocation { parents: 2, interior: X1(GlobalConsensus(NetworkId::Westend)) }; - - AssetHubRococo::execute_with(|| { - assert_ok!(::ForeignAssets::force_create( - sudo_origin, - wnd_at_asset_hub_rococo, - alice.clone().into(), - true, - ASSET_MIN_BALANCE, - )); - assert!(::ForeignAssets::asset_exists( - wnd_at_asset_hub_rococo - )); - type RuntimeEvent = ::RuntimeEvent; - assert_expected_events!( - AssetHubRococo, - vec![ - RuntimeEvent::ForeignAssets(pallet_assets::Event::ForceCreated { - asset_id, - .. - }) => { asset_id: *asset_id == wnd_at_asset_hub_rococo, }, - ] - ); - }); - wnd_at_asset_hub_rococo -} - #[test] fn send_wnds_from_asset_hub_westend_to_asset_hub_rococo() { - let wnd_at_asset_hub_rococo = create_wnd_foreign_asset_on_asset_hub_rococo(); + let prefund_amount = 10_000_000_000_000u128; + let owner: AccountId = AssetHubRococo::account_id_of(ALICE); + let wnd_at_asset_hub_rococo = + MultiLocation { parents: 2, interior: X1(GlobalConsensus(NetworkId::Westend)) }; + AssetHubRococo::force_create_foreign_asset( + wnd_at_asset_hub_rococo, + owner, + true, + ASSET_MIN_BALANCE, + vec![], + ); let sender_balance_before = ::account_data_of(AssetHubWestendSender::get()).free; @@ -74,7 +53,7 @@ fn send_wnds_from_asset_hub_westend_to_asset_hub_rococo() { // fund the AHW's SA on BHW for paying bridge transport fees let ahw_as_seen_by_bhw = BridgeHubWestend::sibling_location_of(AssetHubWestend::para_id()); let sov_ahw_on_bhw = BridgeHubWestend::sovereign_account_id_of(ahw_as_seen_by_bhw); - BridgeHubWestend::fund_accounts(vec![(sov_ahw_on_bhw.into(), 10_000_000_000_000)]); + BridgeHubWestend::fund_accounts(vec![(sov_ahw_on_bhw.into(), prefund_amount)]); AssetHubWestend::execute_with(|| { assert_ok!( From 9ca8e17afb02de062aece33902777ab4ad4fdada Mon Sep 17 00:00:00 2001 From: Adrian Catangiu Date: Tue, 14 Nov 2023 10:42:15 +0200 Subject: [PATCH 8/9] xcm-emulator: add bi-directional transfers of both ROCs & WNDs across R-W bridge --- .../bridges/bridge-hub-rococo/src/lib.rs | 4 +- .../src/tests/asset_transfers.rs | 138 +++++++++++++---- .../bridges/bridge-hub-westend/src/lib.rs | 4 +- .../src/tests/asset_transfers.rs | 140 +++++++++++++----- 4 files changed, 219 insertions(+), 67 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs index e4db0fdff7a0..53665437887c 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs @@ -45,7 +45,9 @@ pub use rococo_westend_system_emulated_network::{ asset_hub_rococo_emulated_chain::{ genesis::ED as ASSET_HUB_ROCOCO_ED, AssetHubRococoParaPallet as AssetHubRococoPallet, }, - asset_hub_westend_emulated_chain::AssetHubWestendParaPallet as AssetHubWestendPallet, + asset_hub_westend_emulated_chain::{ + genesis::ED as ASSET_HUB_WESTEND_ED, AssetHubWestendParaPallet as AssetHubWestendPallet, + }, bridge_hub_rococo_emulated_chain::{ genesis::ED as BRIDGE_HUB_ROCOCO_ED, BridgeHubRococoParaPallet as BridgeHubRococoPallet, }, diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs index 7a9de4767fac..ec0f700d245b 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs @@ -15,27 +15,7 @@ use crate::*; -#[test] -fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() { - let prefund_amount = 10_000_000_000_000u128; - let owner: AccountId = AssetHubWestend::account_id_of(ALICE); - let roc_at_asset_hub_westend = - MultiLocation { parents: 2, interior: X1(GlobalConsensus(NetworkId::Rococo)) }; - AssetHubWestend::force_create_foreign_asset( - roc_at_asset_hub_westend, - owner, - true, - ASSET_MIN_BALANCE, - vec![], - ); - - let sender_balance_before = - ::account_data_of(AssetHubRococoSender::get()).free; - let receiver_rocs_before = AssetHubWestend::execute_with(|| { - type Assets = ::ForeignAssets; - >::balance(roc_at_asset_hub_westend, &AssetHubWestendReceiver::get()) - }); - +fn send_asset_from_asset_hub_rococo_to_asset_hub_westend(id: MultiLocation, amount: u128) { let signed_origin = ::RuntimeOrigin::signed(AssetHubRococoSender::get().into()); let asset_hub_westend_para_id = AssetHubWestend::para_id().into(); @@ -46,14 +26,13 @@ fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() { let beneficiary_id = AssetHubWestendReceiver::get(); let beneficiary: MultiLocation = AccountId32Junction { network: None, id: beneficiary_id.into() }.into(); - let amount_to_send = ASSET_HUB_ROCOCO_ED * 10; - let assets: MultiAssets = (Parent, amount_to_send).into(); + let assets: MultiAssets = (id, amount).into(); let fee_asset_item = 0; // fund the AHR's SA on BHR for paying bridge transport fees let ahr_as_seen_by_bhr = BridgeHubRococo::sibling_location_of(AssetHubRococo::para_id()); let sov_ahr_on_bhr = BridgeHubRococo::sovereign_account_id_of(ahr_as_seen_by_bhr); - BridgeHubRococo::fund_accounts(vec![(sov_ahr_on_bhr.into(), prefund_amount)]); + BridgeHubRococo::fund_accounts(vec![(sov_ahr_on_bhr.into(), 10_000_000_000_000u128)]); AssetHubRococo::execute_with(|| { assert_ok!( @@ -98,18 +77,39 @@ fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() { ] ); }); +} + +#[test] +fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() { + let roc_at_asset_hub_rococo: MultiLocation = Parent.into(); + let roc_at_asset_hub_westend = + MultiLocation { parents: 2, interior: X1(GlobalConsensus(NetworkId::Rococo)) }; + let owner: AccountId = AssetHubWestend::account_id_of(ALICE); + AssetHubWestend::force_create_foreign_asset( + roc_at_asset_hub_westend, + owner, + true, + ASSET_MIN_BALANCE, + vec![], + ); + + let sender_rocs_before = + ::account_data_of(AssetHubRococoSender::get()).free; + let receiver_rocs_before = AssetHubWestend::execute_with(|| { + type Assets = ::ForeignAssets; + >::balance(roc_at_asset_hub_westend, &AssetHubWestendReceiver::get()) + }); + + let amount = ASSET_HUB_ROCOCO_ED * 1_000; + send_asset_from_asset_hub_rococo_to_asset_hub_westend(roc_at_asset_hub_rococo, amount); AssetHubWestend::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; assert_expected_events!( AssetHubWestend, vec![ // issue ROCs on AHW - RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { - asset_id, - owner, - .. - }) => { - asset_id: *asset_id == roc_at_asset_hub_westend, + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + asset_id: *asset_id == roc_at_asset_hub_rococo, owner: *owner == AssetHubWestendReceiver::get(), }, // message processed successfully @@ -120,7 +120,7 @@ fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() { ); }); - let sender_balance_after = + let sender_rocs_after = ::account_data_of(AssetHubRococoSender::get()).free; let receiver_rocs_after = AssetHubWestend::execute_with(|| { type Assets = ::ForeignAssets; @@ -128,7 +128,81 @@ fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() { }); // Sender's balance is reduced - assert!(sender_balance_before > sender_balance_after); + assert!(sender_rocs_before > sender_rocs_after); // Receiver's balance is increased assert!(receiver_rocs_after > receiver_rocs_before); } + +#[test] +fn send_wnds_from_asset_hub_rococo_to_asset_hub_westend() { + let prefund_amount = 10_000_000_000_000u128; + let wnd_at_asset_hub_rococo = + MultiLocation { parents: 2, interior: X1(GlobalConsensus(NetworkId::Westend)) }; + let owner: AccountId = AssetHubWestend::account_id_of(ALICE); + AssetHubRococo::force_create_foreign_asset( + wnd_at_asset_hub_rococo, + owner, + true, + ASSET_MIN_BALANCE, + vec![(AssetHubRococoSender::get(), prefund_amount)], + ); + + // fund the AHR's SA on AHW with the WND tokens held in reserve + let ahr_as_seen_by_ahw = MultiLocation { + parents: 2, + interior: X2( + GlobalConsensus(NetworkId::Rococo), + Parachain(AssetHubRococo::para_id().into()), + ), + }; + let sov_ahr_on_ahw = AssetHubWestend::execute_with(|| { + AssetHubWestend::sovereign_account_id_of(ahr_as_seen_by_ahw) + }); + AssetHubWestend::fund_accounts(vec![(sov_ahr_on_ahw.clone(), prefund_amount)]); + + let sender_wnds_before = AssetHubRococo::execute_with(|| { + type Assets = ::ForeignAssets; + >::balance(wnd_at_asset_hub_rococo, &AssetHubRococoSender::get()) + }); + assert_eq!(sender_wnds_before, prefund_amount); + let receiver_wnds_before = + ::account_data_of(AssetHubWestendReceiver::get()).free; + + let amount_to_send = ASSET_HUB_WESTEND_ED * 1_000; + send_asset_from_asset_hub_rococo_to_asset_hub_westend(wnd_at_asset_hub_rococo, amount_to_send); + AssetHubWestend::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + assert_expected_events!( + AssetHubWestend, + vec![ + // WND is withdrawn from AHR's SA on AHW + RuntimeEvent::Balances( + pallet_balances::Event::Withdraw { who, amount } + ) => { + who: *who == sov_ahr_on_ahw, + amount: *amount == amount_to_send, + }, + // WNDs deposited to beneficiary + RuntimeEvent::Balances(pallet_balances::Event::Deposit { who, .. }) => { + who: *who == AssetHubWestendReceiver::get(), + }, + // message processed successfully + RuntimeEvent::MessageQueue( + pallet_message_queue::Event::Processed { success: true, .. } + ) => {}, + ] + ); + }); + + let sender_wnds_after = AssetHubRococo::execute_with(|| { + type Assets = ::ForeignAssets; + >::balance(wnd_at_asset_hub_rococo, &AssetHubRococoSender::get()) + }); + let receiver_wnds_after = + ::account_data_of(AssetHubWestendReceiver::get()).free; + + // Sender's balance is reduced + assert!(sender_wnds_before > sender_wnds_after); + // Receiver's balance is increased + assert!(receiver_wnds_after > receiver_wnds_before); +} diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs index bcec97c3c1c8..04746aa86705 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs @@ -42,7 +42,9 @@ pub use emulated_integration_tests_common::{ }; pub use parachains_common::{AccountId, Balance}; pub use rococo_westend_system_emulated_network::{ - asset_hub_rococo_emulated_chain::AssetHubRococoParaPallet as AssetHubRococoPallet, + asset_hub_rococo_emulated_chain::{ + genesis::ED as ASSET_HUB_ROCOCO_ED, AssetHubRococoParaPallet as AssetHubRococoPallet, + }, asset_hub_westend_emulated_chain::{ genesis::ED as ASSET_HUB_WESTEND_ED, AssetHubWestendParaPallet as AssetHubWestendPallet, }, diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs index 216344e59108..2be747146893 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs @@ -15,27 +15,7 @@ use crate::*; -#[test] -fn send_wnds_from_asset_hub_westend_to_asset_hub_rococo() { - let prefund_amount = 10_000_000_000_000u128; - let owner: AccountId = AssetHubRococo::account_id_of(ALICE); - let wnd_at_asset_hub_rococo = - MultiLocation { parents: 2, interior: X1(GlobalConsensus(NetworkId::Westend)) }; - AssetHubRococo::force_create_foreign_asset( - wnd_at_asset_hub_rococo, - owner, - true, - ASSET_MIN_BALANCE, - vec![], - ); - - let sender_balance_before = - ::account_data_of(AssetHubWestendSender::get()).free; - let receiver_rocs_before = AssetHubRococo::execute_with(|| { - type Assets = ::ForeignAssets; - >::balance(wnd_at_asset_hub_rococo, &AssetHubRococoReceiver::get()) - }); - +fn send_asset_from_asset_hub_westend_to_asset_hub_rococo(id: MultiLocation, amount: u128) { let signed_origin = ::RuntimeOrigin::signed(AssetHubWestendSender::get().into()); let asset_hub_rococo_para_id = AssetHubRococo::para_id().into(); @@ -46,14 +26,13 @@ fn send_wnds_from_asset_hub_westend_to_asset_hub_rococo() { let beneficiary_id = AssetHubRococoReceiver::get(); let beneficiary: MultiLocation = AccountId32Junction { network: None, id: beneficiary_id.into() }.into(); - let amount_to_send = ASSET_HUB_WESTEND_ED * 10; - let assets: MultiAssets = (Parent, amount_to_send).into(); + let assets: MultiAssets = (id, amount).into(); let fee_asset_item = 0; // fund the AHW's SA on BHW for paying bridge transport fees let ahw_as_seen_by_bhw = BridgeHubWestend::sibling_location_of(AssetHubWestend::para_id()); let sov_ahw_on_bhw = BridgeHubWestend::sovereign_account_id_of(ahw_as_seen_by_bhw); - BridgeHubWestend::fund_accounts(vec![(sov_ahw_on_bhw.into(), prefund_amount)]); + BridgeHubWestend::fund_accounts(vec![(sov_ahw_on_bhw.into(), 10_000_000_000_000u128)]); AssetHubWestend::execute_with(|| { assert_ok!( @@ -98,17 +77,38 @@ fn send_wnds_from_asset_hub_westend_to_asset_hub_rococo() { ] ); }); +} + +#[test] +fn send_wnds_from_asset_hub_westend_to_asset_hub_rococo() { + let wnd_at_asset_hub_westend: MultiLocation = Parent.into(); + let wnd_at_asset_hub_rococo = + MultiLocation { parents: 2, interior: X1(GlobalConsensus(NetworkId::Westend)) }; + let owner: AccountId = AssetHubRococo::account_id_of(ALICE); + AssetHubRococo::force_create_foreign_asset( + wnd_at_asset_hub_rococo, + owner, + true, + ASSET_MIN_BALANCE, + vec![], + ); + + let sender_wnds_before = + ::account_data_of(AssetHubWestendSender::get()).free; + let receiver_wnds_before = AssetHubRococo::execute_with(|| { + type Assets = ::ForeignAssets; + >::balance(wnd_at_asset_hub_rococo, &AssetHubRococoReceiver::get()) + }); + + let amount = ASSET_HUB_WESTEND_ED * 1_000; + send_asset_from_asset_hub_westend_to_asset_hub_rococo(wnd_at_asset_hub_westend, amount); AssetHubRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; assert_expected_events!( AssetHubRococo, vec![ - // issue ROCs on AHW - RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { - asset_id, - owner, - .. - }) => { + // issue WNDs on AHR + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { asset_id: *asset_id == wnd_at_asset_hub_rococo, owner: *owner == AssetHubRococoReceiver::get(), }, @@ -120,15 +120,89 @@ fn send_wnds_from_asset_hub_westend_to_asset_hub_rococo() { ); }); - let sender_balance_after = + let sender_wnds_after = ::account_data_of(AssetHubWestendSender::get()).free; - let receiver_rocs_after = AssetHubRococo::execute_with(|| { + let receiver_wnds_after = AssetHubRococo::execute_with(|| { type Assets = ::ForeignAssets; >::balance(wnd_at_asset_hub_rococo, &AssetHubRococoReceiver::get()) }); // Sender's balance is reduced - assert!(sender_balance_before > sender_balance_after); + assert!(sender_wnds_before > sender_wnds_after); + // Receiver's balance is increased + assert!(receiver_wnds_after > receiver_wnds_before); +} + +#[test] +fn send_rocs_from_asset_hub_westend_to_asset_hub_rococo() { + let prefund_amount = 10_000_000_000_000u128; + let roc_at_asset_hub_westend = + MultiLocation { parents: 2, interior: X1(GlobalConsensus(NetworkId::Rococo)) }; + let owner: AccountId = AssetHubWestend::account_id_of(ALICE); + AssetHubWestend::force_create_foreign_asset( + roc_at_asset_hub_westend, + owner, + true, + ASSET_MIN_BALANCE, + vec![(AssetHubWestendSender::get(), prefund_amount)], + ); + + // fund the AHW's SA on AHR with the ROC tokens held in reserve + let ahw_as_seen_by_ahr = MultiLocation { + parents: 2, + interior: X2( + GlobalConsensus(NetworkId::Westend), + Parachain(AssetHubWestend::para_id().into()), + ), + }; + let sov_ahw_on_ahr = AssetHubRococo::execute_with(|| { + AssetHubRococo::sovereign_account_id_of(ahw_as_seen_by_ahr) + }); + AssetHubRococo::fund_accounts(vec![(sov_ahw_on_ahr.clone(), prefund_amount)]); + + let sender_rocs_before = AssetHubWestend::execute_with(|| { + type Assets = ::ForeignAssets; + >::balance(roc_at_asset_hub_westend, &AssetHubWestendSender::get()) + }); + assert_eq!(sender_rocs_before, prefund_amount); + let receiver_rocs_before = + ::account_data_of(AssetHubRococoReceiver::get()).free; + + let amount_to_send = ASSET_HUB_ROCOCO_ED * 1_000; + send_asset_from_asset_hub_westend_to_asset_hub_rococo(roc_at_asset_hub_westend, amount_to_send); + AssetHubRococo::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + assert_expected_events!( + AssetHubRococo, + vec![ + // ROC is withdrawn from AHW's SA on AHR + RuntimeEvent::Balances( + pallet_balances::Event::Withdraw { who, amount } + ) => { + who: *who == sov_ahw_on_ahr, + amount: *amount == amount_to_send, + }, + // ROCs deposited to beneficiary + RuntimeEvent::Balances(pallet_balances::Event::Deposit { who, .. }) => { + who: *who == AssetHubRococoReceiver::get(), + }, + // message processed successfully + RuntimeEvent::MessageQueue( + pallet_message_queue::Event::Processed { success: true, .. } + ) => {}, + ] + ); + }); + + let sender_rocs_after = AssetHubWestend::execute_with(|| { + type Assets = ::ForeignAssets; + >::balance(roc_at_asset_hub_westend, &AssetHubWestendSender::get()) + }); + let receiver_rocs_after = + ::account_data_of(AssetHubRococoReceiver::get()).free; + + // Sender's balance is reduced + assert!(sender_rocs_before > sender_rocs_after); // Receiver's balance is increased assert!(receiver_rocs_after > receiver_rocs_before); } From 7e8a870eb4a185bc2f19b7e389347dff02ec11b7 Mon Sep 17 00:00:00 2001 From: Adrian Catangiu Date: Tue, 14 Nov 2023 14:08:52 +0200 Subject: [PATCH 9/9] xcm-emulator: add reserve accounts checks to bridge asset transfer tests --- .../assets/asset-hub-rococo/src/lib.rs | 2 +- .../assets/asset-hub-westend/src/lib.rs | 2 +- .../bridges/bridge-hub-rococo/src/lib.rs | 2 +- .../bridges/bridge-hub-westend/src/lib.rs | 2 +- .../parachains/testing/penpal/src/lib.rs | 2 +- .../emulated/common/src/impls.rs | 20 +++++++++++- .../src/tests/asset_transfers.rs | 31 ++++++++++++------ .../src/tests/asset_transfers.rs | 32 ++++++++++++------- 8 files changed, 66 insertions(+), 27 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs index 689d0cd68d9a..1ed22b3cc4f5 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs @@ -21,7 +21,7 @@ use frame_support::traits::OnInitialize; // Cumulus use emulated_integration_tests_common::{ impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, - impl_assets_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain, + impl_assets_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains, }; use rococo_emulated_chain::Rococo; diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs index f6ba92aefc8d..4dcdb613ac20 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs @@ -21,7 +21,7 @@ use frame_support::traits::OnInitialize; // Cumulus use emulated_integration_tests_common::{ impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, - impl_assets_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain, + impl_assets_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains, }; use westend_emulated_chain::Westend; diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/src/lib.rs index f4557021f62b..ea0c9513abc3 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/src/lib.rs @@ -21,7 +21,7 @@ use frame_support::traits::OnInitialize; // Cumulus use emulated_integration_tests_common::{ impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, - xcm_emulator::decl_test_parachains, + impls::Parachain, xcm_emulator::decl_test_parachains, }; // BridgeHubRococo Parachain declaration diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/lib.rs index 1f1126d4565f..4a130ac1f27d 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/lib.rs @@ -21,7 +21,7 @@ use frame_support::traits::OnInitialize; // Cumulus use emulated_integration_tests_common::{ impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, - xcm_emulator::decl_test_parachains, + impls::Parachain, xcm_emulator::decl_test_parachains, }; // BridgeHubWestend Parachain declaration diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs index 537f96f45b47..f9a422bfcba7 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/lib.rs @@ -22,7 +22,7 @@ use frame_support::traits::OnInitialize; // Cumulus use emulated_integration_tests_common::{ impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain, - impl_assets_helpers_for_parachain, xcm_emulator::decl_test_parachains, + impl_assets_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains, }; use rococo_emulated_chain::Rococo; diff --git a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs index a807db72876f..8c94df6d888a 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/impls.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/impls.rs @@ -47,7 +47,8 @@ pub use xcm::{ pub use cumulus_pallet_parachain_system; pub use cumulus_pallet_xcmp_queue; pub use cumulus_primitives_core::{ - relay_chain::HrmpChannelId, DmpMessageHandler, ParaId, XcmpMessageHandler, + relay_chain::HrmpChannelId, DmpMessageHandler, Junction, Junctions, NetworkId, ParaId, + XcmpMessageHandler, }; pub use parachains_common::{AccountId, Balance}; pub use xcm_emulator::{ @@ -393,6 +394,23 @@ macro_rules! impl_accounts_helpers_for_parachain { } }); } + + /// Return local sovereign account of `para_id` on other `network_id` + pub fn sovereign_account_of_parachain_on_other_global_consensus( + network_id: $crate::impls::NetworkId, + para_id: $crate::impls::ParaId, + ) -> $crate::impls::AccountId { + let remote_location = $crate::impls::MultiLocation { + parents: 2, + interior: $crate::impls::Junctions::X2( + $crate::impls::Junction::GlobalConsensus(network_id), + $crate::impls::Junction::Parachain(para_id.into()), + ), + }; + ::execute_with(|| { + Self::sovereign_account_id_of(remote_location) + }) + } } } }; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs index ec0f700d245b..c55613f2826f 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs @@ -92,7 +92,13 @@ fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() { ASSET_MIN_BALANCE, vec![], ); + let sov_ahw_on_ahr = AssetHubRococo::sovereign_account_of_parachain_on_other_global_consensus( + NetworkId::Westend, + AssetHubWestend::para_id(), + ); + let rocs_in_reserve_on_ahr_before = + ::account_data_of(sov_ahw_on_ahr.clone()).free; let sender_rocs_before = ::account_data_of(AssetHubRococoSender::get()).free; let receiver_rocs_before = AssetHubWestend::execute_with(|| { @@ -126,11 +132,15 @@ fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() { type Assets = ::ForeignAssets; >::balance(roc_at_asset_hub_westend, &AssetHubWestendReceiver::get()) }); + let rocs_in_reserve_on_ahr_after = + ::account_data_of(sov_ahw_on_ahr.clone()).free; // Sender's balance is reduced assert!(sender_rocs_before > sender_rocs_after); // Receiver's balance is increased assert!(receiver_rocs_after > receiver_rocs_before); + // Reserve balance is reduced by sent amount + assert_eq!(rocs_in_reserve_on_ahr_after, rocs_in_reserve_on_ahr_before + amount); } #[test] @@ -148,18 +158,15 @@ fn send_wnds_from_asset_hub_rococo_to_asset_hub_westend() { ); // fund the AHR's SA on AHW with the WND tokens held in reserve - let ahr_as_seen_by_ahw = MultiLocation { - parents: 2, - interior: X2( - GlobalConsensus(NetworkId::Rococo), - Parachain(AssetHubRococo::para_id().into()), - ), - }; - let sov_ahr_on_ahw = AssetHubWestend::execute_with(|| { - AssetHubWestend::sovereign_account_id_of(ahr_as_seen_by_ahw) - }); + let sov_ahr_on_ahw = AssetHubWestend::sovereign_account_of_parachain_on_other_global_consensus( + NetworkId::Rococo, + AssetHubRococo::para_id(), + ); AssetHubWestend::fund_accounts(vec![(sov_ahr_on_ahw.clone(), prefund_amount)]); + let wnds_in_reserve_on_ahw_before = + ::account_data_of(sov_ahr_on_ahw.clone()).free; + assert_eq!(wnds_in_reserve_on_ahw_before, prefund_amount); let sender_wnds_before = AssetHubRococo::execute_with(|| { type Assets = ::ForeignAssets; >::balance(wnd_at_asset_hub_rococo, &AssetHubRococoSender::get()) @@ -200,9 +207,13 @@ fn send_wnds_from_asset_hub_rococo_to_asset_hub_westend() { }); let receiver_wnds_after = ::account_data_of(AssetHubWestendReceiver::get()).free; + let wnds_in_reserve_on_ahw_after = + ::account_data_of(sov_ahr_on_ahw).free; // Sender's balance is reduced assert!(sender_wnds_before > sender_wnds_after); // Receiver's balance is increased assert!(receiver_wnds_after > receiver_wnds_before); + // Reserve balance is reduced by sent amount + assert_eq!(wnds_in_reserve_on_ahw_after, wnds_in_reserve_on_ahw_before - amount_to_send); } diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs index 2be747146893..f90514f80c3e 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs @@ -12,7 +12,6 @@ // 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::*; fn send_asset_from_asset_hub_westend_to_asset_hub_rococo(id: MultiLocation, amount: u128) { @@ -92,7 +91,13 @@ fn send_wnds_from_asset_hub_westend_to_asset_hub_rococo() { ASSET_MIN_BALANCE, vec![], ); + let sov_ahr_on_ahw = AssetHubWestend::sovereign_account_of_parachain_on_other_global_consensus( + NetworkId::Rococo, + AssetHubRococo::para_id(), + ); + let wnds_in_reserve_on_ahw_before = + ::account_data_of(sov_ahr_on_ahw.clone()).free; let sender_wnds_before = ::account_data_of(AssetHubWestendSender::get()).free; let receiver_wnds_before = AssetHubRococo::execute_with(|| { @@ -126,11 +131,15 @@ fn send_wnds_from_asset_hub_westend_to_asset_hub_rococo() { type Assets = ::ForeignAssets; >::balance(wnd_at_asset_hub_rococo, &AssetHubRococoReceiver::get()) }); + let wnds_in_reserve_on_ahw_after = + ::account_data_of(sov_ahr_on_ahw).free; // Sender's balance is reduced assert!(sender_wnds_before > sender_wnds_after); // Receiver's balance is increased assert!(receiver_wnds_after > receiver_wnds_before); + // Reserve balance is increased by sent amount + assert_eq!(wnds_in_reserve_on_ahw_after, wnds_in_reserve_on_ahw_before + amount); } #[test] @@ -148,18 +157,15 @@ fn send_rocs_from_asset_hub_westend_to_asset_hub_rococo() { ); // fund the AHW's SA on AHR with the ROC tokens held in reserve - let ahw_as_seen_by_ahr = MultiLocation { - parents: 2, - interior: X2( - GlobalConsensus(NetworkId::Westend), - Parachain(AssetHubWestend::para_id().into()), - ), - }; - let sov_ahw_on_ahr = AssetHubRococo::execute_with(|| { - AssetHubRococo::sovereign_account_id_of(ahw_as_seen_by_ahr) - }); + let sov_ahw_on_ahr = AssetHubRococo::sovereign_account_of_parachain_on_other_global_consensus( + NetworkId::Westend, + AssetHubWestend::para_id(), + ); AssetHubRococo::fund_accounts(vec![(sov_ahw_on_ahr.clone(), prefund_amount)]); + let rocs_in_reserve_on_ahr_before = + ::account_data_of(sov_ahw_on_ahr.clone()).free; + assert_eq!(rocs_in_reserve_on_ahr_before, prefund_amount); let sender_rocs_before = AssetHubWestend::execute_with(|| { type Assets = ::ForeignAssets; >::balance(roc_at_asset_hub_westend, &AssetHubWestendSender::get()) @@ -200,9 +206,13 @@ fn send_rocs_from_asset_hub_westend_to_asset_hub_rococo() { }); let receiver_rocs_after = ::account_data_of(AssetHubRococoReceiver::get()).free; + let rocs_in_reserve_on_ahr_after = + ::account_data_of(sov_ahw_on_ahr.clone()).free; // Sender's balance is reduced assert!(sender_rocs_before > sender_rocs_after); // Receiver's balance is increased assert!(receiver_rocs_after > receiver_rocs_before); + // Reserve balance is reduced by sent amount + assert_eq!(rocs_in_reserve_on_ahr_after, rocs_in_reserve_on_ahr_before - amount_to_send); }