Skip to content
Snippets Groups Projects
Commit e4ec12a6 authored by Bastian Köcher's avatar Bastian Köcher
Browse files

Trying to get the tests back working

parent be6df468
Branches
No related merge requests found
Showing with 944 additions and 796 deletions
This diff is collapsed.
[workspace]
members = [ "consensus", "runtime" ]
members = [
"consensus",
"runtime",
"test/runtime",
"test/client",
]
......@@ -7,15 +7,15 @@ edition = "2018"
[dependencies]
# substrate deps
substrate-client = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-consensus-common = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sr-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-client = { git = "https://github.com/paritytech/substrate", branch = "bkchr-cumulus-branch" }
substrate-consensus-common = { git = "https://github.com/paritytech/substrate", branch = "bkchr-cumulus-branch" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "bkchr-cumulus-branch" }
sr-primitives = { git = "https://github.com/paritytech/substrate", branch = "bkchr-cumulus-branch" }
# polkadot deps
polkadot-service = { git = "https://github.com/paritytech/polkadot" }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot" }
polkadot-runtime = { git = "https://github.com/paritytech/polkadot" }
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"
......
......@@ -6,22 +6,22 @@ edition = "2018"
[dependencies]
codec = { package = "parity-codec", version = "3.1", default-features = false, features = [ "derive" ] }
rstd = { package = "sr-std", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
runtime-primitives = { package = "sr-primitives", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
primitives = { package = "substrate-primitives", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
rio = { package = "sr-io", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
executive = { package = "srml-executive", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
substrate-trie = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
rstd = { package = "sr-std", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
runtime-primitives = { package = "sr-primitives", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
primitives = { package = "substrate-primitives", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
rio = { package = "sr-io", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
executive = { package = "srml-executive", git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
substrate-trie = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
memory-db = { version = "0.12.2", default-features = false }
hash-db = { version = "0.12.2", default-features = false }
trie-db = { version = "0.12.2", default-features = false }
hashbrown = "0.1"
[dev-dependencies]
keyring = { package = "substrate-keyring", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
primitives = { package = "substrate-primitives", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
executor = { package = "substrate-executor", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
test-runtime = { package = "substrate-test-runtime", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
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" }
test-client = { package = "cumulus-test-client", path = "../test/client" }
[features]
default = ["std"]
......@@ -35,5 +35,10 @@ std = [
"memory-db/std",
"hash-db/std",
"trie-db/std",
"test-client/std",
"substrate-trie/std",
]
wasm = [
"hashbrown/nightly",
"rio/wasm-nice-panic-message",
]
wasm = ["hashbrown/nightly"]
......@@ -37,7 +37,7 @@ const STORAGE_ROOT_LEN: usize = 32;
/// Extract the hashing algorithm type from the given block type.
type HashingOf<B> = <<B as BlockT>::Header as HeaderT>::Hashing;
/// Extract the hash type from the given block type.
type HashOf<B> = <<B as BlockT>::Header as HeaderT>::Hash;
type HashOf<B> = <B as BlockT>::Hash;
/// Abstract the storage into a trait without `Block` generic.
trait StorageT {
......
......@@ -14,47 +14,42 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
use crate::ParachainBlock;
use crate::{ParachainBlockData, WitnessData};
use rio::{twox_128, TestExternalities};
use rio::TestExternalities;
use keyring::AccountKeyring;
use primitives::map;
use runtime_primitives::traits::Block as BlockT;
use primitives::{storage::well_known_keys};
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT};
use executor::{WasmExecutor, error::Result, wasmi::RuntimeValue::{I64, I32}};
use test_runtime::{Block, Header, Transfer};
use test_client::{
TestClientBuilder, TestClient,
runtime::{Block, Transfer}, TestClientBuilderExt,
};
use std::collections::BTreeMap;
use std::collections::HashMap;
use codec::{KeyedVec, Encode};
use codec::Encode;
const WASM_CODE: &[u8] =
include_bytes!("../../test-runtime/wasm/target/wasm32-unknown-unknown/release/cumulus_test_runtime.compact.wasm");
include_bytes!("../../../test/runtime/wasm/target/wasm32-unknown-unknown/release/cumulus_test_runtime.compact.wasm");
fn create_witness_data() -> BTreeMap<Vec<u8>, Vec<u8>> {
map![
twox_128(&AccountKeyring::Alice.to_raw_public().to_keyed_vec(b"balance:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0]
]
}
fn call_validate_block(block: ParachainBlock<Block>, prev_header: <Block as BlockT>::Header) -> Result<()> {
fn call_validate_block(block_data: ParachainBlockData<Block>) -> Result<()> {
let mut ext = TestExternalities::default();
WasmExecutor::new().call_with_custom_signature(
&mut ext,
8,
1024,
&WASM_CODE,
"validate_block",
|alloc| {
let block = block.encode();
let prev_header = prev_header.encode();
let block_offset = alloc(&block)?;
let prev_head_offset = alloc(&prev_header)?;
let block_data = block_data.encode();
println!("ALLOC: {}", block_data.len());
let block_data_offset = alloc(&block_data)?;
println!("ALLOC");
Ok(
vec![
I32(block_offset as i32),
I64(block.len() as i64),
I32(prev_head_offset as i32),
I64(prev_header.len() as i64),
I32(block_data_offset as i32),
I64(block_data.len() as i64),
]
)
},
......@@ -79,34 +74,62 @@ fn create_extrinsics() -> Vec<<Block as BlockT>::Extrinsic> {
]
}
fn create_prev_header() -> Header {
Header {
parent_hash: Default::default(),
number: 1,
state_root: Default::default(),
extrinsics_root: Default::default(),
digest: Default::default(),
}
fn create_test_client() -> TestClient {
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()
}
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();
extrinsics.into_iter().for_each(|e| builder.push(e).expect("Pushes an extrinsic"));
let (block, proof) = builder
.bake_and_extract_proof()
.expect("Finalizes block");
(block, proof.expect("We enabled proof recording before."))
}
#[test]
fn validate_block_with_empty_block() {
let prev_header = create_prev_header();
call_validate_block(ParachainBlock::default(), prev_header).expect("Calls `validate_block`");
let client = create_test_client();
let witness_data_storage_root = *client
.best_block_header()
.expect("Best block exists")
.state_root();
let (block, witness_data) = build_block_with_proof(&client, Vec::new());
let (header, extrinsics) = block.deconstruct();
let block_data = ParachainBlockData::new(
header,
extrinsics,
witness_data,
witness_data_storage_root
);
call_validate_block(block_data).expect("Calls `validate_block`");
}
#[test]
fn validate_block_with_empty_witness_data() {
let prev_header = create_prev_header();
// #[test]
// fn validate_block_with_empty_witness_data() {
// let prev_header = create_header();
let block = ParachainBlock::new(create_extrinsics(), Default::default());
assert!(call_validate_block(block, prev_header).is_err());
}
// let block = ParachainBlock::new(create_extrinsics(), Default::default());
// assert!(call_validate_block(block).is_err());
// }
#[test]
fn validate_block_with_witness_data() {
let prev_header = create_prev_header();
// #[test]
// fn validate_block_with_witness_data() {
// let prev_header = create_header();
let block = ParachainBlock::new(create_extrinsics(), create_witness_data());
call_validate_block(block, prev_header).expect("`validate_block` succeeds");
}
\ No newline at end of file
// let block = ParachainBlock::new(create_extrinsics(), create_witness_data());
// call_validate_block(block).expect("`validate_block` succeeds");
// }
\ No newline at end of file
......@@ -4,7 +4,7 @@ ROOT=`dirname "$0"`
# A list of directories which contain wasm projects.
SRCS=(
"runtime/test-runtime/wasm"
"test/runtime/wasm"
)
# Make pushd/popd silent.
......
[package]
name = "cumulus-test-client"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
substrate-test-client = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
[features]
default = ["std"]
std = [
"substrate-test-client/std",
]
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
//! A Cumulus test client.
pub use substrate_test_client::*;
mod local_executor {
#![allow(missing_docs)]
use substrate_test_client::runtime;
use substrate_test_client::executor::native_executor_instance;
native_executor_instance!(
pub LocalExecutor,
runtime::api::dispatch,
runtime::native_version,
include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/cumulus_test_runtime.compact.wasm")
);
}
/// Native executor used for tests.
pub use local_executor::LocalExecutor;
/// Test client executor.
pub type Executor = client::LocalCallExecutor<
Backend,
executor::NativeExecutor<LocalExecutor>,
>;
/// Test client type.
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;
}
impl TestClientBuilderExt for TestClientBuilder {
fn build_cumulus(self) -> TestClient {
self.build_with_native_executor(NativeExecutor::<LocalExecutor>::new(None))
}
}
\ No newline at end of file
......@@ -5,8 +5,8 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
runtime = { package = "cumulus-runtime", path = "..", default-features = false }
substrate-test-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
runtime = { package = "cumulus-runtime", path = "../../runtime", default-features = false }
substrate-test-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "bkchr-cumulus-branch" }
[features]
default = ["std"]
......
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