Tests for Client sealing.
This commit is contained in:
parent
046b8e4704
commit
929f44fe4f
@ -81,9 +81,14 @@ pub trait Engine : Sync + Send {
|
|||||||
self.verify_block_basic(header, None).and_then(|_| self.verify_block_unordered(header, None))
|
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.
|
// 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
|
// 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.
|
// from Spec into here and removing the Spec::builtins field.
|
||||||
|
@ -144,7 +144,8 @@ impl Engine for Ethash {
|
|||||||
let difficulty = Ethash::boundary_to_difficulty(&Ethash::from_ethash(quick_get_difficulty(
|
let difficulty = Ethash::boundary_to_difficulty(&Ethash::from_ethash(quick_get_difficulty(
|
||||||
&Ethash::to_ethash(header.bare_hash()),
|
&Ethash::to_ethash(header.bare_hash()),
|
||||||
header.nonce().low_u64(),
|
header.nonce().low_u64(),
|
||||||
&Ethash::to_ethash(header.mix_hash()) )));
|
&Ethash::to_ethash(header.mix_hash())
|
||||||
|
)));
|
||||||
if difficulty < header.difficulty {
|
if difficulty < header.difficulty {
|
||||||
return Err(From::from(BlockError::InvalidProofOfWork(OutOfBounds { min: Some(header.difficulty), max: None, found: difficulty })));
|
return Err(From::from(BlockError::InvalidProofOfWork(OutOfBounds { min: Some(header.difficulty), max: None, found: difficulty })));
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use client::{BlockChainClient, Client, ClientConfig, BlockId};
|
use client::{BlockChainClient, Client, ClientConfig, BlockId};
|
||||||
|
use block::IsBlock;
|
||||||
use tests::helpers::*;
|
use tests::helpers::*;
|
||||||
use common::*;
|
use common::*;
|
||||||
use devtools::*;
|
use devtools::*;
|
||||||
@ -106,3 +107,22 @@ fn can_collect_garbage() {
|
|||||||
client.tick();
|
client.tick();
|
||||||
assert!(client.blockchain_cache_info().blocks < 100 * 1024);
|
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());
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user