optionally read pending configs in migration (#7489)

This commit is contained in:
Chris Sosnin
2023-07-12 12:22:49 +03:00
committed by GitHub
parent 0ff60f7da1
commit bcb9bd0432
@@ -156,9 +156,8 @@ executor_params : pre.executor_params,
let v7 = translate(v6);
v7::ActiveConfig::<T>::set(Some(v7));
let pending_v6 = v6::PendingConfigs::<T>::get()
.defensive_proof("Could not decode old pending")
.unwrap_or_default();
// Allowed to be empty.
let pending_v6 = v6::PendingConfigs::<T>::get().unwrap_or_default();
let mut pending_v7 = Vec::new();
for (session, v6) in pending_v6.into_iter() {
@@ -291,4 +290,20 @@ mod tests {
}
});
}
// Test that migration doesn't panic in case there're no pending configurations upgrades in pallet's storage.
#[test]
fn test_migrate_to_v7_no_pending() {
let v6 = V6HostConfiguration::<primitives::BlockNumber>::default();
new_test_ext(Default::default()).execute_with(|| {
// Implant the v6 version in the state.
v6::ActiveConfig::<Test>::set(Some(v6));
// Ensure there're no pending configs.
v6::PendingConfigs::<Test>::set(None);
// Shouldn't fail.
migrate_to_v7::<Test>();
});
}
}