Remove debug stuff.

This commit is contained in:
Gav Wood 2016-01-15 04:02:06 +01:00
parent 7c5c2bd9b8
commit b6139d2064
2 changed files with 58 additions and 42 deletions

View File

@ -140,9 +140,9 @@ impl State {
/// This will change the state accordingly.
pub fn apply(&mut self, env_info: &EnvInfo, engine: &Engine, t: &Transaction) -> ApplyResult {
let e = try!(Executive::new(self, env_info, engine).transact(t));
println!("Executed: {:?}", e);
//println!("Executed: {:?}", e);
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) {
@ -156,7 +156,7 @@ impl State {
/// 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.
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.
// TODO: is this necessary or can we dispense with the `ref mut a` for just `a`?
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() {
match a {
&&Some(ref account) => trie.insert(address, &account.rlp()),
@ -178,13 +178,11 @@ impl State {
}
}
}
root
}
/// Commits our cached account changes into the trie.
pub fn commit(&mut self) {
let r = self.root.clone(); // would prefer not to do this, really.
self.root = Self::commit_into(&mut self.db, r, self.cache.borrow_mut().deref_mut());
Self::commit_into(&mut self.db, &mut self.root, self.cache.borrow_mut().deref_mut());
}
/// Populate the state from `accounts`.

View File

@ -4,16 +4,30 @@ use pod_state::*;
use state_diff::*;
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> {
let json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid");
let mut failed = Vec::new();
let engine = ethereum::new_frontier_test().to_engine().unwrap();
flush(format!("\n"));
for (name, test) in json.as_object().unwrap() {
println!("name: {:?}", name);
let mut fail = false;
let mut fail_unless = |cond: bool| if !cond && !fail { failed.push(name.to_string()); fail = true; true } else {false};
{
let mut fail_unless = |cond: bool| if !cond && !fail {
failed.push(name.to_string());
flush(format!("FAIL\n"));
fail = true;
true
} else {false};
flush(format!(" - {}...", name));
let t = Transaction::from_json(&test["transaction"]);
let env = EnvInfo::from_json(&test["env"]);
@ -53,6 +67,10 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
println!("Expect:\n{:?}", logs);
}
}
}
if !fail {
flush(format!("ok\n"));
}
// TODO: Add extra APIs for output
//if fail_unless(out == r.)
}