-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pallet prefix runtime test #573
Conversation
let prefix = |pallet_name, storage_name| { | ||
let mut res = [0u8; 32]; | ||
res[0..16].copy_from_slice(&Twox128::hash(pallet_name)); | ||
res[16..32].copy_from_slice(&Twox128::hash(storage_name)); | ||
res | ||
}; | ||
assert_eq!( | ||
<moonbase_runtime::Sudo as StorageInfoTrait>::storage_info(), | ||
vec![StorageInfo { | ||
prefix: prefix(b"Sudo", b"Key"), | ||
max_values: Some(1), | ||
max_size: Some(20), | ||
}] | ||
); |
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.
Unfortunately some pallet instances do not implement StorageInfoTrait
so I cannot do this test for all pallets. I can remove it if we're satisfied with the above tests.
It still may be worth having some test like this for all storage items in all pallets to ensure the entire storage key does not change with any runtime changes. The tests further above only test the consistency of the pallet prefix part of the storage key.
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.
I like better the test where it queries from a storage item, as it is closer to the actual usage done by the runtime.
But both are good
let prefix = |pallet_name, storage_name| { | ||
let mut res = [0u8; 32]; | ||
res[0..16].copy_from_slice(&Twox128::hash(pallet_name)); | ||
res[16..32].copy_from_slice(&Twox128::hash(storage_name)); | ||
res | ||
}; | ||
assert_eq!( | ||
<moonbase_runtime::Sudo as StorageInfoTrait>::storage_info(), | ||
vec![StorageInfo { | ||
prefix: prefix(b"Sudo", b"Key"), | ||
max_values: Some(1), | ||
max_size: Some(20), | ||
}] | ||
); |
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.
I like better the test where it queries from a storage item, as it is closer to the actual usage done by the runtime.
But both are good
@thiolliere do you know of a more direct way to check that the pallet prefix part of the storage keys match our expectations? The goal is a test that tells us if/when the pallet prefix changes in a way that changes the storage keys. I'd prefer to use the
|
The trait StorageInfoTrait was implemented only when the attribute |
Thank you! I'll use |
…PartialStorageInfo instead of PalletInfo::name() for other prefixes
in the commit, it is StorageInfoTrait which is implemented for all pallets struct. So you can call |
…com/PureStake/moonbeam into amar-verify-storage-pallet-prefixes
Adds a test to tell us if the pallet prefixes for each runtime ever change.
the tested pallet prefix is used to determine the storage key for all storage items in the pallet
The test verifies that the String passed in as an arg matches the
pallet_prefix()
method on the implementation ofStorageInstance
for all storage items in the given pallet (here). The methodpallet_prefix()
(from theStorageInstance
trait) is used in the calculation of the unique storage key in the implementation ofStorageValue
(and all the other storage item types in their respective implementatons).