Uncommenting simple Miner tests (#1571)

This commit is contained in:
Tomasz Drwięga 2016-07-09 11:23:06 +02:00 committed by Arkadiy Paronyan
parent 5fe14e172e
commit b304ce5838
7 changed files with 62 additions and 31 deletions

View File

@ -19,9 +19,9 @@
extern crate rand; extern crate rand;
pub mod random_path; mod random_path;
pub mod test_socket; mod test_socket;
pub mod stop_guard; mod stop_guard;
pub use random_path::*; pub use random_path::*;
pub use test_socket::*; pub use test_socket::*;

View File

@ -74,6 +74,25 @@ impl Drop for RandomTempPath {
} }
} }
pub struct GuardedTempResult<T> {
pub result: Option<T>,
pub _temp: RandomTempPath
}
impl<T> GuardedTempResult<T> {
pub fn reference(&self) -> &T {
self.result.as_ref().unwrap()
}
pub fn reference_mut(&mut self) -> &mut T {
self.result.as_mut().unwrap()
}
pub fn take(&mut self) -> T {
self.result.take().unwrap()
}
}
#[test] #[test]
fn creates_dir() { fn creates_dir() {
let temp = RandomTempPath::create_dir(); let temp = RandomTempPath::create_dir();

View File

@ -18,6 +18,7 @@
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrder}; use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrder};
use util::*; use util::*;
use devtools::*;
use transaction::{Transaction, LocalizedTransaction, SignedTransaction, Action}; use transaction::{Transaction, LocalizedTransaction, SignedTransaction, Action};
use blockchain::TreeRoute; use blockchain::TreeRoute;
use client::{BlockChainClient, MiningBlockChainClient, BlockChainInfo, BlockStatus, BlockID, use client::{BlockChainClient, MiningBlockChainClient, BlockChainInfo, BlockStatus, BlockID,
@ -29,7 +30,7 @@ use log_entry::LocalizedLogEntry;
use receipt::{Receipt, LocalizedReceipt}; use receipt::{Receipt, LocalizedReceipt};
use blockchain::extras::BlockReceipts; use blockchain::extras::BlockReceipts;
use error::{ImportResult}; use error::{ImportResult};
use evm::Factory as EvmFactory; use evm::{Factory as EvmFactory, VMType};
use miner::{Miner, MinerService}; use miner::{Miner, MinerService};
use spec::Spec; use spec::Spec;
@ -67,6 +68,10 @@ pub struct TestBlockChainClient {
pub queue_size: AtomicUsize, pub queue_size: AtomicUsize,
/// Miner /// Miner
pub miner: Arc<Miner>, pub miner: Arc<Miner>,
/// Spec
pub spec: Spec,
/// VM Factory
pub vm_factory: EvmFactory,
} }
#[derive(Clone)] #[derive(Clone)]
@ -106,6 +111,8 @@ impl TestBlockChainClient {
receipts: RwLock::new(HashMap::new()), receipts: RwLock::new(HashMap::new()),
queue_size: AtomicUsize::new(0), queue_size: AtomicUsize::new(0),
miner: Arc::new(Miner::with_spec(Spec::new_test())), miner: Arc::new(Miner::with_spec(Spec::new_test())),
spec: Spec::new_test(),
vm_factory: EvmFactory::new(VMType::Interpreter),
}; };
client.add_blocks(1, EachBlockWith::Nothing); // add genesis block client.add_blocks(1, EachBlockWith::Nothing); // add genesis block
client.genesis_hash = client.last_hash.unwrapped_read().clone(); client.genesis_hash = client.last_hash.unwrapped_read().clone();
@ -239,17 +246,43 @@ impl TestBlockChainClient {
} }
} }
pub fn get_temp_journal_db() -> GuardedTempResult<Box<JournalDB>> {
let temp = RandomTempPath::new();
let journal_db = journaldb::new(temp.as_str(), journaldb::Algorithm::EarlyMerge, DatabaseConfig::default());
GuardedTempResult {
_temp: temp,
result: Some(journal_db)
}
}
impl MiningBlockChainClient for TestBlockChainClient { impl MiningBlockChainClient for TestBlockChainClient {
fn prepare_open_block(&self, _author: Address, _gas_range_target: (U256, U256), _extra_data: Bytes) -> OpenBlock { fn prepare_open_block(&self, _author: Address, _gas_range_target: (U256, U256), _extra_data: Bytes) -> OpenBlock {
unimplemented!(); let engine = &self.spec.engine;
let genesis_header = self.spec.genesis_header();
let mut db_result = get_temp_journal_db();
let mut db = db_result.take();
self.spec.ensure_db_good(db.as_hashdb_mut());
let last_hashes = vec![genesis_header.hash()];
OpenBlock::new(
engine.deref(),
self.vm_factory(),
Default::default(),
false,
db,
&genesis_header,
last_hashes,
Address::zero(),
(3141562.into(), 31415620.into()),
vec![]
).expect("Opening block for tests will not fail.")
} }
fn vm_factory(&self) -> &EvmFactory { fn vm_factory(&self) -> &EvmFactory {
unimplemented!(); &self.vm_factory
} }
fn import_sealed_block(&self, _block: SealedBlock) -> ImportResult { fn import_sealed_block(&self, _block: SealedBlock) -> ImportResult {
unimplemented!(); Ok(H256::default())
} }
} }

View File

@ -298,6 +298,7 @@ mod tests {
use evm::{Ext}; use evm::{Ext};
use substate::*; use substate::*;
use tests::helpers::*; use tests::helpers::*;
use devtools::GuardedTempResult;
use super::*; use super::*;
use trace::{NoopTracer, NoopVMTracer}; use trace::{NoopTracer, NoopVMTracer};

View File

@ -98,7 +98,8 @@ pub extern crate ethstore;
extern crate semver; extern crate semver;
extern crate ethcore_ipc_nano as nanoipc; extern crate ethcore_ipc_nano as nanoipc;
#[cfg(test)] extern crate ethcore_devtools as devtools; extern crate ethcore_devtools as devtools;
#[cfg(feature = "jit" )] extern crate evmjit; #[cfg(feature = "jit" )] extern crate evmjit;
pub mod account_provider; pub mod account_provider;

View File

@ -756,8 +756,6 @@ mod tests {
use block::*; use block::*;
use spec::Spec; use spec::Spec;
// TODO [ToDr] To uncomment` when TestBlockChainClient can actually return a ClosedBlock.
#[ignore]
#[test] #[test]
fn should_prepare_block_to_seal() { fn should_prepare_block_to_seal() {
// given // given
@ -769,7 +767,6 @@ mod tests {
assert!(sealing_work.is_some(), "Expected closed block"); assert!(sealing_work.is_some(), "Expected closed block");
} }
#[ignore]
#[test] #[test]
fn should_still_work_after_a_couple_of_blocks() { fn should_still_work_after_a_couple_of_blocks() {
// given // given

View File

@ -32,26 +32,6 @@ pub enum ChainEra {
Homestead, Homestead,
} }
#[cfg(test)]
pub struct GuardedTempResult<T> {
result: Option<T>,
_temp: RandomTempPath
}
impl<T> GuardedTempResult<T> {
pub fn reference(&self) -> &T {
self.result.as_ref().unwrap()
}
pub fn reference_mut(&mut self) -> &mut T {
self.result.as_mut().unwrap()
}
pub fn take(&mut self) -> T {
self.result.take().unwrap()
}
}
pub struct TestEngine { pub struct TestEngine {
engine: Box<Engine>, engine: Box<Engine>,
max_depth: usize max_depth: usize