Skip to content

Commit

Permalink
add try-runtime testing
Browse files Browse the repository at this point in the history
Signed-off-by: Yi <flame0743@gmail.com>
  • Loading branch information
flame4 committed Aug 5, 2022
1 parent 0edb2cd commit 394a0ca
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions runtime/calamari/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ try-runtime = [
'pallet-assets/try-runtime',
'pallet-tx-pause/try-runtime',
'pallet-asset-manager/try-runtime',
'runtime-common/try-runtime',
]
# Set timing constants (e.g. session period) to faster versions to speed up testing.
fast-runtime = []
Expand Down
4 changes: 3 additions & 1 deletion runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pallet-transaction-payment = { git = 'https://github.com/paritytech/substrate.gi
sp-runtime = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.26", default-features = false }
sp-std = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.26", default-features = false }


# Self dependencies
manta-primitives = { path = '../../primitives/manta', default-features = false }

Expand Down Expand Up @@ -66,3 +65,6 @@ std = [
"pallet-transaction-payment/std",
"sp-runtime/std",
]
try-runtime = [
"frame-support/try-runtime",
]
24 changes: 23 additions & 1 deletion runtime/common/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

use frame_support::{
dispatch::Weight,
ensure,
migrations::migrate_from_pallet_version_to_storage_version,
traits::{GetStorageVersion, OnRuntimeUpgrade, PalletInfoAccess},
traits::{GetStorageVersion, OnRuntimeUpgrade, PalletInfoAccess, StorageVersion},
weights::constants::RocksDbWeight,
};

Expand All @@ -43,6 +44,27 @@ where
let db_weight = RocksDbWeight::get();
migrate_from_pallet_version_to_storage_version::<T>(&db_weight)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
let storage_version = StorageVersion::get::<T>();
frame_support::debug(&"----PreUpgrade----");
frame_support::debug(&T::module_name());
frame_support::debug(&T::name());
frame_support::debug(&storage_version);
Ok(())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
let storage_version = StorageVersion::get::<T>();
frame_support::debug(&"----PostUpgrade----");
frame_support::debug(&T::module_name());
frame_support::debug(&T::name());
frame_support::debug(&storage_version);
ensure!(storage_version == StorageVersion::new(1), T::module_name());
Ok(())
}
}

#[cfg(test)]
Expand Down

0 comments on commit 394a0ca

Please sign in to comment.