make few functions compile only for test target

This commit is contained in:
debris 2016-02-02 23:45:50 +01:00
parent 808e517ff0
commit bc3c983c37
5 changed files with 15 additions and 9 deletions

View File

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

View File

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

View File

@ -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.
@ -21,6 +22,7 @@ impl PodState {
}
/// Drain object to get the underlying map.
#[cfg(test)]
pub fn drain(self) -> BTreeMap<Address, PodAccount> { self.0 }
}

View File

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

View File

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