Remove debug stuff.
This commit is contained in:
parent
7c5c2bd9b8
commit
b6139d2064
12
src/state.rs
12
src/state.rs
@ -140,9 +140,9 @@ impl State {
|
|||||||
/// This will change the state accordingly.
|
/// This will change the state accordingly.
|
||||||
pub fn apply(&mut self, env_info: &EnvInfo, engine: &Engine, t: &Transaction) -> ApplyResult {
|
pub fn apply(&mut self, env_info: &EnvInfo, engine: &Engine, t: &Transaction) -> ApplyResult {
|
||||||
let e = try!(Executive::new(self, env_info, engine).transact(t));
|
let e = try!(Executive::new(self, env_info, engine).transact(t));
|
||||||
println!("Executed: {:?}", e);
|
//println!("Executed: {:?}", e);
|
||||||
self.commit();
|
self.commit();
|
||||||
Ok(Receipt::new(self.root().clone(), e.gas_used, e.logs))
|
Ok(Receipt::new(self.root().clone(), e.cumulative_gas_used, e.logs))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn revert(&mut self, backup: State) {
|
pub fn revert(&mut self, backup: State) {
|
||||||
@ -156,7 +156,7 @@ impl State {
|
|||||||
|
|
||||||
/// Commit accounts to SecTrieDBMut. This is similar to cpp-ethereum's dev::eth::commit.
|
/// 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.
|
/// `accounts` is mutable because we may need to commit the code or storage and record that.
|
||||||
pub fn commit_into(db: &mut HashDB, mut root: H256, accounts: &mut HashMap<Address, Option<Account>>) -> H256 {
|
pub fn commit_into(db: &mut HashDB, root: &mut H256, accounts: &mut HashMap<Address, Option<Account>>) {
|
||||||
// first, commit the sub trees.
|
// first, commit the sub trees.
|
||||||
// TODO: is this necessary or can we dispense with the `ref mut a` for just `a`?
|
// TODO: is this necessary or can we dispense with the `ref mut a` for just `a`?
|
||||||
for (_, ref mut a) in accounts.iter_mut() {
|
for (_, ref mut a) in accounts.iter_mut() {
|
||||||
@ -170,7 +170,7 @@ impl State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut trie = SecTrieDBMut::from_existing(db, &mut root);
|
let mut trie = SecTrieDBMut::from_existing(db, root);
|
||||||
for (address, ref a) in accounts.iter() {
|
for (address, ref a) in accounts.iter() {
|
||||||
match a {
|
match a {
|
||||||
&&Some(ref account) => trie.insert(address, &account.rlp()),
|
&&Some(ref account) => trie.insert(address, &account.rlp()),
|
||||||
@ -178,13 +178,11 @@ impl State {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
root
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Commits our cached account changes into the trie.
|
/// Commits our cached account changes into the trie.
|
||||||
pub fn commit(&mut self) {
|
pub fn commit(&mut self) {
|
||||||
let r = self.root.clone(); // would prefer not to do this, really.
|
Self::commit_into(&mut self.db, &mut self.root, self.cache.borrow_mut().deref_mut());
|
||||||
self.root = Self::commit_into(&mut self.db, r, self.cache.borrow_mut().deref_mut());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Populate the state from `accounts`.
|
/// Populate the state from `accounts`.
|
||||||
|
@ -4,54 +4,72 @@ use pod_state::*;
|
|||||||
use state_diff::*;
|
use state_diff::*;
|
||||||
use ethereum;
|
use ethereum;
|
||||||
|
|
||||||
|
fn flush(s: String) {
|
||||||
|
::std::io::stdout().write(s.as_bytes()).unwrap();
|
||||||
|
::std::io::stdout().flush().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
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 json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid");
|
||||||
let mut failed = Vec::new();
|
let mut failed = Vec::new();
|
||||||
|
|
||||||
let engine = ethereum::new_frontier_test().to_engine().unwrap();
|
let engine = ethereum::new_frontier_test().to_engine().unwrap();
|
||||||
|
|
||||||
|
flush(format!("\n"));
|
||||||
|
|
||||||
for (name, test) in json.as_object().unwrap() {
|
for (name, test) in json.as_object().unwrap() {
|
||||||
println!("name: {:?}", name);
|
|
||||||
let mut fail = false;
|
let mut fail = false;
|
||||||
let mut fail_unless = |cond: bool| if !cond && !fail { failed.push(name.to_string()); fail = true; true } else {false};
|
|
||||||
|
|
||||||
let t = Transaction::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();
|
|
||||||
|
|
||||||
//println!("Transaction: {:?}", t);
|
|
||||||
//println!("Env: {:?}", env);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut s = State::new_temp();
|
let mut fail_unless = |cond: bool| if !cond && !fail {
|
||||||
s.populate_from(post.clone());
|
failed.push(name.to_string());
|
||||||
s.commit();
|
flush(format!("FAIL\n"));
|
||||||
assert_eq!(&post_state_root, s.root());
|
fail = true;
|
||||||
}
|
true
|
||||||
|
} else {false};
|
||||||
|
|
||||||
let mut s = State::new_temp();
|
flush(format!(" - {}...", name));
|
||||||
s.populate_from(pre);
|
|
||||||
s.commit();
|
|
||||||
let res = s.apply(&env, engine.deref(), &t);
|
|
||||||
|
|
||||||
if fail_unless(s.root() == &post_state_root) {
|
let t = Transaction::from_json(&test["transaction"]);
|
||||||
println!("!!! {}: State mismatch (got: {}, expect: {}):", name, s.root(), post_state_root);
|
let env = EnvInfo::from_json(&test["env"]);
|
||||||
let our_post = s.to_pod();
|
let _out = Bytes::from_json(&test["out"]);
|
||||||
println!("Got:\n{}", our_post);
|
let post_state_root = xjson!(&test["postStateRoot"]);
|
||||||
println!("Expect:\n{}", post);
|
let pre = PodState::from_json(&test["pre"]);
|
||||||
println!("Diff ---expect -> +++got:\n{}", StateDiff::diff_pod(&post, &our_post));
|
let post = PodState::from_json(&test["post"]);
|
||||||
}
|
let logs: Vec<_> = test["logs"].as_array().unwrap().iter().map(&LogEntry::from_json).collect();
|
||||||
|
|
||||||
if let Ok(r) = res {
|
//println!("Transaction: {:?}", t);
|
||||||
if fail_unless(logs == r.logs) {
|
//println!("Env: {:?}", env);
|
||||||
println!("!!! {}: Logs mismatch:", name);
|
|
||||||
println!("Got:\n{:?}", r.logs);
|
{
|
||||||
println!("Expect:\n{:?}", logs);
|
let mut s = State::new_temp();
|
||||||
|
s.populate_from(post.clone());
|
||||||
|
s.commit();
|
||||||
|
assert_eq!(&post_state_root, s.root());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut s = State::new_temp();
|
||||||
|
s.populate_from(pre);
|
||||||
|
s.commit();
|
||||||
|
let res = s.apply(&env, engine.deref(), &t);
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(r) = res {
|
||||||
|
if fail_unless(logs == r.logs) {
|
||||||
|
println!("!!! {}: Logs mismatch:", name);
|
||||||
|
println!("Got:\n{:?}", r.logs);
|
||||||
|
println!("Expect:\n{:?}", logs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !fail {
|
||||||
|
flush(format!("ok\n"));
|
||||||
}
|
}
|
||||||
// TODO: Add extra APIs for output
|
// TODO: Add extra APIs for output
|
||||||
//if fail_unless(out == r.)
|
//if fail_unless(out == r.)
|
||||||
|
Loading…
Reference in New Issue
Block a user