From bc3c983c379d3ef2494a47f1313c2147c69fc1be Mon Sep 17 00:00:00 2001 From: debris Date: Tue, 2 Feb 2016 23:45:50 +0100 Subject: [PATCH] make few functions compile only for test target --- ethcore/src/account.rs | 1 + ethcore/src/pod_account.rs | 1 + ethcore/src/pod_state.rs | 2 ++ ethcore/src/state.rs | 10 ++++------ ethcore/src/transaction.rs | 10 +++++++--- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ethcore/src/account.rs b/ethcore/src/account.rs index ec39f8043..0d535f7ce 100644 --- a/ethcore/src/account.rs +++ b/ethcore/src/account.rs @@ -21,6 +21,7 @@ pub struct Account { } impl Account { + #[cfg(test)] /// General constructor. pub fn new(balance: U256, nonce: U256, storage: HashMap, code: Bytes) -> Account { Account { diff --git a/ethcore/src/pod_account.rs b/ethcore/src/pod_account.rs index 97cfcb6fd..76127b89a 100644 --- a/ethcore/src/pod_account.rs +++ b/ethcore/src/pod_account.rs @@ -16,6 +16,7 @@ pub struct PodAccount { impl PodAccount { /// Construct new object. + #[cfg(test)] pub fn new(balance: U256, nonce: U256, code: Bytes, storage: BTreeMap) -> PodAccount { PodAccount { balance: balance, nonce: nonce, code: code, storage: storage } } diff --git a/ethcore/src/pod_state.rs b/ethcore/src/pod_state.rs index f37a327f8..22969f36b 100644 --- a/ethcore/src/pod_state.rs +++ b/ethcore/src/pod_state.rs @@ -10,6 +10,7 @@ impl PodState { pub fn new() -> PodState { Default::default() } /// Contruct a new object from the `m`. + #[cfg(test)] pub fn from(m: BTreeMap) -> PodState { PodState(m) } /// Get the underlying map. @@ -21,6 +22,7 @@ impl PodState { } /// Drain object to get the underlying map. + #[cfg(test)] pub fn drain(self) -> BTreeMap { self.0 } } diff --git a/ethcore/src/state.rs b/ethcore/src/state.rs index 6456aee77..fb336f3bb 100644 --- a/ethcore/src/state.rs +++ b/ethcore/src/state.rs @@ -2,7 +2,7 @@ use common::*; use engine::Engine; use executive::Executive; use pod_account::*; -use pod_state::*; +use pod_state::PodState; //use state_diff::*; // TODO: uncomment once to_pod() works correctly. /// TODO [Gav Wood] Please document me @@ -20,6 +20,7 @@ pub struct State { impl State { /// Creates new state with empty state root + #[cfg(test)] pub fn new(mut db: JournalDB, account_start_nonce: U256) -> State { let mut root = H256::new(); { @@ -60,11 +61,6 @@ impl State { &self.root } - /// Expose the underlying database; good to use for calling `state.db().commit()`. - pub fn db(&mut self) -> &mut JournalDB { - &mut self.db - } - /// Create a new contract at address `contract`. If there is already an account at the address /// it will have its code reset, ready for `init_code()`. pub fn new_contract(&mut self, contract: &Address, balance: U256) { @@ -190,6 +186,7 @@ impl State { } /// Populate the state from `accounts`. + #[cfg(test)] 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))); @@ -207,6 +204,7 @@ impl State { }) } + #[cfg(test)] /// 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/transaction.rs b/ethcore/src/transaction.rs index 73eff953c..d71506672 100644 --- a/ethcore/src/transaction.rs +++ b/ethcore/src/transaction.rs @@ -6,11 +6,11 @@ use error::*; use evm::Schedule; #[derive(Debug, Clone)] -/// TODO [Gav Wood] Please document me +/// Transaction action type. pub enum Action { - /// TODO [Gav Wood] Please document me + /// Create creates new contract. Create, - /// TODO [debris] Please document me + /// Calls contract at given address. Call(Address), } @@ -49,6 +49,7 @@ pub struct Transaction { impl Transaction { /// TODO [Gav Wood] Please document me + #[cfg(test)] pub fn new() -> Self { Transaction { nonce: x!(0), @@ -66,6 +67,7 @@ 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, @@ -83,6 +85,7 @@ impl Transaction { } /// Create a new contract-creation transaction. + #[cfg(test)] pub fn new_create(value: U256, data: Bytes, gas: U256, gas_price: U256, nonce: U256) -> Transaction { Transaction { nonce: nonce, @@ -201,6 +204,7 @@ impl Transaction { } /// Signs the transaction as coming from `sender`. + #[cfg(test)] pub fn signed(self, secret: &Secret) -> Transaction { let mut r = self; r.sign(secret); r } /// Get the transaction cost in gas for the given params.