pass engine in tests
This commit is contained in:
parent
84fdaf966a
commit
66526af5a8
@ -38,6 +38,12 @@ impl NullEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for NullEngine {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new(Default::default(), Default::default())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Engine for NullEngine {
|
impl Engine for NullEngine {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"NullEngine"
|
"NullEngine"
|
||||||
|
@ -31,23 +31,20 @@ use std::collections::HashMap;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::atomic::AtomicBool;
|
use std::sync::atomic::AtomicBool;
|
||||||
|
|
||||||
use spec::Spec;
|
|
||||||
|
|
||||||
fn chunk_and_restore(amount: u64) {
|
fn chunk_and_restore(amount: u64) {
|
||||||
let mut canon_chain = ChainGenerator::default();
|
let mut canon_chain = ChainGenerator::default();
|
||||||
let mut finalizer = BlockFinalizer::default();
|
let mut finalizer = BlockFinalizer::default();
|
||||||
let genesis = canon_chain.generate(&mut finalizer).unwrap();
|
let genesis = canon_chain.generate(&mut finalizer).unwrap();
|
||||||
let db_cfg = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
|
let db_cfg = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
|
||||||
|
|
||||||
|
let engine = Arc::new(::engines::NullEngine::default());
|
||||||
let orig_path = RandomTempPath::create_dir();
|
let orig_path = RandomTempPath::create_dir();
|
||||||
let new_path = RandomTempPath::create_dir();
|
let new_path = RandomTempPath::create_dir();
|
||||||
let mut snapshot_path = new_path.as_path().to_owned();
|
let mut snapshot_path = new_path.as_path().to_owned();
|
||||||
snapshot_path.push("SNAP");
|
snapshot_path.push("SNAP");
|
||||||
|
|
||||||
let new_chain = |db| BlockChain::new(Default::default(), &genesis, db, Spec::new_null().engine);
|
|
||||||
|
|
||||||
let old_db = Arc::new(Database::open(&db_cfg, orig_path.as_str()).unwrap());
|
let old_db = Arc::new(Database::open(&db_cfg, orig_path.as_str()).unwrap());
|
||||||
let bc = new_chain(old_db.clone());
|
let bc = BlockChain::new(Default::default(), &genesis, old_db.clone(), engine.clone());
|
||||||
|
|
||||||
// build the blockchain.
|
// build the blockchain.
|
||||||
let mut batch = old_db.transaction();
|
let mut batch = old_db.transaction();
|
||||||
@ -77,21 +74,20 @@ fn chunk_and_restore(amount: u64) {
|
|||||||
|
|
||||||
// restore it.
|
// restore it.
|
||||||
let new_db = Arc::new(Database::open(&db_cfg, new_path.as_str()).unwrap());
|
let new_db = Arc::new(Database::open(&db_cfg, new_path.as_str()).unwrap());
|
||||||
let new_chain = BlockChain::new(Default::default(), &genesis, new_db.clone(), Spec::new_null().engine);
|
let new_chain = BlockChain::new(Default::default(), &genesis, new_db.clone(), engine.clone());
|
||||||
let mut rebuilder = BlockRebuilder::new(new_chain, new_db.clone(), &manifest).unwrap();
|
let mut rebuilder = BlockRebuilder::new(new_chain, new_db.clone(), &manifest).unwrap();
|
||||||
let reader = PackedReader::new(&snapshot_path).unwrap().unwrap();
|
let reader = PackedReader::new(&snapshot_path).unwrap().unwrap();
|
||||||
let engine = ::engines::NullEngine::new(Default::default(), Default::default());
|
|
||||||
let flag = AtomicBool::new(true);
|
let flag = AtomicBool::new(true);
|
||||||
for chunk_hash in &reader.manifest().block_hashes {
|
for chunk_hash in &reader.manifest().block_hashes {
|
||||||
let compressed = reader.chunk(*chunk_hash).unwrap();
|
let compressed = reader.chunk(*chunk_hash).unwrap();
|
||||||
let chunk = snappy::decompress(&compressed).unwrap();
|
let chunk = snappy::decompress(&compressed).unwrap();
|
||||||
rebuilder.feed(&chunk, &engine, &flag).unwrap();
|
rebuilder.feed(&chunk, engine.as_ref(), &flag).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
rebuilder.finalize(HashMap::new()).unwrap();
|
rebuilder.finalize(HashMap::new()).unwrap();
|
||||||
|
|
||||||
// and test it.
|
// and test it.
|
||||||
let new_chain = BlockChain::new(Default::default(), &genesis, new_db, Spec::new_null().engine);
|
let new_chain = BlockChain::new(Default::default(), &genesis, new_db, engine);
|
||||||
assert_eq!(new_chain.best_block_hash(), best_hash);
|
assert_eq!(new_chain.best_block_hash(), best_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,8 +121,8 @@ fn checks_flag() {
|
|||||||
|
|
||||||
let db_cfg = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
|
let db_cfg = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
|
||||||
let db = Arc::new(Database::open(&db_cfg, path.as_str()).unwrap());
|
let db = Arc::new(Database::open(&db_cfg, path.as_str()).unwrap());
|
||||||
let chain = BlockChain::new(Default::default(), &genesis, db.clone());
|
let engine = Arc::new(::engines::NullEngine::default());
|
||||||
let engine = ::engines::NullEngine::new(Default::default(), Default::default());
|
let chain = BlockChain::new(Default::default(), &genesis, db.clone(), engine.clone());
|
||||||
|
|
||||||
let manifest = ::snapshot::ManifestData {
|
let manifest = ::snapshot::ManifestData {
|
||||||
state_hashes: Vec::new(),
|
state_hashes: Vec::new(),
|
||||||
@ -138,7 +134,7 @@ fn checks_flag() {
|
|||||||
|
|
||||||
let mut rebuilder = BlockRebuilder::new(chain, db.clone(), &manifest).unwrap();
|
let mut rebuilder = BlockRebuilder::new(chain, db.clone(), &manifest).unwrap();
|
||||||
|
|
||||||
match rebuilder.feed(&chunk, &engine, &AtomicBool::new(false)) {
|
match rebuilder.feed(&chunk, engine.as_ref(), &AtomicBool::new(false)) {
|
||||||
Err(Error::Snapshot(SnapshotError::RestorationAborted)) => {}
|
Err(Error::Snapshot(SnapshotError::RestorationAborted)) => {}
|
||||||
_ => panic!("Wrong result on abort flag set")
|
_ => panic!("Wrong result on abort flag set")
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,7 @@ use ethjson;
|
|||||||
use rlp::{Rlp, RlpStream, View, Stream};
|
use rlp::{Rlp, RlpStream, View, Stream};
|
||||||
|
|
||||||
/// Parameters common to all engines.
|
/// Parameters common to all engines.
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone, Default)]
|
||||||
#[cfg_attr(test, derive(Default))]
|
|
||||||
pub struct CommonParams {
|
pub struct CommonParams {
|
||||||
/// Account start nonce.
|
/// Account start nonce.
|
||||||
pub account_start_nonce: U256,
|
pub account_start_nonce: U256,
|
||||||
|
Loading…
Reference in New Issue
Block a user