From 8d30f9fecbd91e132ccf368d4b6eb35ed403718f Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Tue, 26 Jan 2016 17:55:08 +0400 Subject: [PATCH] bad block import checks --- src/tests/client.rs | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/tests/client.rs b/src/tests/client.rs index c14f2e2f0..a9d212bc1 100644 --- a/src/tests/client.rs +++ b/src/tests/client.rs @@ -31,6 +31,21 @@ fn get_good_dummy_block() -> Bytes { create_test_block(&block_header) } +#[cfg(test)] +fn get_bad_state_dummy_block() -> Bytes { + let mut block_header = Header::new(); + let test_spec = get_test_spec(); + let test_engine = test_spec.to_engine().unwrap(); + block_header.gas_limit = decode(test_engine.spec().engine_params.get("minGasLimit").unwrap()); + block_header.difficulty = decode(test_engine.spec().engine_params.get("minimumDifficulty").unwrap()); + block_header.timestamp = 40; + block_header.number = 1; + block_header.parent_hash = test_engine.spec().genesis_header().hash(); + block_header.state_root = x!(0xbad); + + create_test_block(&block_header) +} + #[cfg(test)] fn create_test_block(header: &Header) -> Bytes { let mut rlp = RlpStream::new_list(3); @@ -40,6 +55,23 @@ fn create_test_block(header: &Header) -> Bytes { rlp.out() } +#[cfg(test)] +fn get_test_client_with_blocks(blocks: Vec) -> Arc { + let client = Client::new(get_test_spec(), &get_random_temp_dir(), IoChannel::disconnected()).unwrap(); + + for block in &blocks { + if let Err(_) = client.import_block(block.clone()) { + panic!("panic importing block which is well-formed"); + } + } + + client.flush_queue(); + + client.import_verified_blocks(&IoChannel::disconnected()); + + client +} + #[test] fn created() { @@ -81,5 +113,13 @@ fn query_none_block() { let non_existant = client.block_header_at(188); - assert!(non_existant == Option::None); + assert!(non_existant.is_none()); +} + +#[test] +fn query_bad_block() { + let client = get_test_client_with_blocks(vec![get_bad_state_dummy_block()]); + let bad_block:Option = client.block_header_at(1); + + assert!(bad_block.is_none()); } \ No newline at end of file