This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Initialize on-chain StorageVersion
for pallets added after genesis
#14641
Open
liamaharon
wants to merge
12
commits into
master
Choose a base branch
from
liam-init-pallet-on-chain-version-after-genesis
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cc59e22
init on-chain storage version
liamaharon b56c7cd
fix comment
liamaharon 0cfa0b8
refactor pallet_name repetition
liamaharon 7083af8
use frame_support::traits::Get
liamaharon 3e9ae52
init on-chain versions for pallet without a current version
liamaharon 06ab262
add tests
liamaharon b8e1310
fix test
liamaharon 424455b
put the default version
liamaharon 6f67951
kick ci
liamaharon aa0aa80
kick ci
liamaharon 498d6f9
Merge branch 'master' of github.com:paritytech/substrate into liam-in…
liamaharon ab51996
Update frame/support/procedural/src/pallet/expand/hooks.rs
liamaharon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2110,6 +2110,54 @@ fn test_storage_alias() { | |
}) | ||
} | ||
|
||
#[test] | ||
fn pallet_on_chain_storage_version_initializes_correctly() { | ||
type Executive = frame_executive::Executive< | ||
Runtime, | ||
Block, | ||
frame_system::ChainContext<Runtime>, | ||
Runtime, | ||
AllPalletsWithSystem, | ||
>; | ||
|
||
// Simple example of a pallet with current version 10 being added to the runtime for the first | ||
// time. | ||
TestExternalities::default().execute_with(|| { | ||
let current_version = Example::current_storage_version(); | ||
|
||
// Check the on-chain storage version initially is not set and does not match the current | ||
// version. | ||
let on_chain_version_before = StorageVersion::get::<Example>(); | ||
assert_eq!(StorageVersion::exists::<Example>(), false); | ||
assert_ne!(on_chain_version_before, current_version); | ||
|
||
// OnRuntimeUpgrade calls pallet `before_all` hook which initializes the storage version. | ||
Executive::execute_on_runtime_upgrade(); | ||
|
||
// Check that the storage version was initialized to the current version | ||
let on_chain_version_after = StorageVersion::get::<Example>(); | ||
assert_eq!(on_chain_version_after, current_version); | ||
}); | ||
|
||
// Pallet with no current storage version should have the on-chain version initialized to 0. | ||
TestExternalities::default().execute_with(|| { | ||
// Example4 current_storage_version is NoStorageVersionSet. | ||
|
||
// Check the storage version is not set and implicitly 0. | ||
let on_chain_version_before = StorageVersion::get::<Example4>(); | ||
assert_eq!(StorageVersion::exists::<Example4>(), false); | ||
assert_eq!(on_chain_version_before, StorageVersion::new(0)); | ||
|
||
// OnRuntimeUpgrade calls pallet `before_all` hook which initializes the storage version. | ||
Executive::execute_on_runtime_upgrade(); | ||
|
||
// Check that the storage version now exists and was initialized to 0. | ||
let on_chain_version_after = StorageVersion::get::<Example4>(); | ||
assert_eq!(StorageVersion::exists::<Example4>(), true); | ||
assert_eq!(on_chain_version_after, StorageVersion::new(0)); | ||
}); | ||
} | ||
|
||
#[cfg(feature = "try-runtime")] | ||
#[test] | ||
fn post_runtime_upgrade_detects_storage_version_issues() { | ||
|
@@ -2164,6 +2212,10 @@ fn post_runtime_upgrade_detects_storage_version_issues() { | |
TestExternalities::default().execute_with(|| { | ||
// Call `on_genesis` to put the storage version of `Example` into the storage. | ||
Example::on_genesis(); | ||
|
||
// Set the on-chain version to something different to the current version | ||
StorageVersion::new(100).put::<Example>(); | ||
Comment on lines
+2216
to
+2217
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. otherwise the new before_all hook will init it to the correct value |
||
|
||
// The version isn't changed, we should detect it. | ||
assert!( | ||
Executive::try_runtime_upgrade(UpgradeCheckSelect::PreAndPost).unwrap_err() == | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be cool if there was some way I could assert this. Any ideas?