mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 12:17:58 +00:00
Make sure pallet versions are set at genesis (#7451)
* Make sure pallet versions are set at genesis This pr ensures that pallet versions are also set at genesis. It does this by hooking into the runtime `GenesisConfig` which means that it will only work when the storage is setup using this genesis config. So, the version will not be set in pallet local tests. However, I think this isn't such a problem. The genesis config will call `on_genesis` on all pallets. This function comes from the new trait `OnGenesis`. Currently the user is not able to provide any custom implementation of this trait. Besides that it also implements `Clone` and `Copy` for the pallet version struct. This pr also moves the macro for generating the runtime genesis config to `frame-support` as most of the other FRAME related macros. * Reduce line width * Update frame/support/src/traits.rs Co-authored-by: Alexander Popiak <alexander.popiak@parity.io> Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
This commit is contained in:
@@ -20,9 +20,9 @@
|
||||
#![recursion_limit="128"]
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use sp_runtime::{generic, traits::{BlakeTwo256, Block as _, Verify}};
|
||||
use sp_runtime::{generic, traits::{BlakeTwo256, Block as _, Verify}, BuildStorage};
|
||||
use frame_support::{
|
||||
traits::{PALLET_VERSION_STORAGE_KEY_POSTFIX, PalletVersion, OnRuntimeUpgrade},
|
||||
traits::{PALLET_VERSION_STORAGE_KEY_POSTFIX, PalletVersion, OnRuntimeUpgrade, GetPalletVersion},
|
||||
crate_to_pallet_version, weights::Weight,
|
||||
};
|
||||
use sp_core::{H256, sr25519};
|
||||
@@ -173,3 +173,18 @@ fn on_runtime_upgrade_overwrites_old_version() {
|
||||
check_pallet_version("Module2_2");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn genesis_init_puts_pallet_version_into_storage() {
|
||||
let storage = GenesisConfig::default().build_storage().expect("Builds genesis storage");
|
||||
|
||||
sp_io::TestExternalities::new(storage).execute_with(|| {
|
||||
check_pallet_version("Module1");
|
||||
check_pallet_version("Module2");
|
||||
check_pallet_version("Module2_1");
|
||||
check_pallet_version("Module2_2");
|
||||
|
||||
let system_version = System::storage_version().expect("System version should be set");
|
||||
assert_eq!(System::current_version(), system_version);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user