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
31 VersionedXcm::from(Xcm(vec![
32 WithdrawAsset(fees.clone().into()),
33 BuyExecution { fees, weight_limit },
34 Transact { origin_kind, call, fallback_max_weight: None },
35 RefundSurplus,
36 DepositAsset {
37 assets: All.into(),
38 beneficiary: Location {
39 parents: 0,
40 interior: [AccountId32 { network: None, id: beneficiary.into() }].into(),
41 },
42 },
43 ]))
44}
45
46pub fn xcm_transact_unpaid_execution(
48 call: DoubleEncoded<()>,
49 origin_kind: OriginKind,
50) -> VersionedXcm<()> {
51 let weight_limit = WeightLimit::Unlimited;
52 let check_origin = None;
53
54 VersionedXcm::from(Xcm(vec![
55 UnpaidExecution { weight_limit, check_origin },
56 Transact { origin_kind, call, fallback_max_weight: None },
57 ]))
58}
59
60pub fn non_fee_asset(assets: &Assets, fee_idx: usize) -> Option<(Location, u128)> {
62 let asset = assets.inner().into_iter().enumerate().find(|a| a.0 != fee_idx)?.1.clone();
63 let asset_amount = match asset.fun {
64 Fungible(amount) => amount,
65 _ => return None,
66 };
67 Some((asset.id.0, asset_amount))
68}
69
70pub fn get_amount_from_versioned_assets(assets: VersionedAssets) -> u128 {
71 let latest_assets: Assets = assets.try_into().unwrap();
72 let Fungible(amount) = latest_assets.inner()[0].fun else {
73 unreachable!("asset is non-fungible");
74 };
75 amount
76}