mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 20:01:08 +00:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,8 @@ pub struct GenesisConfig {
|
||||
balances: Vec<(AccountId, u64)>,
|
||||
heap_pages_override: Option<u64>,
|
||||
/// Additional storage key pairs that will be added to the genesis map.
|
||||
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 GenesisConfig {
|
||||
@@ -40,7 +41,8 @@ impl GenesisConfig {
|
||||
endowed_accounts: Vec<AccountId>,
|
||||
balance: u64,
|
||||
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>>>,
|
||||
) -> Self {
|
||||
GenesisConfig {
|
||||
changes_trie_config: match support_changes_trie {
|
||||
@@ -51,6 +53,7 @@ impl GenesisConfig {
|
||||
balances: endowed_accounts.into_iter().map(|a| (a, balance)).collect(),
|
||||
heap_pages_override,
|
||||
extra_storage,
|
||||
child_extra_storage,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,10 +78,9 @@ impl GenesisConfig {
|
||||
}
|
||||
map.insert(twox_128(&b"sys:auth"[..])[..].to_vec(), self.authorities.encode());
|
||||
// Finally, add the extra storage entries.
|
||||
for (key, value) in self.extra_storage.iter().cloned() {
|
||||
map.insert(key, value);
|
||||
}
|
||||
(map, Default::default())
|
||||
map.extend(self.extra_storage.clone().into_iter());
|
||||
|
||||
(map, self.child_extra_storage.clone())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user