diff --git a/cumulus/parachains/integration-tests/emulated/common/src/xcm_helpers.rs b/cumulus/parachains/integration-tests/emulated/common/src/xcm_helpers.rs index 380f4983ad987..a7bcb4ad90438 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/xcm_helpers.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/xcm_helpers.rs @@ -67,6 +67,16 @@ pub fn non_fee_asset(assets: &Assets, fee_idx: usize) -> Option<(Location, u128) Some((asset.id.0, asset_amount)) } +/// Helper method to get the fee asset used in multiple assets transfer +pub fn fee_asset(assets: &Assets, fee_idx: usize) -> Option<(Location, u128)> { + let asset = assets.get(fee_idx)?; + let asset_amount = match asset.fun { + Fungible(amount) => amount, + _ => return None, + }; + Some((asset.id.0.clone(), asset_amount)) +} + pub fn get_amount_from_versioned_assets(assets: VersionedAssets) -> u128 { let latest_assets: Assets = assets.try_into().unwrap(); let Fungible(amount) = latest_assets.inner()[0].fun else { diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs index 513ca278a319e..7f691b977d3e1 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs @@ -43,9 +43,9 @@ mod imports { TestArgs, TestContext, TestExt, }, xcm_helpers::{ - get_amount_from_versioned_assets, non_fee_asset, xcm_transact_paid_execution, + fee_asset, get_amount_from_versioned_assets, non_fee_asset, xcm_transact_paid_execution, }, - ASSETS_PALLET_ID, RESERVABLE_ASSET_ID, XCM_V3, + PenpalATeleportableAssetLocation, ASSETS_PALLET_ID, RESERVABLE_ASSET_ID, XCM_V3, }; pub use parachains_common::Balance; pub use rococo_system_emulated_network::{ @@ -53,7 +53,7 @@ mod imports { asset_hub_rococo_runtime::{ self, xcm_config::{ - self as ahr_xcm_config, TokenLocation as RelayLocation, + self as ahr_xcm_config, TokenLocation as RelayLocation, TreasuryAccount, XcmConfig as AssetHubRococoXcmConfig, }, AssetConversionOrigin as AssetHubRococoAssetConversionOrigin, diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/hybrid_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/hybrid_transfers.rs index fb95c361f0891..6f278cd5024c9 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/hybrid_transfers.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/hybrid_transfers.rs @@ -737,8 +737,10 @@ fn transfer_native_asset_from_relay_to_para_through_asset_hub() { } fn penpal_assertions(t: RelayToParaThroughAHTest) { type RuntimeEvent = ::RuntimeEvent; - let expected_id = - t.args.assets.into_inner().first().unwrap().id.0.clone().try_into().unwrap(); + // Assets in t are relative to the relay chain. The asset here should be relative to + // Penpal, so parents: 1. + let expected_id: Location = Location { parents: 1, interior: Here }; + assert_expected_events!( PenpalA, vec![ diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs index 407a581afeb97..0e08adb8def3c 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs @@ -20,7 +20,7 @@ use sp_core::{crypto::get_public_from_string_or_panic, sr25519}; fn relay_to_para_sender_assertions(t: RelayToParaTest) { type RuntimeEvent = ::RuntimeEvent; - Rococo::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8_799))); + Rococo::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(350_000_000, 7000))); assert_expected_events!( Rococo, @@ -41,7 +41,7 @@ fn relay_to_para_sender_assertions(t: RelayToParaTest) { fn para_to_relay_sender_assertions(t: ParaToRelayTest) { type RuntimeEvent = ::RuntimeEvent; - PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8_799))); + PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(2_000_000_000, 140_000))); assert_expected_events!( PenpalA, vec![ @@ -141,6 +141,34 @@ pub fn system_para_to_para_receiver_assertions(t: SystemParaToParaTest) { } } +pub fn system_para_to_penpal_receiver_assertions(t: SystemParaToParaTest) { + type RuntimeEvent = ::RuntimeEvent; + + PenpalA::assert_xcmp_queue_success(None); + for asset in t.args.assets.into_inner().into_iter() { + let mut expected_id: Location = asset.id.0.try_into().unwrap(); + let relative_id = match expected_id { + Location { parents: 1, interior: Here } => expected_id, + _ => { + expected_id + .push_front_interior(Parachain(AssetHubRococo::para_id().into())) + .unwrap(); + Location::new(1, expected_id.interior().clone()) + }, + }; + + assert_expected_events!( + PenpalA, + vec![ + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + asset_id: *asset_id == relative_id, + owner: *owner == t.receiver.account_id, + }, + ] + ); + } +} + pub fn para_to_system_para_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; PenpalA::assert_xcm_pallet_attempted_complete(None); @@ -195,7 +223,11 @@ pub fn para_to_system_para_receiver_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; AssetHubRococo::assert_xcmp_queue_success(None); - let sov_acc_of_penpal = AssetHubRococo::sovereign_account_id_of(t.args.dest.clone()); + let sov_acc_of_penpal = AssetHubRococo::sovereign_account_id_of(Location::new( + 1, + Parachain(PenpalA::para_id().into()), + )); + for (idx, asset) in t.args.assets.into_inner().into_iter().enumerate() { let expected_id = asset.id.0.clone().try_into().unwrap(); let asset_amount = if let Fungible(a) = asset.fun { Some(a) } else { None }.unwrap(); @@ -255,6 +287,7 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) { 864_610_000, 8799, ))); + assert_expected_events!( AssetHubRococo, vec![ @@ -269,11 +302,9 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) { ), amount: *amount == t.args.amount, }, - // Native asset to pay for fees is transferred to Parachain's Sovereign account + // Native asset to pay for fees is transferred to Treasury RuntimeEvent::Balances(pallet_balances::Event::Minted { who, .. }) => { - who: *who == AssetHubRococo::sovereign_account_id_of( - t.args.dest.clone() - ), + who: *who == TreasuryAccount::get(), }, // Delivery fees are paid RuntimeEvent::PolkadotXcm( @@ -287,7 +318,7 @@ fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; let system_para_native_asset_location = RelayLocation::get(); let reservable_asset_location = PenpalLocalReservableFromAssetHub::get(); - PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8799))); + PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(2_000_000_000, 140000))); assert_expected_events!( PenpalA, vec![ @@ -412,9 +443,8 @@ fn para_to_para_asset_hub_hop_assertions(t: ParaToParaThroughAHTest) { let sov_penpal_a_on_ah = AssetHubRococo::sovereign_account_id_of( AssetHubRococo::sibling_location_of(PenpalA::para_id()), ); - let sov_penpal_b_on_ah = AssetHubRococo::sovereign_account_id_of( - AssetHubRococo::sibling_location_of(PenpalB::para_id()), - ); + + let (_, asset_amount) = fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); assert_expected_events!( AssetHubRococo, @@ -424,13 +454,7 @@ fn para_to_para_asset_hub_hop_assertions(t: ParaToParaThroughAHTest) { pallet_assets::Event::Burned { owner, balance, .. } ) => { owner: *owner == sov_penpal_a_on_ah, - balance: *balance == t.args.amount, - }, - // Deposited to receiver parachain SA - RuntimeEvent::Assets( - pallet_assets::Event::Deposited { who, .. } - ) => { - who: *who == sov_penpal_b_on_ah, + balance: *balance == asset_amount, }, RuntimeEvent::MessageQueue( pallet_message_queue::Event::Processed { success: true, .. } @@ -804,7 +828,7 @@ fn reserve_transfer_native_asset_from_asset_hub_to_para() { // Set assertions and dispatchables test.set_assertion::(system_para_to_para_sender_assertions); - test.set_assertion::(system_para_to_para_receiver_assertions); + test.set_assertion::(system_para_to_penpal_receiver_assertions); test.set_dispatchable::(system_para_to_para_reserve_transfer_assets); test.assert(); @@ -1326,7 +1350,7 @@ fn reserve_transfer_usdt_from_asset_hub_to_para() { }); test.set_assertion::(system_para_to_para_sender_assertions); - test.set_assertion::(system_para_to_para_receiver_assertions); + test.set_assertion::(system_para_to_penpal_receiver_assertions); test.set_dispatchable::(system_para_to_para_reserve_transfer_assets); test.assert(); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs index 89e4588d23bab..b3f156beaf51a 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs @@ -27,8 +27,8 @@ fn para_origin_assertions(t: SystemParaToRelayTest) { type RuntimeEvent = ::RuntimeEvent; AssetHubRococo::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts( - 720_053_000, - 7_203, + 730_053_000, + 4_000, ))); AssetHubRococo::assert_parachain_system_ump_sent(); @@ -76,12 +76,12 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) { let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of( AssetHubRococo::sibling_location_of(PenpalA::para_id()), ); - let (expected_foreign_asset_id, expected_foreign_asset_amount) = + let (_, expected_foreign_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); + let (_, fee_asset_amount) = fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); AssetHubRococo::assert_xcmp_queue_success(None); - println!("expected_foreign_asset_id: {:?}", expected_foreign_asset_id); assert_expected_events!( AssetHubRococo, vec![ @@ -90,13 +90,13 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) { pallet_balances::Event::Burned { who, amount } ) => { who: *who == sov_penpal_on_ahr.clone().into(), - amount: *amount == t.args.amount, + amount: *amount == fee_asset_amount, }, RuntimeEvent::Balances(pallet_balances::Event::Minted { who, .. }) => { who: *who == t.receiver.account_id, }, RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { - asset_id: *asset_id == expected_foreign_asset_id, + asset_id: *asset_id == PenpalATeleportableAssetLocation::get(), owner: *owner == t.receiver.account_id, amount: *amount == expected_foreign_asset_amount, }, @@ -110,6 +110,7 @@ fn ah_to_penpal_foreign_assets_sender_assertions(t: SystemParaToParaTest) { AssetHubRococo::assert_xcm_pallet_attempted_complete(None); let (expected_foreign_asset_id, expected_foreign_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); + let (_, fee_asset_amount) = fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); assert_expected_events!( AssetHubRococo, vec![ @@ -121,7 +122,7 @@ fn ah_to_penpal_foreign_assets_sender_assertions(t: SystemParaToParaTest) { to: *to == AssetHubRococo::sovereign_account_id_of( t.args.dest.clone() ), - amount: *amount == t.args.amount, + amount: *amount == fee_asset_amount, }, // foreign asset is burned locally as part of teleportation RuntimeEvent::ForeignAssets(pallet_assets::Event::Burned { asset_id, owner, balance }) => { @@ -159,10 +160,9 @@ fn ah_to_penpal_foreign_assets_receiver_assertions(t: SystemParaToParaTest) { amount: *amount == expected_asset_amount, }, // native asset for fee is deposited to receiver - RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { asset_id: *asset_id == system_para_native_asset_location, owner: *owner == t.receiver.account_id, - amount: *amount == expected_asset_amount, }, ] ); @@ -291,6 +291,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using _ => unreachable!(), }; let asset_amount_to_send = ASSET_HUB_ROCOCO_ED * 1000; + let asset_owner = PenpalAssetOwner::get(); let system_para_native_asset_location = RelayLocation::get(); let sender = PenpalASender::get(); @@ -457,6 +458,7 @@ pub fn do_bidirectional_teleport_foreign_assets_between_para_and_asset_hub_using fee_asset_index, ), }; + let mut ah_to_penpal = SystemParaToParaTest::new(ah_to_penpal_test_args); let ah_sender_balance_before = ah_to_penpal.sender.balance; diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/xcm_fee_estimation.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/xcm_fee_estimation.rs index 36a3786cd364a..6e3b893e3f6c7 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/xcm_fee_estimation.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/xcm_fee_estimation.rs @@ -51,7 +51,7 @@ fn hop_assertions(test: ParaToParaThroughAHTest) { RuntimeEvent::Balances( pallet_balances::Event::Burned { amount, .. } ) => { - amount: *amount == test.args.amount, + amount: *amount > test.args.amount * 90/100, }, ] ); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs index 1cb148e05f847..7384e691b2cad 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs @@ -44,9 +44,9 @@ mod imports { TestArgs, TestContext, TestExt, }, xcm_helpers::{ - get_amount_from_versioned_assets, non_fee_asset, xcm_transact_paid_execution, + fee_asset, get_amount_from_versioned_assets, non_fee_asset, xcm_transact_paid_execution, }, - ASSETS_PALLET_ID, RESERVABLE_ASSET_ID, USDT_ID, XCM_V3, + PenpalATeleportableAssetLocation, ASSETS_PALLET_ID, RESERVABLE_ASSET_ID, USDT_ID, XCM_V3, }; pub use parachains_common::{AccountId, Balance}; pub use westend_system_emulated_network::{ @@ -54,7 +54,7 @@ mod imports { asset_hub_westend_runtime::{ self, xcm_config::{ - self as ahw_xcm_config, WestendLocation as RelayLocation, + self as ahw_xcm_config, TreasuryAccount, WestendLocation as RelayLocation, XcmConfig as AssetHubWestendXcmConfig, }, AssetConversionOrigin as AssetHubWestendAssetConversionOrigin, diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/hybrid_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/hybrid_transfers.rs index 5437929571846..76f7229031dd5 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/hybrid_transfers.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/hybrid_transfers.rs @@ -738,13 +738,11 @@ fn transfer_native_asset_from_relay_to_penpal_through_asset_hub() { } fn penpal_assertions(t: RelayToParaThroughAHTest) { type RuntimeEvent = ::RuntimeEvent; - let expected_id = - t.args.assets.into_inner().first().unwrap().id.0.clone().try_into().unwrap(); assert_expected_events!( PenpalA, vec![ RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == expected_id, + asset_id: *asset_id == Location::new(1, Here), owner: *owner == t.receiver.account_id, }, ] diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs index dc36fed42932c..d95cd24e97215 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reserve_transfer.rs @@ -20,7 +20,7 @@ use westend_system_emulated_network::westend_emulated_chain::westend_runtime::Dm fn relay_to_para_sender_assertions(t: RelayToParaTest) { type RuntimeEvent = ::RuntimeEvent; - Westend::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8_799))); + Westend::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(350_000_000, 7000))); assert_expected_events!( Westend, @@ -41,7 +41,7 @@ fn relay_to_para_sender_assertions(t: RelayToParaTest) { fn para_to_relay_sender_assertions(t: ParaToRelayTest) { type RuntimeEvent = ::RuntimeEvent; - PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8_799))); + PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(2_000_000_000, 140_000))); assert_expected_events!( PenpalA, vec![ @@ -141,6 +141,34 @@ pub fn system_para_to_para_receiver_assertions(t: SystemParaToParaTest) { } } +pub fn system_para_to_penpal_receiver_assertions(t: SystemParaToParaTest) { + type RuntimeEvent = ::RuntimeEvent; + + PenpalA::assert_xcmp_queue_success(None); + for asset in t.args.assets.into_inner().into_iter() { + let mut expected_id: Location = asset.id.0.try_into().unwrap(); + let relative_id = match expected_id { + Location { parents: 1, interior: Here } => expected_id, + _ => { + expected_id + .push_front_interior(Parachain(AssetHubWestend::para_id().into())) + .unwrap(); + Location::new(1, expected_id.interior().clone()) + }, + }; + + assert_expected_events!( + PenpalA, + vec![ + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + asset_id: *asset_id == relative_id, + owner: *owner == t.receiver.account_id, + }, + ] + ); + } +} + pub fn para_to_system_para_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; PenpalA::assert_xcm_pallet_attempted_complete(None); @@ -195,7 +223,10 @@ pub fn para_to_system_para_receiver_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; AssetHubWestend::assert_xcmp_queue_success(None); - let sov_acc_of_penpal = AssetHubWestend::sovereign_account_id_of(t.args.dest.clone()); + let sov_acc_of_penpal = AssetHubWestend::sovereign_account_id_of(Location::new( + 1, + Parachain(PenpalA::para_id().into()), + )); for (idx, asset) in t.args.assets.into_inner().into_iter().enumerate() { let expected_id = asset.id.0.clone().try_into().unwrap(); let asset_amount = if let Fungible(a) = asset.fun { Some(a) } else { None }.unwrap(); @@ -271,9 +302,7 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) { }, // Native asset to pay for fees is transferred to Parachain's Sovereign account RuntimeEvent::Balances(pallet_balances::Event::Minted { who, .. }) => { - who: *who == AssetHubWestend::sovereign_account_id_of( - t.args.dest.clone() - ), + who: *who == TreasuryAccount::get(), }, // Delivery fees are paid RuntimeEvent::PolkadotXcm( @@ -287,7 +316,7 @@ fn para_to_system_para_assets_sender_assertions(t: ParaToSystemParaTest) { type RuntimeEvent = ::RuntimeEvent; let system_para_native_asset_location = RelayLocation::get(); let reservable_asset_location = PenpalLocalReservableFromAssetHub::get(); - PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(864_610_000, 8799))); + PenpalA::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(2_000_000_000, 140000))); assert_expected_events!( PenpalA, vec![ @@ -442,9 +471,8 @@ fn para_to_para_asset_hub_hop_assertions(t: ParaToParaThroughAHTest) { let sov_penpal_a_on_ah = AssetHubWestend::sovereign_account_id_of( AssetHubWestend::sibling_location_of(PenpalA::para_id()), ); - let sov_penpal_b_on_ah = AssetHubWestend::sovereign_account_id_of( - AssetHubWestend::sibling_location_of(PenpalB::para_id()), - ); + + let (_, asset_amount) = fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); assert_expected_events!( AssetHubWestend, @@ -454,13 +482,7 @@ fn para_to_para_asset_hub_hop_assertions(t: ParaToParaThroughAHTest) { pallet_assets::Event::Burned { owner, balance, .. } ) => { owner: *owner == sov_penpal_a_on_ah, - balance: *balance == t.args.amount, - }, - // Deposited to receiver parachain SA - RuntimeEvent::Assets( - pallet_assets::Event::Deposited { who, .. } - ) => { - who: *who == sov_penpal_b_on_ah, + balance: *balance == asset_amount, }, RuntimeEvent::MessageQueue( pallet_message_queue::Event::Processed { success: true, .. } @@ -1239,7 +1261,7 @@ fn reserve_transfer_usdt_from_asset_hub_to_para() { foreign_balance_on!(PenpalA, usdt_from_asset_hub.clone(), &receiver); test.set_assertion::(system_para_to_para_sender_assertions); - test.set_assertion::(system_para_to_para_receiver_assertions); + test.set_assertion::(system_para_to_penpal_receiver_assertions); test.set_dispatchable::(system_para_to_para_reserve_transfer_assets); test.assert(); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs index 0897c187e7cbc..06bfe75983a34 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs @@ -27,8 +27,8 @@ fn para_origin_assertions(t: SystemParaToRelayTest) { type RuntimeEvent = ::RuntimeEvent; AssetHubWestend::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts( - 720_053_000, - 7_203, + 730_053_000, + 4_000, ))); AssetHubWestend::assert_parachain_system_ump_sent(); @@ -76,8 +76,9 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) { let sov_penpal_on_ahr = AssetHubWestend::sovereign_account_id_of( AssetHubWestend::sibling_location_of(PenpalA::para_id()), ); - let (expected_foreign_asset_id, expected_foreign_asset_amount) = + let (_, expected_foreign_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); + let (_, fee_asset_amount) = fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); AssetHubWestend::assert_xcmp_queue_success(None); @@ -89,13 +90,13 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) { pallet_balances::Event::Burned { who, amount } ) => { who: *who == sov_penpal_on_ahr.clone().into(), - amount: *amount == t.args.amount, + amount: *amount >= fee_asset_amount / 2, }, RuntimeEvent::Balances(pallet_balances::Event::Minted { who, .. }) => { who: *who == t.receiver.account_id, }, RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { - asset_id: *asset_id == expected_foreign_asset_id, + asset_id: *asset_id == PenpalATeleportableAssetLocation::get(), owner: *owner == t.receiver.account_id, amount: *amount == expected_foreign_asset_amount, }, @@ -148,10 +149,9 @@ fn ah_to_penpal_foreign_assets_receiver_assertions(t: SystemParaToParaTest) { amount: *amount == expected_asset_amount, }, // native asset for fee is deposited to receiver - RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { asset_id: *asset_id == system_para_native_asset_location, owner: *owner == t.receiver.account_id, - amount: *amount == expected_asset_amount, }, ] ); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/transact.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/transact.rs index 10a677edddb79..abaa557b0f5b4 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/transact.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/transact.rs @@ -149,7 +149,6 @@ fn transact_from_para_to_para_through_asset_hub() { // (going through Asset Hub) let usdt_to_send: Asset = (usdt_from_asset_hub.clone(), fee_amount_to_send).into(); - let assets: Assets = usdt_to_send.clone().into(); let asset_location_on_penpal_a = Location::new(0, [PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())]); let penpal_a_as_seen_by_penpal_b = PenpalB::sibling_location_of(PenpalA::para_id()); @@ -174,10 +173,7 @@ fn transact_from_para_to_para_through_asset_hub() { let sov_penpal_a_on_ah = AssetHubWestend::sovereign_account_id_of( AssetHubWestend::sibling_location_of(PenpalA::para_id()), ); - let sov_penpal_b_on_ah = AssetHubWestend::sovereign_account_id_of( - AssetHubWestend::sibling_location_of(PenpalB::para_id()), - ); - asset_hub_hop_assertions(&assets, sov_penpal_a_on_ah, sov_penpal_b_on_ah); + asset_hub_hop_assertions(sov_penpal_a_on_ah); }); PenpalB::execute_with(|| { let expected_creator = @@ -198,32 +194,22 @@ fn transact_from_para_to_para_through_asset_hub() { assert!(receiver_assets_after > receiver_assets_before); } -fn asset_hub_hop_assertions(assets: &Assets, sender_sa: AccountId, receiver_sa: AccountId) { +fn asset_hub_hop_assertions(sender_sa: AccountId) { type RuntimeEvent = ::RuntimeEvent; - for asset in assets.inner() { - let amount = if let Fungible(a) = asset.fun { a } else { unreachable!() }; - assert_expected_events!( - AssetHubWestend, - vec![ - // Withdrawn from sender parachain SA - RuntimeEvent::Assets( - pallet_assets::Event::Burned { owner, balance, .. } - ) => { - owner: *owner == sender_sa, - balance: *balance == amount, - }, - // Deposited to receiver parachain SA - RuntimeEvent::Assets( - pallet_assets::Event::Deposited { who, .. } - ) => { - who: *who == receiver_sa, - }, - RuntimeEvent::MessageQueue( - pallet_message_queue::Event::Processed { success: true, .. } - ) => {}, - ] - ); - } + assert_expected_events!( + AssetHubWestend, + vec![ + // Withdrawn from sender parachain SA + RuntimeEvent::Assets( + pallet_assets::Event::Burned { owner, .. } + ) => { + owner: *owner == sender_sa, + }, + RuntimeEvent::MessageQueue( + pallet_message_queue::Event::Processed { success: true, .. } + ) => {}, + ] + ); } fn penpal_b_assertions( diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/xcm_fee_estimation.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/xcm_fee_estimation.rs index 822de21fa4f64..7deaaa9a984f9 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/xcm_fee_estimation.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/xcm_fee_estimation.rs @@ -52,7 +52,7 @@ fn hop_assertions(test: ParaToParaThroughAHTest) { RuntimeEvent::Balances( pallet_balances::Event::Burned { amount, .. } ) => { - amount: *amount == test.args.amount, + amount: *amount >= test.args.amount * 90/100, }, ] ); 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 f89880b284bcc..0eacb31f99608 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 @@ -43,8 +43,9 @@ mod imports { pub use parachains_common::AccountId; pub use rococo_westend_system_emulated_network::{ asset_hub_rococo_emulated_chain::{ - asset_hub_rococo_runtime::xcm_config as ahr_xcm_config, - genesis::ED as ASSET_HUB_ROCOCO_ED, AssetHubRococoParaPallet as AssetHubRococoPallet, + asset_hub_rococo_runtime::xcm_config::{self as ahr_xcm_config, TreasuryAccount}, + genesis::ED as ASSET_HUB_ROCOCO_ED, + AssetHubRococoParaPallet as AssetHubRococoPallet, }, asset_hub_westend_emulated_chain::{ genesis::{AssetHubWestendAssetOwner, ED as ASSET_HUB_WESTEND_ED}, 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 d1fe94962f184..7d13b9fd74196 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 @@ -65,11 +65,6 @@ fn send_assets_from_penpal_rococo_through_rococo_ah_to_westend_ah( let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of( AssetHubRococo::sibling_location_of(PenpalA::para_id()), ); - let sov_ahw_on_ahr = - AssetHubRococo::sovereign_account_of_parachain_on_other_global_consensus( - ByGenesis(WESTEND_GENESIS_HASH), - AssetHubWestend::para_id(), - ); // send message over bridge assert_ok!(PenpalA::execute_with(|| { let signed_origin = ::RuntimeOrigin::signed(PenpalASender::get()); @@ -98,7 +93,7 @@ fn send_assets_from_penpal_rococo_through_rococo_ah_to_westend_ah( }, // Amount deposited in AHW's sovereign account RuntimeEvent::Balances(pallet_balances::Event::Minted { who, .. }) => { - who: *who == sov_ahw_on_ahr.clone().into(), + who: *who == TreasuryAccount::get(), }, RuntimeEvent::XcmpQueue( cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. } @@ -140,6 +135,7 @@ fn send_roc_from_asset_hub_rococo_to_asset_hub_westend() { }); // verify expected events on final destination + let roc = Location::new(2, [GlobalConsensus(ByGenesis(ROCOCO_GENESIS_HASH))]); AssetHubWestend::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; assert_expected_events!( @@ -147,7 +143,7 @@ fn send_roc_from_asset_hub_rococo_to_asset_hub_westend() { vec![ // issue ROCs on AHW RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == roc_at_asset_hub_rococo, + asset_id: *asset_id == roc, owner: owner == &receiver, }, // message processed successfully @@ -388,6 +384,7 @@ fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend() } // process AHW incoming message and check events + let roc = Location::new(2, [GlobalConsensus(ByGenesis(ROCOCO_GENESIS_HASH))]); AssetHubWestend::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; assert_expected_events!( @@ -395,7 +392,7 @@ fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend() vec![ // issue ROCs on AHW RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == roc_at_rococo_parachains.clone(), + asset_id: *asset_id == roc, owner: owner == &receiver, }, // message processed successfully 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 6afa790cfce09..c522b41fd81fe 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 @@ -43,6 +43,7 @@ mod imports { pub use parachains_common::AccountId; pub use rococo_westend_system_emulated_network::{ asset_hub_rococo_emulated_chain::{ + asset_hub_rococo_runtime::xcm_config::TreasuryAccount, genesis::ED as ASSET_HUB_ROCOCO_ED, AssetHubRococoParaPallet as AssetHubRococoPallet, }, asset_hub_westend_emulated_chain::{ 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 3eaa7bd1b83ad..4068e2159bbd5 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 @@ -73,11 +73,6 @@ fn send_assets_from_penpal_westend_through_westend_ah_to_rococo_ah( let sov_penpal_on_ahw = AssetHubWestend::sovereign_account_id_of( AssetHubWestend::sibling_location_of(PenpalB::para_id()), ); - let sov_ahr_on_ahw = - AssetHubWestend::sovereign_account_of_parachain_on_other_global_consensus( - ByGenesis(ROCOCO_GENESIS_HASH), - AssetHubRococo::para_id(), - ); // send message over bridge assert_ok!(PenpalB::execute_with(|| { let signed_origin = ::RuntimeOrigin::signed(PenpalBSender::get()); @@ -106,7 +101,7 @@ fn send_assets_from_penpal_westend_through_westend_ah_to_rococo_ah( }, // Amount deposited in AHR's sovereign account RuntimeEvent::Balances(pallet_balances::Event::Minted { who, .. }) => { - who: *who == sov_ahr_on_ahw.clone().into(), + who: *who == TreasuryAccount::get(), }, RuntimeEvent::XcmpQueue( cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. } @@ -395,7 +390,7 @@ fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo() vec![ // issue WNDs on AHR RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == wnd_at_westend_parachains.clone(), + asset_id: *asset_id == wnd_at_asset_hub_rococo.clone(), owner: owner == &receiver, }, // message processed successfully @@ -1229,6 +1224,7 @@ fn do_send_pens_and_wnds_from_penpal_westend_via_ahw_to_asset_hub_rococo( ByGenesis(ROCOCO_GENESIS_HASH), AssetHubRococo::para_id(), ); + let ahw_fee_amount = 100_000_000_000; // send message over bridge assert_ok!(PenpalB::execute_with(|| { let destination = asset_hub_rococo_location(); @@ -1246,7 +1242,6 @@ fn do_send_pens_and_wnds_from_penpal_westend_via_ahw_to_asset_hub_rococo( // use 100_000_000_000 WNDs in fees on AHW // (exec fees: 3_593_000_000, transpo fees: 69_021_561_290 = 72_614_561_290) // TODO: make this exact once we have bridge dry-running - let ahw_fee_amount = 100_000_000_000; // XCM to be executed at dest (Rococo Asset Hub) let xcm_on_dest = Xcm(vec![ @@ -1322,7 +1317,7 @@ fn do_send_pens_and_wnds_from_penpal_westend_via_ahw_to_asset_hub_rococo( pallet_balances::Event::Burned { who, amount } ) => { who: *who == sov_penpal_on_ahw.clone().into(), - amount: *amount == wnds_amount, + amount: *amount == ahw_fee_amount, }, // Amount deposited in AHR's sovereign account RuntimeEvent::Balances(pallet_balances::Event::Minted { who, .. }) => { @@ -1444,6 +1439,7 @@ fn send_pens_and_wnds_from_penpal_westend_via_ahw_to_ahr() { (pens_location_on_penpal.try_into().unwrap(), pens_to_send), ); + let wnd = Location::new(2, [GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH))]); AssetHubRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; assert_expected_events!( @@ -1451,7 +1447,7 @@ fn send_pens_and_wnds_from_penpal_westend_via_ahw_to_ahr() { vec![ // issue WNDs on AHR RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == wnd_at_westend_parachains.clone().try_into().unwrap(), + asset_id: *asset_id == wnd, owner: *owner == AssetHubRococoReceiver::get(), }, // message processed successfully diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_inbound.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_inbound.rs index 427c93440d6d5..5de66f66658da 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_inbound.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_inbound.rs @@ -654,6 +654,11 @@ fn send_token_to_penpal_v2() { ); }); + let penpal_sov_on_ah = AssetHubWestend::sovereign_account_id_of(Location::new( + 1, + [Parachain(PenpalB::para_id().into())], + )); + AssetHubWestend::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; // Check that the assets were issued on AssetHub @@ -664,10 +669,15 @@ fn send_token_to_penpal_v2() { RuntimeEvent::MessageQueue( pallet_message_queue::Event::Processed { success: true, .. } ) => {}, + // Ether was issued to beneficiary + RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { + asset_id: *asset_id == eth_location(), + owner: *owner == penpal_sov_on_ah, + }, // Token was issued to beneficiary RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { asset_id: *asset_id == token_location, - owner: *owner == beneficiary_acc_bytes.into(), + owner: *owner == penpal_sov_on_ah, }, RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {}, ] diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_rewards.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_rewards.rs index 3593664947ceb..f9520f64ccc6b 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_rewards.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2_rewards.rs @@ -60,11 +60,8 @@ fn claim_rewards_works() { ); let relayer_location = Location::new( - 1, - [ - Parachain(1000), - Junction::AccountId32 { id: reward_address.clone().into(), network: None }, - ], + 0, + [Junction::AccountId32 { id: reward_address.clone().into(), network: None }], ); let reward_beneficiary = BridgeRewardBeneficiaries::AssetHubLocation(VersionedLocation::V5(relayer_location)); diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/transact.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/transact.rs index 76a1d443df103..e22758f893df3 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/transact.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/transact.rs @@ -189,10 +189,7 @@ fn transact_from_ethereum_to_penpalb_through_asset_hub() { ); }); AssetHubWestend::execute_with(|| { - let sov_penpal_b_on_ah = AssetHubWestend::sovereign_account_id_of( - AssetHubWestend::sibling_location_of(PenpalB::para_id()), - ); - asset_hub_hop_assertions(sov_penpal_b_on_ah); + asset_hub_hop_assertions(); }); PenpalB::execute_with(|| { let expected_creator = PenpalB::sovereign_account_id_of(sender); @@ -208,17 +205,15 @@ fn transact_from_ethereum_to_penpalb_through_asset_hub() { assert!(receiver_assets_after > receiver_assets_before); } -fn asset_hub_hop_assertions(receiver_sa: AccountId) { +fn asset_hub_hop_assertions() { type RuntimeEvent = ::RuntimeEvent; assert_expected_events!( AssetHubWestend, vec![ // Deposited to receiver parachain SA RuntimeEvent::ForeignAssets( - pallet_assets::Event::Deposited { who, .. } - ) => { - who: *who == receiver_sa, - }, + pallet_assets::Event::Deposited { .. } + ) => {}, RuntimeEvent::MessageQueue( pallet_message_queue::Event::Processed { success: true, .. } ) => {}, diff --git a/cumulus/xcm/xcm-emulator/src/lib.rs b/cumulus/xcm/xcm-emulator/src/lib.rs index 2387a935c9919..d8c280300b3c6 100644 --- a/cumulus/xcm/xcm-emulator/src/lib.rs +++ b/cumulus/xcm/xcm-emulator/src/lib.rs @@ -1293,63 +1293,62 @@ macro_rules! __impl_check_assertion { #[macro_export] macro_rules! assert_expected_events { - ( $chain:ident, vec![$( $event_pat:pat => { $($attr:ident : $condition:expr, )* }, )*] ) => { - let mut message: Vec = Vec::new(); + ( $chain:ident, vec![$( $event_pat:pat => { $($attr:ident : $condition:expr, )* }, )*] ) => { + let mut messages: Vec = Vec::new(); let mut events = <$chain as $crate::Chain>::events(); + // For each event pattern, we try to find a matching event. $( - let mut event_received = false; - let mut meet_conditions = true; - let mut index_match = 0; - let mut event_message: Vec = Vec::new(); - - for (index, event) in events.iter().enumerate() { - // Have to reset the variable to override a previous partial match - meet_conditions = true; + // We'll store a string representation of the first partially matching event. + let mut failure_message: Option = None; + for index in 0..events.len() { + let event = &events[index]; match event { $event_pat => { - event_received = true; + let mut event_meets_conditions = true; let mut conditions_message: Vec = Vec::new(); $( - // We only want to record condition error messages in case it did not happened before - // Only the first partial match is recorded - if !$condition && event_message.is_empty() { + if !$condition { conditions_message.push( format!( - " - The attribute {:?} = {:?} did not met the condition {:?}\n", + " - The attribute {} = {:?} did not meet the condition {}\n", stringify!($attr), $attr, stringify!($condition) ) ); } - meet_conditions &= $condition; + event_meets_conditions &= $condition; )* - // Set the index where we found a perfect match - if event_received && meet_conditions { - index_match = index; + if failure_message.is_none() && !conditions_message.is_empty() { + // Record the failure message. + failure_message = Some(format!( + "\n\n{}::\x1b[31m{}\x1b[0m was received but some of its attributes did not meet the conditions.\n\ + Actual event:\n{:#?}\n\ + Failures:\n{}", + stringify!($chain), + stringify!($event_pat), + event, + conditions_message.concat() + )); + } + + if event_meets_conditions { + // Found an event where all conditions hold. + failure_message = None; + events.remove(index); break; - } else { - event_message.extend(conditions_message); } }, _ => {} } } - if event_received && !meet_conditions { - message.push( - format!( - "\n\n{}::\x1b[31m{}\x1b[0m was received but some of its attributes did not meet the conditions:\n{}", - stringify!($chain), - stringify!($event_pat), - event_message.concat() - ) - ); - } else if !event_received { - message.push( + if failure_message.is_some() { + // No event matching the pattern was found. + messages.push( format!( "\n\n{}::\x1b[31m{}\x1b[0m was never received. All events:\n{:#?}", stringify!($chain), @@ -1357,18 +1356,15 @@ macro_rules! assert_expected_events { <$chain as $crate::Chain>::events(), ) ); - } else { - // If we find a perfect match we remove the event to avoid being potentially assessed multiple times - events.remove(index_match); } )* - if !message.is_empty() { - // Log events as they will not be logged after the panic + if !messages.is_empty() { + // Log all events (since they won't be logged after the panic). <$chain as $crate::Chain>::events().iter().for_each(|event| { $crate::log::info!(target: concat!("events::", stringify!($chain)), "{:?}", event); }); - panic!("{}", message.concat()) + panic!("{}", messages.concat()) } } } diff --git a/prdoc/pr_7913.prdoc b/prdoc/pr_7913.prdoc new file mode 100644 index 0000000000000..029daac4acf86 --- /dev/null +++ b/prdoc/pr_7913.prdoc @@ -0,0 +1,17 @@ +title: 'Fix assert_expected_events macro' +doc: +- audience: Runtime Dev + description: 'This PR fixes the assert_expected_events macro used in integration tests. Before this PR, the macro did not correctly assert field values. This change might result in tests failing that previously passed, due to false negatives.' +crates: +- name: xcm-emulator + bump: patch +- name: emulated-integration-tests-common + bump: patch +- name: asset-hub-rococo-integration-tests + bump: patch +- name: asset-hub-westend-integration-tests + bump: patch +- name: bridge-hub-rococo-integration-tests + bump: patch +- name: bridge-hub-westend-integration-tests + bump: patch