From 0d686b232701830a9d2ff4de85dbb1bb662baef0 Mon Sep 17 00:00:00 2001 From: debris Date: Sat, 16 Jan 2016 08:56:03 +0100 Subject: [PATCH] cleanup --- src/evm/tests.rs | 2 +- src/externalities.rs | 10 ---------- src/tests/executive.rs | 28 +++++++++++++++++----------- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/evm/tests.rs b/src/evm/tests.rs index 1a688299f..215b7ea85 100644 --- a/src/evm/tests.rs +++ b/src/evm/tests.rs @@ -34,7 +34,7 @@ impl Ext for FakeExt { self.store.insert(key, value); } - fn exists(&self, address: &Address) -> bool { + fn exists(&self, _address: &Address) -> bool { unimplemented!(); } diff --git a/src/externalities.rs b/src/externalities.rs index 4366d3e2f..b3a7e94f9 100644 --- a/src/externalities.rs +++ b/src/externalities.rs @@ -17,21 +17,11 @@ pub enum OutputPolicy<'a> { /// Implementation of evm Externalities. pub struct Externalities<'a> { - - #[cfg(test)] - pub state: &'a mut State, - #[cfg(not(test))] state: &'a mut State, - info: &'a EnvInfo, engine: &'a Engine, depth: usize, - - #[cfg(test)] - pub params: &'a ActionParams, - #[cfg(not(test))] params: &'a ActionParams, - substate: &'a mut Substate, schedule: Schedule, output: OutputPolicy<'a> diff --git a/src/tests/executive.rs b/src/tests/executive.rs index 32ed27d46..4d0898676 100644 --- a/src/tests/executive.rs +++ b/src/tests/executive.rs @@ -44,13 +44,21 @@ struct CallCreate { /// Stores callcreates. struct TestExt<'a> { ext: Externalities<'a>, - callcreates: Vec + callcreates: Vec, + contract_address: Address } impl<'a> TestExt<'a> { - fn new(ext: Externalities<'a>) -> TestExt { + fn new(state: &'a mut State, + info: &'a EnvInfo, + engine: &'a Engine, + depth: usize, + params: &'a ActionParams, + substate: &'a mut Substate, + output: OutputPolicy<'a>) -> Self { TestExt { - ext: ext, + contract_address: contract_address(¶ms.address, &state.nonce(¶ms.address)), + ext: Externalities::new(state, info, engine, depth, params, substate, output), callcreates: vec![] } } @@ -78,14 +86,13 @@ impl<'a> Ext for TestExt<'a> { } fn create(&mut self, gas: &U256, value: &U256, code: &[u8]) -> ContractCreateResult { - let address = contract_address(&self.ext.params.address, &self.ext.state.nonce(&self.ext.params.address)); self.callcreates.push(CallCreate { data: code.to_vec(), destination: None, _gas_limit: *gas, value: *value }); - ContractCreateResult::Created(address, *gas) + ContractCreateResult::Created(self.contract_address.clone(), *gas) } fn call(&mut self, @@ -93,8 +100,8 @@ impl<'a> Ext for TestExt<'a> { receive_address: &Address, value: &U256, data: &[u8], - code_address: &Address, - output: &mut [u8]) -> MessageCallResult { + _code_address: &Address, + _output: &mut [u8]) -> MessageCallResult { self.callcreates.push(CallCreate { data: data.to_vec(), destination: Some(receive_address.clone()), @@ -198,11 +205,10 @@ fn do_json_test(json_data: &[u8]) -> Vec { // execute let (res, callcreates) = { - let ex = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::Return(BytesRef::Flexible(&mut output))); - let mut test_ext = TestExt::new(ex); + let mut ex = TestExt::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::Return(BytesRef::Flexible(&mut output))); let evm = Factory::create(); - let res = evm.exec(¶ms, &mut test_ext); - (res, test_ext.callcreates) + let res = evm.exec(¶ms, &mut ex); + (res, ex.callcreates) }; // then validate