Skip to content

Commit

Permalink
Fix storage parameter name computation (paritytech#1238)
Browse files Browse the repository at this point in the history
* fixed storage_parameter_key

* added test for storage_parameter_key
  • Loading branch information
svyatonik authored Dec 1, 2021
1 parent 8c8d6d4 commit 44748da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions primitives/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }

[dev-dependencies]
hex-literal = "0.3"

[features]
default = ["std"]
std = [
Expand Down
16 changes: 14 additions & 2 deletions primitives/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,22 @@ pub fn storage_map_final_key_identity(
///
/// Copied from `frame_support::parameter_types` macro
pub fn storage_parameter_key(parameter_name: &str) -> StorageKey {
let mut buffer = Vec::with_capacity(1 + parameter_name.len() + 1 + 1);
let mut buffer = Vec::with_capacity(1 + parameter_name.len() + 1);
buffer.push(b':');
buffer.extend_from_slice(parameter_name.as_bytes());
buffer.push(b':');
buffer.push(0);
StorageKey(sp_io::hashing::twox_128(&buffer).to_vec())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn storage_parameter_key_works() {
assert_eq!(
storage_parameter_key("MillauToRialtoConversionRate"),
StorageKey(hex_literal::hex!("58942375551bb0af1682f72786b59d04").to_vec()),
);
}
}

0 comments on commit 44748da

Please sign in to comment.