emulated_integration_tests_common/
xcm_helpers.rs1use parachains_common::AccountId;
18
19use xcm::{prelude::*, DoubleEncoded};
21
22pub fn xcm_transact_paid_execution(
24 call: DoubleEncoded<()>,
25 origin_kind: OriginKind,
26 fees: Asset,
27 beneficiary: AccountId,
28) -> VersionedXcm<()> {
29 let weight_limit = WeightLimit::Unlimited;
30 let require_weight_at_most = Weight::from_parts(1000000000, 200000);
31
32 VersionedXcm::from(Xcm(vec![
33 WithdrawAsset(fees.clone().into()),
34 BuyExecution { fees, weight_limit },
35 Transact { require_weight_at_most, origin_kind, call },
36 RefundSurplus,
37 DepositAsset {
38 assets: All.into(),
39 beneficiary: Location {
40 parents: 0,
41 interior: [AccountId32 { network: None, id: beneficiary.into() }].into(),
42 },
43 },
44 ]))
45}
46
47pub fn xcm_transact_unpaid_execution(
49 call: DoubleEncoded<()>,
50 origin_kind: OriginKind,
51) -> VersionedXcm<()> {
52 let weight_limit = WeightLimit::Unlimited;
53 let require_weight_at_most = Weight::from_parts(1000000000, 200000);
54 let check_origin = None;
55
56 VersionedXcm::from(Xcm(vec![
57 UnpaidExecution { weight_limit, check_origin },
58 Transact { require_weight_at_most, origin_kind, call },
59 ]))
60}
61
62pub fn non_fee_asset(assets: &Assets, fee_idx: usize) -> Option<(Location, u128)> {
64 let asset = assets.inner().into_iter().enumerate().find(|a| a.0 != fee_idx)?.1.clone();
65 let asset_amount = match asset.fun {
66 Fungible(amount) => amount,
67 _ => return None,
68 };
69 Some((asset.id.0, asset_amount))
70}
71
72pub fn get_amount_from_versioned_assets(assets: VersionedAssets) -> u128 {
73 let latest_assets: Assets = assets.try_into().unwrap();
74 let Fungible(amount) = latest_assets.inner()[0].fun else {
75 unreachable!("asset is non-fungible");
76 };
77 amount
78}