Merge remote-tracking branch 'origin/master' into dynamic-gas-price

This commit is contained in:
Gav Wood 2016-07-09 12:29:23 +02:00
commit 9a70f717ad
7 changed files with 62 additions and 31 deletions

View File

@ -19,9 +19,9 @@
extern crate rand;
pub mod random_path;
pub mod test_socket;
pub mod stop_guard;
mod random_path;
mod test_socket;
mod stop_guard;
pub use random_path::*;
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]
fn creates_dir() {
let temp = RandomTempPath::create_dir();

View File

@ -18,6 +18,7 @@
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrder};
use util::*;
use devtools::*;
use transaction::{Transaction, LocalizedTransaction, SignedTransaction, Action};
use blockchain::TreeRoute;
use client::{BlockChainClient, MiningBlockChainClient, BlockChainInfo, BlockStatus, BlockID,
@ -29,7 +30,7 @@ use log_entry::LocalizedLogEntry;
use receipt::{Receipt, LocalizedReceipt};
use blockchain::extras::BlockReceipts;
use error::{ImportResult};
use evm::Factory as EvmFactory;
use evm::{Factory as EvmFactory, VMType};
use miner::{Miner, MinerService};
use spec::Spec;
@ -67,6 +68,10 @@ pub struct TestBlockChainClient {
pub queue_size: AtomicUsize,
/// Miner
pub miner: Arc<Miner>,
/// Spec
pub spec: Spec,
/// VM Factory
pub vm_factory: EvmFactory,
}
#[derive(Clone)]
@ -106,6 +111,8 @@ impl TestBlockChainClient {
receipts: RwLock::new(HashMap::new()),
queue_size: AtomicUsize::new(0),
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.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 {
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 {
unimplemented!();
&self.vm_factory
}
fn import_sealed_block(&self, _block: SealedBlock) -> ImportResult {
unimplemented!();
Ok(H256::default())
}
}

View File

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

View File

@ -98,7 +98,8 @@ pub extern crate ethstore;
extern crate semver;
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;
pub mod account_provider;

View File

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

View File

@ -32,26 +32,6 @@ pub enum ChainEra {
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 {
engine: Box<Engine>,
max_depth: usize