mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 08:07:58 +00:00
Support NMap in generate_storage_alias (#9147)
* Support NMap in generate_storage_alias * Verify that 2-key NMap is identical to DoubleMap * Also compare key hashes and make sure they're identical * Fix and add tests for 1-tuple NMap generated by generate_storage_alias
This commit is contained in:
@@ -433,6 +433,26 @@ mod test_iterators {
|
||||
prefix
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn n_map_double_map_identical_key() {
|
||||
sp_io::TestExternalities::default().execute_with(|| {
|
||||
NMap::insert((1, 2), 50);
|
||||
let key_hash = NMap::hashed_key_for((1, 2));
|
||||
|
||||
{
|
||||
crate::generate_storage_alias!(Test, NMap => DoubleMap<
|
||||
(u16, crate::Blake2_128Concat),
|
||||
(u32, crate::Twox64Concat),
|
||||
u64
|
||||
>);
|
||||
|
||||
let value = NMap::get(1, 2).unwrap();
|
||||
assert_eq!(value, 50);
|
||||
assert_eq!(NMap::hashed_key_for(1, 2), key_hash);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn n_map_reversible_reversible_iteration() {
|
||||
sp_io::TestExternalities::default().execute_with(|| {
|
||||
|
||||
@@ -110,7 +110,7 @@ impl<H: StorageHasher, K: FullCodec> KeyGeneratorInner for Key<H, K> {
|
||||
}
|
||||
}
|
||||
|
||||
#[impl_trait_for_tuples::impl_for_tuples(2, 18)]
|
||||
#[impl_trait_for_tuples::impl_for_tuples(1, 18)]
|
||||
#[tuple_types_custom_trait_bound(KeyGeneratorInner)]
|
||||
impl KeyGenerator for Tuple {
|
||||
for_tuples!( type Key = ( #(Tuple::Key),* ); );
|
||||
@@ -150,7 +150,7 @@ impl KeyGenerator for Tuple {
|
||||
}
|
||||
}
|
||||
|
||||
#[impl_trait_for_tuples::impl_for_tuples(2, 18)]
|
||||
#[impl_trait_for_tuples::impl_for_tuples(1, 18)]
|
||||
#[tuple_types_custom_trait_bound(KeyGeneratorInner + KeyGeneratorMaxEncodedLen)]
|
||||
impl KeyGeneratorMaxEncodedLen for Tuple {
|
||||
fn key_max_encoded_len() -> usize {
|
||||
|
||||
@@ -423,7 +423,7 @@ mod test {
|
||||
fn pallet_prefix() -> &'static str {
|
||||
"test"
|
||||
}
|
||||
const STORAGE_PREFIX: &'static str = "foo";
|
||||
const STORAGE_PREFIX: &'static str = "Foo";
|
||||
}
|
||||
|
||||
struct ADefault;
|
||||
@@ -445,7 +445,7 @@ mod test {
|
||||
TestExternalities::default().execute_with(|| {
|
||||
let mut k: Vec<u8> = vec![];
|
||||
k.extend(&twox_128(b"test"));
|
||||
k.extend(&twox_128(b"foo"));
|
||||
k.extend(&twox_128(b"Foo"));
|
||||
k.extend(&3u16.blake2_128_concat());
|
||||
assert_eq!(A::hashed_key_for((&3,)).to_vec(), k);
|
||||
|
||||
@@ -458,6 +458,16 @@ mod test {
|
||||
assert_eq!(A::get((3,)), Some(10));
|
||||
assert_eq!(AValueQueryWithAnOnEmpty::get((3,)), 10);
|
||||
|
||||
{
|
||||
crate::generate_storage_alias!(test, Foo => NMap<
|
||||
(u16, Blake2_128Concat),
|
||||
u32
|
||||
>);
|
||||
|
||||
assert_eq!(Foo::contains_key((3,)), true);
|
||||
assert_eq!(Foo::get((3,)), Some(10));
|
||||
}
|
||||
|
||||
A::swap::<Key<Blake2_128Concat, u16>, _, _>((3,), (2,));
|
||||
assert_eq!(A::contains_key((3,)), false);
|
||||
assert_eq!(A::contains_key((2,)), true);
|
||||
@@ -575,7 +585,7 @@ mod test {
|
||||
AValueQueryWithAnOnEmpty::MODIFIER,
|
||||
StorageEntryModifier::Default
|
||||
);
|
||||
assert_eq!(A::NAME, "foo");
|
||||
assert_eq!(A::NAME, "Foo");
|
||||
assert_eq!(
|
||||
AValueQueryWithAnOnEmpty::DEFAULT.0.default_byte(),
|
||||
98u32.encode()
|
||||
@@ -617,7 +627,7 @@ mod test {
|
||||
TestExternalities::default().execute_with(|| {
|
||||
let mut k: Vec<u8> = vec![];
|
||||
k.extend(&twox_128(b"test"));
|
||||
k.extend(&twox_128(b"foo"));
|
||||
k.extend(&twox_128(b"Foo"));
|
||||
k.extend(&3u16.blake2_128_concat());
|
||||
k.extend(&30u8.twox_64_concat());
|
||||
assert_eq!(A::hashed_key_for((3, 30)).to_vec(), k);
|
||||
@@ -761,7 +771,7 @@ mod test {
|
||||
AValueQueryWithAnOnEmpty::MODIFIER,
|
||||
StorageEntryModifier::Default
|
||||
);
|
||||
assert_eq!(A::NAME, "foo");
|
||||
assert_eq!(A::NAME, "Foo");
|
||||
assert_eq!(
|
||||
AValueQueryWithAnOnEmpty::DEFAULT.0.default_byte(),
|
||||
98u32.encode()
|
||||
@@ -844,7 +854,7 @@ mod test {
|
||||
TestExternalities::default().execute_with(|| {
|
||||
let mut k: Vec<u8> = vec![];
|
||||
k.extend(&twox_128(b"test"));
|
||||
k.extend(&twox_128(b"foo"));
|
||||
k.extend(&twox_128(b"Foo"));
|
||||
k.extend(&1u16.blake2_128_concat());
|
||||
k.extend(&10u16.blake2_128_concat());
|
||||
k.extend(&100u16.twox_64_concat());
|
||||
@@ -996,7 +1006,7 @@ mod test {
|
||||
AValueQueryWithAnOnEmpty::MODIFIER,
|
||||
StorageEntryModifier::Default
|
||||
);
|
||||
assert_eq!(A::NAME, "foo");
|
||||
assert_eq!(A::NAME, "Foo");
|
||||
assert_eq!(
|
||||
AValueQueryWithAnOnEmpty::DEFAULT.0.default_byte(),
|
||||
98u32.encode()
|
||||
|
||||
Reference in New Issue
Block a user