Skip to content
Snippets Groups Projects
Commit 2bc098ba authored by Bastian Köcher's avatar Bastian Köcher Committed by GitHub
Browse files

Merge pull request #10 from paritytech/bkchr-update-to-latest-substrate

Update to latest Substrate + Polkadot
parents 57b51ff7 7acbc36a
No related merge requests found
This diff is collapsed.
......@@ -13,12 +13,11 @@ substrate-primitives = { git = "https://github.com/paritytech/substrate", branch
sr-primitives = { git = "https://github.com/paritytech/substrate", branch = "bkchr-cumulus-branch" }
# polkadot deps
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "bkchr-cumulus-branch" }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "bkchr-cumulus-branch" }
polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "bkchr-cumulus-branch" }
# other deps
futures = "0.1.21"
tokio = "0.1.8"
parity-codec = "3.1"
parity-codec = "3.5"
log = "0.4"
......@@ -15,15 +15,14 @@
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
use substrate_client::{backend::Backend, CallExecutor, Client, BlockchainEvents};
use substrate_client::error::{Error as ClientError, Result as ClientResult, ErrorKind as ClientErrorKind};
use substrate_client::error::{Error as ClientError, Result as ClientResult};
use substrate_primitives::{Blake2Hasher, H256};
use sr_primitives::generic::BlockId;
use sr_primitives::traits::{Block as BlockT, Header as HeaderT, ProvideRuntimeApi};
use polkadot_primitives::{Hash as PHash, Block as PBlock};
use polkadot_primitives::parachain::{Id as ParaId, ParachainHost};
use futures::prelude::*;
use futures::stream;
use futures::{prelude::*, stream};
use parity_codec::{Encode, Decode};
use log::warn;
......@@ -69,9 +68,9 @@ pub trait PolkadotClient: Clone {
type Error: std::fmt::Debug + Send;
/// A stream that yields updates to the parachain head.
type HeadUpdates: Stream<Item=HeadUpdate,Error=Self::Error> + Send;
type HeadUpdates: Stream<Item=HeadUpdate, Error=Self::Error> + Send;
/// A stream that yields finalized head-data for a certain parachain.
type Finalized: Stream<Item=Vec<u8>,Error=Self::Error> + Send;
type Finalized: Stream<Item=Vec<u8>, Error=Self::Error> + Send;
/// Get a stream of head updates.
fn head_updates(&self, para_id: ParaId) -> Self::HeadUpdates;
......@@ -134,8 +133,8 @@ impl<B, E, Block, RA> LocalClient for Client<B, E, Block, RA> where
fn mark_best(&self, hash: <Self::Block as BlockT>::Hash) -> ClientResult<bool> {
match self.set_head(BlockId::hash(hash)) {
Ok(()) => Ok(true),
Err(e) => match e.kind() {
ClientErrorKind::UnknownBlock(_) => Ok(false),
Err(e) => match e {
ClientError::UnknownBlock(_) => Ok(false),
_ => Err(e),
}
}
......@@ -144,8 +143,8 @@ impl<B, E, Block, RA> LocalClient for Client<B, E, Block, RA> where
fn finalize(&self, hash: <Self::Block as BlockT>::Hash) -> ClientResult<bool> {
match self.finalize_block(BlockId::hash(hash), None, true) {
Ok(()) => Ok(true),
Err(e) => match e.kind() {
ClientErrorKind::UnknownBlock(_) => Ok(false),
Err(e) => match e {
ClientError::UnknownBlock(_) => Ok(false),
_ => Err(e),
}
}
......@@ -169,8 +168,8 @@ impl<B, E, RA> PolkadotClient for Arc<Client<B, E, PBlock, RA>> where
{
type Error = ClientError;
type HeadUpdates = Box<Stream<Item=HeadUpdate, Error=Self::Error> + Send>;
type Finalized = Box<Stream<Item=Vec<u8>, Error=Self::Error> + Send>;
type HeadUpdates = Box<dyn Stream<Item=HeadUpdate, Error=Self::Error> + Send>;
type Finalized = Box<dyn Stream<Item=Vec<u8>, Error=Self::Error> + Send>;
fn head_updates(&self, para_id: ParaId) -> Self::HeadUpdates {
let parachain_key = parachain_key(para_id);
......
......@@ -21,6 +21,7 @@ hashbrown = "0.1"
keyring = { package = "substrate-keyring", git = "https://github.com/paritytech/substrate", branch = "bkchr-cumulus-branch" }
primitives = { package = "substrate-primitives", git = "https://github.com/paritytech/substrate", branch = "bkchr-cumulus-branch" }
executor = { package = "substrate-executor", git = "https://github.com/paritytech/substrate", branch = "bkchr-cumulus-branch" }
consensus-common = { package = "substrate-consensus-common", git = "https://github.com/paritytech/substrate", branch = "bkchr-cumulus-branch" }
test-client = { package = "cumulus-test-client", path = "../test/client" }
[features]
......
......@@ -19,13 +19,10 @@ use crate::{ParachainBlockData, WitnessData};
use rio::TestExternalities;
use keyring::AccountKeyring;
use primitives::{storage::well_known_keys};
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT};
use runtime_primitives::{generic::BlockId, traits::{Block as BlockT, Header as HeaderT}};
use executor::{WasmExecutor, error::Result, wasmi::RuntimeValue::{I64, I32}};
use test_client::{
TestClientBuilder, TestClient,
runtime::{Block, Transfer, Hash}, TestClientBuilderExt,
client_ext::TestClient as _,
};
use test_client::{TestClientBuilder, TestClient, LongestChain, runtime::{Block, Transfer, Hash}};
use consensus_common::SelectChain;
use std::collections::HashMap;
......@@ -91,21 +88,24 @@ fn create_extrinsics() -> Vec<<Block as BlockT>::Extrinsic> {
]
}
fn create_test_client() -> TestClient {
fn create_test_client() -> (TestClient, LongestChain) {
let mut genesis_extension = HashMap::new();
genesis_extension.insert(well_known_keys::CODE.to_vec(), WASM_CODE.to_vec());
TestClientBuilder::new()
.set_genesis_extension(genesis_extension)
.build_cumulus()
.build_with_longest_chain()
}
fn build_block_with_proof(
client: &TestClient,
extrinsics: Vec<<Block as BlockT>::Extrinsic>,
) -> (Block, WitnessData) {
let mut builder = client.new_block().expect("Initializes new block");
builder.record_proof();
let block_id = BlockId::Hash(client.info().chain.best_hash);
let mut builder = client.new_block_at_with_proof_recording(
&block_id,
Default::default()
).expect("Initializes new block");
extrinsics.into_iter().for_each(|e| builder.push(e).expect("Pushes an extrinsic"));
......@@ -118,9 +118,9 @@ fn build_block_with_proof(
#[test]
fn validate_block_with_no_extrinsics() {
let client = create_test_client();
let witness_data_storage_root = *client
.best_block_header()
let (client, longest_chain) = create_test_client();
let witness_data_storage_root = *longest_chain
.best_chain()
.expect("Best block exists")
.state_root();
let (block, witness_data) = build_block_with_proof(&client, Vec::new());
......@@ -132,14 +132,14 @@ fn validate_block_with_no_extrinsics() {
witness_data,
witness_data_storage_root
);
call_validate_block(client.genesis_hash(), block_data).expect("Calls `validate_block`");
call_validate_block(client.info().chain.genesis_hash, block_data).expect("Calls `validate_block`");
}
#[test]
fn validate_block_with_extrinsics() {
let client = create_test_client();
let witness_data_storage_root = *client
.best_block_header()
let (client, longest_chain) = create_test_client();
let witness_data_storage_root = *longest_chain
.best_chain()
.expect("Best block exists")
.state_root();
let (block, witness_data) = build_block_with_proof(&client, create_extrinsics());
......@@ -151,15 +151,15 @@ fn validate_block_with_extrinsics() {
witness_data,
witness_data_storage_root
);
call_validate_block(client.genesis_hash(), block_data).expect("Calls `validate_block`");
call_validate_block(client.info().chain.genesis_hash, block_data).expect("Calls `validate_block`");
}
#[test]
#[should_panic]
fn validate_block_invalid_parent_hash() {
let client = create_test_client();
let witness_data_storage_root = *client
.best_block_header()
let (client, longest_chain) = create_test_client();
let witness_data_storage_root = *longest_chain
.best_chain()
.expect("Best block exists")
.state_root();
let (block, witness_data) = build_block_with_proof(&client, Vec::new());
......@@ -172,5 +172,5 @@ fn validate_block_invalid_parent_hash() {
witness_data,
witness_data_storage_root
);
call_validate_block(client.genesis_hash(), block_data).expect("Calls `validate_block`");
call_validate_block(client.info().chain.genesis_hash, block_data).expect("Calls `validate_block`");
}
......@@ -44,13 +44,8 @@ pub type TestClient = client::Client<
Backend, Executor, runtime::Block, runtime::RuntimeApi
>;
/// An extension to the `TestClientBuilder` for building a cumulus test-client.
pub trait TestClientBuilderExt {
fn build_cumulus(self) -> TestClient;
}
/// Test client builder for Cumulus
pub type TestClientBuilder = substrate_test_client::TestClientBuilder<LocalExecutor, Backend>;
impl TestClientBuilderExt for TestClientBuilder {
fn build_cumulus(self) -> TestClient {
self.build_with_native_executor(NativeExecutor::<LocalExecutor>::new(None))
}
}
\ No newline at end of file
/// LongestChain type for the test runtime/client.
pub type LongestChain = substrate_test_client::client::LongestChain<Backend, runtime::Block>;
\ No newline at end of file
This diff is collapsed.
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment