New account_db key scheme; snapshot tests

This commit is contained in:
arkpar 2016-02-05 12:58:18 +01:00
parent 97082ca807
commit 31cf20ffa2
2 changed files with 36 additions and 1 deletions

View File

@ -13,7 +13,10 @@ pub struct AccountDB<'db> {
#[inline] #[inline]
fn combine_key<'a>(address: &'a H256, key: &'a H256) -> H256 { fn combine_key<'a>(address: &'a H256, key: &'a H256) -> H256 {
address ^ key let mut addr_hash = address.sha3();
// preserve 96 bits of original key for db lookup
addr_hash[0..12].clone_from_slice(&[0u8; 12]);
&addr_hash ^ key
} }
impl<'db> AccountDB<'db> { impl<'db> AccountDB<'db> {

View File

@ -482,6 +482,38 @@ fn ensure_cached() {
assert_eq!(state.root().hex(), "0ce23f3c809de377b008a4a3ee94a0834aac8bec1f86e28ffe4fdb5a15b0c785"); assert_eq!(state.root().hex(), "0ce23f3c809de377b008a4a3ee94a0834aac8bec1f86e28ffe4fdb5a15b0c785");
} }
#[test]
fn snapshot_basic() {
let mut state_result = get_temp_state();
let mut state = state_result.reference_mut();
let a = Address::zero();
state.snapshot();
state.add_balance(&a, &U256::from(69u64));
assert_eq!(state.balance(&a), U256::from(69u64));
state.clear_snapshot();
assert_eq!(state.balance(&a), U256::from(69u64));
state.snapshot();
state.add_balance(&a, &U256::from(1u64));
assert_eq!(state.balance(&a), U256::from(70u64));
state.revert_snapshot();
assert_eq!(state.balance(&a), U256::from(69u64));
}
#[test]
fn snapshot_nested() {
let mut state_result = get_temp_state();
let mut state = state_result.reference_mut();
let a = Address::zero();
state.snapshot();
state.snapshot();
state.add_balance(&a, &U256::from(69u64));
assert_eq!(state.balance(&a), U256::from(69u64));
state.clear_snapshot();
assert_eq!(state.balance(&a), U256::from(69u64));
state.revert_snapshot();
assert_eq!(state.balance(&a), U256::from(0));
}
#[test] #[test]
fn create_empty() { fn create_empty() {
let mut state_result = get_temp_state(); let mut state_result = get_temp_state();