Changing allow(dead_code) to more specific exclusions

This commit is contained in:
Tomusdrw 2016-02-03 15:33:58 +01:00
parent a1bfcf17e3
commit a7b1b70fc1
8 changed files with 29 additions and 39 deletions

View File

@ -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.

View File

@ -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<AccountDiff> {
match (pre, post) {
(None, Some(x)) => Some(AccountDiff {

View File

@ -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")]

View File

@ -23,6 +23,7 @@ impl PodState {
/// Drain object to get the underlying map.
#[cfg(test)]
#[cfg(feature = "json-tests")]
pub fn drain(self) -> BTreeMap<Address, PodAccount> { self.0 }
}

View File

@ -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<Address, PodAccount> {
// 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.

View File

@ -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<Address, AccountDiff>);
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 {

View File

@ -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<Arc<Client>> {
let dir = RandomTempPath::new();
@ -150,6 +154,7 @@ pub fn generate_dummy_client(block_number: u32) -> GuardedTempResult<Arc<Client>
}
}
#[cfg(feature = "json-tests")]
pub fn get_test_client_with_blocks(blocks: Vec<Bytes>) -> GuardedTempResult<Arc<Client>> {
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();

View File

@ -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<Transaction, Error> {
if require_low && !ec::is_low_s(&self.s) {
return Err(Error::Util(UtilError::Crypto(CryptoError::InvalidSignature)));