Skip to content

Commit 50b06d6

Browse files
chore(xcm-executor): test that leftover fees are also trapped
1 parent 49f63a4 commit 50b06d6

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

polkadot/xcm/xcm-executor/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,11 @@ impl<Config: config::Config> XcmExecutor<Config> {
582582
self.process(xcm)
583583
}
584584

585+
#[cfg(any(test, feature = "runtime-benchmarks"))]
586+
pub fn bench_post_process(self, xcm_weight: Weight) -> Outcome {
587+
self.post_process(xcm_weight)
588+
}
589+
585590
fn process(&mut self, xcm: Xcm<Config::RuntimeCall>) -> Result<(), ExecutorError> {
586591
tracing::trace!(
587592
target: "xcm::process",

polkadot/xcm/xcm-executor/src/tests/mock.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ use crate::{
3838
pub fn instantiate_executor(
3939
origin: impl Into<Location>,
4040
message: Xcm<<XcmConfig as Config>::RuntimeCall>,
41-
) -> XcmExecutor<XcmConfig> {
41+
) -> (XcmExecutor<XcmConfig>, Weight) {
4242
let mut vm =
4343
XcmExecutor::<XcmConfig>::new(origin, message.using_encoded(sp_io::hashing::blake2_256));
44-
vm.message_weight = XcmExecutor::<XcmConfig>::prepare(message.clone()).unwrap().weight_of();
45-
vm
44+
let weight = XcmExecutor::<XcmConfig>::prepare(message.clone()).unwrap().weight_of();
45+
vm.message_weight = weight;
46+
(vm, weight)
4647
}
4748

4849
parameter_types! {
@@ -200,15 +201,15 @@ impl WeightTrader for TestTrader {
200201
}
201202

202203
/// Account where all dropped assets are deposited.
203-
pub const VOID_ACCOUNT: [u8; 32] = [255; 32];
204+
pub const TRAPPED_ASSETS: [u8; 32] = [255; 32];
204205

205-
/// Test asset trap that moves all dropped assets to the `VOID_ACCOUNT` account.
206+
/// Test asset trap that moves all dropped assets to the `TRAPPED_ASSETS` account.
206207
pub struct TestAssetTrap;
207208
impl DropAssets for TestAssetTrap {
208209
fn drop_assets(_origin: &Location, assets: AssetsInHolding, _context: &XcmContext) -> Weight {
209210
ASSETS.with(|a| {
210211
a.borrow_mut()
211-
.entry(VOID_ACCOUNT.into())
212+
.entry(TRAPPED_ASSETS.into())
212213
.or_insert(AssetsInHolding::new())
213214
.subsume_assets(assets)
214215
});

polkadot/xcm/xcm-executor/src/tests/pay_fees.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn works_for_execution_fees() {
4444
.deposit_asset(All, RECIPIENT.clone())
4545
.build();
4646

47-
let mut vm = instantiate_executor(SENDER, xcm.clone());
47+
let (mut vm, weight) = instantiate_executor(SENDER, xcm.clone());
4848

4949
// Program runs successfully.
5050
assert!(vm.bench_process(xcm).is_ok());
@@ -57,6 +57,10 @@ fn works_for_execution_fees() {
5757
// The recipient received all the assets in the holding register, so `100` that
5858
// were withdrawn, minus the `10` that were destinated for fee payment.
5959
assert_eq!(asset_list(RECIPIENT), [(Here, 90u128).into()]);
60+
61+
// Leftover fees get trapped.
62+
assert!(vm.bench_post_process(weight).ensure_complete().is_ok());
63+
assert_eq!(asset_list(TRAPPED_ASSETS), [(Here, 6u128).into()])
6064
}
6165

6266
// This tests the new functionality provided by `PayFees`, being able to pay for
@@ -82,7 +86,7 @@ fn works_for_delivery_fees() {
8286
.deposit_asset(All, RECIPIENT.clone())
8387
.build();
8488

85-
let mut vm = instantiate_executor(SENDER.clone(), xcm.clone());
89+
let (mut vm, _) = instantiate_executor(SENDER.clone(), xcm.clone());
8690

8791
// Program runs successfully.
8892
assert!(vm.bench_process(xcm).is_ok());
@@ -135,7 +139,7 @@ fn buy_execution_works_as_before() {
135139
.deposit_asset(All, RECIPIENT.clone())
136140
.build();
137141

138-
let mut vm = instantiate_executor(SENDER, xcm.clone());
142+
let (mut vm, _) = instantiate_executor(SENDER, xcm.clone());
139143

140144
// Program runs successfully.
141145
assert!(vm.bench_process(xcm).is_ok());
@@ -165,7 +169,7 @@ fn fees_can_be_refunded() {
165169
.deposit_asset(All, SENDER.clone())
166170
.build();
167171

168-
let mut vm = instantiate_executor(SENDER.clone(), xcm.clone());
172+
let (mut vm, _) = instantiate_executor(SENDER.clone(), xcm.clone());
169173

170174
// Program runs successfully.
171175
assert!(vm.bench_process(xcm).is_ok());
@@ -197,7 +201,7 @@ fn putting_all_assets_in_pay_fees() {
197201
.deposit_asset(All, RECIPIENT.clone())
198202
.build();
199203

200-
let mut vm = instantiate_executor(SENDER.clone(), xcm.clone());
204+
let (mut vm, _) = instantiate_executor(SENDER.clone(), xcm.clone());
201205

202206
// Program runs successfully.
203207
assert!(vm.bench_process(xcm).is_ok());
@@ -234,7 +238,7 @@ fn refunding_too_early() {
234238
.report_error(query_response_info)
235239
.build();
236240

237-
let mut vm = instantiate_executor(SENDER.clone(), xcm.clone());
241+
let (mut vm, _) = instantiate_executor(SENDER.clone(), xcm.clone());
238242

239243
// Program fails to run.
240244
assert!(vm.bench_process(xcm).is_err());

0 commit comments

Comments
 (0)