Skip to content

Commit

Permalink
Check versions in storage migration
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsso committed Dec 5, 2023
1 parent fda2fa3 commit d234c39
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions runtimes/eden/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,68 @@ where

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
use frame_support::ensure;

log::info!("Pre upgrade");

Check warning on line 107 in runtimes/eden/src/migrations.rs

View check run for this annotation

Codecov / codecov/patch

runtimes/eden/src/migrations.rs#L104-L107

Added lines #L104 - L107 were not covered by tests

ensure!(
StorageVersion::get::<pallet_preimage::Pallet<T>>() == 0,
TryRuntimeError::Other("preimage storage version is not 0")

Check warning on line 111 in runtimes/eden/src/migrations.rs

View check run for this annotation

Codecov / codecov/patch

runtimes/eden/src/migrations.rs#L109-L111

Added lines #L109 - L111 were not covered by tests
);
ensure!(
StorageVersion::get::<pallet_xcm::Pallet<T>>() == 0,
TryRuntimeError::Other("pallet_xcm storage version is not 0")

Check warning on line 115 in runtimes/eden/src/migrations.rs

View check run for this annotation

Codecov / codecov/patch

runtimes/eden/src/migrations.rs#L113-L115

Added lines #L113 - L115 were not covered by tests
);
ensure!(
StorageVersion::get::<pallet_scheduler::Pallet<T>>() == 0,
TryRuntimeError::Other("pallet_scheduler storage version is not 0")

Check warning on line 119 in runtimes/eden/src/migrations.rs

View check run for this annotation

Codecov / codecov/patch

runtimes/eden/src/migrations.rs#L117-L119

Added lines #L117 - L119 were not covered by tests
);
ensure!(
StorageVersion::get::<pallet_collective::Pallet<T, pallet_collective::pallet::Instance1>>() == 0,
TryRuntimeError::Other("pallet_collective storage version is not 0")

Check warning on line 123 in runtimes/eden/src/migrations.rs

View check run for this annotation

Codecov / codecov/patch

runtimes/eden/src/migrations.rs#L121-L123

Added lines #L121 - L123 were not covered by tests
);
ensure!(
StorageVersion::get::<pallet_membership::Pallet<T, pallet_membership::pallet::Instance3>>() == 0,
TryRuntimeError::Other("pallet_membership storage version is not 0")

Check warning on line 127 in runtimes/eden/src/migrations.rs

View check run for this annotation

Codecov / codecov/patch

runtimes/eden/src/migrations.rs#L125-L127

Added lines #L125 - L127 were not covered by tests
);
ensure!(
StorageVersion::get::<pallet_balances::Pallet<T>>() == 0,
TryRuntimeError::Other("pallet_balances storage version is not 0")

Check warning on line 131 in runtimes/eden/src/migrations.rs

View check run for this annotation

Codecov / codecov/patch

runtimes/eden/src/migrations.rs#L129-L131

Added lines #L129 - L131 were not covered by tests
);

Ok(vec![])
}

Check warning on line 135 in runtimes/eden/src/migrations.rs

View check run for this annotation

Codecov / codecov/patch

runtimes/eden/src/migrations.rs#L134-L135

Added lines #L134 - L135 were not covered by tests

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), TryRuntimeError> {
use frame_support::ensure;

log::info!("Post upgrade {_state:?}");
ensure!(
StorageVersion::get::<pallet_preimage::Pallet<T>>() == 1,
TryRuntimeError::Other("preimage post upgrade storage version is not 1")

Check warning on line 144 in runtimes/eden/src/migrations.rs

View check run for this annotation

Codecov / codecov/patch

runtimes/eden/src/migrations.rs#L138-L144

Added lines #L138 - L144 were not covered by tests
);
ensure!(
StorageVersion::get::<pallet_xcm::Pallet<T>>() == 1,
TryRuntimeError::Other("pallet_xcm post upgrade storage version is not 1")

Check warning on line 148 in runtimes/eden/src/migrations.rs

View check run for this annotation

Codecov / codecov/patch

runtimes/eden/src/migrations.rs#L146-L148

Added lines #L146 - L148 were not covered by tests
);
ensure!(
StorageVersion::get::<pallet_scheduler::Pallet<T>>() == 4,
TryRuntimeError::Other("pallet_scheduler post upgrade storage version is not 4")

Check warning on line 152 in runtimes/eden/src/migrations.rs

View check run for this annotation

Codecov / codecov/patch

runtimes/eden/src/migrations.rs#L150-L152

Added lines #L150 - L152 were not covered by tests
);
ensure!(
StorageVersion::get::<pallet_collective::Pallet<T, pallet_collective::pallet::Instance1>>() == 4,
TryRuntimeError::Other("pallet_collective post upgrade storage version is not 4")

Check warning on line 156 in runtimes/eden/src/migrations.rs

View check run for this annotation

Codecov / codecov/patch

runtimes/eden/src/migrations.rs#L154-L156

Added lines #L154 - L156 were not covered by tests
);
ensure!(
StorageVersion::get::<pallet_membership::Pallet<T, pallet_membership::pallet::Instance3>>() == 4,
TryRuntimeError::Other("pallet_membership post upgrade storage version is not 4")

Check warning on line 160 in runtimes/eden/src/migrations.rs

View check run for this annotation

Codecov / codecov/patch

runtimes/eden/src/migrations.rs#L158-L160

Added lines #L158 - L160 were not covered by tests
);
ensure!(
StorageVersion::get::<pallet_balances::Pallet<T>>() == 1,
TryRuntimeError::Other("pallet_balances post upgrade storage version is not 1")

Check warning on line 164 in runtimes/eden/src/migrations.rs

View check run for this annotation

Codecov / codecov/patch

runtimes/eden/src/migrations.rs#L162-L164

Added lines #L162 - L164 were not covered by tests
);

Ok(())
}

Check warning on line 168 in runtimes/eden/src/migrations.rs

View check run for this annotation

Codecov / codecov/patch

runtimes/eden/src/migrations.rs#L167-L168

Added lines #L167 - L168 were not covered by tests
}

0 comments on commit d234c39

Please sign in to comment.