Skip to content

Commit 8e90d6a

Browse files
committed
fix migration and tests
1 parent 6df51b3 commit 8e90d6a

File tree

3 files changed

+83
-14
lines changed

3 files changed

+83
-14
lines changed

asset-registry/src/migrations.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ mod v2 {
2727

2828
weight.saturating_accrue(T::DbWeight::get().reads(1));
2929
let old_data =
30-
storage_key_iter::<xcm::v2::MultiLocation, T::AssetId, Blake2_128Concat>(module_prefix, storage_prefix)
31-
.drain();
30+
storage_key_iter::<xcm::v2::MultiLocation, T::AssetId, Twox64Concat>(module_prefix, storage_prefix)
31+
.drain()
32+
.collect::<sp_std::vec::Vec<_>>();
3233

3334
for (old_key, value) in old_data {
3435
weight.saturating_accrue(T::DbWeight::get().writes(1));

asset-registry/src/tests.rs

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -601,28 +601,71 @@ fn from_unversioned_to_v2_storage() {
601601
// StorageVersion is 0 before migration
602602
assert_eq!(StorageVersion::get::<Pallet<para::Runtime>>(), 0);
603603

604-
// V2 storage key
605-
let old_key = xcm::v2::MultiLocation::new(
604+
// V2 storage
605+
let old_multilocation_0 = xcm::v2::MultiLocation::new(
606606
0,
607607
xcm::v2::Junctions::X1(xcm::v2::Junction::GeneralKey(vec![0].try_into().unwrap())),
608-
)
609-
.encode();
608+
);
609+
let old_multilocation_1 = xcm::v2::MultiLocation::new(
610+
1,
611+
xcm::v2::Junctions::X2(
612+
xcm::v2::Junction::Parachain(2096),
613+
xcm::v2::Junction::GeneralKey(vec![0, 0, 0, 0, 0, 0, 0, 0, 0].try_into().unwrap()),
614+
),
615+
);
616+
let old_multilocation_2 = xcm::v2::MultiLocation::new(
617+
1,
618+
xcm::v2::Junctions::X2(
619+
xcm::v2::Junction::Parachain(2096),
620+
xcm::v2::Junction::GeneralKey(vec![1, 1].try_into().unwrap()),
621+
),
622+
);
610623

611-
let asset_id: para::ParaAssetId = 5u32;
624+
let asset_id_0: para::ParaAssetId = 5u32;
625+
let asset_id_1: para::ParaAssetId = 6u32;
626+
let asset_id_2: para::ParaAssetId = 7u32;
612627

613628
// Store raw xcm::v2 data
614629
put_storage_value(
615630
module_prefix,
616631
storage_prefix,
617-
&Blake2_128Concat::hash(&old_key),
618-
asset_id,
632+
&Twox64Concat::hash(&old_multilocation_0.encode()),
633+
asset_id_0,
634+
);
635+
put_storage_value(
636+
module_prefix,
637+
storage_prefix,
638+
&Twox64Concat::hash(&old_multilocation_1.encode()),
639+
asset_id_1,
640+
);
641+
put_storage_value(
642+
module_prefix,
643+
storage_prefix,
644+
&Twox64Concat::hash(&old_multilocation_2.encode()),
645+
asset_id_2,
619646
);
620647

621648
// V3 storage key
622-
let new_key = MultiLocation::new(0, X1(Junction::from(BoundedVec::try_from(vec![0]).unwrap())));
649+
let new_multilocation_0 = MultiLocation::new(0, X1(Junction::from(BoundedVec::try_from(vec![0]).unwrap())));
650+
let new_multilocation_1 = MultiLocation::new(
651+
1,
652+
X2(
653+
Parachain(2096),
654+
Junction::from(BoundedVec::try_from(vec![0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap()),
655+
),
656+
);
657+
let new_multilocation_2 = MultiLocation::new(
658+
1,
659+
X2(
660+
Parachain(2096),
661+
Junction::from(BoundedVec::try_from(vec![1, 1]).unwrap()),
662+
),
663+
);
623664

624665
// Assert new StorageKey still does not exist
625-
assert_eq!(AssetRegistry::location_to_asset_id(new_key), None);
666+
assert_eq!(AssetRegistry::location_to_asset_id(new_multilocation_0), None);
667+
assert_eq!(AssetRegistry::location_to_asset_id(new_multilocation_1), None);
668+
assert_eq!(AssetRegistry::location_to_asset_id(new_multilocation_2), None);
626669

627670
// Run StorageKey migration
628671
crate::Migration::<para::Runtime>::on_runtime_upgrade();
@@ -631,13 +674,36 @@ fn from_unversioned_to_v2_storage() {
631674
assert_eq!(StorageVersion::get::<Pallet<para::Runtime>>(), 2);
632675

633676
// Assert the StorageKey exists and has been migrated to xcm::v3
634-
assert_eq!(AssetRegistry::location_to_asset_id(new_key), Some(asset_id));
677+
assert_eq!(
678+
AssetRegistry::location_to_asset_id(new_multilocation_0),
679+
Some(asset_id_0)
680+
);
681+
assert_eq!(
682+
AssetRegistry::location_to_asset_id(new_multilocation_1),
683+
Some(asset_id_1)
684+
);
685+
assert_eq!(
686+
AssetRegistry::location_to_asset_id(new_multilocation_2),
687+
Some(asset_id_2)
688+
);
635689

636690
// Assert the old key does not exist anymore
637691
assert!(get_storage_value::<para::ParaAssetId>(
638692
module_prefix,
639693
storage_prefix,
640-
&Blake2_128Concat::hash(&old_key),
694+
&Twox64Concat::hash(&old_multilocation_0.encode()),
695+
)
696+
.is_none());
697+
assert!(get_storage_value::<para::ParaAssetId>(
698+
module_prefix,
699+
storage_prefix,
700+
&Twox64Concat::hash(&old_multilocation_1.encode()),
701+
)
702+
.is_none());
703+
assert!(get_storage_value::<para::ParaAssetId>(
704+
module_prefix,
705+
storage_prefix,
706+
&Twox64Concat::hash(&old_multilocation_2.encode()),
641707
)
642708
.is_none());
643709

unknown-tokens/src/migrations.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ mod v2 {
5757

5858
weight.saturating_accrue(T::DbWeight::get().reads(1));
5959

60-
let old_data = storage_iter::<u128>(module_prefix, storage_prefix).drain();
60+
let old_data = storage_iter::<u128>(module_prefix, storage_prefix)
61+
.drain()
62+
.collect::<sp_std::vec::Vec<_>>();
6163

6264
for (raw_k, value) in old_data {
6365
let mut full_key = Vec::new();

0 commit comments

Comments
 (0)