From 929f44fe4f62910fc0eba95257953b09ccd52b24 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 2 Mar 2016 00:34:38 +0100 Subject: [PATCH] Tests for Client sealing. --- ethcore/src/engine.rs | 9 +++++++-- ethcore/src/ethereum/ethash.rs | 3 ++- ethcore/src/tests/client.rs | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ethcore/src/engine.rs b/ethcore/src/engine.rs index a05c78ff5..6806fcce3 100644 --- a/ethcore/src/engine.rs +++ b/ethcore/src/engine.rs @@ -81,9 +81,14 @@ pub trait Engine : Sync + Send { self.verify_block_basic(header, None).and_then(|_| self.verify_block_unordered(header, None)) } - /// Don't forget to call Super::populateFromParent when subclassing & overriding. + /// Don't forget to call Super::populate_from_parent when subclassing & overriding. // TODO: consider including State in the params. - fn populate_from_parent(&self, _header: &mut Header, _parent: &Header) {} + fn populate_from_parent(&self, header: &mut Header, parent: &Header) { + header.parent_hash = parent.hash; + header.difficulty = parent.difficulty; + header.gas_limit = parent.gas_limit; + header.number = parent.number + 1; + } // TODO: builtin contract routing - to do this properly, it will require removing the built-in configuration-reading logic // from Spec into here and removing the Spec::builtins field. diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 6dabe558f..bf0c1d188 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -144,7 +144,8 @@ impl Engine for Ethash { let difficulty = Ethash::boundary_to_difficulty(&Ethash::from_ethash(quick_get_difficulty( &Ethash::to_ethash(header.bare_hash()), header.nonce().low_u64(), - &Ethash::to_ethash(header.mix_hash()) ))); + &Ethash::to_ethash(header.mix_hash()) + ))); if difficulty < header.difficulty { return Err(From::from(BlockError::InvalidProofOfWork(OutOfBounds { min: Some(header.difficulty), max: None, found: difficulty }))); } diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index 83df81fa2..65c9d7358 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -15,6 +15,7 @@ // along with Parity. If not, see . use client::{BlockChainClient, Client, ClientConfig, BlockId}; +use block::IsBlock; use tests::helpers::*; use common::*; use devtools::*; @@ -106,3 +107,22 @@ fn can_collect_garbage() { client.tick(); assert!(client.blockchain_cache_info().blocks < 100 * 1024); } + +#[test] +fn can_mine() { + let dummy_blocks = get_good_dummy_block_seq(2); + let client_result = get_test_client_with_blocks(vec![dummy_blocks[0].clone()]); + let client = client_result.reference(); + let b = client.sealing_block(); + let pow_hash = { + let u = b.lock().unwrap(); + match *u { + Some(ref b) => { + assert_eq!(*b.block().header().parent_hash(), BlockView::new(&dummy_blocks[0]).header_view().sha3()); + b.hash() + } + None => { panic!(); } + } + }; + assert!(client.submit_seal(pow_hash, vec![]).is_ok()); +} \ No newline at end of file