Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
make few functions compile only for test target
Browse files Browse the repository at this point in the history
  • Loading branch information
debris committed Feb 2, 2016
1 parent 808e517 commit bc3c983
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions ethcore/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct Account {
}

impl Account {
#[cfg(test)]
/// General constructor.
pub fn new(balance: U256, nonce: U256, storage: HashMap<H256, H256>, code: Bytes) -> Account {
Account {
Expand Down
1 change: 1 addition & 0 deletions ethcore/src/pod_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<H256, H256>) -> PodAccount {
PodAccount { balance: balance, nonce: nonce, code: code, storage: storage }
}
Expand Down
2 changes: 2 additions & 0 deletions ethcore/src/pod_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Address, PodAccount>) -> PodState { PodState(m) }

/// Get the underlying map.
Expand All @@ -21,6 +22,7 @@ impl PodState {
}

/// Drain object to get the underlying map.
#[cfg(test)]
pub fn drain(self) -> BTreeMap<Address, PodAccount> { self.0 }
}

Expand Down
10 changes: 4 additions & 6 deletions ethcore/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
{
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)));
Expand All @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions ethcore/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

Expand Down Expand Up @@ -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),
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit bc3c983

Please sign in to comment.