Remove xcm::v3 from assets-common nits (#4037)

This PR mainly removes `xcm::v3` stuff from `assets-common` to make it
more generic and facilitate the transition to newer XCM versions. Some
of the implementations here used hard-coded `xcm::v3::Location`, but now
it's up to the runtime to configure according to its needs.

Additional/consequent changes:
- `penpal` runtime uses now `xcm::latest::Location` for `pallet_assets`
as `AssetId`, because we don't care about migrations here
- it pretty much simplify xcm-emulator integration tests, where we don't
need now a lots of boilerplate conversions:
      ```
      v3::Location::try_from(...).expect("conversion works")`
      ```
- xcm-emulator tests
- split macro `impl_assets_helpers_for_parachain` to the
`impl_assets_helpers_for_parachain` and
`impl_foreign_assets_helpers_for_parachain` (avoids using hard-coded
`xcm::v3::Location`)
This commit is contained in:
Branislav Kontur
2024-04-12 23:24:09 +02:00
committed by GitHub
parent b28ba4ae96
commit 5601f2865b
35 changed files with 654 additions and 549 deletions
@@ -168,9 +168,11 @@ fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() {
<Assets as Inspect<_>>::balance(roc_at_asset_hub_westend, &AssetHubWestendReceiver::get())
});
let roc_at_asset_hub_rococo_latest: Location = roc_at_asset_hub_rococo.try_into().unwrap();
let amount = ASSET_HUB_ROCOCO_ED * 1_000_000;
send_asset_from_asset_hub_rococo_to_asset_hub_westend(roc_at_asset_hub_rococo_latest, amount);
send_asset_from_asset_hub_rococo_to_asset_hub_westend(
roc_at_asset_hub_rococo.try_into().unwrap(),
amount,
);
AssetHubWestend::execute_with(|| {
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
assert_expected_events!(
@@ -238,10 +240,9 @@ fn send_wnds_from_asset_hub_rococo_to_asset_hub_westend() {
let receiver_wnds_before =
<AssetHubWestend as Chain>::account_data_of(AssetHubWestendReceiver::get()).free;
let wnd_at_asset_hub_rococo_latest: Location = wnd_at_asset_hub_rococo.try_into().unwrap();
let amount_to_send = ASSET_HUB_WESTEND_ED * 1_000;
send_asset_from_asset_hub_rococo_to_asset_hub_westend(
wnd_at_asset_hub_rococo_latest.clone(),
Location::try_from(wnd_at_asset_hub_rococo).unwrap(),
amount_to_send,
);
AssetHubWestend::execute_with(|| {
@@ -287,13 +288,11 @@ fn send_wnds_from_asset_hub_rococo_to_asset_hub_westend() {
#[test]
fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend() {
let roc_at_rococo_parachains: v3::Location = v3::Parent.into();
let roc_at_asset_hub_westend =
v3::Location::new(2, [v3::Junction::GlobalConsensus(v3::NetworkId::Rococo)]);
let roc_at_rococo_parachains_latest: Location = roc_at_rococo_parachains.try_into().unwrap();
let roc_at_rococo_parachains: Location = Parent.into();
let roc_at_asset_hub_westend = Location::new(2, [Junction::GlobalConsensus(NetworkId::Rococo)]);
let owner: AccountId = AssetHubWestend::account_id_of(ALICE);
AssetHubWestend::force_create_foreign_asset(
roc_at_asset_hub_westend,
roc_at_asset_hub_westend.clone().try_into().unwrap(),
owner,
true,
ASSET_MIN_BALANCE,
@@ -312,7 +311,7 @@ fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend()
// fund Penpal's sender account
PenpalA::mint_foreign_asset(
<PenpalA as Chain>::RuntimeOrigin::signed(PenpalAssetOwner::get()),
roc_at_rococo_parachains,
roc_at_rococo_parachains.clone(),
PenpalASender::get(),
amount * 2,
);
@@ -322,16 +321,19 @@ fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend()
let sender_rocs_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(
roc_at_rococo_parachains.into(),
roc_at_rococo_parachains.clone(),
&PenpalASender::get(),
)
});
let receiver_rocs_before = AssetHubWestend::execute_with(|| {
type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(roc_at_asset_hub_westend, &AssetHubWestendReceiver::get())
<Assets as Inspect<_>>::balance(
roc_at_asset_hub_westend.clone().try_into().unwrap(),
&AssetHubWestendReceiver::get(),
)
});
send_asset_from_penpal_rococo_through_local_asset_hub_to_westend_asset_hub(
roc_at_rococo_parachains_latest,
roc_at_rococo_parachains.clone(),
amount,
);
@@ -342,7 +344,7 @@ fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend()
vec![
// issue ROCs on AHW
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => {
asset_id: *asset_id == roc_at_rococo_parachains,
asset_id: *asset_id == roc_at_rococo_parachains.clone().try_into().unwrap(),
owner: *owner == AssetHubWestendReceiver::get(),
},
// message processed successfully
@@ -355,14 +357,14 @@ fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend()
let sender_rocs_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(
roc_at_rococo_parachains.into(),
&PenpalASender::get(),
)
<ForeignAssets as Inspect<_>>::balance(roc_at_rococo_parachains, &PenpalASender::get())
});
let receiver_rocs_after = AssetHubWestend::execute_with(|| {
type Assets = <AssetHubWestend as AssetHubWestendPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(roc_at_asset_hub_westend, &AssetHubWestendReceiver::get())
<Assets as Inspect<_>>::balance(
roc_at_asset_hub_westend.try_into().unwrap(),
&AssetHubWestendReceiver::get(),
)
});
let rocs_in_reserve_on_ahr_after =
<AssetHubRococo as Chain>::account_data_of(sov_ahw_on_ahr.clone()).free;
@@ -306,8 +306,6 @@ fn send_token_from_ethereum_to_penpal() {
// The Weth asset location, identified by the contract address on Ethereum
let weth_asset_location: Location =
(Parent, Parent, EthereumNetwork::get(), AccountKey20 { network: None, key: WETH }).into();
// Converts the Weth asset location into an asset ID
let weth_asset_id: v3::Location = weth_asset_location.try_into().unwrap();
let origin_location = (Parent, Parent, EthereumNetwork::get()).into();
@@ -321,12 +319,12 @@ fn send_token_from_ethereum_to_penpal() {
PenpalA::execute_with(|| {
assert_ok!(<PenpalA as PenpalAPallet>::ForeignAssets::create(
<PenpalA as Chain>::RuntimeOrigin::signed(PenpalASender::get()),
weth_asset_id,
weth_asset_location.clone(),
asset_hub_sovereign.into(),
1000,
));
assert!(<PenpalA as PenpalAPallet>::ForeignAssets::asset_exists(weth_asset_id));
assert!(<PenpalA as PenpalAPallet>::ForeignAssets::asset_exists(weth_asset_location));
});
BridgeHubRococo::execute_with(|| {
@@ -236,10 +236,9 @@ fn send_rocs_from_asset_hub_westend_to_asset_hub_rococo() {
let receiver_rocs_before =
<AssetHubRococo as Chain>::account_data_of(AssetHubRococoReceiver::get()).free;
let roc_at_asset_hub_westend_latest: Location = roc_at_asset_hub_westend.try_into().unwrap();
let amount_to_send = ASSET_HUB_ROCOCO_ED * 1_000;
send_asset_from_asset_hub_westend_to_asset_hub_rococo(
roc_at_asset_hub_westend_latest.clone(),
roc_at_asset_hub_westend.try_into().unwrap(),
amount_to_send,
);
AssetHubRococo::execute_with(|| {
@@ -285,13 +284,11 @@ fn send_rocs_from_asset_hub_westend_to_asset_hub_rococo() {
#[test]
fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo() {
let wnd_at_westend_parachains: v3::Location = v3::Parent.into();
let wnd_at_asset_hub_rococo =
v3::Location::new(2, [v3::Junction::GlobalConsensus(v3::NetworkId::Westend)]);
let wnd_at_westend_parachains_latest: Location = wnd_at_westend_parachains.try_into().unwrap();
let wnd_at_westend_parachains: Location = Parent.into();
let wnd_at_asset_hub_rococo = Location::new(2, [Junction::GlobalConsensus(NetworkId::Westend)]);
let owner: AccountId = AssetHubRococo::account_id_of(ALICE);
AssetHubRococo::force_create_foreign_asset(
wnd_at_asset_hub_rococo,
wnd_at_asset_hub_rococo.clone().try_into().unwrap(),
owner,
true,
ASSET_MIN_BALANCE,
@@ -310,7 +307,7 @@ fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo()
// fund Penpal's sender account
PenpalB::mint_foreign_asset(
<PenpalB as Chain>::RuntimeOrigin::signed(PenpalAssetOwner::get()),
wnd_at_westend_parachains,
wnd_at_westend_parachains.clone(),
PenpalBSender::get(),
amount * 2,
);
@@ -320,16 +317,19 @@ fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo()
let sender_wnds_before = PenpalB::execute_with(|| {
type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(
wnd_at_westend_parachains.into(),
wnd_at_westend_parachains.clone(),
&PenpalBSender::get(),
)
});
let receiver_wnds_before = AssetHubRococo::execute_with(|| {
type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(wnd_at_asset_hub_rococo, &AssetHubRococoReceiver::get())
<Assets as Inspect<_>>::balance(
wnd_at_asset_hub_rococo.clone().try_into().unwrap(),
&AssetHubRococoReceiver::get(),
)
});
send_asset_from_penpal_westend_through_local_asset_hub_to_rococo_asset_hub(
wnd_at_westend_parachains_latest,
wnd_at_westend_parachains.clone(),
amount,
);
@@ -340,7 +340,7 @@ fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo()
vec![
// issue WNDs on AHR
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => {
asset_id: *asset_id == wnd_at_westend_parachains,
asset_id: *asset_id == wnd_at_westend_parachains.clone().try_into().unwrap(),
owner: *owner == AssetHubRococoReceiver::get(),
},
// message processed successfully
@@ -353,14 +353,14 @@ fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo()
let sender_wnds_after = PenpalB::execute_with(|| {
type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(
wnd_at_westend_parachains.into(),
&PenpalBSender::get(),
)
<ForeignAssets as Inspect<_>>::balance(wnd_at_westend_parachains, &PenpalBSender::get())
});
let receiver_wnds_after = AssetHubRococo::execute_with(|| {
type Assets = <AssetHubRococo as AssetHubRococoPallet>::ForeignAssets;
<Assets as Inspect<_>>::balance(wnd_at_asset_hub_rococo, &AssetHubRococoReceiver::get())
<Assets as Inspect<_>>::balance(
wnd_at_asset_hub_rococo.try_into().unwrap(),
&AssetHubRococoReceiver::get(),
)
});
let wnds_in_reserve_on_ahw_after =
<AssetHubWestend as Chain>::account_data_of(sov_ahr_on_ahw.clone()).free;