moving around setups

This commit is contained in:
Nikolay Volf 2016-02-09 07:31:57 -08:00
parent cc4206f690
commit 7f607905ed
3 changed files with 79 additions and 63 deletions

View File

@ -364,42 +364,10 @@ impl<'a> Executive<'a> {
mod tests {
use super::*;
use common::*;
use ethereum;
use engine::*;
use spec::*;
use evm::{Schedule, Factory, VMType};
use evm::{Factory, VMType};
use substate::*;
use tests::helpers::*;
struct TestEngine {
factory: Factory,
spec: Spec,
max_depth: usize
}
impl TestEngine {
fn new(max_depth: usize, factory: Factory) -> TestEngine {
TestEngine {
factory: factory,
spec: ethereum::new_frontier_test(),
max_depth: max_depth
}
}
}
impl Engine for TestEngine {
fn name(&self) -> &str { "TestEngine" }
fn spec(&self) -> &Spec { &self.spec }
fn vm_factory(&self) -> &Factory {
&self.factory
}
fn schedule(&self, _env_info: &EnvInfo) -> Schedule {
let mut schedule = Schedule::new_frontier();
schedule.max_depth = self.max_depth;
schedule
}
}
#[test]
fn test_contract_address() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();

View File

@ -300,6 +300,23 @@ mod tests {
let env_info = get_test_env_info();
let ext = Externalities::new(state, &env_info, test_engine, 0, get_test_origin(), &mut test_sub_state, OutputPolicy::InitContract);
assert_eq!(ext.env_info().number, 100);
}
#[test]
fn can_return_block_hash() {
let mut state_result = get_temp_state();
let state = state_result.reference_mut();
let test_spec = get_test_spec();
let test_engine: &Engine = &*test_spec.to_engine().unwrap();
let mut test_sub_state = Substate::new();
let env_info = get_test_env_info();
let ext = Externalities::new(state, &env_info, test_engine, 0, get_test_origin(), &mut test_sub_state, OutputPolicy::InitContract);
let hash = ext.blockhash(&U256::from_str("0000000000000000000000000000000000000000000000000000000000120000").unwrap());
assert_eq!(hash, H256::zero());
}
}

View File

@ -23,7 +23,9 @@ use std::fs::{remove_dir_all};
use blockchain::{BlockChain};
use state::*;
use rocksdb::*;
use evm::{Schedule, Factory};
use engine::*;
use ethereum;
#[cfg(feature = "json-tests")]
pub enum ChainEra {
@ -81,6 +83,35 @@ impl<T> GuardedTempResult<T> {
}
}
pub struct TestEngine {
factory: Factory,
spec: Spec,
max_depth: usize
}
impl TestEngine {
pub fn new(max_depth: usize, factory: Factory) -> TestEngine {
TestEngine {
factory: factory,
spec: ethereum::new_frontier_test(),
max_depth: max_depth
}
}
}
impl Engine for TestEngine {
fn name(&self) -> &str { "TestEngine" }
fn spec(&self) -> &Spec { &self.spec }
fn vm_factory(&self) -> &Factory {
&self.factory
}
fn schedule(&self, _env_info: &EnvInfo) -> Schedule {
let mut schedule = Schedule::new_frontier();
schedule.max_depth = self.max_depth;
schedule
}
}
pub fn get_test_spec() -> Spec {
Spec::new_test()
}