From 4f69ee04373333615d60c2cd6103e601e2ab3f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Mon, 28 Aug 2017 12:32:19 +0200 Subject: [PATCH] Add test to cover that. --- ethcore/evm/src/interpreter/mod.rs | 33 ++++++++++++++++++++++++++++++ ethcore/vm/src/tests.rs | 5 +++++ 2 files changed, 38 insertions(+) diff --git a/ethcore/evm/src/interpreter/mod.rs b/ethcore/evm/src/interpreter/mod.rs index 709ffe4d9..cb8fe3a52 100644 --- a/ethcore/evm/src/interpreter/mod.rs +++ b/ethcore/evm/src/interpreter/mod.rs @@ -873,3 +873,36 @@ fn address_to_u256(value: Address) -> U256 { U256::from(&*H256::from(value)) } + +#[cfg(test)] +mod tests { + use std::sync::Arc; + use rustc_hex::FromHex; + use vmtype::VMType; + use factory::Factory; + use vm::{self, ActionParams, ActionValue}; + use vm::tests::{FakeExt, test_finalize}; + + #[test] + fn should_not_fail_on_tracing_mem() { + let code = "7feeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff006000527faaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa6020526000620f120660406000601773945304eb96065b2a98b57a48a06ae28d285a71b56101f4f1600055".from_hex().unwrap(); + + let mut params = ActionParams::default(); + params.address = 5.into(); + params.gas = 300_000.into(); + params.gas_price = 1.into(); + params.value = ActionValue::Transfer(100_000.into()); + params.code = Some(Arc::new(code)); + let mut ext = FakeExt::new(); + ext.balances.insert(5.into(), 1_000_000_000.into()); + ext.tracing = true; + + let gas_left = { + let mut vm = Factory::new(VMType::Interpreter, 1).create(params.gas); + test_finalize(vm.exec(params, &mut ext)).unwrap() + }; + + assert_eq!(ext.calls.len(), 1); + assert_eq!(gas_left, 248_212.into()); + } +} diff --git a/ethcore/vm/src/tests.rs b/ethcore/vm/src/tests.rs index c8afedaff..c3a290d41 100644 --- a/ethcore/vm/src/tests.rs +++ b/ethcore/vm/src/tests.rs @@ -61,6 +61,7 @@ pub struct FakeExt { pub info: EnvInfo, pub schedule: Schedule, pub balances: HashMap, + pub tracing: bool, } // similar to the normal `finalize` function, but ignoring NeedsReturn. @@ -184,4 +185,8 @@ impl Ext for FakeExt { fn inc_sstore_clears(&mut self) { self.sstore_clears += 1; } + + fn trace_next_instruction(&mut self, _pc: usize, _instruction: u8) -> bool { + self.tracing + } }