Merge pull request #102 from gavofyork/gav
Pretty-print and fix for state.
This commit is contained in:
commit
dc9625de62
@ -59,7 +59,30 @@ pub struct StateDiff (BTreeMap<Address, AccountDiff>);
|
|||||||
|
|
||||||
impl fmt::Display for AccountDiff {
|
impl fmt::Display for AccountDiff {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
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 {
|
match self {
|
||||||
&Existance::Born => try!(write!(f, "+++")),
|
&Existance::Born => try!(write!(f, "+++")),
|
||||||
&Existance::Alive => try!(write!(f, "***")),
|
&Existance::Alive => try!(write!(f, "***")),
|
||||||
&Existance::Died => try!(write!(f, "---")),
|
&Existance::Died => try!(write!(f, "XXX")),
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use super::test_common::*;
|
use super::test_common::*;
|
||||||
use state::*;
|
use state::*;
|
||||||
|
use executive::*;
|
||||||
use ethereum;
|
use ethereum;
|
||||||
|
|
||||||
pub fn map_h256_h256_from_json(json: &Json) -> BTreeMap<H256, H256> {
|
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"]);
|
let post = pod_map_from_json(&test["post"]);
|
||||||
// TODO: read test["logs"]
|
// TODO: read test["logs"]
|
||||||
|
|
||||||
println!("Transaction: {:?}", t);
|
//println!("Transaction: {:?}", t);
|
||||||
println!("Env: {:?}", env);
|
//println!("Env: {:?}", env);
|
||||||
|
|
||||||
let mut s = State::new_temp();
|
let mut s = State::new_temp();
|
||||||
s.populate_from(pre);
|
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();
|
let our_post = s.to_pod_map();
|
||||||
|
|
||||||
if fail_unless(s.root() == &post_state_root) {
|
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.
|
// TODO: Compare logs.
|
||||||
|
Loading…
Reference in New Issue
Block a user