Cumulus changes version 2 (#2313)

* ensure imbalances are properly accounted for (#2183)

* ensure imbalances are properly accounted for

* bump runtime version

* Update node/runtime/src/lib.rs

* implement contract events (#2161)

* implement contract events

* update runtime

* renaming

* update test code hash

* improve complexity details

* add deposit event base cost

* add test

* Revert "add deposit event base cost"

This reverts commit 58ec010c0f4f4f0e16935ad41da32aedd17a8c57.

* update test

* Revert "update test"

This reverts commit 6fe61a593ccf0d41f09a0b97472b28ed8751a999.

* Revert "Revert "add deposit event base cost""

This reverts commit 145e8a9bac15313a4c380aa66b94fd4d36fa3f6d.

* Fix format a bit

*  Replace Vec<u8> with [u8; 32] for contract storage key (#2184)

* Replace Vec<u8> with [u8; 32] for contract storage key

* Read storage keys from sandbox memory into fixed size buffer

* Increment `impl_version`

* Remove redundant Ok(()) and explicitly specify StorageKey buffer type (#2188)

* Switch to `derive(Encode, Decode)` for `Call` (#2178)

* Add some tests

* More tests

* Switch to `derive(Encode, Decode)` for `Call`

* Update lock files

* Simplify the macro cases

* Cache changes trie config in db storage (#2170)

* cache changes trie config in db storage

* Update core/client/db/src/lib.rs

Co-Authored-By: svyatonik <svyatonik@gmail.com>

* Update core/client/db/src/lib.rs

Co-Authored-By: svyatonik <svyatonik@gmail.com>

* Fix version check for renamed runtime api methods (#2190)

* Add feature to disable including the test-runtime wasm blob

* Enable `std` feature for `consensus_authorities`

* Implement `skip_initialize_block` and `initialize_block` for runtime api

* Add test and fixes bug

* Begin to implement support for passing the `ProofRecorder`

* Make sure proof generation works as intended

* Fixes tests

* Make `BlockBuilder` generate proofs on request.

* Adds `TestClientBuilder` to simplify creating a test client

* Add `include-wasm-blob` to `test-client` as well

* Make `test-client` compile without including the wasm file

* Disable more stuff in test-client without wasm

* Reorganize the re-exports

* Use correct bounds

* Update docs

* Update core/client/src/block_builder/block_builder.rs

Co-Authored-By: bkchr <bkchr@users.noreply.github.com>

* Extend test to actually generated proof

* Switch to enum for `skip_initialize_block`

* Some wasm files updates
This commit is contained in:
Bastian Köcher
2019-04-29 16:55:20 +02:00
committed by GitHub
parent bb9746c798
commit bad3ce4e17
27 changed files with 800 additions and 267 deletions
+26 -8
View File
@@ -17,7 +17,10 @@
//! Client extension for tests.
use client::{self, Client};
use consensus::{ImportBlock, BlockImport, BlockOrigin, Error as ConsensusError, ForkChoiceStrategy};
use consensus::{
ImportBlock, BlockImport, BlockOrigin, Error as ConsensusError,
ForkChoiceStrategy,
};
use runtime_primitives::Justification;
use runtime_primitives::generic::BlockId;
use primitives::Blake2Hasher;
@@ -31,11 +34,19 @@ pub trait TestClient: Sized {
-> Result<(), ConsensusError>;
/// Import block with justification, finalizes block.
fn import_justified(&self, origin: BlockOrigin, block: runtime::Block, justification: Justification)
-> Result<(), ConsensusError>;
fn import_justified(
&self,
origin: BlockOrigin,
block: runtime::Block,
justification: Justification
) -> Result<(), ConsensusError>;
/// Finalize a block.
fn finalize_block(&self, id: BlockId<runtime::Block>, justification: Option<Justification>) -> client::error::Result<()>;
fn finalize_block(
&self,
id: BlockId<runtime::Block>,
justification: Option<Justification>,
) -> client::error::Result<()>;
/// Returns hash of the genesis block.
fn genesis_hash(&self) -> runtime::Hash;
@@ -64,9 +75,12 @@ impl<B, E, RA> TestClient for Client<B, E, runtime::Block, RA>
self.import_block(import, HashMap::new()).map(|_| ())
}
fn import_justified(&self, origin: BlockOrigin, block: runtime::Block, justification: Justification)
-> Result<(), ConsensusError>
{
fn import_justified(
&self,
origin: BlockOrigin,
block: runtime::Block,
justification: Justification,
) -> Result<(), ConsensusError> {
let import = ImportBlock {
origin,
header: block.header,
@@ -81,7 +95,11 @@ impl<B, E, RA> TestClient for Client<B, E, runtime::Block, RA>
self.import_block(import, HashMap::new()).map(|_| ())
}
fn finalize_block(&self, id: BlockId<runtime::Block>, justification: Option<Justification>) -> client::error::Result<()> {
fn finalize_block(
&self,
id: BlockId<runtime::Block>,
justification: Option<Justification>,
) -> client::error::Result<()> {
self.finalize_block(id, justification, true)
}
+129 -31
View File
@@ -19,29 +19,30 @@
#![warn(missing_docs)]
pub mod client_ext;
#[cfg(feature = "include-wasm-blob")]
pub mod trait_tests;
mod block_builder_ext;
pub use client_ext::TestClient;
pub use block_builder_ext::BlockBuilderExt;
pub use client;
pub use client::ExecutionStrategies;
pub use client::blockchain;
pub use client::backend;
pub use executor::NativeExecutor;
pub use client::{ExecutionStrategies, blockchain, backend, self};
pub use executor::{NativeExecutor, self};
pub use runtime;
pub use consensus;
pub use keyring::{AuthorityKeyring, AccountKeyring};
use std::sync::Arc;
use std::{sync::Arc, collections::HashMap};
use futures::future::FutureResult;
use primitives::Blake2Hasher;
use runtime_primitives::StorageOverlay;
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Hash as HashT, NumberFor};
use runtime_primitives::traits::{
Block as BlockT, Header as HeaderT, Hash as HashT, NumberFor
};
use runtime::genesismap::{GenesisConfig, additional_storage_with_genesis};
use state_machine::ExecutionStrategy;
use client::LocalCallExecutor;
#[cfg(feature = "include-wasm-blob")]
mod local_executor {
#![allow(missing_docs)]
use runtime;
@@ -56,12 +57,14 @@ mod local_executor {
}
/// Native executor used for tests.
#[cfg(feature = "include-wasm-blob")]
pub use local_executor::LocalExecutor;
/// Test client database backend.
pub type Backend = client_db::Backend<runtime::Block>;
/// Test client executor.
#[cfg(feature = "include-wasm-blob")]
pub type Executor = client::LocalCallExecutor<
Backend,
executor::NativeExecutor<LocalExecutor>,
@@ -78,6 +81,7 @@ pub type LightBackend = client::light::backend::Backend<
pub struct LightFetcher;
/// Test client light executor.
#[cfg(feature = "include-wasm-blob")]
pub type LightExecutor = client::light::call_executor::RemoteOrLocalCallExecutor<
runtime::Block,
LightBackend,
@@ -98,12 +102,112 @@ pub type LightExecutor = client::light::call_executor::RemoteOrLocalCallExecutor
>
>;
/// A builder for creating a test client instance.
pub struct TestClientBuilder {
execution_strategies: ExecutionStrategies,
genesis_extension: HashMap<Vec<u8>, Vec<u8>>,
support_changes_trie: bool,
}
impl TestClientBuilder {
/// Create a new instance of the test client builder.
pub fn new() -> Self {
TestClientBuilder {
execution_strategies: ExecutionStrategies::default(),
genesis_extension: HashMap::default(),
support_changes_trie: false,
}
}
/// Set the execution strategy that should be used by all contexts.
pub fn set_execution_strategy(
mut self,
execution_strategy: ExecutionStrategy
) -> Self {
self.execution_strategies = ExecutionStrategies {
syncing: execution_strategy,
importing: execution_strategy,
block_construction: execution_strategy,
offchain_worker: execution_strategy,
other: execution_strategy,
};
self
}
/// Set an extension of the genesis storage.
pub fn set_genesis_extension(
mut self,
extension: HashMap<Vec<u8>, Vec<u8>>
) -> Self {
self.genesis_extension = extension;
self
}
/// Enable/Disable changes trie support.
pub fn set_support_changes_trie(mut self, enable: bool) -> Self {
self.support_changes_trie = enable;
self
}
/// Build the test client.
#[cfg(feature = "include-wasm-blob")]
pub fn build(self) -> client::Client<
Backend, Executor, runtime::Block, runtime::RuntimeApi
> {
let backend = Arc::new(Backend::new_test(std::u32::MAX, std::u64::MAX));
self.build_with_backend(backend)
}
/// Build the test client with the given backend.
#[cfg(feature = "include-wasm-blob")]
pub fn build_with_backend<B>(self, backend: Arc<B>) -> client::Client<
B,
client::LocalCallExecutor<B, executor::NativeExecutor<LocalExecutor>>,
runtime::Block,
runtime::RuntimeApi
> where B: backend::LocalBackend<runtime::Block, Blake2Hasher> {
let executor = NativeExecutor::new(None);
let executor = LocalCallExecutor::new(backend.clone(), executor);
client::Client::new(
backend,
executor,
genesis_storage(self.support_changes_trie, self.genesis_extension),
self.execution_strategies
).expect("Creates new client")
}
/// Build the test client with the given native executor.
pub fn build_with_native_executor<E>(
self,
executor: executor::NativeExecutor<E>
) -> client::Client<
Backend,
client::LocalCallExecutor<Backend, executor::NativeExecutor<E>>,
runtime::Block,
runtime::RuntimeApi
> where E: executor::NativeExecutionDispatch
{
let backend = Arc::new(Backend::new_test(std::u32::MAX, std::u64::MAX));
let executor = LocalCallExecutor::new(backend.clone(), executor);
client::Client::new(
backend,
executor,
genesis_storage(self.support_changes_trie, self.genesis_extension),
self.execution_strategies
).expect("Creates new client")
}
}
/// Creates new client instance used for tests.
#[cfg(feature = "include-wasm-blob")]
pub fn new() -> client::Client<Backend, Executor, runtime::Block, runtime::RuntimeApi> {
new_with_backend(Arc::new(Backend::new_test(::std::u32::MAX, ::std::u64::MAX)), false)
}
/// Creates new light client instance used for tests.
#[cfg(feature = "include-wasm-blob")]
pub fn new_light() -> client::Client<LightBackend, LightExecutor, runtime::Block, runtime::RuntimeApi> {
let storage = client_db::light::LightStorage::new_test();
let blockchain = Arc::new(client::light::blockchain::Blockchain::new(storage));
@@ -113,42 +217,28 @@ pub fn new_light() -> client::Client<LightBackend, LightExecutor, runtime::Block
let remote_call_executor = client::light::call_executor::RemoteCallExecutor::new(blockchain.clone(), fetcher);
let local_call_executor = client::LocalCallExecutor::new(backend.clone(), executor);
let call_executor = LightExecutor::new(backend.clone(), remote_call_executor, local_call_executor);
client::Client::new(backend, call_executor, genesis_storage(false), Default::default()).unwrap()
client::Client::new(backend, call_executor, genesis_storage(false, Default::default()), Default::default()).unwrap()
}
/// Creates new client instance used for tests with the given api execution strategy.
#[cfg(feature = "include-wasm-blob")]
pub fn new_with_execution_strategy(
execution_strategy: ExecutionStrategy
) -> client::Client<Backend, Executor, runtime::Block, runtime::RuntimeApi> {
let backend = Arc::new(Backend::new_test(::std::u32::MAX, ::std::u64::MAX));
let executor = NativeExecutor::new(None);
let executor = LocalCallExecutor::new(backend.clone(), executor);
let execution_strategies = ExecutionStrategies {
syncing: execution_strategy,
importing: execution_strategy,
block_construction: execution_strategy,
offchain_worker: execution_strategy,
other: execution_strategy,
};
client::Client::new(
backend,
executor,
genesis_storage(false),
execution_strategies
).expect("Creates new client")
TestClientBuilder::new().set_execution_strategy(execution_strategy).build()
}
/// Creates new test client instance that suports changes trie creation.
#[cfg(feature = "include-wasm-blob")]
pub fn new_with_changes_trie()
-> client::Client<Backend, Executor, runtime::Block, runtime::RuntimeApi>
{
new_with_backend(Arc::new(Backend::new_test(::std::u32::MAX, ::std::u64::MAX)), true)
TestClientBuilder::new().set_support_changes_trie(true).build()
}
/// Creates new client instance used for tests with an explicitly provided backend.
/// This is useful for testing backend implementations.
#[cfg(feature = "include-wasm-blob")]
pub fn new_with_backend<B>(
backend: Arc<B>,
support_changes_trie: bool
@@ -159,8 +249,9 @@ pub fn new_with_backend<B>(
runtime::RuntimeApi
> where B: backend::LocalBackend<runtime::Block, Blake2Hasher>
{
let executor = NativeExecutor::new(None);
client::new_with_backend(backend, executor, genesis_storage(support_changes_trie)).unwrap()
TestClientBuilder::new()
.set_support_changes_trie(support_changes_trie)
.build_with_backend(backend)
}
fn genesis_config(support_changes_trie: bool) -> GenesisConfig {
@@ -177,9 +268,16 @@ fn genesis_config(support_changes_trie: bool) -> GenesisConfig {
)
}
fn genesis_storage(support_changes_trie: bool) -> StorageOverlay {
fn genesis_storage(
support_changes_trie: bool,
extension: HashMap<Vec<u8>, Vec<u8>>
) -> StorageOverlay {
let mut storage = genesis_config(support_changes_trie).genesis_map();
let state_root = <<<runtime::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(storage.clone().into_iter());
storage.extend(extension.into_iter());
let state_root = <<<runtime::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
storage.clone().into_iter()
);
let block: runtime::Block = client::genesis::construct_genesis_block(state_root);
storage.extend(additional_storage_with_genesis(&block));
storage