Fixes tests

This commit is contained in:
Bastian Köcher
2019-11-06 09:00:29 +01:00
parent ae2b9249e4
commit 1c5e2132d8
4 changed files with 94 additions and 14 deletions
+4
View File
@@ -553,13 +553,16 @@ version = "0.1.0"
dependencies = [ dependencies = [
"cumulus-consensus 0.1.0", "cumulus-consensus 0.1.0",
"cumulus-runtime 0.1.0", "cumulus-runtime 0.1.0",
"cumulus-test-client 0.1.0",
"cumulus-test-runtime 0.1.0", "cumulus-test-runtime 0.1.0",
"env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"polkadot-collator 0.6.0 (git+https://github.com/paritytech/polkadot?branch=bkchr-cumulus-branch)", "polkadot-collator 0.6.0 (git+https://github.com/paritytech/polkadot?branch=bkchr-cumulus-branch)",
"polkadot-executor 0.6.0 (git+https://github.com/paritytech/polkadot?branch=bkchr-cumulus-branch)",
"polkadot-primitives 0.6.0 (git+https://github.com/paritytech/polkadot?branch=bkchr-cumulus-branch)", "polkadot-primitives 0.6.0 (git+https://github.com/paritytech/polkadot?branch=bkchr-cumulus-branch)",
"sr-primitives 2.0.0 (git+https://github.com/paritytech/substrate?branch=bkchr-cumulus-branch)", "sr-primitives 2.0.0 (git+https://github.com/paritytech/substrate?branch=bkchr-cumulus-branch)",
"substrate-cli 2.0.0 (git+https://github.com/paritytech/substrate?branch=bkchr-cumulus-branch)", "substrate-cli 2.0.0 (git+https://github.com/paritytech/substrate?branch=bkchr-cumulus-branch)",
@@ -569,6 +572,7 @@ dependencies = [
"substrate-keyring 2.0.0 (git+https://github.com/paritytech/substrate?branch=bkchr-cumulus-branch)", "substrate-keyring 2.0.0 (git+https://github.com/paritytech/substrate?branch=bkchr-cumulus-branch)",
"substrate-primitives 2.0.0 (git+https://github.com/paritytech/substrate?branch=bkchr-cumulus-branch)", "substrate-primitives 2.0.0 (git+https://github.com/paritytech/substrate?branch=bkchr-cumulus-branch)",
"substrate-service 2.0.0 (git+https://github.com/paritytech/substrate?branch=bkchr-cumulus-branch)", "substrate-service 2.0.0 (git+https://github.com/paritytech/substrate?branch=bkchr-cumulus-branch)",
"substrate-test-client 2.0.0 (git+https://github.com/paritytech/substrate?branch=bkchr-cumulus-branch)",
] ]
[[package]] [[package]]
+4
View File
@@ -31,4 +31,8 @@ parking_lot = "0.9"
[dev-dependencies] [dev-dependencies]
test-runtime = { package = "cumulus-test-runtime", path = "../test/runtime" } test-runtime = { package = "cumulus-test-runtime", path = "../test/runtime" }
test-client = { package = "cumulus-test-client", path = "../test/client" }
substrate-test-client = { git = "https://github.com/paritytech/substrate", branch = "bkchr-cumulus-branch" }
polkadot-executor = { git = "https://github.com/paritytech/polkadot", branch = "bkchr-cumulus-branch" }
keyring = { package = "substrate-keyring", git = "https://github.com/paritytech/substrate", branch = "bkchr-cumulus-branch" } keyring = { package = "substrate-keyring", git = "https://github.com/paritytech/substrate", branch = "bkchr-cumulus-branch" }
env_logger = "0.7.1"
+69 -6
View File
@@ -319,10 +319,13 @@ mod tests {
use polkadot_primitives::parachain::{ConsolidatedIngress, HeadData, FeeSchedule}; use polkadot_primitives::parachain::{ConsolidatedIngress, HeadData, FeeSchedule};
use keyring::Sr25519Keyring; use keyring::Sr25519Keyring;
use sr_primitives::traits::{DigestFor, Header as HeaderT}; use sr_primitives::{generic::BlockId, traits::{DigestFor, Header as HeaderT}};
use inherents::InherentData; use inherents::InherentData;
use substrate_client::error::Result as ClientResult;
use substrate_test_client::{NativeExecutor, WasmExecutionMethod::Interpreted};
use test_runtime::{Block, Header}; use test_runtime::{Block, Header};
use test_client::{Client, DefaultTestClientBuilderExt, TestClientBuilder, TestClientBuilderExt};
use futures03::future; use futures03::future;
use futures::Stream; use futures::Stream;
@@ -368,7 +371,7 @@ mod tests {
digest, digest,
); );
future::ready(Ok((Block::new(header, Vec::new()), None))) future::ready(Ok((Block::new(header, Vec::new()), Some(Default::default()))))
} }
} }
@@ -398,11 +401,72 @@ mod tests {
Ok(ConsolidatedIngress(Vec::new())) Ok(ConsolidatedIngress(Vec::new()))
} }
} }
/*
#[derive(Clone)]
struct DummyPolkadotClient;
impl cumulus_consensus::PolkadotClient for DummyPolkadotClient {
type Error = Error;
type Finalized = Box<dyn futures03::Stream<Item=Vec<u8>> + Send + Unpin>;
fn finalized_heads(&self, _: ParaId) -> ClientResult<Self::Finalized> {
unimplemented!("Not required in tests")
}
fn parachain_head_at(
&self,
_: &BlockId<PBlock>,
_: ParaId,
) -> ClientResult<Option<Vec<u8>>>{
unimplemented!("Not required in tests")
}
}
struct DummySetup;
impl SetupParachain<Block> for DummySetup {
type ProposerFactory = DummyFactory;
type BlockImport = Client;
fn setup_parachain<P: cumulus_consensus::PolkadotClient>(
self,
_: P,
_: TaskExecutor,
) -> Result<(Self::ProposerFactory, Self::BlockImport, InherentDataProviders), String> {
Ok((DummyFactory, TestClientBuilder::new().build(), InherentDataProviders::default()))
}
}
type BoxFuture = Box<dyn Future<Item = (), Error = ()> + Send>;
struct DummyFutureExecutor;
impl futures::future::Executor<BoxFuture>
for DummyFutureExecutor
{
fn execute(
&self,
_: BoxFuture,
) -> Result<(), futures::future::ExecuteError<BoxFuture>> {
unimplemented!("Not required in tests")
}
}
#[test] #[test]
fn collates_produces_a_block() { fn collates_produces_a_block() {
let builder = CollatorBuilder::new(DummyFactory); let _ = env_logger::try_init();
let context = builder.build(Arc::new(DummyCollatorNetwork)).expect("Creates parachain context");
let builder = CollatorBuilder::new(DummySetup);
let context = builder.build(
Arc::new(
substrate_test_client::TestClientBuilder::<_, _, ()>::default()
.build_with_native_executor(
Some(NativeExecutor::<polkadot_executor::Executor>::new(Interpreted, None)),
).0
),
Arc::new(DummyFutureExecutor),
Arc::new(DummyCollatorNetwork),
).expect("Creates parachain context");
let id = ParaId::from(100); let id = ParaId::from(100);
let header = Header::new( let header = Header::new(
@@ -435,5 +499,4 @@ mod tests {
assert_eq!(1337, *block.header().number()); assert_eq!(1337, *block.header().number());
} }
*/
} }
+17 -8
View File
@@ -25,11 +25,14 @@ use test_client::{
runtime::{Block, Transfer, Hash, WASM_BINARY, Header} runtime::{Block, Transfer, Hash, WASM_BINARY, Header}
}; };
use consensus_common::SelectChain; use consensus_common::SelectChain;
use parachain::ValidationParams; use parachain::{ValidationParams, ValidationResult};
use codec::Encode; use codec::{Encode, Decode};
fn call_validate_block(parent_head: Header, block_data: ParachainBlockData<Block>) -> Result<()> { fn call_validate_block(
parent_head: Header,
block_data: ParachainBlockData<Block>,
) -> Result<Header> {
let mut ext = TestExternalities::default(); let mut ext = TestExternalities::default();
let mut ext_ext = ext.ext(); let mut ext_ext = ext.ext();
let params = ValidationParams { let params = ValidationParams {
@@ -45,7 +48,9 @@ fn call_validate_block(parent_head: Header, block_data: ParachainBlockData<Block
&mut ext_ext, &mut ext_ext,
&WASM_BINARY, &WASM_BINARY,
1024, 1024,
).map(|v| assert!(v.is_empty(), "`validate_block` does not return anything")) )
.map(|v| ValidationResult::decode(&mut &v[..]).expect("Decode `ValidationResult`."))
.map(|v| Header::decode(&mut &v.head_data[..]).expect("Decode `Header`."))
} }
fn create_extrinsics() -> Vec<<Block as BlockT>::Extrinsic> { fn create_extrinsics() -> Vec<<Block as BlockT>::Extrinsic> {
@@ -110,12 +115,14 @@ fn validate_block_with_no_extrinsics() {
let (header, extrinsics) = block.deconstruct(); let (header, extrinsics) = block.deconstruct();
let block_data = ParachainBlockData::new( let block_data = ParachainBlockData::new(
header, header.clone(),
extrinsics, extrinsics,
witness_data, witness_data,
witness_data_storage_root witness_data_storage_root
); );
call_validate_block(parent_head, block_data).expect("Calls `validate_block`");
let res_header = call_validate_block(parent_head, block_data).expect("Calls `validate_block`");
assert_eq!(header, res_header);
} }
#[test] #[test]
@@ -127,12 +134,14 @@ fn validate_block_with_extrinsics() {
let (header, extrinsics) = block.deconstruct(); let (header, extrinsics) = block.deconstruct();
let block_data = ParachainBlockData::new( let block_data = ParachainBlockData::new(
header, header.clone(),
extrinsics, extrinsics,
witness_data, witness_data,
witness_data_storage_root witness_data_storage_root
); );
call_validate_block(parent_head, block_data).expect("Calls `validate_block`");
let res_header = call_validate_block(parent_head, block_data).expect("Calls `validate_block`");
assert_eq!(header, res_header);
} }
#[test] #[test]