Skip to content

Commit

Permalink
Change Versioned*::V4 to Versioned*::from to use latest (for easi…
Browse files Browse the repository at this point in the history
…er migration to xcm:v5)
  • Loading branch information
bkontur committed Jul 24, 2024
1 parent a8ec0dd commit e813ddb
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 58 deletions.
8 changes: 4 additions & 4 deletions integration-tests/emulated/helpers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ macro_rules! test_relay_is_trusted_teleporter {
weight_limit: weight_limit.clone(),
});
let mut delivery_fees_amount = 0;
let mut remote_message = VersionedXcm::V4(Xcm(Vec::new()));
let mut remote_message = VersionedXcm::from(Xcm(Vec::new()));
<$sender_relay>::execute_with(|| {
type Runtime = <$sender_relay as Chain>::Runtime;
type OriginCaller = <$sender_relay as Chain>::OriginCaller;
Expand All @@ -75,7 +75,7 @@ macro_rules! test_relay_is_trusted_teleporter {
.forwarded_xcms
.iter()
.find(|(destination, _)| {
*destination == VersionedLocation::V4(Location::new(0, [Parachain(<$receiver_para>::para_id().into())]))
*destination == VersionedLocation::from(Location::new(0, [Parachain(<$receiver_para>::para_id().into())]))
})
.unwrap();
assert_eq!(messages_to_query.len(), 1);
Expand Down Expand Up @@ -201,7 +201,7 @@ macro_rules! test_parachain_is_trusted_teleporter_for_relay {
});
// These will be filled in the closure.
let mut delivery_fees_amount = 0;
let mut remote_message = VersionedXcm::V4(Xcm(Vec::new()));
let mut remote_message = VersionedXcm::from(Xcm(Vec::new()));
<$sender_para>::execute_with(|| {
type Runtime = <$sender_para as Chain>::Runtime;
type OriginCaller = <$sender_para as Chain>::OriginCaller;
Expand All @@ -213,7 +213,7 @@ macro_rules! test_parachain_is_trusted_teleporter_for_relay {
.forwarded_xcms
.iter()
.find(|(destination, _)| {
*destination == VersionedLocation::V4(Location::new(1, []))
*destination == VersionedLocation::from(Location::parent())
})
.unwrap();
assert_eq!(messages_to_query.len(), 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ fn spend_ksm_on_asset_hub() {
let teleport_call = RuntimeCall::Utility(pallet_utility::Call::<Runtime>::dispatch_as {
as_origin: bx!(OriginCaller::system(RawOrigin::Signed(treasury_account))),
call: bx!(RuntimeCall::XcmPallet(pallet_xcm::Call::<Runtime>::teleport_assets {
dest: bx!(VersionedLocation::V4(asset_hub_location.clone())),
beneficiary: bx!(VersionedLocation::V4(treasury_location)),
assets: bx!(VersionedAssets::V4(
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 @@ -114,7 +115,7 @@ fn spend_ksm_on_asset_hub() {
asset_id: native_asset_on_asset_hub.into(),
}),
amount: treasury_spend_balance,
beneficiary: bx!(VersionedLocation::V4(alice_location)),
beneficiary: bx!(VersionedLocation::from(alice_location)),
valid_from: None,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn multi_hop_works() {

// We get them from the PenpalA closure.
let mut delivery_fees_amount = 0;
let mut remote_message = VersionedXcm::V4(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 @@ -89,7 +89,7 @@ fn multi_hop_works() {
.forwarded_xcms
.iter()
.find(|(destination, _)| {
*destination == VersionedLocation::V4(Location::new(1, [Parachain(1000)]))
*destination == VersionedLocation::from(Location::new(1, [Parachain(1000)]))
})
.unwrap();
assert_eq!(messages_to_query.len(), 1);
Expand All @@ -103,7 +103,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::V4(Xcm::<()>(Vec::new()));
let mut intermediate_remote_message = VersionedXcm::from(Xcm::<()>(Vec::new()));
<AssetHubKusama as TestExt>::execute_with(|| {
type Runtime = <AssetHubKusama as Chain>::Runtime;
type RuntimeCall = <AssetHubKusama as Chain>::RuntimeCall;
Expand All @@ -112,13 +112,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::V4(Location::new(1, []).into()),
VersionedAssetId::from(AssetId(Location::parent())),
)
.unwrap();

// We have to do this to turn `VersionedXcm<()>` into `VersionedXcm<RuntimeCall>`.
let xcm_program =
VersionedXcm::V4(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 @@ -127,7 +128,7 @@ fn multi_hop_works() {
.forwarded_xcms
.iter()
.find(|(destination, _)| {
*destination == VersionedLocation::V4(Location::new(1, [Parachain(2001)]))
*destination == VersionedLocation::from(Location::new(1, [Parachain(2001)]))
})
.unwrap();
// There's actually two messages here.
Expand All @@ -150,9 +151,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::V4(Parent.into()))
.unwrap();
final_execution_fees = Runtime::query_weight_to_asset_fee(
weight,
VersionedAssetId::from(AssetId(Parent.into())),
)
.unwrap();
});

// Dry-running is done.
Expand Down Expand Up @@ -220,7 +223,7 @@ fn sender_assertions(test: ParaToParaThroughAHTest) {
RuntimeEvent::ForeignAssets(
pallet_assets::Event::Burned { asset_id, owner, balance }
) => {
asset_id: *asset_id == Location::new(1, []),
asset_id: *asset_id == Location::parent(),
owner: *owner == test.sender.account_id,
balance: *balance == test.args.amount,
},
Expand Down Expand Up @@ -254,7 +257,7 @@ fn receiver_assertions(test: ParaToParaThroughAHTest) {
RuntimeEvent::ForeignAssets(
pallet_assets::Event::Issued { asset_id, owner, .. }
) => {
asset_id: *asset_id == Location::new(1, []),
asset_id: *asset_id == Location::parent(),
owner: *owner == test.receiver.account_id,
},
]
Expand Down Expand Up @@ -293,7 +296,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::V4(AssetId(Location::new(1, [])))),
remote_fees_id: bx!(VersionedAssetId::from(AssetId(Location::parent()))),
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn multi_hop_works() {

// We get them from the PenpalB closure.
let mut delivery_fees_amount = 0;
let mut remote_message = VersionedXcm::V4(Xcm(Vec::new()));
let mut remote_message = VersionedXcm::from(Xcm(Vec::new()));
<PenpalB as TestExt>::execute_with(|| {
type Runtime = <PenpalB as Chain>::Runtime;
type OriginCaller = <PenpalB as Chain>::OriginCaller;
Expand All @@ -90,7 +90,7 @@ fn multi_hop_works() {
.forwarded_xcms
.iter()
.find(|(destination, _)| {
*destination == VersionedLocation::V4(Location::new(1, [Parachain(1000)]))
*destination == VersionedLocation::from(Location::new(1, [Parachain(1000)]))
})
.unwrap();
assert_eq!(messages_to_query.len(), 1);
Expand All @@ -104,7 +104,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::V4(Xcm::<()>(Vec::new()));
let mut intermediate_remote_message = VersionedXcm::from(Xcm::<()>(Vec::new()));
<AssetHubPolkadot as TestExt>::execute_with(|| {
type Runtime = <AssetHubPolkadot as Chain>::Runtime;
type RuntimeCall = <AssetHubPolkadot as Chain>::RuntimeCall;
Expand All @@ -113,13 +113,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::V4(Location::new(1, []).into()),
VersionedAssetId::from(AssetId(Location::parent())),
)
.unwrap();

// We have to do this to turn `VersionedXcm<()>` into `VersionedXcm<RuntimeCall>`.
let xcm_program =
VersionedXcm::V4(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 @@ -128,7 +129,7 @@ fn multi_hop_works() {
.forwarded_xcms
.iter()
.find(|(destination, _)| {
*destination == VersionedLocation::V4(Location::new(1, [Parachain(2000)]))
*destination == VersionedLocation::from(Location::new(1, [Parachain(2000)]))
})
.unwrap();
// There's actually two messages here.
Expand All @@ -151,9 +152,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::V4(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 Expand Up @@ -221,7 +224,7 @@ fn sender_assertions(test: ParaToParaThroughAHTest) {
RuntimeEvent::ForeignAssets(
pallet_assets::Event::Burned { asset_id, owner, balance }
) => {
asset_id: *asset_id == Location::new(1, []),
asset_id: *asset_id == Location::parent(),
owner: *owner == test.sender.account_id,
balance: *balance == test.args.amount,
},
Expand Down Expand Up @@ -255,7 +258,7 @@ fn receiver_assertions(test: ParaToParaThroughAHTest) {
RuntimeEvent::ForeignAssets(
pallet_assets::Event::Issued { asset_id, owner, .. }
) => {
asset_id: *asset_id == Location::new(1, []),
asset_id: *asset_id == Location::parent(),
owner: *owner == test.receiver.account_id,
},
]
Expand Down Expand Up @@ -294,7 +297,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::V4(AssetId(Location::new(1, [])))),
remote_fees_id: bx!(VersionedAssetId::from(AssetId(Location::parent()))),
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn dry_run_send_asset_from_asset_hub_kusama_to_asset_hub_polkadot(id: Location,
.forwarded_xcms
.into_iter()
.find(|(destination, _)| {
*destination == VersionedLocation::V4(Location::new(1, [Parachain(1002)]))
*destination == VersionedLocation::from(Location::new(1, [Parachain(1002)]))
})
.unwrap();
assert_eq!(messages_to_query.len(), 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,14 +584,14 @@ fn send_weth_asset_from_asset_hub_to_ethereum() {
)),
fun: Fungible(WETH_AMOUNT),
}];
let multi_assets = VersionedAssets::V4(Assets::from(assets));
let multi_assets = VersionedAssets::from(Assets::from(assets));

let destination = VersionedLocation::V4(Location::new(
let destination = VersionedLocation::from(Location::new(
2,
[GlobalConsensus(Ethereum { chain_id: CHAIN_ID })],
));

let beneficiary = VersionedLocation::V4(Location::new(
let beneficiary = VersionedLocation::from(Location::new(
0,
[AccountKey20 { network: None, key: ETHEREUM_DESTINATION_ADDRESS }],
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,14 +588,14 @@ fn send_weth_asset_from_asset_hub_to_ethereum() {
)),
fun: Fungible(WETH_AMOUNT),
}];
let multi_assets = VersionedAssets::V4(Assets::from(assets));
let multi_assets = VersionedAssets::from(Assets::from(assets));

let destination = VersionedLocation::V4(Location::new(
let destination = VersionedLocation::from(Location::new(
2,
[GlobalConsensus(Ethereum { chain_id: CHAIN_ID })],
));

let beneficiary = VersionedLocation::V4(Location::new(
let beneficiary = VersionedLocation::from(Location::new(
0,
[AccountKey20 { network: None, key: ETHEREUM_DESTINATION_ADDRESS }],
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ fn fellows_whitelist_call() {
let call_hash = [1u8; 32].into();

let whitelist_call = RuntimeCall::PolkadotXcm(pallet_xcm::Call::<Runtime>::send {
dest: bx!(VersionedLocation::V4(Parent.into())),
message: bx!(VersionedXcm::V4(Xcm(vec![
dest: bx!(VersionedLocation::from(Location::parent())),
message: bx!(VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
Transact {
origin_kind: OriginKind::Xcm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ fn fellowship_treasury_spend() {
let teleport_call = RuntimeCall::Utility(pallet_utility::Call::<Runtime>::dispatch_as {
as_origin: bx!(OriginCaller::system(RawOrigin::Signed(treasury_account))),
call: bx!(RuntimeCall::XcmPallet(pallet_xcm::Call::<Runtime>::teleport_assets {
dest: bx!(VersionedLocation::V4(asset_hub_location.clone())),
beneficiary: bx!(VersionedLocation::V4(treasury_location)),
assets: bx!(VersionedAssets::V4(
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 @@ -109,7 +110,7 @@ fn fellowship_treasury_spend() {
asset_id: native_asset_on_asset_hub.into(),
}),
amount: fellowship_treasury_balance,
beneficiary: bx!(VersionedLocation::V4(fellowship_treasury_location)),
beneficiary: bx!(VersionedLocation::from(fellowship_treasury_location)),
valid_from: None,
});

Expand Down Expand Up @@ -186,7 +187,7 @@ fn fellowship_treasury_spend() {
asset_id: native_asset_on_asset_hub.into(),
}),
amount: fellowship_spend_balance,
beneficiary: bx!(VersionedLocation::V4(alice_location)),
beneficiary: bx!(VersionedLocation::from(alice_location)),
valid_from: None,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ fn relay_commands_add_registrar() {
});

let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::<Runtime>::send {
dest: bx!(VersionedLocation::V4(Location::new(0, [Parachain(1004)]))),
message: bx!(VersionedXcm::V4(Xcm(vec![
dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))),
message: bx!(VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
Transact {
origin_kind,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ fn relay_commands_add_registrar() {
});

let xcm_message = RuntimeCall::XcmPallet(pallet_xcm::Call::<Runtime>::send {
dest: bx!(VersionedLocation::V4(Location::new(0, [Parachain(1004)]))),
message: bx!(VersionedXcm::V4(Xcm(vec![
dest: bx!(VersionedLocation::from(Location::new(0, [Parachain(1004)]))),
message: bx!(VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
Transact {
origin_kind,
Expand Down
4 changes: 2 additions & 2 deletions relay/polkadot/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ where
// send
<pallet_xcm::Pallet<Runtime>>::send(
RawOrigin::Root.into(),
Box::new(VersionedLocation::V4(destination)),
Box::new(VersionedXcm::V4(program)),
Box::new(VersionedLocation::from(destination)),
Box::new(VersionedXcm::from(program)),
)?;
Ok(())
}
Expand Down

0 comments on commit e813ddb

Please sign in to comment.