|
3 | 3 | use super::*;
|
4 | 4 | use crate as orml_asset_registry;
|
5 | 5 | use crate::tests::para::{AdminAssetTwo, AssetRegistry, CustomMetadata, RuntimeOrigin, Tokens, TreasuryAccount};
|
| 6 | +use frame_support::migration::put_storage_value; |
6 | 7 | use frame_support::{assert_noop, assert_ok};
|
7 | 8 | use mock::{para::RuntimeCall, *};
|
8 | 9 | use orml_traits::MultiCurrency;
|
9 | 10 | use polkadot_parachain_primitives::primitives::Sibling;
|
10 | 11 |
|
| 12 | +use sp_runtime::traits::MaybeEquivalence; |
11 | 13 | use sp_runtime::{
|
12 | 14 | traits::{AccountIdConversion, BadOrigin, Dispatchable},
|
13 | 15 | AccountId32,
|
14 | 16 | };
|
| 17 | +use xcm_builder::V4V3LocationConverter; |
15 | 18 | use xcm_simulator::TestExt;
|
16 | 19 |
|
17 |
| -type OldLocation = xcm::v2::MultiLocation; |
18 |
| -type OldJunctions = xcm::v2::Junctions; |
19 |
| -type OldJunction = xcm::v2::Junction; |
20 |
| - |
21 | 20 | fn treasury_account() -> AccountId32 {
|
22 | 21 | TreasuryAccount::get()
|
23 | 22 | }
|
@@ -578,11 +577,15 @@ fn test_asset_authority() {
|
578 | 577 | fn test_v2_to_v3_incompatible_multilocation() {
|
579 | 578 | // Assert that V2 and V3 Location both are encoded differently
|
580 | 579 | 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( |
582 | 585 | 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())) |
584 | 587 | )
|
585 |
| - .encode() != Location::new(0, [Junction::from(BoundedVec::try_from(vec![0]).unwrap())]).encode() |
| 588 | + .encode() |
586 | 589 | );
|
587 | 590 | }
|
588 | 591 |
|
@@ -640,3 +643,81 @@ fn test_decode_bounded_vec() {
|
640 | 643 | );
|
641 | 644 | });
|
642 | 645 | }
|
| 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