srml_support storage reorganize (#3344)

* impl

* file split

* old comment

* better error message

* WIP

* basti test works

* comment

* remove old files

* impl swap for storage map

* fix

* fix and comment

* code refactor

* code refactor

* code format

* code refactor

* fix

* fix

* fix

* document generators

* license

* doc

* doc

* fmt

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* some comment addressed

* storage_items small refactor

* fix storage_items

* more precise returned type

* fix

* code fmt suggestion

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* remove box allocation

* bump version

* rename function as behavior has changed

* fix doc
This commit is contained in:
thiolliere
2019-08-29 17:04:46 +02:00
committed by Bastian Köcher
parent 7126ade259
commit 9900562389
38 changed files with 1468 additions and 2201 deletions
+30 -32
View File
@@ -42,9 +42,7 @@ mod tests {
use codec::{Encode, Decode, Joiner};
use runtime_support::{Hashable, StorageValue, StorageMap, assert_eq_error_rate, traits::Currency};
use state_machine::{CodeExecutor, Externalities, TestExternalities as CoreTestExternalities};
use primitives::{
twox_128, blake2_256, Blake2Hasher, NeverNativeValue, NativeOrEncoded, map
};
use primitives::{Blake2Hasher, NeverNativeValue, NativeOrEncoded, map};
use sr_primitives::traits::{Header as HeaderT, Hash as HashT, Convert};
use sr_primitives::{ApplyOutcome, ApplyError, ApplyResult};
use sr_primitives::weights::{WeightMultiplier, GetDispatchInfo};
@@ -122,16 +120,16 @@ mod tests {
#[test]
fn panic_execution_with_foreign_code_gives_error() {
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(BLOATY_CODE, (map![
blake2_256(&<balances::FreeBalance<Runtime>>::key_for(alice())).to_vec() => {
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
69_u128.encode()
},
twox_128(<balances::TotalIssuance<Runtime>>::key()).to_vec() => {
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
69_u128.encode()
},
twox_128(<indices::NextEnumSet<Runtime>>::key()).to_vec() => {
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => {
0_u128.encode()
},
blake2_256(&<system::BlockHash<Runtime>>::key_for(0)).to_vec() => {
<system::BlockHash<Runtime>>::hashed_key_for(0) => {
vec![0u8; 32]
}
], map![]));
@@ -158,16 +156,16 @@ mod tests {
#[test]
fn bad_extrinsic_with_native_equivalent_code_gives_error() {
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, (map![
blake2_256(&<balances::FreeBalance<Runtime>>::key_for(alice())).to_vec() => {
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
69_u128.encode()
},
twox_128(<balances::TotalIssuance<Runtime>>::key()).to_vec() => {
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
69_u128.encode()
},
twox_128(<indices::NextEnumSet<Runtime>>::key()).to_vec() => {
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => {
0_u128.encode()
},
blake2_256(&<system::BlockHash<Runtime>>::key_for(0)).to_vec() => {
<system::BlockHash<Runtime>>::hashed_key_for(0) => {
vec![0u8; 32]
}
], map![]));
@@ -194,14 +192,14 @@ mod tests {
#[test]
fn successful_execution_with_native_equivalent_code_gives_ok() {
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, (map![
blake2_256(&<balances::FreeBalance<Runtime>>::key_for(alice())).to_vec() => {
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
(111 * DOLLARS).encode()
},
twox_128(<balances::TotalIssuance<Runtime>>::key()).to_vec() => {
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
(111 * DOLLARS).encode()
},
twox_128(<indices::NextEnumSet<Runtime>>::key()).to_vec() => vec![0u8; 16],
blake2_256(&<system::BlockHash<Runtime>>::key_for(0)).to_vec() => vec![0u8; 32]
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
<system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
], map![]));
let r = executor().call::<_, NeverNativeValue, fn() -> _>(
@@ -230,14 +228,14 @@ mod tests {
#[test]
fn successful_execution_with_foreign_code_gives_ok() {
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(BLOATY_CODE, (map![
blake2_256(&<balances::FreeBalance<Runtime>>::key_for(alice())).to_vec() => {
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
(111 * DOLLARS).encode()
},
twox_128(<balances::TotalIssuance<Runtime>>::key()).to_vec() => {
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
(111 * DOLLARS).encode()
},
twox_128(<indices::NextEnumSet<Runtime>>::key()).to_vec() => vec![0u8; 16],
blake2_256(&<system::BlockHash<Runtime>>::key_for(0)).to_vec() => vec![0u8; 32]
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
<system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
], map![]));
let r = executor().call::<_, NeverNativeValue, fn() -> _>(
@@ -749,14 +747,14 @@ mod tests {
#[test]
fn panic_execution_gives_error() {
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(BLOATY_CODE, (map![
blake2_256(&<balances::FreeBalance<Runtime>>::key_for(alice())).to_vec() => {
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
0_u128.encode()
},
twox_128(<balances::TotalIssuance<Runtime>>::key()).to_vec() => {
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
0_u128.encode()
},
twox_128(<indices::NextEnumSet<Runtime>>::key()).to_vec() => vec![0u8; 16],
blake2_256(&<system::BlockHash<Runtime>>::key_for(0)).to_vec() => vec![0u8; 32]
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
<system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
], map![]));
let r = WasmExecutor::new()
@@ -771,14 +769,14 @@ mod tests {
#[test]
fn successful_execution_gives_ok() {
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, (map![
blake2_256(&<balances::FreeBalance<Runtime>>::key_for(alice())).to_vec() => {
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
(111 * DOLLARS).encode()
},
twox_128(<balances::TotalIssuance<Runtime>>::key()).to_vec() => {
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
(111 * DOLLARS).encode()
},
twox_128(<indices::NextEnumSet<Runtime>>::key()).to_vec() => vec![0u8; 16],
blake2_256(&<system::BlockHash<Runtime>>::key_for(0)).to_vec() => vec![0u8; 32]
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
<system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
], map![]));
let r = WasmExecutor::new()
@@ -928,17 +926,17 @@ mod tests {
// - 1 milldot based on current polkadot runtime.
// (this baed on assigning 0.1 CENT to the cheapest tx with `weight = 100`)
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, (map![
blake2_256(&<balances::FreeBalance<Runtime>>::key_for(alice())).to_vec() => {
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
(100 * DOLLARS).encode()
},
blake2_256(&<balances::FreeBalance<Runtime>>::key_for(bob())).to_vec() => {
<balances::FreeBalance<Runtime>>::hashed_key_for(bob()) => {
(10 * DOLLARS).encode()
},
twox_128(<balances::TotalIssuance<Runtime>>::key()).to_vec() => {
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
(110 * DOLLARS).encode()
},
twox_128(<indices::NextEnumSet<Runtime>>::key()).to_vec() => vec![0u8; 16],
blake2_256(&<system::BlockHash<Runtime>>::key_for(0)).to_vec() => vec![0u8; 32]
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
<system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
], map![]));
let tip = 1_000_000;