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)));