From 40341e8852434437880106b5df8b092e4a5e24c7 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 14 Jan 2016 00:27:36 +0100 Subject: [PATCH] Pretty-print and fix for state. --- src/account.rs | 27 +++++++++++++++++++++++++-- src/tests/state.rs | 9 +++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/account.rs b/src/account.rs index cbae80a61..032caf30d 100644 --- a/src/account.rs +++ b/src/account.rs @@ -59,7 +59,30 @@ pub struct StateDiff (BTreeMap); impl fmt::Display for AccountDiff { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "...\n") + match self.nonce { + Diff::Born(ref x) => try!(write!(f, "#{}", x)), + Diff::Changed(ref pre, ref post) => try!(write!(f, "#{} ({} {} {})", post, pre, if pre > post {"-"} else {"+"}, *max(pre, post) - * min(pre, post))), + _ => {}, + } + match self.balance { + Diff::Born(ref x) => try!(write!(f, "${}", x)), + Diff::Changed(ref pre, ref post) => try!(write!(f, "${} ({} {} {})", post, pre, if pre > post {"-"} else {"+"}, *max(pre, post) - *min(pre, post))), + _ => {}, + } + match self.code { + Diff::Born(ref x) => try!(write!(f, "@{}", x.pretty())), + _ => {}, + } + try!(write!(f, "\n")); + for (k, dv) in self.storage.iter() { + match dv { + &Diff::Born(ref v) => try!(write!(f, " + {} => {}\n", k, v)), + &Diff::Changed(ref pre, ref post) => try!(write!(f, " * {} => {} (was {})\n", k, post, pre)), + &Diff::Died(_) => try!(write!(f, " X {}\n", k)), + _ => {}, + } + } + Ok(()) } } @@ -68,7 +91,7 @@ impl fmt::Display for Existance { match self { &Existance::Born => try!(write!(f, "+++")), &Existance::Alive => try!(write!(f, "***")), - &Existance::Died => try!(write!(f, "---")), + &Existance::Died => try!(write!(f, "XXX")), } Ok(()) } diff --git a/src/tests/state.rs b/src/tests/state.rs index 23d894936..18c23e528 100644 --- a/src/tests/state.rs +++ b/src/tests/state.rs @@ -1,5 +1,6 @@ use super::test_common::*; use state::*; +use executive::*; use ethereum; pub fn map_h256_h256_from_json(json: &Json) -> BTreeMap { @@ -46,17 +47,17 @@ fn do_json_test(json_data: &[u8]) -> Vec { let post = pod_map_from_json(&test["post"]); // TODO: read test["logs"] - println!("Transaction: {:?}", t); - println!("Env: {:?}", env); + //println!("Transaction: {:?}", t); + //println!("Env: {:?}", env); let mut s = State::new_temp(); s.populate_from(pre); - s.apply(&env, engine.deref(), &t).unwrap(); + Executive::new(&mut s, &env, engine.deref()).transact(&t).unwrap(); let our_post = s.to_pod_map(); if fail_unless(s.root() == &post_state_root) { - println!("DIFF:\n{}", pod_map_diff(&post, &our_post)); + println!("FAILED {}. Diff:\n{}", name, pod_map_diff(&post, &our_post)); } // TODO: Compare logs.