Fix storage parameter name computation (#1238)

* fixed storage_parameter_key

* added test for storage_parameter_key
This commit is contained in:
Svyatoslav Nikolsky
2021-12-01 15:57:21 +03:00
committed by Bastian Köcher
parent 1fb70c7ed7
commit edd1724957
2 changed files with 17 additions and 2 deletions
+3
View File
@@ -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 = [
+14 -2
View File
@@ -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()),
);
}
}