I modified the template pallet from the substrate node template 681a9d8e3e8becf99aabf1cc76e1c08016db2e1a to contain a storage version:
const STORAGE_VERSION: StorageVersion = StorageVersion::new(123);
// -- snip --
#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);
Then I wrote the following test:
#[test]
fn storage_version_is_correct() {
new_test_ext().execute_with(|| {
assert_eq!(<Pallet<Test> as GetStorageVersion>::current_storage_version(), 123);
assert_eq!(<Pallet<Test> as GetStorageVersion>::on_chain_storage_version(), 123);
assert_eq!(StorageVersion::get::<Pallet<Test>>(), 123);
});
}
The first assert_eq!
succeeds, the other two fail. Is this expected behavior? I would have expected the storage version of the pallet to be written to storage at genesis. If this is expected behavior, why is this the case?
I expanded lib.rs
and found the following snippet:
impl<T: Config> frame_support::traits::OnGenesis for Pallet<T> {
fn on_genesis() {
let storage_version = STORAGE_VERSION;
storage_version.put::<Self>();
}
}
So it appears that the storage version is supposed to be written to the on-chain storage on genesis, right? Why didn't it happen in this case?