queue duplicates error check
This commit is contained in:
parent
9645ba8625
commit
64a84b91bc
@ -292,12 +292,47 @@ mod tests {
|
|||||||
use util::*;
|
use util::*;
|
||||||
use spec::*;
|
use spec::*;
|
||||||
use block_queue::*;
|
use block_queue::*;
|
||||||
|
use tests::helpers::*;
|
||||||
|
use error::*;
|
||||||
|
|
||||||
|
fn get_test_queue() -> BlockQueue {
|
||||||
|
let spec = get_test_spec();
|
||||||
|
let engine = spec.to_engine().unwrap();
|
||||||
|
BlockQueue::new(Arc::new(engine), IoChannel::disconnected())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_block_queue() {
|
fn can_be_created() {
|
||||||
// TODO better test
|
// TODO better test
|
||||||
let spec = Spec::new_test();
|
let spec = Spec::new_test();
|
||||||
let engine = spec.to_engine().unwrap();
|
let engine = spec.to_engine().unwrap();
|
||||||
let _ = BlockQueue::new(Arc::new(engine), IoChannel::disconnected());
|
let _ = BlockQueue::new(Arc::new(engine), IoChannel::disconnected());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_verify_blocks() {
|
||||||
|
let mut queue = get_test_queue();
|
||||||
|
if let Err(e) = queue.import_block(get_good_dummy_block()) {
|
||||||
|
panic!("error importing block that is valid by definition({:?})", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn returns_error_for_duplicates() {
|
||||||
|
let mut queue = get_test_queue();
|
||||||
|
if let Err(e) = queue.import_block(get_good_dummy_block()) {
|
||||||
|
panic!("error importing block that is valid by definition({:?})", e);
|
||||||
|
}
|
||||||
|
let duplicate_import = queue.import_block(get_good_dummy_block());
|
||||||
|
|
||||||
|
match duplicate_import {
|
||||||
|
Err(e) => {
|
||||||
|
match e {
|
||||||
|
ImportError::AlreadyQueued => {},
|
||||||
|
_ => { panic!("must return AlreadyQueued error"); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(_) => { panic!("must produce error"); }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,34 +2,6 @@ use client::{BlockChainClient,Client};
|
|||||||
use super::test_common::*;
|
use super::test_common::*;
|
||||||
use super::helpers::*;
|
use super::helpers::*;
|
||||||
|
|
||||||
fn get_good_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 = test_engine.spec().genesis_header().state_root;
|
|
||||||
|
|
||||||
create_test_block(&block_header)
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn created() {
|
fn created() {
|
||||||
let dir = RandomTempPath::new();
|
let dir = RandomTempPath::new();
|
||||||
|
@ -177,3 +177,31 @@ pub fn generate_dummy_empty_blockchain() -> GuardedTempResult<BlockChain> {
|
|||||||
result: bc
|
result: bc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_good_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 = test_engine.spec().genesis_header().state_root;
|
||||||
|
|
||||||
|
create_test_block(&block_header)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub 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)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user