Skip to content

Commit

Permalink
Use Versioned*::from instead of concrete V* when using `xcm::late…
Browse files Browse the repository at this point in the history
…st` (#6092)

Relates to: #5420

This PR includes some cleanup, as every time we upgrade XCM, we will
need to rewrite all instances of `V5` to `V6`.

---------

Co-authored-by: command-bot <>
  • Loading branch information
bkontur authored Oct 17, 2024
1 parent 2cc969b commit 8b49830
Show file tree
Hide file tree
Showing 25 changed files with 139 additions and 146 deletions.
4 changes: 2 additions & 2 deletions bridges/modules/xcm-bridge-hub-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,8 @@ mod tests {
assert_eq!(
XcmBridgeHubRouter::get_messages(),
vec![(
VersionedLocation::V5((Parent, Parachain(1002)).into()),
vec![VersionedXcm::V5(
VersionedLocation::from(Location::new(1, Parachain(1002))),
vec![VersionedXcm::from(
Xcm::builder()
.withdraw_asset((Parent, 1_002_000))
.buy_execution((Parent, 1_002_000), Unlimited)
Expand Down
4 changes: 2 additions & 2 deletions bridges/modules/xcm-bridge-hub-router/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ impl InspectMessageQueues for TestToBridgeHubSender {
.iter()
.map(|(location, message)| {
(
VersionedLocation::V5(location.clone()),
vec![VersionedXcm::V5(message.clone())],
VersionedLocation::from(location.clone()),
vec![VersionedXcm::from(message.clone())],
)
})
.collect()
Expand Down
2 changes: 1 addition & 1 deletion cumulus/pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,7 @@ impl<T: Config> InspectMessageQueues for Pallet<T> {
.map(|encoded_message| VersionedXcm::<()>::decode(&mut &encoded_message[..]).unwrap())
.collect();

vec![(VersionedLocation::V5(Parent.into()), messages)]
vec![(VersionedLocation::from(Location::parent()), messages)]
}
}

Expand Down
2 changes: 1 addition & 1 deletion cumulus/pallets/xcmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ impl<T: Config> InspectMessageQueues for Pallet<T> {
}

(
VersionedLocation::V5((Parent, Parachain(para_id.into())).into()),
VersionedLocation::from(Location::new(1, Parachain(para_id.into()))),
decoded_messages,
)
})
Expand Down
22 changes: 11 additions & 11 deletions cumulus/pallets/xcmp-queue/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ fn send_xcm_nested_works() {
XcmpQueue::take_outbound_messages(usize::MAX),
vec![(
HRMP_PARA_ID.into(),
(XcmpMessageFormat::ConcatenatedVersionedXcm, VersionedXcm::V5(good.clone()))
(XcmpMessageFormat::ConcatenatedVersionedXcm, VersionedXcm::from(good.clone()))
.encode(),
)]
);
Expand Down Expand Up @@ -512,7 +512,7 @@ fn hrmp_signals_are_prioritized() {
// Without a signal we get the messages in order:
let mut expected_msg = XcmpMessageFormat::ConcatenatedVersionedXcm.encode();
for _ in 0..31 {
expected_msg.extend(VersionedXcm::V5(message.clone()).encode());
expected_msg.extend(VersionedXcm::from(message.clone()).encode());
}

hypothetically!({
Expand Down Expand Up @@ -598,7 +598,7 @@ fn take_first_concatenated_xcm_good_recursion_depth_works() {
for _ in 0..MAX_XCM_DECODE_DEPTH - 1 {
good = Xcm(vec![SetAppendix(good)]);
}
let good = VersionedXcm::V5(good);
let good = VersionedXcm::from(good);

let page = good.encode();
assert_ok!(XcmpQueue::take_first_concatenated_xcm(&mut &page[..], &mut WeightMeter::new()));
Expand All @@ -611,7 +611,7 @@ fn take_first_concatenated_xcm_good_bad_depth_errors() {
for _ in 0..MAX_XCM_DECODE_DEPTH {
bad = Xcm(vec![SetAppendix(bad)]);
}
let bad = VersionedXcm::V5(bad);
let bad = VersionedXcm::from(bad);

let page = bad.encode();
assert_err!(
Expand Down Expand Up @@ -873,18 +873,18 @@ fn get_messages_works() {
queued_messages,
vec![
(
VersionedLocation::V5(other_destination),
VersionedLocation::from(other_destination),
vec![
VersionedXcm::V5(Xcm(vec![ClearOrigin])),
VersionedXcm::V5(Xcm(vec![ClearOrigin])),
VersionedXcm::from(Xcm(vec![ClearOrigin])),
VersionedXcm::from(Xcm(vec![ClearOrigin])),
],
),
(
VersionedLocation::V5(destination),
VersionedLocation::from(destination),
vec![
VersionedXcm::V5(Xcm(vec![ClearOrigin])),
VersionedXcm::V5(Xcm(vec![ClearOrigin])),
VersionedXcm::V5(Xcm(vec![ClearOrigin])),
VersionedXcm::from(Xcm(vec![ClearOrigin])),
VersionedXcm::from(Xcm(vec![ClearOrigin])),
VersionedXcm::from(Xcm(vec![ClearOrigin])),
],
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,15 +495,15 @@ macro_rules! test_can_estimate_and_pay_exact_fees {
let local_xcm_weight = Runtime::query_xcm_weight(local_xcm).unwrap();
local_execution_fees = Runtime::query_weight_to_asset_fee(
local_xcm_weight,
VersionedAssetId::V5(Location::parent().into()),
VersionedAssetId::from(AssetId(Location::parent())),
)
.unwrap();
// We filter the result to get only the messages we are interested in.
let (destination_to_query, messages_to_query) = &result
.forwarded_xcms
.iter()
.find(|(destination, _)| {
*destination == VersionedLocation::V5(Location::new(1, [Parachain(1000)]))
*destination == VersionedLocation::from(Location::new(1, [Parachain(1000)]))
})
.unwrap();
assert_eq!(messages_to_query.len(), 1);
Expand All @@ -517,7 +517,7 @@ macro_rules! test_can_estimate_and_pay_exact_fees {
// These are set in the AssetHub closure.
let mut intermediate_execution_fees = 0;
let mut intermediate_delivery_fees = 0;
let mut intermediate_remote_message = VersionedXcm::V5(Xcm::<()>(Vec::new()));
let mut intermediate_remote_message = VersionedXcm::from(Xcm::<()>(Vec::new()));
<$asset_hub as TestExt>::execute_with(|| {
type Runtime = <$asset_hub as Chain>::Runtime;
type RuntimeCall = <$asset_hub as Chain>::RuntimeCall;
Expand All @@ -526,13 +526,13 @@ macro_rules! test_can_estimate_and_pay_exact_fees {
let weight = Runtime::query_xcm_weight(remote_message.clone()).unwrap();
intermediate_execution_fees = Runtime::query_weight_to_asset_fee(
weight,
VersionedAssetId::V5(Location::new(1, []).into()),
VersionedAssetId::from(AssetId(Location::new(1, []))),
)
.unwrap();

// We have to do this to turn `VersionedXcm<()>` into `VersionedXcm<RuntimeCall>`.
let xcm_program =
VersionedXcm::V5(Xcm::<RuntimeCall>::from(remote_message.clone().try_into().unwrap()));
VersionedXcm::from(Xcm::<RuntimeCall>::from(remote_message.clone().try_into().unwrap()));

// Now we get the delivery fees to the final destination.
let result =
Expand All @@ -541,7 +541,7 @@ macro_rules! test_can_estimate_and_pay_exact_fees {
.forwarded_xcms
.iter()
.find(|(destination, _)| {
*destination == VersionedLocation::V5(Location::new(1, [Parachain(2001)]))
*destination == VersionedLocation::from(Location::new(1, [Parachain(2001)]))
})
.unwrap();
// There's actually two messages here.
Expand All @@ -565,7 +565,7 @@ macro_rules! test_can_estimate_and_pay_exact_fees {

let weight = Runtime::query_xcm_weight(intermediate_remote_message.clone()).unwrap();
final_execution_fees =
Runtime::query_weight_to_asset_fee(weight, VersionedAssetId::V5(Parent.into()))
Runtime::query_weight_to_asset_fee(weight, VersionedAssetId::from(AssetId(Location::parent())))
.unwrap();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ mod imports {
};

// Polkadot
pub use xcm::{
prelude::{AccountId32 as AccountId32Junction, *},
v3,
};
pub use xcm::prelude::{AccountId32 as AccountId32Junction, *};
pub use xcm_executor::traits::TransferType;

// Cumulus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ fn spend_roc_on_asset_hub() {
let teleport_call = RuntimeCall::Utility(pallet_utility::Call::<Runtime>::dispatch_as {
as_origin: bx!(RococoOriginCaller::system(RawOrigin::Signed(treasury_account))),
call: bx!(RuntimeCall::XcmPallet(pallet_xcm::Call::<Runtime>::teleport_assets {
dest: bx!(VersionedLocation::V5(asset_hub_location.clone())),
beneficiary: bx!(VersionedLocation::V5(treasury_location)),
assets: bx!(VersionedAssets::V5(
Asset { id: native_asset.clone().into(), fun: treasury_balance.into() }.into()
)),
dest: bx!(VersionedLocation::from(asset_hub_location.clone())),
beneficiary: bx!(VersionedLocation::from(treasury_location)),
assets: bx!(VersionedAssets::from(Assets::from(Asset {
id: native_asset.clone().into(),
fun: treasury_balance.into()
}))),
fee_asset_item: 0,
})),
});
Expand Down Expand Up @@ -110,12 +111,12 @@ fn spend_roc_on_asset_hub() {
let native_asset = Location::parent();

let treasury_spend_call = RuntimeCall::Treasury(pallet_treasury::Call::<Runtime>::spend {
asset_kind: bx!(VersionedLocatableAsset::V5 {
location: asset_hub_location.clone(),
asset_id: native_asset.into(),
}),
asset_kind: bx!(VersionedLocatableAsset::from((
asset_hub_location.clone(),
native_asset.into()
))),
amount: treasury_spend_balance,
beneficiary: bx!(VersionedLocation::V5(alice_location)),
beneficiary: bx!(VersionedLocation::from(alice_location)),
valid_from: None,
});

Expand Down Expand Up @@ -170,16 +171,12 @@ fn create_and_claim_treasury_spend_in_usdt() {
// treasury account on a sibling parachain.
let treasury_account =
ahr_xcm_config::LocationToAccountId::convert_location(&treasury_location).unwrap();
let asset_hub_location =
v3::Location::new(0, v3::Junction::Parachain(AssetHubRococo::para_id().into()));
let asset_hub_location = Location::new(0, Parachain(AssetHubRococo::para_id().into()));
let root = <Rococo as Chain>::RuntimeOrigin::root();
// asset kind to be spend from the treasury.
let asset_kind = VersionedLocatableAsset::V3 {
location: asset_hub_location,
asset_id: v3::AssetId::Concrete(
(v3::Junction::PalletInstance(50), v3::Junction::GeneralIndex(USDT_ID.into())).into(),
),
};
// asset kind to be spent from the treasury.
let asset_kind: VersionedLocatableAsset =
(asset_hub_location, AssetId((PalletInstance(50), GeneralIndex(USDT_ID.into())).into()))
.into();
// treasury spend beneficiary.
let alice: AccountId = Rococo::account_id_of(ALICE);
let bob: AccountId = Rococo::account_id_of(BOB);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn transfer_assets_para_to_para_through_ah_call(
dest: bx!(test.args.dest.into()),
assets: bx!(test.args.assets.clone().into()),
assets_transfer_type: bx!(TransferType::RemoteReserve(asset_hub_location.clone().into())),
remote_fees_id: bx!(VersionedAssetId::V5(AssetId(Location::new(1, [])))),
remote_fees_id: bx!(VersionedAssetId::from(AssetId(Location::new(1, [])))),
fees_transfer_type: bx!(TransferType::RemoteReserve(asset_hub_location.into())),
custom_xcm_on_dest: bx!(VersionedXcm::from(custom_xcm_on_dest)),
weight_limit: test.args.weight_limit,
Expand Down Expand Up @@ -139,7 +139,7 @@ fn multi_hop_works() {

// We get them from the PenpalA closure.
let mut delivery_fees_amount = 0;
let mut remote_message = VersionedXcm::V5(Xcm(Vec::new()));
let mut remote_message = VersionedXcm::from(Xcm(Vec::new()));
<PenpalA as TestExt>::execute_with(|| {
type Runtime = <PenpalA as Chain>::Runtime;
type OriginCaller = <PenpalA as Chain>::OriginCaller;
Expand All @@ -152,7 +152,7 @@ fn multi_hop_works() {
.forwarded_xcms
.iter()
.find(|(destination, _)| {
*destination == VersionedLocation::V5(Location::new(1, [Parachain(1000)]))
*destination == VersionedLocation::from(Location::new(1, [Parachain(1000)]))
})
.unwrap();
assert_eq!(messages_to_query.len(), 1);
Expand All @@ -166,7 +166,7 @@ fn multi_hop_works() {
// These are set in the AssetHub closure.
let mut intermediate_execution_fees = 0;
let mut intermediate_delivery_fees_amount = 0;
let mut intermediate_remote_message = VersionedXcm::V5(Xcm::<()>(Vec::new()));
let mut intermediate_remote_message = VersionedXcm::from(Xcm::<()>(Vec::new()));
<AssetHubRococo as TestExt>::execute_with(|| {
type Runtime = <AssetHubRococo as Chain>::Runtime;
type RuntimeCall = <AssetHubRococo as Chain>::RuntimeCall;
Expand All @@ -175,13 +175,14 @@ fn multi_hop_works() {
let weight = Runtime::query_xcm_weight(remote_message.clone()).unwrap();
intermediate_execution_fees = Runtime::query_weight_to_asset_fee(
weight,
VersionedAssetId::V5(Location::new(1, []).into()),
VersionedAssetId::from(AssetId(Location::new(1, []))),
)
.unwrap();

// We have to do this to turn `VersionedXcm<()>` into `VersionedXcm<RuntimeCall>`.
let xcm_program =
VersionedXcm::V5(Xcm::<RuntimeCall>::from(remote_message.clone().try_into().unwrap()));
let xcm_program = VersionedXcm::from(Xcm::<RuntimeCall>::from(
remote_message.clone().try_into().unwrap(),
));

// Now we get the delivery fees to the final destination.
let result =
Expand All @@ -190,7 +191,7 @@ fn multi_hop_works() {
.forwarded_xcms
.iter()
.find(|(destination, _)| {
*destination == VersionedLocation::V5(Location::new(1, [Parachain(2001)]))
*destination == VersionedLocation::from(Location::new(1, [Parachain(2001)]))
})
.unwrap();
// There's actually two messages here.
Expand All @@ -213,9 +214,11 @@ fn multi_hop_works() {
type Runtime = <PenpalA as Chain>::Runtime;

let weight = Runtime::query_xcm_weight(intermediate_remote_message.clone()).unwrap();
final_execution_fees =
Runtime::query_weight_to_asset_fee(weight, VersionedAssetId::V5(Parent.into()))
.unwrap();
final_execution_fees = Runtime::query_weight_to_asset_fee(
weight,
VersionedAssetId::from(AssetId(Location::parent())),
)
.unwrap();
});

// Dry-running is done.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ fn create_and_claim_treasury_spend() {
let asset_hub_location = Location::new(1, [Parachain(AssetHubWestend::para_id().into())]);
let root = <CollectivesWestend as Chain>::RuntimeOrigin::root();
// asset kind to be spent from the treasury.
let asset_kind = VersionedLocatableAsset::V5 {
location: asset_hub_location,
asset_id: AssetId((PalletInstance(50), GeneralIndex(USDT_ID.into())).into()),
};
let asset_kind: VersionedLocatableAsset =
(asset_hub_location, AssetId((PalletInstance(50), GeneralIndex(USDT_ID.into())).into()))
.into();
// treasury spend beneficiary.
let alice: AccountId = Westend::account_id_of(ALICE);
let bob: AccountId = CollectivesWestend::account_id_of(BOB);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ fn create_and_claim_treasury_spend() {
ahw_xcm_config::LocationToAccountId::convert_location(&treasury_location).unwrap();
let asset_hub_location = Location::new(0, Parachain(AssetHubWestend::para_id().into()));
let root = <Westend as Chain>::RuntimeOrigin::root();
// asset kind to be spend from the treasury.
let asset_kind = VersionedLocatableAsset::V5 {
location: asset_hub_location,
asset_id: AssetId([PalletInstance(50), GeneralIndex(USDT_ID.into())].into()),
};
// asset kind to be spent from the treasury.
let asset_kind: VersionedLocatableAsset =
(asset_hub_location, AssetId([PalletInstance(50), GeneralIndex(USDT_ID.into())].into()))
.into();
// treasury spend beneficiary.
let alice: AccountId = Westend::account_id_of(ALICE);
let bob: AccountId = Westend::account_id_of(BOB);
Expand Down
Loading

0 comments on commit 8b49830

Please sign in to comment.