If only one hasher, always treat any key as a single and not NMap key, even if it's a tuple. (#2010)

* If only one hasher, always treat any key as a single and not DoubleMap or NMap key

* Fix test

* Make the dyanmic storage key handling match our codegen handling
This commit is contained in:
James Wilson
2025-06-02 15:18:00 +01:00
committed by GitHub
parent dfb4b2f68a
commit a4331dfa08
3 changed files with 78 additions and 66 deletions
@@ -72,7 +72,7 @@ async fn storage_n_mapish_key_is_properly_created() -> Result<(), subxt::Error>
// This is what the generated code hashes a `session().key_owner(..)` key into:
let actual_key = node_runtime::storage()
.session()
.key_owner(KeyTypeId([1, 2, 3, 4]), vec![5, 6, 7, 8]);
.key_owner((KeyTypeId([1, 2, 3, 4]), vec![5, 6, 7, 8]));
let actual_key_bytes = api.storage().address_bytes(&actual_key)?;
// Let's manually hash to what we assume it should be and compare:
@@ -80,13 +80,12 @@ async fn storage_n_mapish_key_is_properly_created() -> Result<(), subxt::Error>
// Hash the prefix to the storage entry:
let mut bytes = sp_core::twox_128("Session".as_bytes()).to_vec();
bytes.extend(&sp_core::twox_128("KeyOwner".as_bytes())[..]);
// Both keys, use twox64_concat hashers:
let key1 = [1u8, 2, 3, 4].encode();
let key2 = vec![5u8, 6, 7, 8].encode();
bytes.extend(sp_core::twox_64(&key1));
bytes.extend(&key1);
bytes.extend(sp_core::twox_64(&key2));
bytes.extend(&key2);
// Key is a tuple of 2 args, so encode each arg and then hash the concatenation:
let mut key_bytes = vec![];
[1u8, 2, 3, 4].encode_to(&mut key_bytes);
vec![5u8, 6, 7, 8].encode_to(&mut key_bytes);
bytes.extend(sp_core::twox_64(&key_bytes));
bytes.extend(&key_bytes);
bytes
};