Merge pull request #102 from gavofyork/gav

Pretty-print and fix for state.
This commit is contained in:
Gav Wood 2016-01-14 00:29:22 +01:00
commit dc9625de62
2 changed files with 30 additions and 6 deletions

View File

@ -59,7 +59,30 @@ pub struct StateDiff (BTreeMap<Address, AccountDiff>);
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(())
}

View File

@ -1,5 +1,6 @@
use super::test_common::*;
use state::*;
use executive::*;
use ethereum;
pub fn map_h256_h256_from_json(json: &Json) -> BTreeMap<H256, H256> {
@ -46,17 +47,17 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
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.