Skip to content

Commit

Permalink
WIP: Attempt at setting up old storage items before migration tests
Browse files Browse the repository at this point in the history
WARNING: adds an assert inside v1::migrate() which should be removed!
  • Loading branch information
atodorov committed Dec 7, 2023
1 parent 1aca9d5 commit c96b6ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pallets/bridge/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,28 @@ pub(crate) fn migrate<T: Config>() -> Weight {
#[cfg(test)]
pub mod tests {
use super::{migrate, Weight};
use crate::mock::{ExtBuilder, Test};
use crate::{
mock::{ExtBuilder, Test},
Authorities,
};
use frame_support::{storage::unhashed, StoragePrefixedMap};
use sp_io::hashing::twox_128;

#[test]
fn migrate_should_not_crash() {
ExtBuilder.build_and_execute(|| {
let weight = migrate::<Test>();
// simulate an environment where the old "bridge" pallet has some items in storage
// before we apply the migrations
let authority = b"authority";

let authorities_prefix = [
&twox_128(b"bridge"),
&twox_128(Authorities::<Test>::storage_prefix())[..],
]
.concat();
unhashed::put_raw(&authorities_prefix, authority);

let weight = migrate::<Test>();
assert_ne!(weight, Weight::zero());
});
}
Expand Down
1 change: 1 addition & 0 deletions pallets/bridge/src/migrations/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl<T: Config> Migrate for Migration<T> {
}

let old_count = count_storage_items(OLD_PALLET_NAME);
assert_ne!(old_count, 0, "Old pallet storage must not be empty");

move_pallet(OLD_PALLET_NAME.as_bytes(), new_pallet_name.as_bytes());

Expand Down

0 comments on commit c96b6ca

Please sign in to comment.