Merge branch 'master' into evm-tests

This commit is contained in:
Tomusdrw 2016-02-03 13:06:21 +01:00
commit a8bd37d5d2
26 changed files with 143 additions and 166 deletions

View File

@ -49,9 +49,8 @@ after_success: |
cargo doc --no-deps --verbose ${KCOV_FEATURES} ${TARGETS} &&
echo '<meta http-equiv=refresh content=0;url=ethcore/index.html>' > target/doc/index.html &&
pip install --user ghp-import &&
/home/travis/.local/bin/ghp-import -n target/doc
#&&
#git push -fq https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages
/home/travis/.local/bin/ghp-import -n target/doc &&
git push -fq https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages
env:
global:
- secure: 3sUjNi9mhdL5h1GTm8LONnDN/SYvUHT+WSkMl93h3nYiLCQXk8eZaPS98AS7oOaTsfW4UvnwckVFCFl49ttInsv4cd/TkAxmrJHe6kPyS9/4NWUdmP8BjicbBvL/ioSdXMECMEYzPDLV+I3KhtC2LcB6ceDEl/XwMOJlzbGf7RbtcXGVQgMLqSYY1YKjQA4vbT5nFgIS/sZu3Z9yFgN0GafnihKcizqoHhdJjs/zxmX+qJepnC6o3V6KcFnS7QHhM1JOr85twE6S422UlvNaEb5ovwLPqmOl5+fA+6shbx4AxFTY6E9Iors+OVY/JliFhrqOdCt0i2P1FUHN4kbGZQkf0rphN/ZOI2uKNFTOyXiPvppfo/ZemKmcqkwkqP9+lf5QqYmtE6hsAYagxn49xJZILl8tAYbdqxF5gxa+TEVrfsBFtz/Sv3q8QhKQNPAmjEcKyMatyEreLUIFEpFTGIco8jN4eXeSoLRdJ+Z75ihttfQWhNfUDgNL30iQLy0AgFSsh/cyb5M8y9lxrGDzDTogvaiKGwr/V45sPkcXWCkmOgMdINqBB6ZtdL3bGHdyjmYj+y3btjf3aP11k++BL0fXIaKn25aS/p/9iyGb1FyGCM03o4ZRQ3YhTOvfMRfRGf6nWbaMx9upv8o5ShSdysewhrnh3082r7u896ny1Ho=
@ -60,7 +59,7 @@ env:
deploy:
provider: releases
api_key:
secure: 3sUjNi9mhdL5h1GTm8LONnDN/SYvUHT+WSkMl93h3nYiLCQXk8eZaPS98AS7oOaTsfW4UvnwckVFCFl49ttInsv4cd/TkAxmrJHe6kPyS9/4NWUdmP8BjicbBvL/ioSdXMECMEYzPDLV+I3KhtC2LcB6ceDEl/XwMOJlzbGf7RbtcXGVQgMLqSYY1YKjQA4vbT5nFgIS/sZu3Z9yFgN0GafnihKcizqoHhdJjs/zxmX+qJepnC6o3V6KcFnS7QHhM1JOr85twE6S422UlvNaEb5ovwLPqmOl5+fA+6shbx4AxFTY6E9Iors+OVY/JliFhrqOdCt0i2P1FUHN4kbGZQkf0rphN/ZOI2uKNFTOyXiPvppfo/ZemKmcqkwkqP9+lf5QqYmtE6hsAYagxn49xJZILl8tAYbdqxF5gxa+TEVrfsBFtz/Sv3q8QhKQNPAmjEcKyMatyEreLUIFEpFTGIco8jN4eXeSoLRdJ+Z75ihttfQWhNfUDgNL30iQLy0AgFSsh/cyb5M8y9lxrGDzDTogvaiKGwr/V45sPkcXWCkmOgMdINqBB6ZtdL3bGHdyjmYj+y3btjf3aP11k++BL0fXIaKn25aS/p/9iyGb1FyGCM03o4ZRQ3YhTOvfMRfRGf6nWbaMx9upv8o5ShSdysewhrnh3082r7u896ny1Ho=
secure: "t+oGT/4lsy7IScw5s86Dpntl5Nyck4qG6nhHwMScc6FYzwLldgwgJaafL8Ej+HG+b7nFLriN+Snoa4YQ5o74X5ZlSWubVREOYQlL/fq7vcPB0DwAZ0Jufq1QW2R1M+3SwwF1eAwTv2W3G7A2K7dxjCVvENcy/gdxnZ36NeUPsqaCC9UcI2Yc7+4jyQwvx6ZfBvQeu+HbKENA0eUNs2ZQOID/1IPy0LJBvSyxAQYsysXdjTzGdNu4+Iba20E8uWYe4fAbgz+gwGarXg1L6D6gKyMlWkViqWjvXWBuDJJqMQZ3rw41AwZOoh3mKd2Lc0l6l4oZcEqPuob0yKTNjz1tuJy9xKTC2F2bDzsvUgk1IRfMK5ukXXXS09ZCZWuA9/GtnsqJ1xGTiwX+DhQzpVBHaBiseSNlYE1YN/3jNyGY+iSts1qut+1BwE7swmcTLsAPoAy8Ue+f7ErNoCg1lm71vq7VO2DLn7x2NqHyHUEuJ+7olDHSdE84G7d9otDRu/+TfMOw7GXwTaha6yJRInuNsnj4CFMLNVvYACzCC2idB7f7nUZoSFi9jf18S9fCMPVmazMrFj4g95HWrVHkjpV5zRTeUdTWw6DJl6pC9HFqORHdCvLv4Rc4dm5r3CmOcAQ0ZuiccV2oKzw4/Wic96daae8M5f5KSQ/WTr+h0wXZKp0="
skip_cleanup: true
file: parity${ARCHIVE_SUFFIX}.tar.gz
on:

View File

@ -10,12 +10,10 @@ authors = ["Ethcore <admin@ethcore.io>"]
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" }

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

View File

@ -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 {
@ -97,4 +90,4 @@ r#"
assert_eq!(default_env_info.difficulty, x!(0));
}
}
}

View File

@ -5,22 +5,22 @@ use header::BlockNumber;
use basic_types::LogBloom;
#[derive(Debug, PartialEq, Eq)]
/// TODO [Gav Wood] Please document me
/// Error indicating an expected value was not found.
pub struct Mismatch<T: fmt::Debug> {
/// TODO [Gav Wood] Please document me
/// Value expected.
pub expected: T,
/// TODO [Gav Wood] Please document me
/// Value found.
pub found: T,
}
#[derive(Debug, PartialEq, Eq)]
/// TODO [Gav Wood] Please document me
/// Error indicating value found is outside of a valid range.
pub struct OutOfBounds<T: fmt::Debug> {
/// TODO [Gav Wood] Please document me
/// Minimum allowed value.
pub min: Option<T>,
/// TODO [Gav Wood] Please document me
/// Maximum allowed value.
pub max: Option<T>,
/// TODO [Gav Wood] Please document me
/// Value found.
pub found: T,
}
@ -29,11 +29,10 @@ pub struct OutOfBounds<T: fmt::Debug> {
pub enum ExecutionError {
/// Returned when there gas paid for transaction execution is
/// lower than base gas required.
/// TODO [Gav Wood] Please document me
NotEnoughBaseGas {
/// TODO [Gav Wood] Please document me
/// Absolute minimum gas required.
required: U256,
/// TODO [Gav Wood] Please document me
/// Gas provided.
got: U256
},
/// Returned when block (gas_used + gas) > gas_limit.
@ -41,26 +40,26 @@ pub enum ExecutionError {
/// If gas =< gas_limit, upstream may try to execute the transaction
/// in next block.
BlockGasLimitReached {
/// TODO [Gav Wood] Please document me
/// Gas limit of block for transaction.
gas_limit: U256,
/// TODO [Gav Wood] Please document me
/// Gas used in block prior to transaction.
gas_used: U256,
/// TODO [Gav Wood] Please document me
/// Amount of gas in block.
gas: U256
},
/// Returned when transaction nonce does not match state nonce.
InvalidNonce {
/// TODO [Gav Wood] Please document me
/// Nonce expected.
expected: U256,
/// TODO [Gav Wood] Please document me
/// Nonce found.
got: U256
},
/// Returned when cost of transaction (value + gas_price * gas) exceeds
/// current sender balance.
NotEnoughCash {
/// TODO [Gav Wood] Please document me
/// Minimum required balance.
required: U512,
/// TODO [Gav Wood] Please document me
/// Actual balance.
got: U512
},
/// Returned when internal evm error occurs.
@ -68,64 +67,68 @@ pub enum ExecutionError {
}
#[derive(Debug)]
/// TODO [Gav Wood] Please document me
/// Errors concerning transaction proessing.
pub enum TransactionError {
/// TODO [Gav Wood] Please document me
/// Transaction's gas limit (aka gas) is invalid.
InvalidGasLimit(OutOfBounds<U256>),
}
#[derive(Debug, PartialEq, Eq)]
/// TODO [arkpar] Please document me
/// Errors concerning block processing.
pub enum BlockError {
/// TODO [Gav Wood] Please document me
/// Block has too many uncles.
TooManyUncles(OutOfBounds<usize>),
/// TODO [Gav Wood] Please document me
UncleWrongGeneration,
/// TODO [Gav Wood] Please document me
/// Extra data is of an invalid length.
ExtraDataOutOfBounds(OutOfBounds<usize>),
/// TODO [arkpar] Please document me
/// Seal is incorrect format.
InvalidSealArity(Mismatch<usize>),
/// TODO [arkpar] Please document me
/// Block has too much gas used.
TooMuchGasUsed(OutOfBounds<U256>),
/// TODO [arkpar] Please document me
/// Uncles hash in header is invalid.
InvalidUnclesHash(Mismatch<H256>),
/// TODO [arkpar] Please document me
/// An uncle is from a generation too old.
UncleTooOld(OutOfBounds<BlockNumber>),
/// TODO [arkpar] Please document me
/// An uncle is from the same generation as the block.
UncleIsBrother(OutOfBounds<BlockNumber>),
/// TODO [arkpar] Please document me
/// An uncle is already in the chain.
UncleInChain(H256),
/// TODO [arkpar] Please document me
/// An uncle has a parent not in the chain.
UncleParentNotInChain(H256),
/// TODO [arkpar] Please document me
/// State root header field is invalid.
InvalidStateRoot(Mismatch<H256>),
/// TODO [arkpar] Please document me
/// Gas used header field is invalid.
InvalidGasUsed(Mismatch<U256>),
/// TODO [arkpar] Please document me
/// Transactions root header field is invalid.
InvalidTransactionsRoot(Mismatch<H256>),
/// TODO [arkpar] Please document me
/// Difficulty is out of range; this can be used as an looser error prior to getting a definitive
/// value for difficulty. This error needs only provide bounds of which it is out.
DifficultyOutOfBounds(OutOfBounds<U256>),
/// Difficulty header field is invalid; this is a strong error used after getting a definitive
/// value for difficulty (which is provided).
InvalidDifficulty(Mismatch<U256>),
/// TODO [arkpar] Please document me
/// Seal element of type H256 (max_hash for Ethash, but could be something else for
/// other seal engines) is out of bounds.
MismatchedH256SealElement(Mismatch<H256>),
/// Proof-of-work aspect of seal, which we assume is a 256-bit value, is invalid.
InvalidProofOfWork(OutOfBounds<U256>),
/// Gas limit header field is invalid.
InvalidGasLimit(OutOfBounds<U256>),
/// TODO [arkpar] Please document me
InvalidReceiptsStateRoot(Mismatch<H256>),
/// TODO [arkpar] Please document me
/// Receipts trie root header field is invalid.
InvalidReceiptsRoot(Mismatch<H256>),
/// Timestamp header field is invalid.
InvalidTimestamp(OutOfBounds<u64>),
/// TODO [arkpar] Please document me
/// Log bloom header field is invalid.
InvalidLogBloom(Mismatch<LogBloom>),
/// TODO [arkpar] Please document me
InvalidEthashDifficulty(Mismatch<U256>),
/// TODO [arkpar] Please document me
InvalidBlockNonce(Mismatch<H256>),
/// TODO [arkpar] Please document me
/// Parent hash field of header is invalid; this is an invalid error indicating a logic flaw in the codebase.
/// TODO: remove and favour an assert!/panic!.
InvalidParentHash(Mismatch<H256>),
/// TODO [arkpar] Please document me
/// Number field of header is invalid.
InvalidNumber(Mismatch<BlockNumber>),
/// Block number isn't sensible.
RidiculousNumber(OutOfBounds<BlockNumber>),
/// TODO [arkpar] Please document me
/// Parent given is unknown.
UnknownParent(H256),
/// TODO [Gav Wood] Please document me
/// Uncle parent given is unknown.
UnknownUncleParent(H256),
}
@ -154,15 +157,15 @@ pub type ImportResult = Result<H256, ImportError>;
#[derive(Debug)]
/// General error type which should be capable of representing all errors in ethcore.
pub enum Error {
/// TODO [Gav Wood] Please document me
/// Error concerning a utility.
Util(UtilError),
/// TODO [Gav Wood] Please document me
/// Error concerning block processing.
Block(BlockError),
/// TODO [Gav Wood] Please document me
/// Unknown engine given.
UnknownEngineName(String),
/// TODO [Gav Wood] Please document me
/// Error concerning EVM code execution.
Execution(ExecutionError),
/// TODO [Gav Wood] Please document me
/// Error concerning transaction processing.
Transaction(TransactionError),
}

View File

@ -110,16 +110,18 @@ impl Engine for Ethash {
try!(UntrustedRlp::new(&header.seal[0]).as_val::<H256>());
try!(UntrustedRlp::new(&header.seal[1]).as_val::<H64>());
// TODO: consider removing these lines.
let min_difficulty = decode(self.spec().engine_params.get("minimumDifficulty").unwrap());
if header.difficulty < min_difficulty {
return Err(From::from(BlockError::InvalidDifficulty(Mismatch { expected: min_difficulty, found: header.difficulty })))
return Err(From::from(BlockError::DifficultyOutOfBounds(OutOfBounds { min: Some(min_difficulty), max: None, found: header.difficulty })))
}
let difficulty = Ethash::boundary_to_difficulty(&Ethash::from_ethash(quick_get_difficulty(
&Ethash::to_ethash(header.bare_hash()),
header.nonce().low_u64(),
&Ethash::to_ethash(header.mix_hash()))));
if difficulty < header.difficulty {
return Err(From::from(BlockError::InvalidEthashDifficulty(Mismatch { expected: header.difficulty, found: difficulty })));
return Err(From::from(BlockError::InvalidProofOfWork(OutOfBounds { min: Some(header.difficulty), max: None, found: difficulty })));
}
Ok(())
}
@ -129,10 +131,10 @@ impl Engine for Ethash {
let mix = Ethash::from_ethash(result.mix_hash);
let difficulty = Ethash::boundary_to_difficulty(&Ethash::from_ethash(result.value));
if mix != header.mix_hash() {
return Err(From::from(BlockError::InvalidBlockNonce(Mismatch { expected: mix, found: header.mix_hash() })));
return Err(From::from(BlockError::MismatchedH256SealElement(Mismatch { expected: mix, found: header.mix_hash() })));
}
if difficulty < header.difficulty {
return Err(From::from(BlockError::InvalidEthashDifficulty(Mismatch { expected: header.difficulty, found: difficulty })));
return Err(From::from(BlockError::InvalidProofOfWork(OutOfBounds { min: Some(header.difficulty), max: None, found: difficulty })));
}
Ok(())
}

View File

@ -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();
@ -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();
@ -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();
@ -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();
@ -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();
@ -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();
@ -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);
@ -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);
@ -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);
@ -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);
@ -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);
@ -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();

View File

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

View File

@ -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();

View File

@ -1,6 +1,6 @@
use client::{BlockChainClient,Client};
use super::test_common::*;
use super::helpers::*;
use tests::helpers::*;
#[test]
fn created() {
@ -75,4 +75,4 @@ fn can_collect_garbage() {
let client = client_result.reference();
client.tick();
assert!(client.cache_info().blocks < 100 * 1024);
}
}

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
use super::test_common::*;
use super::helpers::*;
use tests::helpers::*;
use pod_state::*;
use state_diff::*;
use ethereum;

View File

@ -12,7 +12,6 @@ macro_rules! declare_test {
#[ignore]
#[test]
#[allow(non_snake_case)]
#[cfg(feature="json-tests")]
fn $id() {
test!($name);
}
@ -21,7 +20,6 @@ macro_rules! declare_test {
#[cfg(feature = "test-heavy")]
#[test]
#[allow(non_snake_case)]
#[cfg(feature="json-tests")]
fn $id() {
test!($name);
}
@ -29,7 +27,6 @@ macro_rules! declare_test {
($id: ident, $name: expr) => {
#[test]
#[allow(non_snake_case)]
#[cfg(feature="json-tests")]
fn $id() {
test!($name);
}

View File

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

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

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

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) {
@ -143,7 +139,6 @@ impl State {
// let old = self.to_pod();
let e = try!(Executive::new(self, env_info, engine).transact(t));
//println!("Executed: {:?}", e);
// TODO uncomment once to_pod() works correctly.
// trace!("Applied transaction. Diff:\n{}\n", StateDiff::diff_pod(&old, &self.to_pod()));
@ -153,16 +148,11 @@ impl State {
Ok(receipt)
}
/// TODO [debris] Please document me
/// Reverts uncommited changed.
pub fn revert(&mut self, backup: State) {
self.cache = backup.cache;
}
/// Convert into a JSON representation.
pub fn as_json(&self) -> String {
unimplemented!();
}
/// Commit accounts to SecTrieDBMut. This is similar to cpp-ethereum's dev::eth::commit.
/// `accounts` is mutable because we may need to commit the code or storage and record that.
#[allow(match_ref_pats)]
@ -196,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)));
@ -213,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

@ -1,6 +1,6 @@
use client::{BlockChainClient,Client};
use std::env;
use super::test_common::*;
use common::*;
use std::path::PathBuf;
use spec::*;
use std::fs::{remove_dir_all};

View File

@ -1,11 +1 @@
#[macro_use]
mod test_common;
mod transaction;
mod executive;
mod state;
mod client;
mod chain;
pub mod helpers;
mod homestead_state;
mod homestead_chain;

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),
@ -64,7 +65,9 @@ impl Transaction {
sender: RefCell::new(None),
}
}
/// 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,
@ -82,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,
@ -168,11 +172,6 @@ impl Transaction {
}
}
/// Note that some fields have changed. Resets the memoised hash.
pub fn note_dirty(&self) {
*self.hash.borrow_mut() = None;
}
/// 0 is `v` is 27, 1 if 28, and 4 otherwise.
pub fn standard_v(&self) -> u8 { match self.v { 27 => 0, 28 => 1, _ => 4 } }
@ -205,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.

View File

@ -154,7 +154,7 @@ pub fn verify_block_final(expected: &Header, got: &Header) -> Result<(), Error>
return Err(From::from(BlockError::InvalidStateRoot(Mismatch { expected: expected.state_root.clone(), found: got.state_root.clone() })))
}
if expected.receipts_root != got.receipts_root {
return Err(From::from(BlockError::InvalidReceiptsStateRoot(Mismatch { expected: expected.receipts_root.clone(), found: got.receipts_root.clone() })))
return Err(From::from(BlockError::InvalidReceiptsRoot(Mismatch { expected: expected.receipts_root.clone(), found: got.receipts_root.clone() })))
}
Ok(())
}