Run cargo fmt on the whole code base (#9394)

* Run cargo fmt on the whole code base

* Second run

* Add CI check

* Fix compilation

* More unnecessary braces

* Handle weights

* Use --all

* Use correct attributes...

* Fix UI tests

* AHHHHHHHHH

* 🤦

* Docs

* Fix compilation

* 🤷

* Please stop

* 🤦 x 2

* More

* make rustfmt.toml consistent with polkadot

Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
Bastian Köcher
2021-07-21 16:32:32 +02:00
committed by GitHub
parent d451c38c1c
commit 7b56ab15b4
1010 changed files with 53339 additions and 51208 deletions
@@ -17,16 +17,19 @@
//! Block Builder extensions for tests.
use sc_client_api::backend;
use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_core::ChangesTrieConfiguration;
use sc_client_api::backend;
use sc_block_builder::BlockBuilderApi;
/// Extension trait for test block builder.
pub trait BlockBuilderExt {
/// Add transfer extrinsic to the block.
fn push_transfer(&mut self, transfer: substrate_test_runtime::Transfer) -> Result<(), sp_blockchain::Error>;
fn push_transfer(
&mut self,
transfer: substrate_test_runtime::Transfer,
) -> Result<(), sp_blockchain::Error>;
/// Add storage change extrinsic to the block.
fn push_storage_change(
&mut self,
@@ -40,16 +43,21 @@ pub trait BlockBuilderExt {
) -> Result<(), sp_blockchain::Error>;
}
impl<'a, A, B> BlockBuilderExt for sc_block_builder::BlockBuilder<'a, substrate_test_runtime::Block, A, B> where
impl<'a, A, B> BlockBuilderExt
for sc_block_builder::BlockBuilder<'a, substrate_test_runtime::Block, A, B>
where
A: ProvideRuntimeApi<substrate_test_runtime::Block> + 'a,
A::Api: BlockBuilderApi<substrate_test_runtime::Block> +
ApiExt<
A::Api: BlockBuilderApi<substrate_test_runtime::Block>
+ ApiExt<
substrate_test_runtime::Block,
StateBackend = backend::StateBackendFor<B, substrate_test_runtime::Block>
StateBackend = backend::StateBackendFor<B, substrate_test_runtime::Block>,
>,
B: backend::Backend<substrate_test_runtime::Block>,
{
fn push_transfer(&mut self, transfer: substrate_test_runtime::Transfer) -> Result<(), sp_blockchain::Error> {
fn push_transfer(
&mut self,
transfer: substrate_test_runtime::Transfer,
) -> Result<(), sp_blockchain::Error> {
self.push(transfer.into_signed_tx())
}
+93 -59
View File
@@ -23,34 +23,36 @@ pub mod trait_tests;
mod block_builder_ext;
use std::sync::Arc;
use std::collections::HashMap;
pub use sc_consensus::LongestChain;
use std::{collections::HashMap, sync::Arc};
pub use substrate_test_client::*;
pub use substrate_test_runtime as runtime;
pub use sc_consensus::LongestChain;
pub use self::block_builder_ext::BlockBuilderExt;
use sp_core::{sr25519, ChangesTrieConfiguration};
use sp_core::storage::{ChildInfo, Storage, StorageChild};
use substrate_test_runtime::genesismap::{GenesisConfig, additional_storage_with_genesis};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Hash as HashT, NumberFor, HashFor};
use sc_client_api::light::{
RemoteCallRequest, RemoteChangesRequest, RemoteBodyRequest,
Fetcher, RemoteHeaderRequest, RemoteReadRequest, RemoteReadChildRequest,
Fetcher, RemoteBodyRequest, RemoteCallRequest, RemoteChangesRequest, RemoteHeaderRequest,
RemoteReadChildRequest, RemoteReadRequest,
};
use sp_core::{
sr25519,
storage::{ChildInfo, Storage, StorageChild},
ChangesTrieConfiguration,
};
use sp_runtime::traits::{Block as BlockT, Hash as HashT, HashFor, Header as HeaderT, NumberFor};
use substrate_test_runtime::genesismap::{additional_storage_with_genesis, GenesisConfig};
/// A prelude to import in tests.
pub mod prelude {
// Trait extensions
pub use super::{
BlockBuilderExt, DefaultTestClientBuilderExt, TestClientBuilderExt, ClientExt,
ClientBlockImportExt,
BlockBuilderExt, ClientBlockImportExt, ClientExt, DefaultTestClientBuilderExt,
TestClientBuilderExt,
};
// Client structs
pub use super::{
TestClient, TestClientBuilder, Backend, LightBackend,
Executor, LightExecutor, LocalExecutor, NativeExecutor, WasmExecutionMethod,
Backend, Executor, LightBackend, LightExecutor, LocalExecutor, NativeExecutor, TestClient,
TestClientBuilder, WasmExecutionMethod,
};
// Keyring
pub use super::{AccountKeyring, Sr25519Keyring};
@@ -82,10 +84,10 @@ pub type LightExecutor = sc_light::GenesisCallExecutor<
substrate_test_runtime::Block,
sc_light::Backend<
sc_client_db::light::LightStorage<substrate_test_runtime::Block>,
HashFor<substrate_test_runtime::Block>
HashFor<substrate_test_runtime::Block>,
>,
NativeExecutor<LocalExecutor>
>
NativeExecutor<LocalExecutor>,
>,
>;
/// Parameters of test-client builder with test-runtime.
@@ -130,19 +132,23 @@ impl substrate_test_client::GenesisInit for GenesisParameters {
let mut storage = self.genesis_config().genesis_map();
if let Some(ref code) = self.wasm_code {
storage.top.insert(sp_core::storage::well_known_keys::CODE.to_vec(), code.clone());
storage
.top
.insert(sp_core::storage::well_known_keys::CODE.to_vec(), code.clone());
}
let child_roots = storage.children_default.iter().map(|(_sk, child_content)| {
let state_root = <<<runtime::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
child_content.data.clone().into_iter().collect()
);
let state_root =
<<<runtime::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
child_content.data.clone().into_iter().collect(),
);
let prefixed_storage_key = child_content.child_info.prefixed_storage_key();
(prefixed_storage_key.into_inner(), state_root.encode())
});
let state_root = <<<runtime::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
storage.top.clone().into_iter().chain(child_roots).collect()
);
let state_root =
<<<runtime::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
storage.top.clone().into_iter().chain(child_roots).collect(),
);
let block: runtime::Block = client::genesis::construct_genesis_block(state_root);
storage.top.extend(additional_storage_with_genesis(&block));
@@ -164,7 +170,7 @@ pub type Client<B> = client::Client<
client::LocalCallExecutor<
substrate_test_runtime::Block,
B,
sc_executor::NativeExecutor<LocalExecutor>
sc_executor::NativeExecutor<LocalExecutor>,
>,
substrate_test_runtime::Block,
substrate_test_runtime::RuntimeApi,
@@ -217,12 +223,16 @@ pub trait TestClientBuilderExt<B>: Sized {
let key = key.into();
assert!(!storage_key.is_empty());
assert!(!key.is_empty());
self.genesis_init_mut().extra_storage.children_default
self.genesis_init_mut()
.extra_storage
.children_default
.entry(storage_key)
.or_insert_with(|| StorageChild {
data: Default::default(),
child_info: child_info.clone(),
}).data.insert(key, value.into());
})
.data
.insert(key, value.into());
self
}
@@ -244,27 +254,32 @@ pub trait TestClientBuilderExt<B>: Sized {
}
/// Build the test client and longest chain selector.
fn build_with_longest_chain(self) -> (Client<B>, sc_consensus::LongestChain<B, substrate_test_runtime::Block>);
fn build_with_longest_chain(
self,
) -> (Client<B>, sc_consensus::LongestChain<B, substrate_test_runtime::Block>);
/// Build the test client and the backend.
fn build_with_backend(self) -> (Client<B>, Arc<B>);
}
impl<B> TestClientBuilderExt<B> for TestClientBuilder<
client::LocalCallExecutor<
substrate_test_runtime::Block,
impl<B> TestClientBuilderExt<B>
for TestClientBuilder<
client::LocalCallExecutor<
substrate_test_runtime::Block,
B,
sc_executor::NativeExecutor<LocalExecutor>,
>,
B,
sc_executor::NativeExecutor<LocalExecutor>
>,
B
> where
> where
B: sc_client_api::backend::Backend<substrate_test_runtime::Block> + 'static,
{
fn genesis_init_mut(&mut self) -> &mut GenesisParameters {
Self::genesis_init_mut(self)
}
fn build_with_longest_chain(self) -> (Client<B>, sc_consensus::LongestChain<B, substrate_test_runtime::Block>) {
fn build_with_longest_chain(
self,
) -> (Client<B>, sc_consensus::LongestChain<B, substrate_test_runtime::Block>) {
self.build_with_native_executor(None)
}
@@ -275,7 +290,8 @@ impl<B> TestClientBuilderExt<B> for TestClientBuilder<
}
/// Type of optional fetch callback.
type MaybeFetcherCallback<Req, Resp> = Option<Box<dyn Fn(Req) -> Result<Resp, sp_blockchain::Error> + Send + Sync>>;
type MaybeFetcherCallback<Req, Resp> =
Option<Box<dyn Fn(Req) -> Result<Resp, sp_blockchain::Error> + Send + Sync>>;
/// Type of fetcher future result.
type FetcherFutureResult<Resp> = futures::future::Ready<Result<Resp, sp_blockchain::Error>>;
@@ -284,7 +300,10 @@ type FetcherFutureResult<Resp> = futures::future::Ready<Result<Resp, sp_blockcha
#[derive(Default)]
pub struct LightFetcher {
call: MaybeFetcherCallback<RemoteCallRequest<substrate_test_runtime::Header>, Vec<u8>>,
body: MaybeFetcherCallback<RemoteBodyRequest<substrate_test_runtime::Header>, Vec<substrate_test_runtime::Extrinsic>>,
body: MaybeFetcherCallback<
RemoteBodyRequest<substrate_test_runtime::Header>,
Vec<substrate_test_runtime::Extrinsic>,
>,
}
impl LightFetcher {
@@ -293,21 +312,18 @@ impl LightFetcher {
self,
call: MaybeFetcherCallback<RemoteCallRequest<substrate_test_runtime::Header>, Vec<u8>>,
) -> Self {
LightFetcher {
call,
body: self.body,
}
LightFetcher { call, body: self.body }
}
/// Sets remote body callback.
pub fn with_remote_body(
self,
body: MaybeFetcherCallback<RemoteBodyRequest<substrate_test_runtime::Header>, Vec<substrate_test_runtime::Extrinsic>>,
body: MaybeFetcherCallback<
RemoteBodyRequest<substrate_test_runtime::Header>,
Vec<substrate_test_runtime::Extrinsic>,
>,
) -> Self {
LightFetcher {
call: self.call,
body,
}
LightFetcher { call: self.call, body }
}
}
@@ -315,14 +331,21 @@ impl Fetcher<substrate_test_runtime::Block> for LightFetcher {
type RemoteHeaderResult = FetcherFutureResult<substrate_test_runtime::Header>;
type RemoteReadResult = FetcherFutureResult<HashMap<Vec<u8>, Option<Vec<u8>>>>;
type RemoteCallResult = FetcherFutureResult<Vec<u8>>;
type RemoteChangesResult = FetcherFutureResult<Vec<(NumberFor<substrate_test_runtime::Block>, u32)>>;
type RemoteChangesResult =
FetcherFutureResult<Vec<(NumberFor<substrate_test_runtime::Block>, u32)>>;
type RemoteBodyResult = FetcherFutureResult<Vec<substrate_test_runtime::Extrinsic>>;
fn remote_header(&self, _: RemoteHeaderRequest<substrate_test_runtime::Header>) -> Self::RemoteHeaderResult {
fn remote_header(
&self,
_: RemoteHeaderRequest<substrate_test_runtime::Header>,
) -> Self::RemoteHeaderResult {
unimplemented!()
}
fn remote_read(&self, _: RemoteReadRequest<substrate_test_runtime::Header>) -> Self::RemoteReadResult {
fn remote_read(
&self,
_: RemoteReadRequest<substrate_test_runtime::Header>,
) -> Self::RemoteReadResult {
unimplemented!()
}
@@ -333,18 +356,27 @@ impl Fetcher<substrate_test_runtime::Block> for LightFetcher {
unimplemented!()
}
fn remote_call(&self, req: RemoteCallRequest<substrate_test_runtime::Header>) -> Self::RemoteCallResult {
fn remote_call(
&self,
req: RemoteCallRequest<substrate_test_runtime::Header>,
) -> Self::RemoteCallResult {
match self.call {
Some(ref call) => futures::future::ready(call(req)),
None => unimplemented!(),
}
}
fn remote_changes(&self, _: RemoteChangesRequest<substrate_test_runtime::Header>) -> Self::RemoteChangesResult {
fn remote_changes(
&self,
_: RemoteChangesRequest<substrate_test_runtime::Header>,
) -> Self::RemoteChangesResult {
unimplemented!()
}
fn remote_body(&self, req: RemoteBodyRequest<substrate_test_runtime::Header>) -> Self::RemoteBodyResult {
fn remote_body(
&self,
req: RemoteBodyRequest<substrate_test_runtime::Header>,
) -> Self::RemoteBodyResult {
match self.body {
Some(ref body) => futures::future::ready(body(req)),
None => unimplemented!(),
@@ -359,10 +391,14 @@ pub fn new() -> Client<Backend> {
/// Creates new light client instance used for tests.
pub fn new_light() -> (
client::Client<LightBackend, LightExecutor, substrate_test_runtime::Block, substrate_test_runtime::RuntimeApi>,
client::Client<
LightBackend,
LightExecutor,
substrate_test_runtime::Block,
substrate_test_runtime::RuntimeApi,
>,
Arc<LightBackend>,
) {
let storage = sc_client_db::light::LightStorage::new_test();
let blockchain = Arc::new(sc_light::Blockchain::new(storage));
let backend = Arc::new(LightBackend::new(blockchain));
@@ -372,11 +408,9 @@ pub fn new_light() -> (
executor,
Box::new(sp_core::testing::TaskExecutor::new()),
Default::default(),
).expect("Creates LocalCallExecutor");
let call_executor = LightExecutor::new(
backend.clone(),
local_call_executor,
);
)
.expect("Creates LocalCallExecutor");
let call_executor = LightExecutor::new(backend.clone(), local_call_executor);
(
TestClientBuilder::with_backend(backend.clone())
@@ -23,192 +23,169 @@
use std::sync::Arc;
use crate::{
AccountKeyring, ClientBlockImportExt, BlockBuilderExt, TestClientBuilder, TestClientBuilderExt,
AccountKeyring, BlockBuilderExt, ClientBlockImportExt, TestClientBuilder, TestClientBuilderExt,
};
use sc_client_api::backend;
use sc_client_api::blockchain::{Backend as BlockChainBackendT, HeaderBackend};
use sp_consensus::BlockOrigin;
use substrate_test_runtime::{self, Transfer};
use sp_runtime::generic::BlockId;
use sp_runtime::traits::Block as BlockT;
use sc_block_builder::BlockBuilderProvider;
use futures::executor::block_on;
use sc_block_builder::BlockBuilderProvider;
use sc_client_api::{
backend,
blockchain::{Backend as BlockChainBackendT, HeaderBackend},
};
use sp_consensus::BlockOrigin;
use sp_runtime::{generic::BlockId, traits::Block as BlockT};
use substrate_test_runtime::{self, Transfer};
/// helper to test the `leaves` implementation for various backends
pub fn test_leaves_for_backend<B: 'static>(backend: Arc<B>) where
pub fn test_leaves_for_backend<B: 'static>(backend: Arc<B>)
where
B: backend::Backend<substrate_test_runtime::Block>,
{
// block tree:
// G -> A1 -> A2 -> A3 -> A4 -> A5
// A1 -> B2 -> B3 -> B4
// B2 -> C3
// A1 -> D2
// A1 -> B2 -> B3 -> B4
// B2 -> C3
// A1 -> D2
let mut client = TestClientBuilder::with_backend(backend.clone()).build();
let blockchain = backend.blockchain();
let genesis_hash = client.chain_info().genesis_hash;
assert_eq!(
blockchain.leaves().unwrap(),
vec![genesis_hash]);
assert_eq!(blockchain.leaves().unwrap(), vec![genesis_hash]);
// G -> A1
let a1 = client.new_block(Default::default()).unwrap().build().unwrap().block;
block_on(client.import(BlockOrigin::Own, a1.clone())).unwrap();
assert_eq!(
blockchain.leaves().unwrap(),
vec![a1.hash()],
);
assert_eq!(blockchain.leaves().unwrap(), vec![a1.hash()],);
// A1 -> A2
let a2 = client.new_block_at(
&BlockId::Hash(a1.hash()),
Default::default(),
false,
).unwrap().build().unwrap().block;
let a2 = client
.new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false)
.unwrap()
.build()
.unwrap()
.block;
block_on(client.import(BlockOrigin::Own, a2.clone())).unwrap();
#[allow(deprecated)]
assert_eq!(
blockchain.leaves().unwrap(),
vec![a2.hash()],
);
assert_eq!(blockchain.leaves().unwrap(), vec![a2.hash()],);
// A2 -> A3
let a3 = client.new_block_at(
&BlockId::Hash(a2.hash()),
Default::default(),
false,
).unwrap().build().unwrap().block;
let a3 = client
.new_block_at(&BlockId::Hash(a2.hash()), Default::default(), false)
.unwrap()
.build()
.unwrap()
.block;
block_on(client.import(BlockOrigin::Own, a3.clone())).unwrap();
assert_eq!(
blockchain.leaves().unwrap(),
vec![a3.hash()],
);
assert_eq!(blockchain.leaves().unwrap(), vec![a3.hash()],);
// A3 -> A4
let a4 = client.new_block_at(
&BlockId::Hash(a3.hash()),
Default::default(),
false,
).unwrap().build().unwrap().block;
let a4 = client
.new_block_at(&BlockId::Hash(a3.hash()), Default::default(), false)
.unwrap()
.build()
.unwrap()
.block;
block_on(client.import(BlockOrigin::Own, a4.clone())).unwrap();
assert_eq!(
blockchain.leaves().unwrap(),
vec![a4.hash()],
);
assert_eq!(blockchain.leaves().unwrap(), vec![a4.hash()],);
// A4 -> A5
let a5 = client.new_block_at(
&BlockId::Hash(a4.hash()),
Default::default(),
false,
).unwrap().build().unwrap().block;
let a5 = client
.new_block_at(&BlockId::Hash(a4.hash()), Default::default(), false)
.unwrap()
.build()
.unwrap()
.block;
block_on(client.import(BlockOrigin::Own, a5.clone())).unwrap();
assert_eq!(
blockchain.leaves().unwrap(),
vec![a5.hash()],
);
assert_eq!(blockchain.leaves().unwrap(), vec![a5.hash()],);
// A1 -> B2
let mut builder = client.new_block_at(
&BlockId::Hash(a1.hash()),
Default::default(),
false,
).unwrap();
let mut builder = client
.new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false)
.unwrap();
// this push is required as otherwise B2 has the same hash as A2 and won't get imported
builder.push_transfer(Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 41,
nonce: 0,
}).unwrap();
builder
.push_transfer(Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 41,
nonce: 0,
})
.unwrap();
let b2 = builder.build().unwrap().block;
block_on(client.import(BlockOrigin::Own, b2.clone())).unwrap();
assert_eq!(
blockchain.leaves().unwrap(),
vec![a5.hash(), b2.hash()],
);
assert_eq!(blockchain.leaves().unwrap(), vec![a5.hash(), b2.hash()],);
// B2 -> B3
let b3 = client.new_block_at(
&BlockId::Hash(b2.hash()),
Default::default(),
false,
).unwrap().build().unwrap().block;
let b3 = client
.new_block_at(&BlockId::Hash(b2.hash()), Default::default(), false)
.unwrap()
.build()
.unwrap()
.block;
block_on(client.import(BlockOrigin::Own, b3.clone())).unwrap();
assert_eq!(
blockchain.leaves().unwrap(),
vec![a5.hash(), b3.hash()],
);
assert_eq!(blockchain.leaves().unwrap(), vec![a5.hash(), b3.hash()],);
// B3 -> B4
let b4 = client.new_block_at(
&BlockId::Hash(b3.hash()),
Default::default(),
false,
).unwrap().build().unwrap().block;
let b4 = client
.new_block_at(&BlockId::Hash(b3.hash()), Default::default(), false)
.unwrap()
.build()
.unwrap()
.block;
block_on(client.import(BlockOrigin::Own, b4.clone())).unwrap();
assert_eq!(
blockchain.leaves().unwrap(),
vec![a5.hash(), b4.hash()],
);
assert_eq!(blockchain.leaves().unwrap(), vec![a5.hash(), b4.hash()],);
// // B2 -> C3
let mut builder = client.new_block_at(
&BlockId::Hash(b2.hash()),
Default::default(),
false,
).unwrap();
let mut builder = client
.new_block_at(&BlockId::Hash(b2.hash()), Default::default(), false)
.unwrap();
// this push is required as otherwise C3 has the same hash as B3 and won't get imported
builder.push_transfer(Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 1,
nonce: 1,
}).unwrap();
builder
.push_transfer(Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 1,
nonce: 1,
})
.unwrap();
let c3 = builder.build().unwrap().block;
block_on(client.import(BlockOrigin::Own, c3.clone())).unwrap();
assert_eq!(
blockchain.leaves().unwrap(),
vec![a5.hash(), b4.hash(), c3.hash()],
);
assert_eq!(blockchain.leaves().unwrap(), vec![a5.hash(), b4.hash(), c3.hash()],);
// A1 -> D2
let mut builder = client.new_block_at(
&BlockId::Hash(a1.hash()),
Default::default(),
false,
).unwrap();
let mut builder = client
.new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false)
.unwrap();
// this push is required as otherwise D2 has the same hash as B2 and won't get imported
builder.push_transfer(Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 1,
nonce: 0,
}).unwrap();
builder
.push_transfer(Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 1,
nonce: 0,
})
.unwrap();
let d2 = builder.build().unwrap().block;
block_on(client.import(BlockOrigin::Own, d2.clone())).unwrap();
assert_eq!(
blockchain.leaves().unwrap(),
vec![a5.hash(), b4.hash(), c3.hash(), d2.hash()],
);
assert_eq!(blockchain.leaves().unwrap(), vec![a5.hash(), b4.hash(), c3.hash(), d2.hash()],);
}
/// helper to test the `children` implementation for various backends
pub fn test_children_for_backend<B: 'static>(backend: Arc<B>) where
pub fn test_children_for_backend<B: 'static>(backend: Arc<B>)
where
B: backend::LocalBackend<substrate_test_runtime::Block>,
{
// block tree:
// G -> A1 -> A2 -> A3 -> A4 -> A5
// A1 -> B2 -> B3 -> B4
// B2 -> C3
// A1 -> D2
// A1 -> B2 -> B3 -> B4
// B2 -> C3
// A1 -> D2
let mut client = TestClientBuilder::with_backend(backend.clone()).build();
let blockchain = backend.blockchain();
@@ -218,98 +195,104 @@ pub fn test_children_for_backend<B: 'static>(backend: Arc<B>) where
block_on(client.import(BlockOrigin::Own, a1.clone())).unwrap();
// A1 -> A2
let a2 = client.new_block_at(
&BlockId::Hash(a1.hash()),
Default::default(),
false,
).unwrap().build().unwrap().block;
let a2 = client
.new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false)
.unwrap()
.build()
.unwrap()
.block;
block_on(client.import(BlockOrigin::Own, a2.clone())).unwrap();
// A2 -> A3
let a3 = client.new_block_at(
&BlockId::Hash(a2.hash()),
Default::default(),
false,
).unwrap().build().unwrap().block;
let a3 = client
.new_block_at(&BlockId::Hash(a2.hash()), Default::default(), false)
.unwrap()
.build()
.unwrap()
.block;
block_on(client.import(BlockOrigin::Own, a3.clone())).unwrap();
// A3 -> A4
let a4 = client.new_block_at(
&BlockId::Hash(a3.hash()),
Default::default(),
false,
).unwrap().build().unwrap().block;
let a4 = client
.new_block_at(&BlockId::Hash(a3.hash()), Default::default(), false)
.unwrap()
.build()
.unwrap()
.block;
block_on(client.import(BlockOrigin::Own, a4.clone())).unwrap();
// A4 -> A5
let a5 = client.new_block_at(
&BlockId::Hash(a4.hash()),
Default::default(),
false,
).unwrap().build().unwrap().block;
let a5 = client
.new_block_at(&BlockId::Hash(a4.hash()), Default::default(), false)
.unwrap()
.build()
.unwrap()
.block;
block_on(client.import(BlockOrigin::Own, a5.clone())).unwrap();
// A1 -> B2
let mut builder = client.new_block_at(
&BlockId::Hash(a1.hash()),
Default::default(),
false,
).unwrap();
let mut builder = client
.new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false)
.unwrap();
// this push is required as otherwise B2 has the same hash as A2 and won't get imported
builder.push_transfer(Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 41,
nonce: 0,
}).unwrap();
builder
.push_transfer(Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 41,
nonce: 0,
})
.unwrap();
let b2 = builder.build().unwrap().block;
block_on(client.import(BlockOrigin::Own, b2.clone())).unwrap();
// B2 -> B3
let b3 = client.new_block_at(
&BlockId::Hash(b2.hash()),
Default::default(),
false,
).unwrap().build().unwrap().block;
let b3 = client
.new_block_at(&BlockId::Hash(b2.hash()), Default::default(), false)
.unwrap()
.build()
.unwrap()
.block;
block_on(client.import(BlockOrigin::Own, b3.clone())).unwrap();
// B3 -> B4
let b4 = client.new_block_at(
&BlockId::Hash(b3.hash()),
Default::default(),
false,
).unwrap().build().unwrap().block;
let b4 = client
.new_block_at(&BlockId::Hash(b3.hash()), Default::default(), false)
.unwrap()
.build()
.unwrap()
.block;
block_on(client.import(BlockOrigin::Own, b4)).unwrap();
// // B2 -> C3
let mut builder = client.new_block_at(
&BlockId::Hash(b2.hash()),
Default::default(),
false,
).unwrap();
let mut builder = client
.new_block_at(&BlockId::Hash(b2.hash()), Default::default(), false)
.unwrap();
// this push is required as otherwise C3 has the same hash as B3 and won't get imported
builder.push_transfer(Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 1,
nonce: 1,
}).unwrap();
builder
.push_transfer(Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 1,
nonce: 1,
})
.unwrap();
let c3 = builder.build().unwrap().block;
block_on(client.import(BlockOrigin::Own, c3.clone())).unwrap();
// A1 -> D2
let mut builder = client.new_block_at(
&BlockId::Hash(a1.hash()),
Default::default(),
false,
).unwrap();
let mut builder = client
.new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false)
.unwrap();
// this push is required as otherwise D2 has the same hash as B2 and won't get imported
builder.push_transfer(Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 1,
nonce: 0,
}).unwrap();
builder
.push_transfer(Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 1,
nonce: 0,
})
.unwrap();
let d2 = builder.build().unwrap().block;
block_on(client.import(BlockOrigin::Own, d2.clone())).unwrap();
@@ -334,9 +317,9 @@ where
{
// block tree:
// G -> A1 -> A2 -> A3 -> A4 -> A5
// A1 -> B2 -> B3 -> B4
// B2 -> C3
// A1 -> D2
// A1 -> B2 -> B3 -> B4
// B2 -> C3
// A1 -> D2
let mut client = TestClientBuilder::with_backend(backend.clone()).build();
let blockchain = backend.blockchain();
@@ -345,98 +328,104 @@ where
block_on(client.import(BlockOrigin::Own, a1.clone())).unwrap();
// A1 -> A2
let a2 = client.new_block_at(
&BlockId::Hash(a1.hash()),
Default::default(),
false,
).unwrap().build().unwrap().block;
let a2 = client
.new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false)
.unwrap()
.build()
.unwrap()
.block;
block_on(client.import(BlockOrigin::Own, a2.clone())).unwrap();
// A2 -> A3
let a3 = client.new_block_at(
&BlockId::Hash(a2.hash()),
Default::default(),
false,
).unwrap().build().unwrap().block;
let a3 = client
.new_block_at(&BlockId::Hash(a2.hash()), Default::default(), false)
.unwrap()
.build()
.unwrap()
.block;
block_on(client.import(BlockOrigin::Own, a3.clone())).unwrap();
// A3 -> A4
let a4 = client.new_block_at(
&BlockId::Hash(a3.hash()),
Default::default(),
false,
).unwrap().build().unwrap().block;
let a4 = client
.new_block_at(&BlockId::Hash(a3.hash()), Default::default(), false)
.unwrap()
.build()
.unwrap()
.block;
block_on(client.import(BlockOrigin::Own, a4.clone())).unwrap();
// A4 -> A5
let a5 = client.new_block_at(
&BlockId::Hash(a4.hash()),
Default::default(),
false,
).unwrap().build().unwrap().block;
let a5 = client
.new_block_at(&BlockId::Hash(a4.hash()), Default::default(), false)
.unwrap()
.build()
.unwrap()
.block;
block_on(client.import(BlockOrigin::Own, a5.clone())).unwrap();
// A1 -> B2
let mut builder = client.new_block_at(
&BlockId::Hash(a1.hash()),
Default::default(),
false,
).unwrap();
let mut builder = client
.new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false)
.unwrap();
// this push is required as otherwise B2 has the same hash as A2 and won't get imported
builder.push_transfer(Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 41,
nonce: 0,
}).unwrap();
builder
.push_transfer(Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 41,
nonce: 0,
})
.unwrap();
let b2 = builder.build().unwrap().block;
block_on(client.import(BlockOrigin::Own, b2.clone())).unwrap();
// B2 -> B3
let b3 = client.new_block_at(
&BlockId::Hash(b2.hash()),
Default::default(),
false,
).unwrap().build().unwrap().block;
let b3 = client
.new_block_at(&BlockId::Hash(b2.hash()), Default::default(), false)
.unwrap()
.build()
.unwrap()
.block;
block_on(client.import(BlockOrigin::Own, b3.clone())).unwrap();
// B3 -> B4
let b4 = client.new_block_at(
&BlockId::Hash(b3.hash()),
Default::default(),
false,
).unwrap().build().unwrap().block;
let b4 = client
.new_block_at(&BlockId::Hash(b3.hash()), Default::default(), false)
.unwrap()
.build()
.unwrap()
.block;
block_on(client.import(BlockOrigin::Own, b4)).unwrap();
// // B2 -> C3
let mut builder = client.new_block_at(
&BlockId::Hash(b2.hash()),
Default::default(),
false,
).unwrap();
let mut builder = client
.new_block_at(&BlockId::Hash(b2.hash()), Default::default(), false)
.unwrap();
// this push is required as otherwise C3 has the same hash as B3 and won't get imported
builder.push_transfer(Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 1,
nonce: 1,
}).unwrap();
builder
.push_transfer(Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 1,
nonce: 1,
})
.unwrap();
let c3 = builder.build().unwrap().block;
block_on(client.import(BlockOrigin::Own, c3)).unwrap();
// A1 -> D2
let mut builder = client.new_block_at(
&BlockId::Hash(a1.hash()),
Default::default(),
false,
).unwrap();
let mut builder = client
.new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false)
.unwrap();
// this push is required as otherwise D2 has the same hash as B2 and won't get imported
builder.push_transfer(Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 1,
nonce: 0,
}).unwrap();
builder
.push_transfer(Transfer {
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Ferdie.into(),
amount: 1,
nonce: 0,
})
.unwrap();
let d2 = builder.build().unwrap().block;
block_on(client.import(BlockOrigin::Own, d2)).unwrap();