Implement a proper generic resolution in decl_storage! (#2913)

* Add failing test case

* move storage maps to blake2_128 (#2268)

* remove default hash, introduce twox_128 and blake2

* use blake2_128 & create ext_blake2_128

* refactor code

* add benchmark

* factorize generator

* fix

* parameterizable hasher

* some fix

* fix

* fix

* fix

* metadata

* fix

* remove debug print

* map -> blake2_256

* fix test

* fix test

* Apply suggestions from code review

Co-Authored-By: thiolliere <gui.thiolliere@gmail.com>

* impl twox 128 concat (#2353)

* impl twox_128_concat

* comment addressed

* fix

* impl twox_128->64_concat

* fix test

* Fix compilation and cleanup some docs

* Lol

* Remove traits from storage types that are not generic

* Get instance test almost working as wanted

* Make `srml-support-test` compile again :)

* Fixes test of srml-support

* Fix compilation

* Break some lines

* Remove incorrect macro match arm

* Integrates review feedback

* Update documentation

* Fix compilation
This commit is contained in:
Bastian Köcher
2019-06-27 13:40:22 +02:00
committed by GitHub
parent 23ea5d1795
commit 62b7c05def
55 changed files with 1441 additions and 860 deletions
@@ -17,7 +17,6 @@
use runtime_io::{with_externalities, Blake2Hasher};
use srml_support::{StorageValue, StorageMap, StorageDoubleMap};
use srml_support::storage::unhashed;
use srml_support::runtime_primitives::BuildStorage;
use parity_codec::{Encode, Decode};
pub trait Trait {
@@ -60,37 +59,37 @@ fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
#[test]
fn final_keys() {
with_externalities(&mut new_test_ext(), || {
<Value<Test>>::put(1);
Value::put(1);
assert_eq!(unhashed::get::<u32>(&runtime_io::twox_128(b"Module Value")), Some(1u32));
<Map<Test>>::insert(1, 2);
Map::insert(1, 2);
let mut k = b"Module Map".to_vec();
k.extend(1u32.encode());
assert_eq!(unhashed::get::<u32>(&runtime_io::blake2_256(&k)), Some(2u32));
<Map2<Test>>::insert(1, 2);
Map2::insert(1, 2);
let mut k = b"Module Map2".to_vec();
k.extend(1u32.encode());
assert_eq!(unhashed::get::<u32>(&runtime_io::twox_128(&k)), Some(2u32));
<LinkedMap<Test>>::insert(1, 2);
LinkedMap::insert(1, 2);
let mut k = b"Module LinkedMap".to_vec();
k.extend(1u32.encode());
assert_eq!(unhashed::get::<u32>(&runtime_io::blake2_256(&k)), Some(2u32));
<LinkedMap2<Test>>::insert(1, 2);
LinkedMap2::insert(1, 2);
let mut k = b"Module LinkedMap2".to_vec();
k.extend(1u32.encode());
assert_eq!(unhashed::get::<u32>(&runtime_io::twox_128(&k)), Some(2u32));
<DoubleMap<Test>>::insert(1, 2, 3);
DoubleMap::insert(1, 2, 3);
let mut k = b"Module DoubleMap".to_vec();
k.extend(1u32.encode());
let mut k = runtime_io::blake2_256(&k).to_vec();
k.extend(&runtime_io::blake2_256(&2u32.encode()));
assert_eq!(unhashed::get::<u32>(&k), Some(3u32));
<DoubleMap2<Test>>::insert(1, 2, 3);
DoubleMap2::insert(1, 2, 3);
let mut k = b"Module DoubleMap2".to_vec();
k.extend(1u32.encode());
let mut k = runtime_io::twox_128(&k).to_vec();