Eradicate native_equivalent (#3494)

* Add ability to supply extra storage in test-client

* Don't use native_equivalent in tests.

* Get rid of native_equivalent

* Try to make fields private

* Apply Basti's suggestions

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Sergei Pepyakin
2019-08-27 22:20:47 +02:00
committed by GitHub
parent 095c7de7ff
commit 36ef4c067b
9 changed files with 70 additions and 51 deletions
+38 -20
View File
@@ -51,8 +51,7 @@ mod local_executor {
native_executor_instance!(
pub LocalExecutor,
runtime::api::dispatch,
runtime::native_version,
runtime::WASM_BINARY
runtime::native_version
);
}
@@ -97,12 +96,34 @@ 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>)>,
}
impl GenesisParameters {
fn genesis_config(&self) -> GenesisConfig {
GenesisConfig::new(
self.support_changes_trie,
vec![
sr25519::Public::from(Sr25519Keyring::Alice).into(),
sr25519::Public::from(Sr25519Keyring::Bob).into(),
sr25519::Public::from(Sr25519Keyring::Charlie).into(),
],
vec![
AccountKeyring::Alice.into(),
AccountKeyring::Bob.into(),
AccountKeyring::Charlie.into(),
],
1000,
self.heap_pages_override,
self.extra_storage.clone(),
)
}
}
impl generic_test_client::GenesisInit for GenesisParameters {
fn genesis_storage(&self) -> (StorageOverlay, ChildrenStorageOverlay) {
use codec::Encode;
let mut storage = genesis_config(self.support_changes_trie, self.heap_pages_override).genesis_map();
let mut storage = self.genesis_config().genesis_map();
let child_roots = storage.1.iter().map(|(sk, child_map)| {
let state_root = <<<runtime::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
@@ -157,6 +178,13 @@ pub trait TestClientBuilderExt<B>: Sized {
/// Override the default value for Wasm heap pages.
fn set_heap_pages(self, heap_pages: u64) -> Self;
/// Add an extra 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.
fn build(self) -> Client<B> {
self.build_with_longest_chain().0
@@ -182,28 +210,18 @@ impl<B> TestClientBuilderExt<B> for TestClientBuilder<
self
}
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
}
fn build_with_longest_chain(self) -> (Client<B>, client::LongestChain<B, runtime::Block>) {
self.build_with_native_executor(None)
}
}
fn genesis_config(support_changes_trie: bool, heap_pages_override: Option<u64>) -> GenesisConfig {
GenesisConfig::new(
support_changes_trie,
vec![
sr25519::Public::from(Sr25519Keyring::Alice).into(),
sr25519::Public::from(Sr25519Keyring::Bob).into(),
sr25519::Public::from(Sr25519Keyring::Charlie).into(),
], vec![
AccountKeyring::Alice.into(),
AccountKeyring::Bob.into(),
AccountKeyring::Charlie.into(),
],
1000,
heap_pages_override,
)
}
/// Creates new client instance used for tests.
pub fn new() -> Client<Backend> {
TestClientBuilder::new().build()