Run all tests with try-runtime feature enabled (#14396)

* Run all tests with `try-runtime` feature enabled

There are some tests that are guarded behind the `try-runtime` feature which are currently not being
executed. This pull requests changes this and enables the feature for the test run.

* Add some docs

* Rename variable
This commit is contained in:
Bastian Köcher
2023-06-16 12:16:19 +02:00
committed by GitHub
parent 4311411133
commit 53f4b4df76
7 changed files with 46 additions and 22 deletions
@@ -281,7 +281,7 @@ benchmarks! {
#[pov_mode = Measured]
migrate {
StorageVersion::new(0).put::<Pallet<T>>();
<Migration::<T> as frame_support::traits::OnRuntimeUpgrade>::on_runtime_upgrade();
<Migration::<T, false> as frame_support::traits::OnRuntimeUpgrade>::on_runtime_upgrade();
let origin: RawOrigin<<T as frame_system::Config>::AccountId> = RawOrigin::Signed(whitelisted_caller());
}: {
<Contracts<T>>::migrate(origin.into(), Weight::MAX).unwrap()
@@ -294,7 +294,7 @@ benchmarks! {
on_runtime_upgrade_noop {
assert_eq!(StorageVersion::get::<Pallet<T>>(), 2);
}: {
<Migration::<T> as frame_support::traits::OnRuntimeUpgrade>::on_runtime_upgrade()
<Migration::<T, false> as frame_support::traits::OnRuntimeUpgrade>::on_runtime_upgrade()
} verify {
assert!(MigrationInProgress::<T>::get().is_none());
}
@@ -306,7 +306,7 @@ benchmarks! {
let v = vec![42u8].try_into().ok();
MigrationInProgress::<T>::set(v.clone());
}: {
<Migration::<T> as frame_support::traits::OnRuntimeUpgrade>::on_runtime_upgrade()
<Migration::<T, false> as frame_support::traits::OnRuntimeUpgrade>::on_runtime_upgrade()
} verify {
assert!(MigrationInProgress::<T>::get().is_some());
assert_eq!(MigrationInProgress::<T>::get(), v);
@@ -317,7 +317,7 @@ benchmarks! {
on_runtime_upgrade {
StorageVersion::new(0).put::<Pallet<T>>();
}: {
<Migration::<T> as frame_support::traits::OnRuntimeUpgrade>::on_runtime_upgrade()
<Migration::<T, false> as frame_support::traits::OnRuntimeUpgrade>::on_runtime_upgrade()
} verify {
assert!(MigrationInProgress::<T>::get().is_some());
}
+15 -8
View File
@@ -191,10 +191,14 @@ pub trait MigrateSequence: private::Sealed {
}
/// Performs all necessary migrations based on `StorageVersion`.
pub struct Migration<T: Config>(PhantomData<T>);
///
/// If `TEST_ALL_STEPS == true` and `try-runtime` is enabled, this will run all the migrations
/// inside `on_runtime_upgrade`. This should be set to false in tests that want to ensure the step
/// by step migration works.
pub struct Migration<T: Config, const TEST_ALL_STEPS: bool = true>(PhantomData<T>);
#[cfg(feature = "try-runtime")]
impl<T: Config> Migration<T> {
impl<T: Config, const TEST_ALL_STEPS: bool> Migration<T, TEST_ALL_STEPS> {
fn run_all_steps() -> Result<(), TryRuntimeError> {
let mut weight = Weight::zero();
let name = <Pallet<T>>::name();
@@ -221,7 +225,7 @@ impl<T: Config> Migration<T> {
}
}
impl<T: Config> OnRuntimeUpgrade for Migration<T> {
impl<T: Config, const TEST_ALL_STEPS: bool> OnRuntimeUpgrade for Migration<T, TEST_ALL_STEPS> {
fn on_runtime_upgrade() -> Weight {
let name = <Pallet<T>>::name();
let latest_version = <Pallet<T>>::current_storage_version();
@@ -244,6 +248,7 @@ impl<T: Config> OnRuntimeUpgrade for Migration<T> {
"{name}: Migration already in progress {:?}",
&storage_version
);
return T::WeightInfo::on_runtime_upgrade_in_progress()
}
@@ -256,9 +261,11 @@ impl<T: Config> OnRuntimeUpgrade for Migration<T> {
MigrationInProgress::<T>::set(Some(cursor));
#[cfg(feature = "try-runtime")]
Self::run_all_steps().unwrap();
if TEST_ALL_STEPS {
Self::run_all_steps().unwrap();
}
return T::WeightInfo::on_runtime_upgrade()
T::WeightInfo::on_runtime_upgrade()
}
#[cfg(feature = "try-runtime")]
@@ -305,7 +312,7 @@ pub enum StepResult {
Completed { steps_done: u32 },
}
impl<T: Config> Migration<T> {
impl<T: Config, const TEST_ALL_STEPS: bool> Migration<T, TEST_ALL_STEPS> {
/// Verify that each migration's step of the [`T::Migrations`] sequence fits into `Cursor`.
pub(crate) fn integrity_test() {
let max_weight = <T as frame_system::Config>::BlockWeights::get().max_block;
@@ -460,7 +467,7 @@ impl MigrateSequence for Tuple {
return StepResult::Completed{ steps_done }
}
}
return StepResult::InProgress{cursor: migration.encode().try_into().expect(PROOF_ENCODE), steps_done }
return StepResult::InProgress{cursor: migration.encode().try_into().expect(PROOF_ENCODE), steps_done }
}
)*
);
@@ -569,7 +576,7 @@ mod test {
#[test]
fn migration_works() {
type TestMigration = Migration<Test>;
type TestMigration = Migration<Test, false>;
ExtBuilder::default().set_storage_version(0).build().execute_with(|| {
assert_eq!(StorageVersion::get::<Pallet<Test>>(), 0);
@@ -150,8 +150,17 @@ where
log::info!(target: LOG_TARGET, "Total accounts: {:?}", all_accounts.len());
log::info!(target: LOG_TARGET, "Total stake to unlock: {:?}", total_stake_to_unlock);
log::info!(target: LOG_TARGET, "Total deposit to unreserve: {:?}", total_deposits_to_unreserve);
log::info!(target: LOG_TARGET, "Bugged deposits: {}/{}", bugged_deposits, account_deposits.len());
log::info!(
target: LOG_TARGET,
"Total deposit to unreserve: {:?}",
total_deposits_to_unreserve
);
log::info!(
target: LOG_TARGET,
"Bugged deposits: {}/{}",
bugged_deposits,
account_deposits.len()
);
Ok(account_reserved_before.encode())
}
@@ -165,11 +165,20 @@ where
let total_stake_to_unlock = account_staked_sums.clone().into_values().sum::<BalanceOf<T>>();
let total_deposits_to_unreserve =
account_deposited_sums.clone().into_values().sum::<BalanceOf<T>>();
log::info!(target: LOG_TARGET, "Total accounts: {:?}", all_accounts.len());
log::info!(target: LOG_TARGET, "Total accounts: {:?}", all_accounts.len());
log::info!(target: LOG_TARGET, "Total stake to unlock: {:?}", total_stake_to_unlock);
log::info!(target: LOG_TARGET, "Total deposit to unreserve: {:?}", total_deposits_to_unreserve);
log::info!(
target: LOG_TARGET,
"Total deposit to unreserve: {:?}",
total_deposits_to_unreserve
);
if bugged_deposits > 0 {
log::warn!(target: LOG_TARGET, "Bugged deposits: {}/{}", bugged_deposits, all_accounts.len());
log::warn!(
target: LOG_TARGET,
"Bugged deposits: {}/{}",
bugged_deposits,
all_accounts.len()
);
}
Ok(account_reserved_before.encode())
+2 -3
View File
@@ -33,7 +33,7 @@ mod v0 {
use super::*;
use frame_support::traits::WrapperOpaque;
#[derive(Encode, Decode)]
#[derive(Encode, Decode, Default)]
pub(super) struct BoundedOpaqueNetworkState {
/// PeerId of the local node in SCALE encoded.
pub peer_id: Vec<u8>,
@@ -118,8 +118,7 @@ pub mod v1 {
}
}
#[cfg(test)]
#[cfg(feature = "try-runtime")]
#[cfg(all(feature = "try-runtime", test))]
mod test {
use super::*;
use crate::mock::{new_test_ext, Runtime as T};
+1 -1
View File
@@ -499,7 +499,7 @@ mod test {
// The pre_upgrade hook fails:
let err = v3::MigrateToV4::<Test>::pre_upgrade().unwrap_err();
assert!(err == "Call is too large".into());
assert_eq!(DispatchError::from("Call is too large."), err);
// But the migration itself works:
let _w = v3::MigrateToV4::<Test>::on_runtime_upgrade();
@@ -221,7 +221,7 @@ test-linux-stable:
--locked
--release
--verbose
--features runtime-benchmarks
--features runtime-benchmarks,try-runtime
--manifest-path ./bin/node/cli/Cargo.toml
--partition count:${CI_NODE_INDEX}/${CI_NODE_TOTAL}
# we need to update cache only from one job