mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 22:51:13 +00:00
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:
@@ -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()
|
||||
|
||||
@@ -25,10 +25,12 @@ use sr_primitives::traits::{Block as BlockT, Hash as HashT, Header as HeaderT};
|
||||
|
||||
/// Configuration of a general Substrate test genesis block.
|
||||
pub struct GenesisConfig {
|
||||
pub changes_trie_config: Option<ChangesTrieConfiguration>,
|
||||
pub authorities: Vec<AuthorityId>,
|
||||
pub balances: Vec<(AccountId, u64)>,
|
||||
pub heap_pages_override: Option<u64>,
|
||||
changes_trie_config: Option<ChangesTrieConfiguration>,
|
||||
authorities: Vec<AuthorityId>,
|
||||
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>)>,
|
||||
}
|
||||
|
||||
impl GenesisConfig {
|
||||
@@ -38,6 +40,7 @@ impl GenesisConfig {
|
||||
endowed_accounts: Vec<AccountId>,
|
||||
balance: u64,
|
||||
heap_pages_override: Option<u64>,
|
||||
extra_storage: Vec<(Vec<u8>, Vec<u8>)>,
|
||||
) -> Self {
|
||||
GenesisConfig {
|
||||
changes_trie_config: match support_changes_trie {
|
||||
@@ -47,6 +50,7 @@ impl GenesisConfig {
|
||||
authorities: authorities.clone(),
|
||||
balances: endowed_accounts.into_iter().map(|a| (a, balance)).collect(),
|
||||
heap_pages_override,
|
||||
extra_storage,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +74,10 @@ impl GenesisConfig {
|
||||
map.insert(well_known_keys::CHANGES_TRIE_CONFIG.to_vec(), changes_trie_config.encode());
|
||||
}
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user