2016-01-13 01:19:05 +01:00
|
|
|
use super::test_common::*;
|
|
|
|
use state::*;
|
2016-01-14 16:46:32 +01:00
|
|
|
use pod_state::*;
|
|
|
|
use state_diff::*;
|
2016-01-13 01:19:05 +01:00
|
|
|
use ethereum;
|
|
|
|
|
|
|
|
fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
|
|
|
let json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid");
|
|
|
|
let mut failed = Vec::new();
|
|
|
|
|
2016-01-16 21:08:04 +01:00
|
|
|
let engine = ethereum::new_frontier_like_test().to_engine().unwrap();
|
2016-01-15 04:02:06 +01:00
|
|
|
flush(format!("\n"));
|
|
|
|
|
2016-01-13 01:19:05 +01:00
|
|
|
for (name, test) in json.as_object().unwrap() {
|
|
|
|
let mut fail = false;
|
2016-01-15 04:02:06 +01:00
|
|
|
{
|
|
|
|
let mut fail_unless = |cond: bool| if !cond && !fail {
|
2016-01-19 13:47:30 +01:00
|
|
|
failed.push(name.clone());
|
2016-01-15 04:02:06 +01:00
|
|
|
flush(format!("FAIL\n"));
|
|
|
|
fail = true;
|
|
|
|
true
|
|
|
|
} else {false};
|
2016-01-13 01:19:05 +01:00
|
|
|
|
2016-01-15 04:02:06 +01:00
|
|
|
flush(format!(" - {}...", name));
|
2016-01-13 01:19:05 +01:00
|
|
|
|
2016-01-16 20:11:12 +01:00
|
|
|
let t = Transaction::from_json(&test["transaction"]);
|
2016-01-16 21:08:04 +01:00
|
|
|
let env = EnvInfo::from_json(&test["env"]);
|
2016-01-15 04:02:06 +01:00
|
|
|
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();
|
|
|
|
|
|
|
|
//println!("Transaction: {:?}", t);
|
|
|
|
//println!("Env: {:?}", env);
|
2016-01-15 13:08:37 +01:00
|
|
|
let calc_post = sec_trie_root(post.get().iter().map(|(k, v)| (k.to_vec(), v.rlp())).collect());
|
2016-01-15 04:02:06 +01:00
|
|
|
|
2016-01-15 13:08:37 +01:00
|
|
|
if fail_unless(post_state_root == calc_post) {
|
|
|
|
println!("!!! {}: Trie root mismatch (got: {}, expect: {}):", name, calc_post, post_state_root);
|
|
|
|
println!("!!! Post:\n{}", post);
|
|
|
|
} else {
|
2016-01-15 04:02:06 +01:00
|
|
|
let mut s = State::new_temp();
|
2016-01-15 13:08:37 +01:00
|
|
|
s.populate_from(pre);
|
2016-01-15 04:02:06 +01:00
|
|
|
s.commit();
|
2016-01-15 13:08:37 +01:00
|
|
|
let res = s.apply(&env, engine.deref(), &t);
|
2016-01-13 15:54:17 +01:00
|
|
|
|
2016-01-15 13:08:37 +01:00
|
|
|
if fail_unless(s.root() == &post_state_root) {
|
|
|
|
println!("!!! {}: State mismatch (got: {}, expect: {}):", name, s.root(), post_state_root);
|
|
|
|
let our_post = s.to_pod();
|
|
|
|
println!("Got:\n{}", our_post);
|
|
|
|
println!("Expect:\n{}", post);
|
|
|
|
println!("Diff ---expect -> +++got:\n{}", StateDiff::diff_pod(&post, &our_post));
|
|
|
|
}
|
2016-01-13 15:54:17 +01:00
|
|
|
|
2016-01-15 13:08:37 +01:00
|
|
|
if let Ok(r) = res {
|
|
|
|
if fail_unless(logs == r.logs) {
|
|
|
|
println!("!!! {}: Logs mismatch:", name);
|
|
|
|
println!("Got:\n{:?}", r.logs);
|
|
|
|
println!("Expect:\n{:?}", logs);
|
|
|
|
}
|
2016-01-15 04:02:06 +01:00
|
|
|
}
|
2016-01-15 01:44:23 +01:00
|
|
|
}
|
2016-01-13 01:19:05 +01:00
|
|
|
}
|
2016-01-15 04:02:06 +01:00
|
|
|
if !fail {
|
|
|
|
flush(format!("ok\n"));
|
|
|
|
}
|
2016-01-14 12:27:35 +01:00
|
|
|
// TODO: Add extra APIs for output
|
|
|
|
//if fail_unless(out == r.)
|
2016-01-13 01:19:05 +01:00
|
|
|
}
|
2016-01-14 12:39:14 +01:00
|
|
|
println!("!!! {:?} tests from failed.", failed.len());
|
2016-01-13 01:19:05 +01:00
|
|
|
failed
|
|
|
|
}
|
|
|
|
|
2016-01-14 22:41:39 +01:00
|
|
|
declare_test!{StateTests_stBlockHashTest, "StateTests/stBlockHashTest"}
|
|
|
|
declare_test!{StateTests_stCallCodes, "StateTests/stCallCodes"}
|
2016-01-26 10:15:55 +01:00
|
|
|
declare_test!{StateTests_stCallCreateCallCodeTest, "StateTests/stCallCreateCallCodeTest"}
|
2016-01-22 08:04:52 +01:00
|
|
|
declare_test!{StateTests_stDelegatecallTest, "StateTests/stDelegatecallTest"}
|
2016-01-15 01:02:14 +01:00
|
|
|
declare_test!{StateTests_stExample, "StateTests/stExample"}
|
|
|
|
declare_test!{StateTests_stInitCodeTest, "StateTests/stInitCodeTest"}
|
|
|
|
declare_test!{StateTests_stLogTests, "StateTests/stLogTests"}
|
2016-01-22 08:07:53 +01:00
|
|
|
declare_test!{heavy => StateTests_stMemoryStressTest, "StateTests/stMemoryStressTest"}
|
|
|
|
declare_test!{heavy => StateTests_stMemoryTest, "StateTests/stMemoryTest"}
|
2016-01-15 01:02:14 +01:00
|
|
|
declare_test!{StateTests_stPreCompiledContracts, "StateTests/stPreCompiledContracts"}
|
2016-01-26 10:15:55 +01:00
|
|
|
declare_test!{heavy => StateTests_stQuadraticComplexityTest, "StateTests/stQuadraticComplexityTest"}
|
|
|
|
declare_test!{StateTests_stRecursiveCreate, "StateTests/stRecursiveCreate"}
|
2016-01-15 01:02:14 +01:00
|
|
|
declare_test!{StateTests_stRefundTest, "StateTests/stRefundTest"}
|
|
|
|
declare_test!{StateTests_stSolidityTest, "StateTests/stSolidityTest"}
|
2016-01-26 10:15:55 +01:00
|
|
|
declare_test!{StateTests_stSpecialTest, "StateTests/stSpecialTest"}
|
|
|
|
declare_test!{StateTests_stSystemOperationsTest, "StateTests/stSystemOperationsTest"}
|
2016-01-15 01:02:14 +01:00
|
|
|
declare_test!{StateTests_stTransactionTest, "StateTests/stTransactionTest"}
|
|
|
|
declare_test!{StateTests_stTransitionTest, "StateTests/stTransitionTest"}
|
|
|
|
declare_test!{StateTests_stWalletTest, "StateTests/stWalletTest"}
|