Merge remote-tracking branch 'origin/master' into bettermining
This commit is contained in:
@@ -19,6 +19,7 @@ use tests::helpers::*;
|
||||
use pod_state::*;
|
||||
use state_diff::*;
|
||||
use ethereum;
|
||||
use ethjson;
|
||||
|
||||
fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
||||
json_chain_test(json_data, ChainEra::Frontier)
|
||||
@@ -26,18 +27,14 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
||||
|
||||
pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
|
||||
init_log();
|
||||
|
||||
let json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid");
|
||||
let tests = ethjson::state::Test::load(json_data).unwrap();
|
||||
let mut failed = Vec::new();
|
||||
|
||||
let engine = match era {
|
||||
ChainEra::Frontier => ethereum::new_mainnet_like(),
|
||||
ChainEra::Homestead => ethereum::new_homestead_test(),
|
||||
}.to_engine().unwrap();
|
||||
|
||||
flushln!("");
|
||||
|
||||
for (name, test) in json.as_object().unwrap() {
|
||||
for (name, test) in tests.into_iter() {
|
||||
let mut fail = false;
|
||||
{
|
||||
let mut fail_unless = |cond: bool| if !cond && !fail {
|
||||
@@ -49,16 +46,13 @@ pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
|
||||
|
||||
flush!(" - {}...", name);
|
||||
|
||||
let t = SignedTransaction::from_json(&test["transaction"]);
|
||||
let env = EnvInfo::from_json(&test["env"]);
|
||||
let _out = Bytes::from_json(&test["out"]);
|
||||
let post_state_root = xjson!(&test["postStateRoot"]);
|
||||
let pre = PodState::from_json(&test["pre"]);
|
||||
let post = PodState::from_json(&test["post"]);
|
||||
let logs: Vec<_> = test["logs"].as_array().unwrap().iter().map(&LogEntry::from_json).collect();
|
||||
let transaction = test.transaction.into();
|
||||
let post_state_root = test.post_state_root.into();
|
||||
let env = test.env.into();
|
||||
let pre: PodState = test.pre_state.into();
|
||||
let post: PodState = test.post_state.into();
|
||||
let logs: Vec<LogEntry> = test.logs.into_iter().map(Into::into).collect();
|
||||
|
||||
//println!("Transaction: {:?}", t);
|
||||
//println!("Env: {:?}", env);
|
||||
let calc_post = sec_trie_root(post.get().iter().map(|(k, v)| (k.to_vec(), v.rlp())).collect());
|
||||
|
||||
if fail_unless(post_state_root == calc_post) {
|
||||
@@ -69,7 +63,7 @@ pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
|
||||
let mut state = state_result.reference_mut();
|
||||
state.populate_from(pre);
|
||||
state.commit();
|
||||
let res = state.apply(&env, engine.deref(), &t, false);
|
||||
let res = state.apply(&env, engine.deref(), &transaction, false);
|
||||
|
||||
if fail_unless(state.root() == &post_state_root) {
|
||||
println!("!!! {}: State mismatch (got: {}, expect: {}):", name, state.root(), post_state_root);
|
||||
@@ -88,12 +82,12 @@ pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !fail {
|
||||
flushln!("ok");
|
||||
}
|
||||
// TODO: Add extra APIs for output
|
||||
//if fail_unless(out == r.)
|
||||
}
|
||||
|
||||
println!("!!! {:?} tests from failed.", failed.len());
|
||||
failed
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
use util::*;
|
||||
use basic_types::LogBloom;
|
||||
use header::BlockNumber;
|
||||
use ethjson;
|
||||
|
||||
/// A record of execution for a `LOG` operation.
|
||||
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
||||
@@ -65,6 +66,16 @@ impl LogEntry {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ethjson::state::Log> for LogEntry {
|
||||
fn from(l: ethjson::state::Log) -> Self {
|
||||
LogEntry {
|
||||
address: l.address.into(),
|
||||
topics: l.topics.into_iter().map(Into::into).collect(),
|
||||
data: l.data.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromJson for LogEntry {
|
||||
/// Convert given JSON object to a LogEntry.
|
||||
fn from_json(json: &Json) -> LogEntry {
|
||||
|
||||
@@ -20,6 +20,7 @@ use util::*;
|
||||
use error::*;
|
||||
use evm::Schedule;
|
||||
use header::BlockNumber;
|
||||
use ethjson;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
/// Transaction action type.
|
||||
@@ -79,6 +80,23 @@ impl Transaction {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ethjson::state::Transaction> for SignedTransaction {
|
||||
fn from(t: ethjson::state::Transaction) -> Self {
|
||||
let to: Option<_> = t.to.into();
|
||||
Transaction {
|
||||
nonce: t.nonce.into(),
|
||||
gas_price: t.gas_price.into(),
|
||||
gas: t.gas_limit.into(),
|
||||
action: match to {
|
||||
Some(to) => Action::Call(to.into()),
|
||||
None => Action::Create
|
||||
},
|
||||
value: t.value.into(),
|
||||
data: t.data.into(),
|
||||
}.sign(&t.secret.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl FromJson for SignedTransaction {
|
||||
#[cfg_attr(feature="dev", allow(single_char_pattern))]
|
||||
fn from_json(json: &Json) -> SignedTransaction {
|
||||
|
||||
Reference in New Issue
Block a user