diff --git a/polkadot/xcm/xcm-executor/src/lib.rs b/polkadot/xcm/xcm-executor/src/lib.rs index 2f84662e6bc56..f3acca51a713f 100644 --- a/polkadot/xcm/xcm-executor/src/lib.rs +++ b/polkadot/xcm/xcm-executor/src/lib.rs @@ -582,6 +582,11 @@ impl XcmExecutor { self.process(xcm) } + #[cfg(any(test, feature = "runtime-benchmarks"))] + pub fn bench_post_process(self, xcm_weight: Weight) -> Outcome { + self.post_process(xcm_weight) + } + fn process(&mut self, xcm: Xcm) -> Result<(), ExecutorError> { tracing::trace!( target: "xcm::process", diff --git a/polkadot/xcm/xcm-executor/src/tests/mock.rs b/polkadot/xcm/xcm-executor/src/tests/mock.rs index a777541ac5ae2..cd612879d205a 100644 --- a/polkadot/xcm/xcm-executor/src/tests/mock.rs +++ b/polkadot/xcm/xcm-executor/src/tests/mock.rs @@ -38,11 +38,12 @@ use crate::{ pub fn instantiate_executor( origin: impl Into, message: Xcm<::RuntimeCall>, -) -> XcmExecutor { +) -> (XcmExecutor, Weight) { let mut vm = XcmExecutor::::new(origin, message.using_encoded(sp_io::hashing::blake2_256)); - vm.message_weight = XcmExecutor::::prepare(message.clone()).unwrap().weight_of(); - vm + let weight = XcmExecutor::::prepare(message.clone()).unwrap().weight_of(); + vm.message_weight = weight; + (vm, weight) } parameter_types! { @@ -200,15 +201,15 @@ impl WeightTrader for TestTrader { } /// Account where all dropped assets are deposited. -pub const VOID_ACCOUNT: [u8; 32] = [255; 32]; +pub const TRAPPED_ASSETS: [u8; 32] = [255; 32]; -/// Test asset trap that moves all dropped assets to the `VOID_ACCOUNT` account. +/// Test asset trap that moves all dropped assets to the `TRAPPED_ASSETS` account. pub struct TestAssetTrap; impl DropAssets for TestAssetTrap { fn drop_assets(_origin: &Location, assets: AssetsInHolding, _context: &XcmContext) -> Weight { ASSETS.with(|a| { a.borrow_mut() - .entry(VOID_ACCOUNT.into()) + .entry(TRAPPED_ASSETS.into()) .or_insert(AssetsInHolding::new()) .subsume_assets(assets) }); diff --git a/polkadot/xcm/xcm-executor/src/tests/pay_fees.rs b/polkadot/xcm/xcm-executor/src/tests/pay_fees.rs index e8e83191ff86b..96ec5b43d0c8e 100644 --- a/polkadot/xcm/xcm-executor/src/tests/pay_fees.rs +++ b/polkadot/xcm/xcm-executor/src/tests/pay_fees.rs @@ -44,7 +44,7 @@ fn works_for_execution_fees() { .deposit_asset(All, RECIPIENT.clone()) .build(); - let mut vm = instantiate_executor(SENDER, xcm.clone()); + let (mut vm, weight) = instantiate_executor(SENDER, xcm.clone()); // Program runs successfully. assert!(vm.bench_process(xcm).is_ok()); @@ -57,6 +57,10 @@ fn works_for_execution_fees() { // The recipient received all the assets in the holding register, so `100` that // were withdrawn, minus the `10` that were destinated for fee payment. assert_eq!(asset_list(RECIPIENT), [(Here, 90u128).into()]); + + // Leftover fees get trapped. + assert!(vm.bench_post_process(weight).ensure_complete().is_ok()); + assert_eq!(asset_list(TRAPPED_ASSETS), [(Here, 6u128).into()]) } // This tests the new functionality provided by `PayFees`, being able to pay for @@ -82,7 +86,7 @@ fn works_for_delivery_fees() { .deposit_asset(All, RECIPIENT.clone()) .build(); - let mut vm = instantiate_executor(SENDER.clone(), xcm.clone()); + let (mut vm, _) = instantiate_executor(SENDER.clone(), xcm.clone()); // Program runs successfully. assert!(vm.bench_process(xcm).is_ok()); @@ -135,7 +139,7 @@ fn buy_execution_works_as_before() { .deposit_asset(All, RECIPIENT.clone()) .build(); - let mut vm = instantiate_executor(SENDER, xcm.clone()); + let (mut vm, _) = instantiate_executor(SENDER, xcm.clone()); // Program runs successfully. assert!(vm.bench_process(xcm).is_ok()); @@ -165,7 +169,7 @@ fn fees_can_be_refunded() { .deposit_asset(All, SENDER.clone()) .build(); - let mut vm = instantiate_executor(SENDER.clone(), xcm.clone()); + let (mut vm, _) = instantiate_executor(SENDER.clone(), xcm.clone()); // Program runs successfully. assert!(vm.bench_process(xcm).is_ok()); @@ -197,7 +201,7 @@ fn putting_all_assets_in_pay_fees() { .deposit_asset(All, RECIPIENT.clone()) .build(); - let mut vm = instantiate_executor(SENDER.clone(), xcm.clone()); + let (mut vm, _) = instantiate_executor(SENDER.clone(), xcm.clone()); // Program runs successfully. assert!(vm.bench_process(xcm).is_ok()); @@ -234,7 +238,7 @@ fn refunding_too_early() { .report_error(query_response_info) .build(); - let mut vm = instantiate_executor(SENDER.clone(), xcm.clone()); + let (mut vm, _) = instantiate_executor(SENDER.clone(), xcm.clone()); // Program fails to run. assert!(vm.bench_process(xcm).is_err());