Skip to content

Commit 38f45f2

Browse files
committed
test: test compatibility between xcm v3 MultiLocation and xcm v4 Location
1 parent b559343 commit 38f45f2

File tree

1 file changed

+88
-7
lines changed

1 file changed

+88
-7
lines changed

asset-registry/src/tests.rs

Lines changed: 88 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@
33
use super::*;
44
use crate as orml_asset_registry;
55
use crate::tests::para::{AdminAssetTwo, AssetRegistry, CustomMetadata, RuntimeOrigin, Tokens, TreasuryAccount};
6+
use frame_support::migration::put_storage_value;
67
use frame_support::{assert_noop, assert_ok};
78
use mock::{para::RuntimeCall, *};
89
use orml_traits::MultiCurrency;
910
use polkadot_parachain_primitives::primitives::Sibling;
1011

12+
use sp_runtime::traits::MaybeEquivalence;
1113
use sp_runtime::{
1214
traits::{AccountIdConversion, BadOrigin, Dispatchable},
1315
AccountId32,
1416
};
17+
use xcm_builder::V4V3LocationConverter;
1518
use xcm_simulator::TestExt;
1619

17-
type OldLocation = xcm::v2::MultiLocation;
18-
type OldJunctions = xcm::v2::Junctions;
19-
type OldJunction = xcm::v2::Junction;
20-
2120
fn treasury_account() -> AccountId32 {
2221
TreasuryAccount::get()
2322
}
@@ -578,11 +577,15 @@ fn test_asset_authority() {
578577
fn test_v2_to_v3_incompatible_multilocation() {
579578
// Assert that V2 and V3 Location both are encoded differently
580579
assert!(
581-
OldLocation::new(
580+
xcm::v2::MultiLocation::new(
581+
0,
582+
xcm::v2::Junctions::X1(xcm::v2::Junction::GeneralKey(vec![0].try_into().unwrap()))
583+
)
584+
.encode() != xcm::v3::MultiLocation::new(
582585
0,
583-
OldJunctions::X1(OldJunction::GeneralKey(vec![0].try_into().unwrap()))
586+
xcm::v3::Junctions::X1(xcm::v3::Junction::from(BoundedVec::try_from(vec![0]).unwrap()))
584587
)
585-
.encode() != Location::new(0, [Junction::from(BoundedVec::try_from(vec![0]).unwrap())]).encode()
588+
.encode()
586589
);
587590
}
588591

@@ -640,3 +643,81 @@ fn test_decode_bounded_vec() {
640643
);
641644
});
642645
}
646+
647+
#[test]
648+
fn validate_xcmv3v4_location_compatibility() {
649+
TestNet::reset();
650+
651+
ParaA::execute_with(|| {
652+
let pallet_prefix = b"AssetRegistry";
653+
let storage_prefix = b"LocationToAssetId";
654+
655+
let parents = 0;
656+
657+
// xcm::v3 storage keys
658+
let v3_keys = vec![
659+
xcm::v3::MultiLocation::new(
660+
parents,
661+
xcm::v3::Junctions::X8(
662+
xcm::v3::Junction::AccountId32 {
663+
network: None,
664+
id: [0; 32],
665+
},
666+
xcm::v3::Junction::AccountIndex64 {
667+
network: None,
668+
index: 0,
669+
},
670+
xcm::v3::Junction::AccountKey20 {
671+
network: None,
672+
key: [0; 20],
673+
},
674+
xcm::v3::Junction::GeneralIndex(10),
675+
xcm::v3::Junction::GeneralKey {
676+
length: 10,
677+
data: [0; 32],
678+
},
679+
xcm::v3::Junction::GlobalConsensus(xcm::v3::NetworkId::Polkadot),
680+
xcm::v3::Junction::OnlyChild,
681+
xcm::v3::Junction::PalletInstance(10),
682+
),
683+
),
684+
xcm::v3::MultiLocation::new(
685+
parents,
686+
xcm::v3::Junctions::X2(
687+
xcm::v3::Junction::Parachain(1000),
688+
xcm::v3::Junction::Plurality {
689+
id: xcm_simulator::BodyId::Index(1),
690+
part: xcm_simulator::BodyPart::Members { count: 1 },
691+
},
692+
),
693+
),
694+
];
695+
// xcm::v4 storage keys
696+
let v4_keys: Vec<Location> = v3_keys
697+
.iter()
698+
.map(|key| V4V3LocationConverter::convert_back(key).unwrap())
699+
.collect();
700+
701+
let asset_id: para::ParaAssetId = 10u32;
702+
703+
// Verify that there is nothing stored yet
704+
v4_keys
705+
.iter()
706+
.for_each(|key| assert_eq!(AssetRegistry::location_to_asset_id(key.clone()), None));
707+
708+
// Store raw xcm::v3 data
709+
v3_keys.iter().for_each(|key| {
710+
put_storage_value(
711+
pallet_prefix,
712+
storage_prefix,
713+
&<Twox64Concat as frame_support::StorageHasher>::hash(&key.encode()),
714+
asset_id,
715+
)
716+
});
717+
718+
// Verify that (xcm::v3) and (xcm::v4) are equivalent
719+
v4_keys
720+
.iter()
721+
.for_each(|key| assert_eq!(AssetRegistry::location_to_asset_id(key.clone()), Some(asset_id.clone())));
722+
});
723+
}

0 commit comments

Comments
 (0)