From f75fb6a59faae7f6d7665153de4d4fbcdc2c8ccf Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 20 Mar 2016 11:33:36 +0100 Subject: [PATCH] Create transaction tracing test. --- ethcore/src/evm/factory.rs | 12 +++++------ ethcore/src/executive.rs | 2 ++ ethcore/src/state.rs | 42 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/ethcore/src/evm/factory.rs b/ethcore/src/evm/factory.rs index 4a9bd38ba..65add0050 100644 --- a/ethcore/src/evm/factory.rs +++ b/ethcore/src/evm/factory.rs @@ -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 { vec![VMType::Jit, VMType::Interpreter] } /// Return all possible VMs (Interpreter) - #[cfg(not(feature="jit"))] + #[cfg(not(feature = "jit"))] pub fn all() -> Vec { 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 { 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 { match self.evm { VMType::Interpreter => { diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs index 2421150e5..49cea6f23 100644 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -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 diff --git a/ethcore/src/state.rs b/ethcore/src/state.rs index cad29b678..2f64401d2 100644 --- a/ethcore/src/state.rs +++ b/ethcore/src/state.rs @@ -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() {