Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Pretty-print and fix for state. #102

Merged
merged 2 commits into from
Jan 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}

Expand All @@ -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(())
}
Expand Down
9 changes: 5 additions & 4 deletions src/tests/state.rs
Original file line number Diff line number Diff line change
@@ -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> {
Expand Down Expand Up @@ -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.
Expand Down