Skip to content

Commit

Permalink
emulated-test: Send WNDs: PenpalRococo -> AssetHubRococo -> AssetHubW…
Browse files Browse the repository at this point in the history
…estend

doesn't work because:

RPP -> withdrawRes -> AHR -> withdrawRes -> AHW (needs to pay fees with transferred assets)

Could make it work by adding ROCs to the transfer to pay for fees.
  • Loading branch information
acatangiu committed Jun 24, 2024
1 parent 5e62782 commit 31a1153
Showing 1 changed file with 118 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,121 @@ fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend()
assert!(rocs_in_reserve_on_ahr_after > rocs_in_reserve_on_ahr_before);
assert!(rocs_in_reserve_on_ahr_after <= rocs_in_reserve_on_ahr_before + amount);
}

#[test]
fn send_wnds_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend() {
let wnd_at_rococo_parachains =
v3::Location::new(2, [v3::Junction::GlobalConsensus(v3::NetworkId::Westend)]);
let wnd_at_rococo_parachains_latest: Location = wnd_at_rococo_parachains.try_into().unwrap();
let owner: AccountId = AssetHubRococo::account_id_of(ALICE);
println!("🤡 1");
AssetHubRococo::force_create_foreign_asset(
wnd_at_rococo_parachains,
owner.clone(),
true,
ASSET_MIN_BALANCE,
vec![],
);
PenpalA::force_create_foreign_asset(
wnd_at_rococo_parachains_latest.clone(),
owner.clone(),
true,
ASSET_MIN_BALANCE,
vec![],
);
let amount = ASSET_HUB_ROCOCO_ED * 10_000_000;
println!("🤡 2");

// fund the AHR's SA on AHW with the WND tokens held in reserve
let sov_ahr_on_ahw = AssetHubWestend::sovereign_account_of_parachain_on_other_global_consensus(
NetworkId::Rococo,
AssetHubRococo::para_id(),
);
AssetHubWestend::fund_accounts(vec![(sov_ahr_on_ahw.clone(), amount * 2)]);

let sov_ahw_on_ahr = AssetHubRococo::sovereign_account_of_parachain_on_other_global_consensus(
NetworkId::Westend,
AssetHubWestend::para_id(),
);
println!("🤡 3");

let penpal_location = AssetHubRococo::sibling_location_of(PenpalA::para_id());
let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of(penpal_location);
// fund Penpal's sovereign account on AssetHub
AssetHubRococo::mint_foreign_asset(
<AssetHubRococo as Chain>::RuntimeOrigin::signed(owner.clone()),
wnd_at_rococo_parachains,
sov_penpal_on_ahr,
amount * 2,
);
println!("🤡 4");
// fund Penpal's sender account
PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(PenpalAssetOwner::get()),
wnd_at_rococo_parachains_latest.clone(),
PenpalASender::get(),
amount * 2,
);
println!("🤡 5");

let wnds_in_reserve_on_ahr_before = AssetHubRococo::execute_with(|| {
type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(wnd_at_rococo_parachains, &sov_ahw_on_ahr)
});
let sender_wnds_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(
wnd_at_rococo_parachains_latest.clone().into(),
&PenpalASender::get(),
)
});
println!("🤡 6");

let receiver_wnds_before =
<AssetHubWestend as Chain>::account_data_of(AssetHubWestendReceiver::get()).free;
send_asset_from_penpal_rococo_through_local_asset_hub_to_westend_asset_hub(
wnd_at_rococo_parachains_latest.clone(),
amount,
);

AssetHubWestend::execute_with(|| {
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
println!("🤡 AHW events: {:?}", <AssetHubWestend as Chain>::events());
assert_expected_events!(
AssetHubWestend,
vec![
// issue ROCs on AHW
// RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => {
// asset_id: *asset_id == roc_at_rococo_parachains,
// owner: *owner == AssetHubWestendReceiver::get(),
// },
// message processed successfully
RuntimeEvent::MessageQueue(
pallet_message_queue::Event::Processed { success: true, .. }
) => {},
]
);
});

let sender_wnds_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(
wnd_at_rococo_parachains_latest.into(),
&PenpalASender::get(),
)
});
let receiver_wnds_after =
<AssetHubWestend as Chain>::account_data_of(AssetHubWestendReceiver::get()).free;
let wnds_in_reserve_on_ahr_after = AssetHubRococo::execute_with(|| {
type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(wnd_at_rococo_parachains, &sov_ahw_on_ahr)
});

// Sender's balance is reduced
assert!(sender_wnds_after < sender_wnds_before);
// Receiver's balance is increased
assert!(receiver_wnds_after > receiver_wnds_before);
// Reserve balance is increased by sent amount (less fess)
assert!(wnds_in_reserve_on_ahr_after > wnds_in_reserve_on_ahr_before);
assert!(wnds_in_reserve_on_ahr_after <= wnds_in_reserve_on_ahr_before + amount);
}

0 comments on commit 31a1153

Please sign in to comment.