Skip to content

Commit

Permalink
have tests use PayFees
Browse files Browse the repository at this point in the history
  • Loading branch information
acatangiu committed Oct 2, 2024
1 parent adb4ac2 commit 4e568d1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -827,20 +827,22 @@ fn transfer_native_asset_from_relay_to_para_through_asset_hub() {
/// Transfers of native asset plus teleportable foreign asset from Parachain to AssetHub and back
/// with fees paid using native asset.
#[test]
fn poc_new_instructions_test() {
fn bidirectional_transfer_multiple_assets_between_penpal_and_asset_hub() {
fn execute_xcm_penpal_to_asset_hub(t: ParaToSystemParaTest) -> DispatchResult {
// let transport_fees: Asset = (Parent, 40_000_000_000u128).into();
let all_assets = t.args.assets.clone().into_inner();
let mut assets = all_assets.clone();
let fees = assets.remove(t.args.fee_asset_item as usize);
let mut fees = assets.remove(t.args.fee_asset_item as usize);
// TODO: dry-run to get exact fees, for now just use half the fees locally, half on dest
if let Fungible(fees_amount) = fees.fun {
fees.fun = Fungible(fees_amount / 2);
}
// xcm to be executed at dest
let xcm_on_dest =
Xcm(vec![DepositAsset { assets: Wild(All), beneficiary: t.args.beneficiary }]);
let xcm = Xcm::<()>(vec![
// WithdrawAsset(transport_fees.into()),
WithdrawAsset(all_assets.into()),
// TODO: replace this with `PayFees` when available
SetFeesMode { jit_withdraw: true },
PayFees { asset: fees.clone() },
InitiateTransfer {
destination: t.args.dest,
remote_fees: Some(AssetTransferFilter::ReserveWithdraw(fees.into())),
Expand All @@ -859,14 +861,17 @@ fn poc_new_instructions_test() {
fn execute_xcm_asset_hub_to_penpal(t: SystemParaToParaTest) -> DispatchResult {
let all_assets = t.args.assets.clone().into_inner();
let mut assets = all_assets.clone();
let fees = assets.remove(t.args.fee_asset_item as usize);
let mut fees = assets.remove(t.args.fee_asset_item as usize);
// TODO: dry-run to get exact fees, for now just use half the fees locally, half on dest
if let Fungible(fees_amount) = fees.fun {
fees.fun = Fungible(fees_amount / 2);
}
// xcm to be executed at dest
let xcm_on_dest =
Xcm(vec![DepositAsset { assets: Wild(All), beneficiary: t.args.beneficiary }]);
let xcm = Xcm::<()>(vec![
WithdrawAsset(all_assets.into()),
// TODO: replace this with `PayFees` when available
SetFeesMode { jit_withdraw: true },
PayFees { asset: fees.clone() },
InitiateTransfer {
destination: t.args.dest,
remote_fees: Some(AssetTransferFilter::ReserveDeposit(fees.into())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,13 @@ fn do_send_pens_and_wnds_from_penpal_westend_via_ahw_to_asset_hub_rococo(
let pens: Asset = (pens_id, pens_amount).into();
let assets: Assets = vec![wnds.clone(), pens.clone()].into();

// TODO: dry-run to get exact fees, for now just some static value 100_000_000_000
let penpal_fees_amount = 100_000_000_000;
// use 100_000_000_000 WNDs in fees on AHW
// (exec fees: 3_593_000_000, transpo fees: 69_021_561_290 = 72_614_561_290)
// TODO: make this exact once we have bridge dry-running
let ahw_fee_amount = 100_000_000_000;

// XCM to be executed at dest (Rococo Asset Hub)
let xcm_on_dest =
Xcm(vec![DepositAsset { assets: Wild(All), beneficiary: beneficiary.clone() }]);
Expand All @@ -601,10 +608,7 @@ fn do_send_pens_and_wnds_from_penpal_westend_via_ahw_to_asset_hub_rococo(
let reanchored_dest = destination.clone().reanchored(&local_asset_hub, &context).unwrap();
let reanchored_pens = pens.clone().reanchored(&local_asset_hub, &context).unwrap();
let mut onward_wnds = wnds.clone().reanchored(&local_asset_hub, &context).unwrap();
// reserve 100_000_000_000 WNDs in fees on AHW
// (exec fees: 3_593_000_000, transpo fees: 69_021_561_290 = 72_614_561_290)
// TODO: make this exact once we have PayFees + bridge dry-running
onward_wnds.fun = Fungible(wnds_amount - 100_000_000_000);
onward_wnds.fun = Fungible(wnds_amount - ahw_fee_amount - penpal_fees_amount);
let xcm_on_ahw = Xcm(vec![
// both WNDs and PENs are local-reserve transferred to Rococo Asset Hub
InitiateTransfer {
Expand All @@ -615,19 +619,25 @@ fn do_send_pens_and_wnds_from_penpal_westend_via_ahw_to_asset_hub_rococo(
},
]);

let penpal_fees = (wnds.id.clone(), Fungible(penpal_fees_amount));
let ahw_fees: Asset = (wnds.id.clone(), Fungible(ahw_fee_amount)).into();
let ahw_non_fees_wnds: Asset =
(wnds.id.clone(), Fungible(wnds_amount - ahw_fee_amount - penpal_fees_amount)).into();
// XCM to be executed locally
let xcm = Xcm::<()>(vec![
// Withdraw both WNDs and PENs from origin account
WithdrawAsset(assets.into()),
// TODO: replace this with `PayFees` when available
SetFeesMode { jit_withdraw: true },
PayFees { asset: penpal_fees.into() },
// Execute the transfers while paying remote fees with WNDs
InitiateTransfer {
destination: local_asset_hub,
// WNDs are reserve-withdrawn at AHW
remote_fees: Some(AssetTransferFilter::ReserveWithdraw(wnds.into())),
remote_fees: Some(AssetTransferFilter::ReserveWithdraw(ahw_fees.into())),
// PENs are teleported to AHW
assets: vec![AssetTransferFilter::Teleport(pens.into())],
assets: vec![
AssetTransferFilter::Teleport(pens.into()),
AssetTransferFilter::ReserveWithdraw(ahw_non_fees_wnds.into()),
],
remote_xcm: xcm_on_ahw,
},
]);
Expand All @@ -640,6 +650,7 @@ fn do_send_pens_and_wnds_from_penpal_westend_via_ahw_to_asset_hub_rococo(
Weight::MAX,
)
}));
println!("πŸ’˜ on ahw -------------------- ");
AssetHubWestend::execute_with(|| {
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
assert_expected_events!(
Expand All @@ -662,8 +673,11 @@ fn do_send_pens_and_wnds_from_penpal_westend_via_ahw_to_asset_hub_rococo(
]
);
});
println!("πŸ’˜ on bhw -------------------- ");
assert_bridge_hub_westend_message_accepted(true);
println!("πŸ’˜ on bhr -------------------- ");
assert_bridge_hub_rococo_message_received();
println!("πŸ’˜ on ahr -------------------- ");
}

/// Transfer "PEN"s plus "WND"s from PenpalWestend to AssetHubWestend, over bridge to
Expand Down

0 comments on commit 4e568d1

Please sign in to comment.