Create transaction tracing test.

This commit is contained in:
Gav Wood 2016-03-20 11:33:36 +01:00
parent 2cb1937e1e
commit f75fb6a59f
3 changed files with 50 additions and 6 deletions

View File

@ -25,7 +25,7 @@ use evm::Evm;
/// Type of EVM to use.
pub enum VMType {
/// JIT EVM
#[cfg(feature="jit")]
#[cfg(feature = "jit")]
Jit,
/// RUST EVM
Interpreter
@ -52,13 +52,13 @@ impl fmt::Display for VMType {
#[cfg(feature = "json-tests")]
impl VMType {
/// Return all possible VMs (JIT, Interpreter)
#[cfg(feature="jit")]
#[cfg(feature = "jit")]
pub fn all() -> Vec<VMType> {
vec![VMType::Jit, VMType::Interpreter]
}
/// Return all possible VMs (Interpreter)
#[cfg(not(feature="jit"))]
#[cfg(not(feature = "jit"))]
pub fn all() -> Vec<VMType> {
vec![VMType::Interpreter]
}
@ -66,12 +66,12 @@ impl VMType {
/// Evm factory. Creates appropriate Evm.
pub struct Factory {
evm : VMType
evm: VMType
}
impl Factory {
/// Create fresh instance of VM
#[cfg(feature="jit")]
#[cfg(feature = "jit")]
pub fn create(&self) -> Box<Evm> {
match self.evm {
VMType::Jit => {
@ -84,7 +84,7 @@ impl Factory {
}
/// Create fresh instance of VM
#[cfg(not(feature="jit"))]
#[cfg(not(feature = "jit"))]
pub fn create(&self) -> Box<Evm> {
match self.evm {
VMType::Interpreter => {

View File

@ -310,6 +310,8 @@ impl<'a> Executive<'a> {
c.result = res.as_ref().ok().map(|gas_left| (c.gas - *gas_left, created, output));
}
}
trace!(target: "executive", "trace_info={:?}", trace_info);
self.enact_result(&res, substate, unconfirmed_substate, trace_info);
res

View File

@ -349,6 +349,48 @@ use util::rlp::*;
use account::*;
use tests::helpers::*;
use devtools::*;
use evm::factory::*;
use env_info::*;
use transaction::*;
use util::log::init_log;
use trace::*;
#[test]
fn should_apply_create_transaction() {
init_log();
let temp = RandomTempPath::new();
let mut state = get_temp_state_in(temp.as_path());
let mut info = EnvInfo::default();
info.gas_limit = x!(1_000_000);
let engine = TestEngine::new(5, Factory::default());
let t = Transaction {
nonce: x!(0),
gas_price: x!(0),
gas: x!(100_000),
action: Action::Create,
value: x!(100),
data: FromHex::from_hex("601080600c6000396000f3006000355415600957005b60203560003555").unwrap(),
}.sign(&"".sha3());
state.add_balance(t.sender().as_ref().unwrap(), &x!(100));
let result = state.apply(&info, &engine, &t, true).unwrap();
let expected_trace = Some(Trace {
depth: 0,
action: TraceAction::Create(TraceCreate {
from: x!("9cce34f7ab185c7aba1b7c8140d620b4bda941d6"),
value: x!(100),
gas: x!(77412),
init: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85],
result: Some((x!(3224), x!("8988167e088c87cd314df6d3c2b83da5acb93ace"), vec![96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53]))
}),
subs: vec![]
});
assert_eq!(result.trace, expected_trace);
}
#[test]
fn code_from_database() {