From 44748dae22da9f28ebd66e0aac2e1c3866666bf9 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Wed, 1 Dec 2021 15:57:21 +0300 Subject: [PATCH] Fix storage parameter name computation (#1238) * fixed storage_parameter_key * added test for storage_parameter_key --- primitives/runtime/Cargo.toml | 3 +++ primitives/runtime/src/lib.rs | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/primitives/runtime/Cargo.toml b/primitives/runtime/Cargo.toml index 944f84a6c68..7cc165fb4e9 100644 --- a/primitives/runtime/Cargo.toml +++ b/primitives/runtime/Cargo.toml @@ -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 = [ diff --git a/primitives/runtime/src/lib.rs b/primitives/runtime/src/lib.rs index 460f1b19dfe..051dc1f43c0 100644 --- a/primitives/runtime/src/lib.rs +++ b/primitives/runtime/src/lib.rs @@ -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()), + ); + } +}