common changes, added json state tests

This commit is contained in:
debris 2016-01-14 22:41:39 +01:00
parent 98ae8ce36a
commit 4ca353b021
6 changed files with 30 additions and 9 deletions

View File

@ -514,6 +514,10 @@ impl Account {
self.storage_overlay.borrow_mut().insert(key, (Filth::Dirty, value));
}
pub fn reset_storage(&mut self, key: &H256) {
self.storage_overlay.borrow_mut().remove(key);
}
/// Get (and cache) the contents of the trie's storage at `key`.
pub fn storage_at(&self, db: &HashDB, key: &H256) -> H256 {
self.storage_overlay.borrow_mut().entry(key.clone()).or_insert_with(||{

View File

@ -39,7 +39,7 @@ impl EnvInfo {
pub fn from_json(json: &Json) -> EnvInfo {
let current_number = u64_from_json(&json["currentNumber"]);
EnvInfo {
let e = EnvInfo {
number: current_number,
author: address_from_json(&json["currentCoinbase"]),
difficulty: u256_from_json(&json["currentDifficulty"]),
@ -47,7 +47,9 @@ impl EnvInfo {
timestamp: u64_from_json(&json["currentTimestamp"]),
last_hashes: (0..current_number).map(|i| format!("{}", current_number - i).as_bytes().sha3()).collect(),
gas_used: x!(0),
}
};
println!("hashes: {:?}", e.last_hashes);
e
}
}

View File

@ -325,7 +325,6 @@ impl evm::Evm for JitEvm {
let mut context = unsafe { evmjit::ContextHandle::new(data.into_jit(), &mut ext_handle) };
let res = context.exec();
println!("jit res: {:?}", res);
// check in adapter if execution of children contracts failed.
if let Some(err) = optional_err {

View File

@ -278,7 +278,17 @@ impl<'a> Executive<'a> {
contracts_created: substate.contracts_created
})
},
_err => { unreachable!() }
_err => {
Ok(Executed {
gas: t.gas,
gas_used: t.gas,
refunded: U256::zero(),
cumulative_gas_used: self.info.gas_used + t.gas,
logs: vec![],
out_of_gas: true,
contracts_created: vec![]
})
}
}
}

View File

@ -125,7 +125,10 @@ impl State {
/// Mutate storage of account `a` so that it is `value` for `key`.
pub fn set_storage(&mut self, a: &Address, key: H256, value: H256) {
self.require(a, false).set_storage(key, value);
match value == H256::new() {
true => self.require(a, false).reset_storage(&key),
false => self.require(a, false).set_storage(key, value)
}
}
/// Initialise the code of account `a` so that it is `value` for `key`.
@ -138,7 +141,7 @@ 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))
}

View File

@ -39,8 +39,8 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
if fail_unless(&r.state_root == &post_state_root) {
println!("!!! {}: State mismatch (got: {}, expect: {}):", name, r.state_root, post_state_root);
let our_post = s.to_pod();
println!("Got:\n{}", our_post);
println!("Expect:\n{}", post);
println!("Got:\n{:?}", our_post);
println!("Expect:\n{:?}", post);
println!("Diff ---expect -> +++got:\n{}", pod_state_diff(&post, &our_post));
}
@ -58,4 +58,7 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
}
declare_test!{StateTests_stExample, "StateTests/stExample"}
declare_test!{StateTests_stBlockHashTest, "StateTests/stBlockHashTest"}
declare_test!{StateTests_stLogTests, "StateTests/stLogTests"}
declare_test!{StateTests_stCallCodes, "StateTests/stCallCodes"}
declare_test_ignore!{StateTests_stCallCreateCallCodeTest, "StateTests/stCallCreateCallCodeTest"}