Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SetAssetClaimer Instruction to XCM v5 #5585

Merged
merged 157 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 147 commits
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
3d7e24a
feat(xcm): add PayFees instruction
franciscoaguirre Aug 20, 2024
0a88320
chore(xcm-executor): clean up executor unit test and move everything …
franciscoaguirre Aug 21, 2024
0b16ca5
Merge branch 'xcm-v5' into xcm-pay-fees
franciscoaguirre Aug 21, 2024
2393087
feat(xcm-executor): tests for delivery fees and old BuyExecution
franciscoaguirre Aug 21, 2024
b9ca9e0
feat(xcm-executor): interaction between PayFees and RefundSurplus
franciscoaguirre Aug 21, 2024
22efce5
fix(xcm): add builder(pays_fees) to old xcm versions
franciscoaguirre Aug 21, 2024
49f63a4
chore(xcm-executor): unhappy tests for PayFees
franciscoaguirre Aug 21, 2024
50b06d6
chore(xcm-executor): test that leftover fees are also trapped
franciscoaguirre Aug 23, 2024
738a8c1
chore: add made-up benchmarks to all runtimes
franciscoaguirre Aug 26, 2024
995cc09
feat(xcm-builder): allow PayFees in AllowTopLevelPaidExecutionFrom ba…
franciscoaguirre Aug 26, 2024
679c3c7
feat(xcm-executor): use fees register in DepositReserveAsset
franciscoaguirre Aug 26, 2024
d934c64
feat(xcm-emulator): add set_call method for dispatching calls
franciscoaguirre Aug 26, 2024
52f3ba1
test(asset-hub-westend-integration-tests): add xcm estimation test wi…
franciscoaguirre Aug 26, 2024
900bb46
fix: fmt
franciscoaguirre Aug 26, 2024
56bcd4d
fix(xcm-executor): remove unnecessary clones
franciscoaguirre Aug 27, 2024
c062c0c
chore(asset-hub-westend-integration-tests): refactor test to decl macro
franciscoaguirre Aug 27, 2024
94f831f
feat(asset-hub-rococo-integration-tests): add PayFees test
franciscoaguirre Aug 27, 2024
3198950
fix: fmt
franciscoaguirre Aug 27, 2024
6bf562b
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=ro…
Aug 27, 2024
15a5333
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=we…
Aug 27, 2024
fb79e69
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=co…
Aug 27, 2024
4c9dddc
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=as…
Aug 27, 2024
a8d5d1d
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=as…
Aug 27, 2024
c1c95dc
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=co…
Aug 27, 2024
0c5afe3
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=br…
Aug 27, 2024
338d8de
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=br…
Aug 27, 2024
12164f8
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=pe…
Aug 27, 2024
c3b6bd0
chore: add missing benchmark and made up benchmarks for all runtimes
franciscoaguirre Aug 27, 2024
e2c620e
fix: remove duplicated weight
franciscoaguirre Aug 27, 2024
86b151c
fix: remove unused imports
franciscoaguirre Aug 27, 2024
2937662
Merge branch 'xcm-v5' into xcm-pay-fees
franciscoaguirre Aug 27, 2024
0eaa9fb
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=we…
Aug 27, 2024
39cf7b1
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=ro…
Aug 27, 2024
abe36c3
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=co…
Aug 27, 2024
a60172c
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=as…
Aug 27, 2024
8470fca
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=as…
Aug 27, 2024
6a59c1d
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=br…
Aug 27, 2024
bdae9ec
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=co…
Aug 27, 2024
6b339a0
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=br…
Aug 27, 2024
02b0fbb
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=pe…
Aug 27, 2024
ec92154
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=pe…
Aug 27, 2024
1091ac7
doc: add prdoc
franciscoaguirre Aug 30, 2024
f0f1aac
fix: prdoc
franciscoaguirre Aug 30, 2024
b1e850e
Added SetAssetClaimer instruction
x3c41a Aug 20, 2024
1a77953
added prdoc
x3c41a Aug 20, 2024
eca1375
added missing column
x3c41a Aug 20, 2024
09046e6
fixed prdoc: added crates
x3c41a Aug 20, 2024
7c8e2a4
Update SetAssetClaimer description
x3c41a Aug 20, 2024
0a8d2f9
Formated SetAssetClaimer
x3c41a Aug 20, 2024
497bb95
Removed v3::MultiLocation
x3c41a Aug 20, 2024
d68ac96
changed asset claimer variable name from camel case to snake case
x3c41a Aug 20, 2024
2dd1718
initialized XCMExecutor with an empty asset_claimer
x3c41a Aug 20, 2024
69c9570
Added missing instructions coverter
x3c41a Aug 20, 2024
17e758c
applied linter suggestions
x3c41a Aug 20, 2024
1cd2822
applied linter suggestions[2]
x3c41a Aug 20, 2024
d070cd7
fixed type mismatch and other compilation errs
x3c41a Aug 21, 2024
64cc40e
added missing implementation (or todo!() ) for AssetHubWestendXcmWeight
x3c41a Aug 21, 2024
953463c
few minor refactors
x3c41a Aug 21, 2024
e2b0777
unit tests in progress
x3c41a Aug 26, 2024
236e91f
Added unit test for SetAssetClaimer
x3c41a Aug 26, 2024
5abbdf6
[WIP] set_asset_claimer e2e test
x3c41a Aug 28, 2024
5a7c195
Implemented pay_fees for the testnets
x3c41a Aug 28, 2024
6800d9f
WIP e2e tests - claimAssets step
x3c41a Aug 30, 2024
b5a2cd0
Fixed dispatch
x3c41a Aug 30, 2024
2fec6d4
finished first SAC e2e single chain test
x3c41a Sep 2, 2024
0ff7c67
benchmarks initial commit
x3c41a Sep 2, 2024
4f8aada
Reverted cumulus/parachains/runtimes/assets/asset-hub-westend/src/wei…
x3c41a Sep 3, 2024
7c8df66
add made-up benchmarks to all runtimes
x3c41a Sep 3, 2024
7f4412e
removed commented instruction
x3c41a Sep 3, 2024
c8cddbb
added set_asset_claimer to pallet_xcm WeightInfo trait and implemente…
x3c41a Sep 3, 2024
38f3691
resolved merge conflicts
x3c41a Sep 3, 2024
cfb23bf
Added unit test for SetAssetClaimer
x3c41a Aug 26, 2024
5ced85a
resolved merge conflicts[3]
x3c41a Sep 3, 2024
ef911c5
resolved merge conflicts[4]
x3c41a Sep 3, 2024
84ad4ce
reverted cumulus/parachains/runtimes/assets/asset-hub-westend/src/wei…
x3c41a Sep 3, 2024
dd39a1b
fixed benchmark
x3c41a Sep 3, 2024
69362da
removed unused file and import
x3c41a Sep 4, 2024
d32a028
Merge branch 'xcm-v5' into xcm-pay-fees
franciscoaguirre Sep 4, 2024
e21cae1
Merge remote-tracking branch 'origin/xcm-pay-fees' into xcm-sac-1
x3c41a Sep 5, 2024
416fe4a
added missing fn definition to trait
x3c41a Sep 5, 2024
9b364a6
added westhub sac weights
x3c41a Sep 5, 2024
aa0d457
removed unused sender_account
x3c41a Sep 5, 2024
18576bb
added sac to people-westend
x3c41a Sep 5, 2024
8c3e3c3
added sac to runtimes/collectives/collectives-westend/src/weights/pal…
x3c41a Sep 5, 2024
ebd9668
added sac to rococo runtime
x3c41a Sep 5, 2024
139a066
added sac to all the weights/xcm_pallet
x3c41a Sep 5, 2024
68efec5
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=we…
Sep 5, 2024
43a1231
Added SetAssetClaimer instruction
x3c41a Aug 20, 2024
1d71fb7
added prdoc
x3c41a Aug 20, 2024
224a6d6
added missing column
x3c41a Aug 20, 2024
5c035cc
fixed prdoc: added crates
x3c41a Aug 20, 2024
bfe7627
Update SetAssetClaimer description
x3c41a Aug 20, 2024
802ece4
Formated SetAssetClaimer
x3c41a Aug 20, 2024
ee9e8d5
Removed v3::MultiLocation
x3c41a Aug 20, 2024
3be8339
changed asset claimer variable name from camel case to snake case
x3c41a Aug 20, 2024
202d4d1
initialized XCMExecutor with an empty asset_claimer
x3c41a Aug 20, 2024
455678d
Added missing instructions coverter
x3c41a Aug 20, 2024
3d47c4b
applied linter suggestions
x3c41a Aug 20, 2024
d4a7004
applied linter suggestions[2]
x3c41a Aug 20, 2024
c4da6f1
fixed type mismatch and other compilation errs
x3c41a Aug 21, 2024
8212c5b
added missing implementation (or todo!() ) for AssetHubWestendXcmWeight
x3c41a Aug 21, 2024
a43735d
few minor refactors
x3c41a Aug 21, 2024
50e566d
unit tests in progress
x3c41a Aug 26, 2024
cb2fc15
Added unit test for SetAssetClaimer
x3c41a Aug 26, 2024
d89fb70
[WIP] set_asset_claimer e2e test
x3c41a Aug 28, 2024
aff5fd4
Implemented pay_fees for the testnets
x3c41a Aug 28, 2024
13b5619
WIP e2e tests - claimAssets step
x3c41a Aug 30, 2024
129d8cb
Fixed dispatch
x3c41a Aug 30, 2024
737943c
finished first SAC e2e single chain test
x3c41a Sep 2, 2024
465bd7e
benchmarks initial commit
x3c41a Sep 2, 2024
80d7e6e
Reverted cumulus/parachains/runtimes/assets/asset-hub-westend/src/wei…
x3c41a Sep 3, 2024
1754578
add made-up benchmarks to all runtimes
x3c41a Sep 3, 2024
c0081ae
removed commented instruction
x3c41a Sep 3, 2024
0db627d
added set_asset_claimer to pallet_xcm WeightInfo trait and implemente…
x3c41a Sep 3, 2024
89a8ee2
resolved merge conflicts
x3c41a Sep 3, 2024
7a487a0
Added unit test for SetAssetClaimer
x3c41a Aug 26, 2024
fdd45af
resolved merge conflicts[3]
x3c41a Sep 3, 2024
e467e4a
resolved merge conflicts[4]
x3c41a Sep 3, 2024
145de1e
reverted cumulus/parachains/runtimes/assets/asset-hub-westend/src/wei…
x3c41a Sep 3, 2024
571510c
fixed benchmark
x3c41a Sep 3, 2024
97b2e51
removed unused file and import
x3c41a Sep 4, 2024
d8c4651
added missing fn definition to trait
x3c41a Sep 5, 2024
c44584f
added westhub sac weights
x3c41a Sep 5, 2024
7d1c21f
removed unused sender_account
x3c41a Sep 5, 2024
9920ddf
added sac to people-westend
x3c41a Sep 5, 2024
fc997ec
added sac to runtimes/collectives/collectives-westend/src/weights/pal…
x3c41a Sep 5, 2024
2135b58
added sac to rococo runtime
x3c41a Sep 5, 2024
687271a
added sac to all the weights/xcm_pallet
x3c41a Sep 5, 2024
582a397
added _ to all the unused location
x3c41a Sep 5, 2024
71ba3d7
updated westend benchmarks
x3c41a Sep 5, 2024
9ad82b7
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=we…
Sep 5, 2024
b02c831
fixed e2e tests
x3c41a Sep 5, 2024
660cfcc
changed benchmark values for all the set_asset_claimers
x3c41a Sep 5, 2024
5ac4e7e
WIP: multi-chain set asset claimer test
x3c41a Sep 18, 2024
b35d56b
added HashedDescription conversion to BridgeHub
x3c41a Sep 18, 2024
833ce02
WIP: merging set_asset_claimer tests
x3c41a Sep 19, 2024
ec4854a
trying to add bridge_hub_westend_runtime to asset_hub_westend tests
x3c41a Sep 19, 2024
c4ab166
fixed set_asset_claimer emulated tests and resolved PR comments
x3c41a Sep 22, 2024
11a5b72
improved emulated tests, removed unnecessary weight calculations
x3c41a Sep 25, 2024
7ea3ffe
refactored test_sac_between_the_chains
x3c41a Sep 26, 2024
7a90cb3
removed unnecessary weight and fixed prdoc
x3c41a Sep 26, 2024
7b949ca
refactored set_asset_claimer tests
x3c41a Sep 27, 2024
21bd49d
removed unnecessary set_asset_claimer from pallet_xcm
x3c41a Sep 27, 2024
f5e3587
Update test description
x3c41a Sep 27, 2024
598ae4a
removed extra spaces and an extra set_asset_claimer fn
x3c41a Sep 27, 2024
bf1f2b3
formatted affected crates
x3c41a Sep 27, 2024
23a7e65
changed pr_doc number
x3c41a Sep 27, 2024
c37ac54
removed unused imports
x3c41a Sep 30, 2024
f0631fb
removed dead code
x3c41a Oct 1, 2024
c8b5e64
Merged set_asset_claimer branch into xcm-v5 with pay_fees branch
x3c41a Oct 18, 2024
df4df98
fixed westend benchmarks
x3c41a Oct 18, 2024
20a5b85
Update test name
x3c41a Oct 21, 2024
d4e0f4b
renamed a variable and removed a duplicate variable
x3c41a Oct 21, 2024
9e575f6
Added missing v4 import
x3c41a Oct 21, 2024
93f96c8
used proper version of xcm junction
x3c41a Oct 21, 2024
f99c3f6
removed self dependency
x3c41a Oct 21, 2024
8f42b3e
formatted the imports
x3c41a Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
pub mod genesis;

pub use bridge_hub_westend_runtime::{
xcm_config::XcmConfig as BridgeHubWestendXcmConfig,
self, xcm_config::XcmConfig as BridgeHubWestendXcmConfig,
ExistentialDeposit as BridgeHubWestendExistentialDeposit,
};

Expand Down
224 changes: 224 additions & 0 deletions cumulus/parachains/integration-tests/emulated/common/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,227 @@ macro_rules! test_chain_can_claim_assets {
}
};
}

#[macro_export]
macro_rules! test_can_estimate_and_pay_exact_fees {
( $sender_para:ty, $asset_hub:ty, $receiver_para:ty, ($asset_id:expr, $amount:expr), $owner_prefix:ty ) => {
$crate::macros::paste::paste! {
// We first define the call we'll use throughout the test.
fn get_call(
estimated_local_fees: impl Into<Asset>,
estimated_intermediate_fees: impl Into<Asset>,
estimated_remote_fees: impl Into<Asset>,
) -> <$sender_para as Chain>::RuntimeCall {
type RuntimeCall = <$sender_para as Chain>::RuntimeCall;

let beneficiary = [<$receiver_para Receiver>]::get();
let xcm_in_destination = Xcm::<()>::builder_unsafe()
.pay_fees(estimated_remote_fees)
.deposit_asset(AllCounted(1), beneficiary)
.build();
let ah_to_receiver = $asset_hub::sibling_location_of($receiver_para::para_id());
let xcm_in_reserve = Xcm::<()>::builder_unsafe()
.pay_fees(estimated_intermediate_fees)
.deposit_reserve_asset(
AllCounted(1),
ah_to_receiver,
xcm_in_destination,
)
.build();
let sender_to_ah = $sender_para::sibling_location_of($asset_hub::para_id());
let local_xcm = Xcm::<<$sender_para as Chain>::RuntimeCall>::builder()
.withdraw_asset(($asset_id, $amount))
.pay_fees(estimated_local_fees)
.initiate_reserve_withdraw(AllCounted(1), sender_to_ah, xcm_in_reserve)
.build();

RuntimeCall::PolkadotXcm(pallet_xcm::Call::execute {
message: bx!(VersionedXcm::from(local_xcm)),
max_weight: Weight::from_parts(10_000_000_000, 500_000),
})
}

let destination = $sender_para::sibling_location_of($receiver_para::para_id());
let sender = [<$sender_para Sender>]::get();
let sender_as_seen_by_ah = $asset_hub::sibling_location_of($sender_para::para_id());
let sov_of_sender_on_ah = $asset_hub::sovereign_account_id_of(sender_as_seen_by_ah.clone());
let asset_owner = [<$owner_prefix AssetOwner>]::get();

// Fund parachain's sender account.
$sender_para::mint_foreign_asset(
<$sender_para as Chain>::RuntimeOrigin::signed(asset_owner.clone()),
$asset_id.clone().into(),
sender.clone(),
$amount * 2,
);

// Fund the parachain origin's SA on Asset Hub with the native tokens.
$asset_hub::fund_accounts(vec![(sov_of_sender_on_ah.clone(), $amount * 2)]);

let beneficiary_id = [<$receiver_para Receiver>]::get();

let test_args = TestContext {
sender: sender.clone(),
receiver: beneficiary_id.clone(),
args: TestArgs::new_para(
destination,
beneficiary_id.clone(),
$amount,
($asset_id, $amount).into(),
None,
0,
),
};
let mut test = ParaToParaThroughAHTest::new(test_args);

// We get these from the closure.
let mut local_execution_fees = 0;
let mut local_delivery_fees = 0;
let mut remote_message = VersionedXcm::from(Xcm::<()>(Vec::new()));
<$sender_para as TestExt>::execute_with(|| {
type Runtime = <$sender_para as Chain>::Runtime;
type OriginCaller = <$sender_para as Chain>::OriginCaller;

let call = get_call(
(Parent, 100_000_000_000u128),
(Parent, 100_000_000_000u128),
(Parent, 100_000_000_000u128),
);
let origin = OriginCaller::system(RawOrigin::Signed(sender.clone()));
let result = Runtime::dry_run_call(origin, call).unwrap();
let local_xcm = result.local_xcm.unwrap().clone();
let local_xcm_weight = Runtime::query_xcm_weight(local_xcm).unwrap();
local_execution_fees = Runtime::query_weight_to_asset_fee(
local_xcm_weight,
VersionedAssetId::V5(Location::parent().into()),
)
.unwrap();
// We filter the result to get only the messages we are interested in.
let (destination_to_query, messages_to_query) = &result
.forwarded_xcms
.iter()
.find(|(destination, _)| {
*destination == VersionedLocation::V5(Location::new(1, [Parachain(1000)]))
})
.unwrap();
assert_eq!(messages_to_query.len(), 1);
remote_message = messages_to_query[0].clone();
let delivery_fees =
Runtime::query_delivery_fees(destination_to_query.clone(), remote_message.clone())
.unwrap();
local_delivery_fees = $crate::xcm_helpers::get_amount_from_versioned_assets(delivery_fees);
});

// These are set in the AssetHub closure.
let mut intermediate_execution_fees = 0;
let mut intermediate_delivery_fees = 0;
let mut intermediate_remote_message = VersionedXcm::V5(Xcm::<()>(Vec::new()));
<$asset_hub as TestExt>::execute_with(|| {
type Runtime = <$asset_hub as Chain>::Runtime;
type RuntimeCall = <$asset_hub as Chain>::RuntimeCall;

// First we get the execution fees.
let weight = Runtime::query_xcm_weight(remote_message.clone()).unwrap();
intermediate_execution_fees = Runtime::query_weight_to_asset_fee(
weight,
VersionedAssetId::V5(Location::new(1, []).into()),
)
.unwrap();

// We have to do this to turn `VersionedXcm<()>` into `VersionedXcm<RuntimeCall>`.
let xcm_program =
VersionedXcm::V5(Xcm::<RuntimeCall>::from(remote_message.clone().try_into().unwrap()));

// Now we get the delivery fees to the final destination.
let result =
Runtime::dry_run_xcm(sender_as_seen_by_ah.clone().into(), xcm_program).unwrap();
let (destination_to_query, messages_to_query) = &result
.forwarded_xcms
.iter()
.find(|(destination, _)| {
*destination == VersionedLocation::V5(Location::new(1, [Parachain(2001)]))
})
.unwrap();
// There's actually two messages here.
// One created when the message we sent from `$sender_para` arrived and was executed.
// The second one when we dry-run the xcm.
// We could've gotten the message from the queue without having to dry-run, but
// offchain applications would have to dry-run, so we do it here as well.
intermediate_remote_message = messages_to_query[0].clone();
let delivery_fees = Runtime::query_delivery_fees(
destination_to_query.clone(),
intermediate_remote_message.clone(),
)
.unwrap();
intermediate_delivery_fees = $crate::xcm_helpers::get_amount_from_versioned_assets(delivery_fees);
});

// Get the final execution fees in the destination.
let mut final_execution_fees = 0;
<$receiver_para as TestExt>::execute_with(|| {
type Runtime = <$sender_para as Chain>::Runtime;

let weight = Runtime::query_xcm_weight(intermediate_remote_message.clone()).unwrap();
final_execution_fees =
Runtime::query_weight_to_asset_fee(weight, VersionedAssetId::V5(Parent.into()))
.unwrap();
});

// Dry-running is done.
$sender_para::reset_ext();
$asset_hub::reset_ext();
$receiver_para::reset_ext();

// Fund accounts again.
$sender_para::mint_foreign_asset(
<$sender_para as Chain>::RuntimeOrigin::signed(asset_owner),
$asset_id.clone().into(),
sender.clone(),
$amount * 2,
);
$asset_hub::fund_accounts(vec![(sov_of_sender_on_ah, $amount * 2)]);

// Actually run the extrinsic.
let sender_assets_before = $sender_para::execute_with(|| {
type ForeignAssets = <$sender_para as [<$sender_para Pallet>]>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance($asset_id.clone().into(), &sender)
});
let receiver_assets_before = $receiver_para::execute_with(|| {
type ForeignAssets = <$receiver_para as [<$receiver_para Pallet>]>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance($asset_id.clone().into(), &beneficiary_id)
});

test.set_assertion::<$sender_para>(sender_assertions);
test.set_assertion::<$asset_hub>(hop_assertions);
test.set_assertion::<$receiver_para>(receiver_assertions);
let call = get_call(
(Parent, local_execution_fees + local_delivery_fees),
(Parent, intermediate_execution_fees + intermediate_delivery_fees),
(Parent, final_execution_fees),
);
test.set_call(call);
test.assert();

let sender_assets_after = $sender_para::execute_with(|| {
type ForeignAssets = <$sender_para as [<$sender_para Pallet>]>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance($asset_id.clone().into(), &sender)
});
let receiver_assets_after = $receiver_para::execute_with(|| {
type ForeignAssets = <$receiver_para as [<$receiver_para Pallet>]>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance($asset_id.into(), &beneficiary_id)
});

// We know the exact fees on every hop.
assert_eq!(sender_assets_after, sender_assets_before - $amount);
assert_eq!(
receiver_assets_after,
receiver_assets_before + $amount -
local_execution_fees -
local_delivery_fees -
intermediate_execution_fees -
intermediate_delivery_fees -
final_execution_fees
);
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
//! Tests for XCM fee estimation in the runtime.

use crate::imports::*;
use frame_support::{
dispatch::RawOrigin,
sp_runtime::{traits::Dispatchable, DispatchResult},
};
use emulated_integration_tests_common::test_can_estimate_and_pay_exact_fees;
use frame_support::dispatch::RawOrigin;
use xcm_runtime_apis::{
dry_run::runtime_decl_for_dry_run_api::DryRunApiV1,
fees::runtime_decl_for_xcm_payment_api::XcmPaymentApiV1,
Expand Down Expand Up @@ -76,16 +74,6 @@ fn receiver_assertions(test: ParaToParaThroughAHTest) {
);
}

fn transfer_assets_para_to_para_through_ah_dispatchable(
test: ParaToParaThroughAHTest,
) -> DispatchResult {
let call = transfer_assets_para_to_para_through_ah_call(test.clone());
match call.dispatch(test.signed_origin) {
Ok(_) => Ok(()),
Err(error_with_post_info) => Err(error_with_post_info.error),
}
}

fn transfer_assets_para_to_para_through_ah_call(
test: ParaToParaThroughAHTest,
) -> <PenpalA as Chain>::RuntimeCall {
Expand Down Expand Up @@ -257,7 +245,8 @@ fn multi_hop_works() {
test.set_assertion::<PenpalA>(sender_assertions);
test.set_assertion::<AssetHubRococo>(hop_assertions);
test.set_assertion::<PenpalB>(receiver_assertions);
test.set_dispatchable::<PenpalA>(transfer_assets_para_to_para_through_ah_dispatchable);
let call = transfer_assets_para_to_para_through_ah_call(test.clone());
test.set_call(call);
test.assert();

let sender_assets_after = PenpalA::execute_with(|| {
Expand All @@ -284,3 +273,14 @@ fn multi_hop_works() {
final_execution_fees
);
}

#[test]
fn multi_hop_pay_fees_works() {
test_can_estimate_and_pay_exact_fees!(
PenpalA,
AssetHubRococo,
PenpalB,
(Parent, 1_000_000_000_000u128),
Penpal
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ mod imports {
genesis::{AssetHubWestendAssetOwner, ED as ASSET_HUB_WESTEND_ED},
AssetHubWestendParaPallet as AssetHubWestendPallet,
},
bridge_hub_westend_emulated_chain::bridge_hub_westend_runtime::xcm_config::{
self as bhw_xcm_config, XcmConfig as BridgeHubWestendXcmConfig,
},
collectives_westend_emulated_chain::CollectivesWestendParaPallet as CollectivesWestendPallet,
penpal_emulated_chain::{
penpal_runtime::xcm_config::{
Expand Down Expand Up @@ -98,6 +101,8 @@ mod imports {
pub type ParaToParaThroughRelayTest = Test<PenpalA, PenpalB, Westend>;
pub type ParaToParaThroughAHTest = Test<PenpalA, PenpalB, AssetHubWestend>;
pub type RelayToParaThroughAHTest = Test<Westend, PenpalA, AssetHubWestend>;
pub type BridgeHubToAssetHubTest = Test<BridgeHubWestend, AssetHubWestend>;
pub type AssetHubToBridgeHubTest = Test<AssetHubWestend, BridgeHubWestend>;
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod fellowship_treasury;
mod hybrid_transfers;
mod reserve_transfer;
mod send;
mod set_asset_claimer;
mod set_xcm_versions;
mod swap;
mod teleport;
Expand Down
Loading
Loading