Add missing child trie rpc on_custom_message handler (#3522)

* missing on_custom for child read.

* fix and complete, add test cases.

* shorten line.

* replace vecs of key value tuple with maps.
This commit is contained in:
cheme
2019-09-01 02:19:54 +02:00
committed by Gavin Wood
parent 63c15c9803
commit 816e132cd7
7 changed files with 167 additions and 14 deletions
+35 -2
View File
@@ -23,6 +23,7 @@ pub mod trait_tests;
mod block_builder_ext;
use std::sync::Arc;
use std::collections::HashMap;
pub use block_builder_ext::BlockBuilderExt;
pub use generic_test_client::*;
pub use runtime;
@@ -97,7 +98,8 @@ pub type LightExecutor = client::light::call_executor::RemoteOrLocalCallExecutor
pub struct GenesisParameters {
support_changes_trie: bool,
heap_pages_override: Option<u64>,
extra_storage: Vec<(Vec<u8>, Vec<u8>)>,
extra_storage: HashMap<Vec<u8>, Vec<u8>>,
child_extra_storage: HashMap<Vec<u8>, HashMap<Vec<u8>, Vec<u8>>>,
}
impl GenesisParameters {
@@ -117,6 +119,7 @@ impl GenesisParameters {
1000,
self.heap_pages_override,
self.extra_storage.clone(),
self.child_extra_storage.clone(),
)
}
}
@@ -184,6 +187,18 @@ pub trait TestClientBuilderExt<B>: Sized {
/// # Panics
///
/// Panics if the key is empty.
fn add_extra_child_storage<SK: Into<Vec<u8>>, K: Into<Vec<u8>>, V: Into<Vec<u8>>>(
self,
storage_key: SK,
key: K,
value: V,
) -> Self;
/// Add an extra child value into the genesis storage.
///
/// # Panics
///
/// Panics if the key is empty.
fn add_extra_storage<K: Into<Vec<u8>>, V: Into<Vec<u8>>>(self, key: K, value: V) -> Self;
/// Build the test client.
@@ -214,10 +229,28 @@ impl<B> TestClientBuilderExt<B> for TestClientBuilder<
fn add_extra_storage<K: Into<Vec<u8>>, V: Into<Vec<u8>>>(mut self, key: K, value: V) -> Self {
let key = key.into();
assert!(!key.is_empty());
self.genesis_init_mut().extra_storage.push((key, value.into()));
self.genesis_init_mut().extra_storage.insert(key, value.into());
self
}
fn add_extra_child_storage<SK: Into<Vec<u8>>, K: Into<Vec<u8>>, V: Into<Vec<u8>>>(
mut self,
storage_key: SK,
key: K,
value: V,
) -> Self {
let storage_key = storage_key.into();
let key = key.into();
assert!(!storage_key.is_empty());
assert!(!key.is_empty());
self.genesis_init_mut().child_extra_storage
.entry(storage_key)
.or_insert_with(Default::default)
.insert(key, value.into());
self
}
fn build_with_longest_chain(self) -> (Client<B>, client::LongestChain<B, runtime::Block>) {
self.build_with_native_executor(None)
}