From a7b1b70fc16acb876be761239656dea16ea47ee1 Mon Sep 17 00:00:00 2001 From: Tomusdrw Date: Wed, 3 Feb 2016 15:33:58 +0100 Subject: [PATCH 1/4] Changing `allow(dead_code)` to more specific exclusions --- ethcore/src/account.rs | 11 ++++++----- ethcore/src/account_diff.rs | 3 ++- ethcore/src/evm/factory.rs | 1 + ethcore/src/pod_state.rs | 1 + ethcore/src/state.rs | 19 ++++++------------- ethcore/src/state_diff.rs | 2 ++ ethcore/src/tests/helpers.rs | 8 +++++++- ethcore/src/transaction.rs | 23 ++++------------------- 8 files changed, 29 insertions(+), 39 deletions(-) diff --git a/ethcore/src/account.rs b/ethcore/src/account.rs index 24386e839..63f86b171 100644 --- a/ethcore/src/account.rs +++ b/ethcore/src/account.rs @@ -34,8 +34,9 @@ impl Account { } } + #[cfg(test)] + #[cfg(feature = "json-tests")] /// General constructor. - #[allow(dead_code)] // Used only in test code for now. pub fn from_pod(pod: PodAccount) -> Account { Account { balance: pod.balance, @@ -110,8 +111,8 @@ impl Account { /// return the nonce associated with this account. pub fn nonce(&self) -> &U256 { &self.nonce } + #[cfg(test)] /// return the code hash associated with this account. - #[allow(dead_code)] // Used only in test code for now. pub fn code_hash(&self) -> H256 { self.code_hash.clone().unwrap_or(SHA3_EMPTY) } @@ -127,8 +128,8 @@ impl Account { } } + #[cfg(test)] /// Provide a byte array which hashes to the `code_hash`. returns the hash as a result. - #[allow(dead_code)] // Used only in test code for now. pub fn note_code(&mut self, code: Bytes) -> Result<(), H256> { let h = code.sha3(); match self.code_hash { @@ -162,12 +163,12 @@ impl Account { } } + #[cfg(test)] /// Determine whether there are any un-`commit()`-ed storage-setting operations. - #[allow(dead_code)] pub fn storage_is_clean(&self) -> bool { self.storage_overlay.borrow().iter().find(|&(_, &(f, _))| f == Filth::Dirty).is_none() } + #[cfg(test)] /// return the storage root associated with this account or None if it has been altered via the overlay. - #[allow(dead_code)] pub fn storage_root(&self) -> Option<&H256> { if self.storage_is_clean() {Some(&self.storage_root)} else {None} } /// return the storage overlay. diff --git a/ethcore/src/account_diff.rs b/ethcore/src/account_diff.rs index 72c331959..86faf40de 100644 --- a/ethcore/src/account_diff.rs +++ b/ethcore/src/account_diff.rs @@ -1,6 +1,7 @@ //! Diff between two accounts. use util::*; +#[cfg(test)] use pod_account::*; #[derive(Debug,Clone,PartialEq,Eq)] @@ -49,9 +50,9 @@ impl AccountDiff { } } + #[cfg(test)] /// Determine difference between two optionally existant `Account`s. Returns None /// if they are the same. - #[allow(dead_code)] // Used only in test code for now. pub fn diff_pod(pre: Option<&PodAccount>, post: Option<&PodAccount>) -> Option { match (pre, post) { (None, Some(x)) => Some(AccountDiff { diff --git a/ethcore/src/evm/factory.rs b/ethcore/src/evm/factory.rs index f97c157a8..eff2a1850 100644 --- a/ethcore/src/evm/factory.rs +++ b/ethcore/src/evm/factory.rs @@ -24,6 +24,7 @@ impl fmt::Display for VMType { } #[cfg(test)] +#[cfg(feature = "json-tests")] impl VMType { /// Return all possible VMs (JIT, Interpreter) #[cfg(feature="jit")] diff --git a/ethcore/src/pod_state.rs b/ethcore/src/pod_state.rs index b373171ad..69eca17b6 100644 --- a/ethcore/src/pod_state.rs +++ b/ethcore/src/pod_state.rs @@ -23,6 +23,7 @@ impl PodState { /// Drain object to get the underlying map. #[cfg(test)] + #[cfg(feature = "json-tests")] pub fn drain(self) -> BTreeMap { self.0 } } diff --git a/ethcore/src/state.rs b/ethcore/src/state.rs index 0fbdc194a..ed7d29813 100644 --- a/ethcore/src/state.rs +++ b/ethcore/src/state.rs @@ -1,8 +1,11 @@ use common::*; use engine::Engine; use executive::Executive; +#[cfg(test)] +#[cfg(feature = "json-tests")] use pod_account::*; #[cfg(test)] +#[cfg(feature = "json-tests")] use pod_state::PodState; //use state_diff::*; // TODO: uncomment once to_pod() works correctly. @@ -186,27 +189,17 @@ impl State { Self::commit_into(&mut self.db, &mut self.root, self.cache.borrow_mut().deref_mut()); } - /// Populate the state from `accounts`. #[cfg(test)] + #[cfg(feature = "json-tests")] + /// Populate the state from `accounts`. pub fn populate_from(&mut self, accounts: PodState) { for (add, acc) in accounts.drain().into_iter() { self.cache.borrow_mut().insert(add, Some(Account::from_pod(acc))); } } - /// Populate a PodAccount map from this state. - #[allow(dead_code)] // Used only in test code for now. - pub fn to_hashmap_pod(&self) -> HashMap { - // TODO: handle database rather than just the cache. - self.cache.borrow().iter().fold(HashMap::new(), |mut m, (add, opt)| { - if let Some(ref acc) = *opt { - m.insert(add.clone(), PodAccount::from_account(acc)); - } - m - }) - } - #[cfg(test)] + #[cfg(feature = "json-tests")] /// Populate a PodAccount map from this state. pub fn to_pod(&self) -> PodState { // TODO: handle database rather than just the cache. diff --git a/ethcore/src/state_diff.rs b/ethcore/src/state_diff.rs index b3bc4b4e5..0d0f63fd8 100644 --- a/ethcore/src/state_diff.rs +++ b/ethcore/src/state_diff.rs @@ -1,4 +1,5 @@ use util::*; +#[cfg(test)] use pod_state::*; use account_diff::*; @@ -8,6 +9,7 @@ use account_diff::*; pub struct StateDiff (BTreeMap); impl StateDiff { + #[cfg(test)] /// Calculate and return diff between `pre` state and `post` state. #[allow(dead_code)] // Used only in test code for now. pub fn diff_pod(pre: &PodState, post: &PodState) -> StateDiff { diff --git a/ethcore/src/tests/helpers.rs b/ethcore/src/tests/helpers.rs index ddc2aedc2..9d784ea98 100644 --- a/ethcore/src/tests/helpers.rs +++ b/ethcore/src/tests/helpers.rs @@ -1,4 +1,5 @@ -use client::{BlockChainClient,Client}; +#[cfg(feature = "json-tests")] +use client::{BlockChainClient, Client}; use std::env; use common::*; use std::path::PathBuf; @@ -8,6 +9,8 @@ use blockchain::{BlockChain}; use state::*; use rocksdb::*; + +#[cfg(feature = "json-tests")] pub enum ChainEra { Frontier, Homestead, @@ -111,6 +114,7 @@ pub fn create_test_block_with_data(header: &Header, transactions: &[&Transaction rlp.out() } +#[cfg(feature = "json-tests")] pub fn generate_dummy_client(block_number: u32) -> GuardedTempResult> { let dir = RandomTempPath::new(); @@ -150,6 +154,7 @@ pub fn generate_dummy_client(block_number: u32) -> GuardedTempResult } } +#[cfg(feature = "json-tests")] pub fn get_test_client_with_blocks(blocks: Vec) -> GuardedTempResult> { let dir = RandomTempPath::new(); let client = Client::new(get_test_spec(), dir.as_path(), IoChannel::disconnected()).unwrap(); @@ -246,6 +251,7 @@ pub fn get_good_dummy_block() -> Bytes { create_test_block(&block_header) } +#[cfg(feature = "json-tests")] pub fn get_bad_state_dummy_block() -> Bytes { let mut block_header = Header::new(); let test_spec = get_test_spec(); diff --git a/ethcore/src/transaction.rs b/ethcore/src/transaction.rs index 3b9d0e162..00ea784d4 100644 --- a/ethcore/src/transaction.rs +++ b/ethcore/src/transaction.rs @@ -50,6 +50,7 @@ pub struct Transaction { impl Transaction { /// Create a new transaction. #[cfg(test)] + #[cfg(feature = "json-tests")] pub fn new() -> Self { Transaction { nonce: x!(0), @@ -66,24 +67,6 @@ impl Transaction { } } - /// Create a new message-call transaction. - #[cfg(test)] - pub fn new_call(to: Address, value: U256, data: Bytes, gas: U256, gas_price: U256, nonce: U256) -> Transaction { - Transaction { - nonce: nonce, - gas_price: gas_price, - gas: gas, - action: Action::Call(to), - value: value, - data: data, - v: 0, - r: x!(0), - s: x!(0), - hash: RefCell::new(None), - sender: RefCell::new(None), - } - } - /// Create a new contract-creation transaction. #[cfg(test)] pub fn new_create(value: U256, data: Bytes, gas: U256, gas_price: U256, nonce: U256) -> Transaction { @@ -230,7 +213,9 @@ impl Transaction { } /// Do basic validation, checking for valid signature and minimum gas, - #[allow(dead_code)] // Used only in tests. TODO: consider use in block validation. + // TODO: consider use in block validation. + #[cfg(test)] + #[cfg(feature = "json-tests")] pub fn validate(self, schedule: &Schedule, require_low: bool) -> Result { if require_low && !ec::is_low_s(&self.s) { return Err(Error::Util(UtilError::Crypto(CryptoError::InvalidSignature))); From 471f1f82be3849afcc2ed04d3544f466cceb9860 Mon Sep 17 00:00:00 2001 From: Tomusdrw Date: Wed, 3 Feb 2016 15:35:03 +0100 Subject: [PATCH 2/4] Fixing unused variable warning --- ethcore/src/evm/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethcore/src/evm/tests.rs b/ethcore/src/evm/tests.rs index bcd0819de..28d01835f 100644 --- a/ethcore/src/evm/tests.rs +++ b/ethcore/src/evm/tests.rs @@ -95,7 +95,7 @@ impl Ext for FakeExt { value: Option, data: &[u8], code_address: &Address, - output: &mut [u8]) -> MessageCallResult { + _output: &mut [u8]) -> MessageCallResult { self.calls.insert(FakeCall { call_type: FakeCallType::CALL, From 8a2db838034b15662dcd96f0c74329aab3f06bc3 Mon Sep 17 00:00:00 2001 From: Tomusdrw Date: Wed, 3 Feb 2016 15:57:17 +0100 Subject: [PATCH 3/4] Removing --- ethcore/src/evm/factory.rs | 35 +++++++++++++++++++++++------------ ethcore/src/state_diff.rs | 1 - ethcore/src/tests/helpers.rs | 18 +++++++++--------- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/ethcore/src/evm/factory.rs b/ethcore/src/evm/factory.rs index eff2a1850..923de26f4 100644 --- a/ethcore/src/evm/factory.rs +++ b/ethcore/src/evm/factory.rs @@ -1,26 +1,35 @@ //! Evm factory. //! //! TODO: consider spliting it into two separate files. +#[cfg(test)] use std::fmt; use evm::Evm; #[derive(Clone)] /// Type of EVM to use. pub enum VMType { - #[allow(dead_code)] // crated only by jit /// JIT EVM + #[cfg(feature="jit")] Jit, /// RUST EVM Interpreter } +#[cfg(test)] impl fmt::Display for VMType { + #[cfg(feature="jit")] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", match *self { VMType::Jit => "JIT", VMType::Interpreter => "INT" }) } + #[cfg(not(feature="jit"))] + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", match *self { + VMType::Interpreter => "INT" + }) + } } #[cfg(test)] @@ -46,10 +55,12 @@ pub struct Factory { impl Factory { /// Create fresh instance of VM + #[cfg(test)] + #[cfg(feature="jit")] pub fn create(&self) -> Box { match self.evm { VMType::Jit => { - Factory::jit() + Box::new(super::jit::JitEvm) }, VMType::Interpreter => { Box::new(super::interpreter::Interpreter) @@ -57,6 +68,16 @@ impl Factory { } } + /// Create fresh instance of VM + #[cfg(not(feature="jit"))] + pub fn create(&self) -> Box { + match self.evm { + VMType::Interpreter => { + Box::new(super::interpreter::Interpreter) + } + } + } + /// Create new instance of specific `VMType` factory #[cfg(test)] pub fn new(evm: VMType) -> Factory { @@ -64,16 +85,6 @@ impl Factory { evm: evm } } - - #[cfg(feature = "jit")] - fn jit() -> Box { - Box::new(super::jit::JitEvm) - } - - #[cfg(not(feature = "jit"))] - fn jit() -> Box { - unimplemented!() - } } impl Default for Factory { /// Returns jitvm factory diff --git a/ethcore/src/state_diff.rs b/ethcore/src/state_diff.rs index 0d0f63fd8..ba9e6e816 100644 --- a/ethcore/src/state_diff.rs +++ b/ethcore/src/state_diff.rs @@ -11,7 +11,6 @@ pub struct StateDiff (BTreeMap); impl StateDiff { #[cfg(test)] /// Calculate and return diff between `pre` state and `post` state. - #[allow(dead_code)] // Used only in test code for now. pub fn diff_pod(pre: &PodState, post: &PodState) -> StateDiff { StateDiff(pre.get().keys().merge(post.get().keys()).filter_map(|acc| AccountDiff::diff_pod(pre.get().get(acc), post.get().get(acc)).map(|d|(acc.clone(), d))).collect()) } diff --git a/ethcore/src/tests/helpers.rs b/ethcore/src/tests/helpers.rs index 9d784ea98..04d47cbd3 100644 --- a/ethcore/src/tests/helpers.rs +++ b/ethcore/src/tests/helpers.rs @@ -46,10 +46,10 @@ impl Drop for RandomTempPath { } } -#[allow(dead_code)] +#[cfg(test)] pub struct GuardedTempResult { result: T, - temp: RandomTempPath + _temp: RandomTempPath } impl GuardedTempResult { @@ -149,7 +149,7 @@ pub fn generate_dummy_client(block_number: u32) -> GuardedTempResult client.import_verified_blocks(&IoChannel::disconnected()); GuardedTempResult::> { - temp: dir, + _temp: dir, result: client } } @@ -167,7 +167,7 @@ pub fn get_test_client_with_blocks(blocks: Vec) -> GuardedTempResult> { - temp: dir, + _temp: dir, result: client } } @@ -180,7 +180,7 @@ pub fn generate_dummy_blockchain(block_number: u32) -> GuardedTempResult { - temp: temp, + _temp: temp, result: bc } } @@ -193,7 +193,7 @@ pub fn generate_dummy_blockchain_with_extra(block_number: u32) -> GuardedTempRes } GuardedTempResult:: { - temp: temp, + _temp: temp, result: bc } } @@ -203,7 +203,7 @@ pub fn generate_dummy_empty_blockchain() -> GuardedTempResult { let bc = BlockChain::new(&create_unverifiable_block(0, H256::zero()), temp.as_path()); GuardedTempResult:: { - temp: temp, + _temp: temp, result: bc } } @@ -213,7 +213,7 @@ pub fn get_temp_journal_db() -> GuardedTempResult { let db = DB::open_default(temp.as_str()).unwrap(); let journal_db = JournalDB::new(db); GuardedTempResult { - temp: temp, + _temp: temp, result: journal_db } } @@ -222,7 +222,7 @@ pub fn get_temp_state() -> GuardedTempResult { let temp = RandomTempPath::new(); let journal_db = get_temp_journal_db_in(temp.as_path()); GuardedTempResult { - temp: temp, + _temp: temp, result: State::new(journal_db, U256::from(0u8)) } } From 83bfd43a90a93a62060a41c1a71515dc57a5aabe Mon Sep 17 00:00:00 2001 From: Tomusdrw Date: Wed, 3 Feb 2016 15:59:53 +0100 Subject: [PATCH 4/4] Fixing JIT compilation --- ethcore/src/evm/factory.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/ethcore/src/evm/factory.rs b/ethcore/src/evm/factory.rs index 923de26f4..30666f1c4 100644 --- a/ethcore/src/evm/factory.rs +++ b/ethcore/src/evm/factory.rs @@ -55,7 +55,6 @@ pub struct Factory { impl Factory { /// Create fresh instance of VM - #[cfg(test)] #[cfg(feature="jit")] pub fn create(&self) -> Box { match self.evm {