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

Commit

Permalink
Merge pull request #310 from ethcore/json_tests_split
Browse files Browse the repository at this point in the history
unused functions cleanup
  • Loading branch information
Gav Wood committed Feb 3, 2016
2 parents c5ce71a + bc3c983 commit b7edc95
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 104 deletions.
2 changes: 0 additions & 2 deletions ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ authors = ["Ethcore <[email protected]>"]
log = "0.3"
env_logger = "0.3"
rustc-serialize = "0.3"
flate2 = "0.2"
rocksdb = "0.3"
heapsize = "0.2.0"
rust-crypto = "0.2.34"
time = "0.1"
#interpolate_idents = { git = "https://github.com/SkylerLipthay/interpolate_idents" }
ethcore-util = { path = "../util" }
evmjit = { path = "../evmjit", optional = true }
ethash = { path = "../ethash" }
Expand Down
10 changes: 2 additions & 8 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 Expand Up @@ -83,15 +84,8 @@ impl Account {
}
}

/// Reset this account to the status of a not-yet-initialised contract.
/// NOTE: Account should have `init_code()` called on it later.
pub fn reset_code(&mut self) {
self.code_hash = None;
self.code_cache = vec![];
}

/// Set this account's code to the given code.
/// NOTE: Account should have been created with `new_contract()` or have `reset_code()` called on it.
/// NOTE: Account should have been created with `new_contract()`
pub fn init_code(&mut self, code: Bytes) {
assert!(self.code_hash.is_none());
self.code_cache = code;
Expand Down
9 changes: 1 addition & 8 deletions ethcore/src/env_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ pub struct EnvInfo {
pub gas_used: U256,
}

impl EnvInfo {
/// Create empty env_info initialized with zeros
pub fn new() -> EnvInfo {
EnvInfo::default()
}
}

impl Default for EnvInfo {
fn default() -> Self {
EnvInfo {
Expand Down Expand Up @@ -97,4 +90,4 @@ r#"

assert_eq!(default_env_info.difficulty, x!(0));
}
}
}
24 changes: 12 additions & 12 deletions ethcore/src/executive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ mod tests {
let mut state_result = get_temp_state();
let mut state = state_result.reference_mut();
state.add_balance(&sender, &U256::from(0x100u64));
let info = EnvInfo::new();
let info = EnvInfo::default();
let engine = TestEngine::new(0, factory);
let mut substate = Substate::new();

Expand Down Expand Up @@ -458,7 +458,7 @@ mod tests {
let mut state_result = get_temp_state();
let mut state = state_result.reference_mut();
state.add_balance(&sender, &U256::from(100));
let info = EnvInfo::new();
let info = EnvInfo::default();
let engine = TestEngine::new(0, factory);
let mut substate = Substate::new();

Expand Down Expand Up @@ -512,7 +512,7 @@ mod tests {
let mut state_result = get_temp_state();
let mut state = state_result.reference_mut();
state.add_balance(&sender, &U256::from(100));
let info = EnvInfo::new();
let info = EnvInfo::default();
let engine = TestEngine::new(0, factory);
let mut substate = Substate::new();

Expand Down Expand Up @@ -564,7 +564,7 @@ mod tests {
let mut state_result = get_temp_state();
let mut state = state_result.reference_mut();
state.add_balance(&sender, &U256::from(100));
let info = EnvInfo::new();
let info = EnvInfo::default();
let engine = TestEngine::new(1024, factory);
let mut substate = Substate::new();

Expand Down Expand Up @@ -624,7 +624,7 @@ mod tests {
state.init_code(&address_b, code_b.clone());
state.add_balance(&sender, &U256::from(100_000));

let info = EnvInfo::new();
let info = EnvInfo::default();
let engine = TestEngine::new(0, factory);
let mut substate = Substate::new();

Expand Down Expand Up @@ -668,7 +668,7 @@ mod tests {
let mut state_result = get_temp_state();
let mut state = state_result.reference_mut();
state.init_code(&address, code.clone());
let info = EnvInfo::new();
let info = EnvInfo::default();
let engine = TestEngine::new(0, factory);
let mut substate = Substate::new();

Expand All @@ -694,7 +694,7 @@ mod tests {
let mut state_result = get_temp_state();
let mut state = state_result.reference_mut();
state.add_balance(&sender, &U256::from(18));
let mut info = EnvInfo::new();
let mut info = EnvInfo::default();
info.gas_limit = U256::from(100_000);
let engine = TestEngine::new(0, factory);

Expand All @@ -721,7 +721,7 @@ mod tests {

let mut state_result = get_temp_state();
let mut state = state_result.reference_mut();
let mut info = EnvInfo::new();
let mut info = EnvInfo::default();
info.gas_limit = U256::from(100_000);
let engine = TestEngine::new(0, factory);

Expand All @@ -746,7 +746,7 @@ mod tests {
let mut state_result = get_temp_state();
let mut state = state_result.reference_mut();
state.add_balance(&sender, &U256::from(17));
let mut info = EnvInfo::new();
let mut info = EnvInfo::default();
info.gas_limit = U256::from(100_000);
let engine = TestEngine::new(0, factory);

Expand All @@ -772,7 +772,7 @@ mod tests {
let mut state_result = get_temp_state();
let mut state = state_result.reference_mut();
state.add_balance(&sender, &U256::from(17));
let mut info = EnvInfo::new();
let mut info = EnvInfo::default();
info.gas_used = U256::from(20_000);
info.gas_limit = U256::from(100_000);
let engine = TestEngine::new(0, factory);
Expand All @@ -799,7 +799,7 @@ mod tests {
let mut state_result = get_temp_state();
let mut state = state_result.reference_mut();
state.add_balance(&sender, &U256::from(100_017));
let mut info = EnvInfo::new();
let mut info = EnvInfo::default();
info.gas_limit = U256::from(100_000);
let engine = TestEngine::new(0, factory);

Expand Down Expand Up @@ -833,7 +833,7 @@ mod tests {
let mut state_result = get_temp_state();
let mut state = state_result.reference_mut();
state.add_balance(&sender, &U256::from_str("152d02c7e14af6800000").unwrap());
let info = EnvInfo::new();
let info = EnvInfo::default();
let engine = TestEngine::new(0, factory);
let mut substate = Substate::new();

Expand Down
42 changes: 24 additions & 18 deletions ethcore/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,39 @@ pub type BlockNumber = u64;
/// which is non-specific.
///
/// Doesn't do all that much on its own.
#[derive(Default, Debug, Clone)]
#[derive(Debug, Clone)]
pub struct Header {
// TODO: make all private.
/// TODO [Gav Wood] Please document me
/// Parent hash.
pub parent_hash: H256,
/// TODO [arkpar] Please document me
/// Block timestamp.
pub timestamp: u64,
/// TODO [debris] Please document me
/// Block number.
pub number: BlockNumber,
/// TODO [Gav Wood] Please document me
/// Block author.
pub author: Address,

/// TODO [debris] Please document me
/// Transactions root.
pub transactions_root: H256,
/// TODO [debris] Please document me
/// Block uncles hash.
pub uncles_hash: H256,
/// TODO [Gav Wood] Please document me
/// Block extra data.
pub extra_data: Bytes,

/// TODO [debris] Please document me
/// State root.
pub state_root: H256,
/// TODO [debris] Please document me
/// Block receipts root.
pub receipts_root: H256,
/// TODO [debris] Please document me
/// Block bloom.
pub log_bloom: LogBloom,
/// TODO [debris] Please document me
/// Gas used for contracts execution.
pub gas_used: U256,
/// TODO [Gav Wood] Please document me
/// Block gas limit.
pub gas_limit: U256,

/// TODO [debris] Please document me
/// Block difficulty.
pub difficulty: U256,
/// TODO [arkpar] Please document me
/// Block seal.
pub seal: Vec<Bytes>,

/// TODO [arkpar] Please document me
Expand All @@ -54,9 +54,8 @@ pub struct Header {
pub bare_hash: RefCell<Option<H256>>,
}

impl Header {
/// Create a new, default-valued, header.
pub fn new() -> Header {
impl Default for Header {
fn default() -> Self {
Header {
parent_hash: ZERO_H256.clone(),
timestamp: 0,
Expand All @@ -79,6 +78,13 @@ impl Header {
bare_hash: RefCell::new(None),
}
}
}

impl Header {
/// Create a new, default-valued, header.
pub fn new() -> Self {
Self::default()
}

/// TODO [Gav Wood] Please document me
pub fn number(&self) -> BlockNumber { self.number }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use client::{BlockChainClient,Client};
use pod_state::*;
use block::Block;
use ethereum;
use super::helpers::*;
use tests::helpers::*;

pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
init_log();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use client::{BlockChainClient,Client};
use super::test_common::*;
use super::helpers::*;
use tests::helpers::*;

#[test]
fn created() {
Expand Down Expand Up @@ -75,4 +75,4 @@ fn can_collect_garbage() {
let client = client_result.reference();
client.tick();
assert!(client.cache_info().blocks < 100 * 1024);
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::test_common::*;
use super::helpers::*;
use super::chain::json_chain_test;
use tests::helpers::*;

fn do_json_test(json_data: &[u8]) -> Vec<String> {
json_chain_test(json_data, ChainEra::Homestead)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::test_common::*;
use super::helpers::*;
use tests::helpers::*;
use super::state::json_chain_test;

fn do_json_test(json_data: &[u8]) -> Vec<String> {
Expand Down
10 changes: 10 additions & 0 deletions ethcore/src/json_tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#[macro_use]
mod test_common;

mod transaction;
mod executive;
mod state;
mod client;
mod chain;
mod homestead_state;
mod homestead_chain;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::test_common::*;
use super::helpers::*;
use tests::helpers::*;
use pod_state::*;
use state_diff::*;
use ethereum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ macro_rules! declare_test {
#[ignore]
#[test]
#[allow(non_snake_case)]
#[cfg(feature="json-tests")]
fn $id() {
test!($name);
}
Expand All @@ -21,15 +20,13 @@ macro_rules! declare_test {
#[cfg(feature = "test-heavy")]
#[test]
#[allow(non_snake_case)]
#[cfg(feature="json-tests")]
fn $id() {
test!($name);
}
};
($id: ident, $name: expr) => {
#[test]
#[allow(non_snake_case)]
#[cfg(feature="json-tests")]
fn $id() {
test!($name);
}
Expand Down
File renamed without changes.
7 changes: 5 additions & 2 deletions ethcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
#[macro_use] extern crate ethcore_util as util;
#[macro_use] extern crate lazy_static;
extern crate rustc_serialize;
extern crate flate2;
extern crate rocksdb;
extern crate heapsize;
extern crate crypto;
Expand Down Expand Up @@ -108,4 +107,8 @@ mod executive;
mod externalities;
mod verification;

#[cfg(test)] mod tests;
#[cfg(test)]
mod tests;
#[cfg(test)]
#[cfg(feature="json-tests")]
mod json_tests;
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
13 changes: 0 additions & 13 deletions ethcore/src/spec.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
//! Parameters for a block chain.
use common::*;
use flate2::read::GzDecoder;
use engine::*;
use pod_state::*;
use null_engine::*;

/// Converts file from base64 gzipped bytes to json
fn gzip64res_to_json(source: &[u8]) -> Json {
// there is probably no need to store genesis in based64 gzip,
// but that's what go does, and it was easy to load it this way
let data = source.from_base64().expect("Genesis block is malformed!");
let data_ref: &[u8] = &data;
let mut decoder = GzDecoder::new(data_ref).expect("Gzip is invalid");
let mut s: String = "".to_owned();
decoder.read_to_string(&mut s).expect("Gzip is invalid");
Json::from_str(&s).expect("Json is invalid")
}

/// Convert JSON value to equivalent RLP representation.
// TODO: handle container types.
fn json_to_rlp(json: &Json) -> Bytes {
Expand Down
Loading

0 comments on commit b7edc95

Please sign in to comment.