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

Commit

Permalink
Fix checkpointing when creating contract failed (#9514)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorpaas authored and 5chdn committed Sep 11, 2018
1 parent 4858702 commit 631df0f
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions ethcore/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,16 +421,7 @@ impl<B: Backend> State<B> {
**prev = checkpoint;
} else {
for (k, v) in checkpoint.drain() {
match prev.entry(k) {
Entry::Occupied(mut e) => {
if e.get().is_none() {
e.insert(v);
}
},
Entry::Vacant(e) => {
e.insert(v);
}
}
prev.entry(k).or_insert(v);
}
}
}
Expand Down Expand Up @@ -2462,6 +2453,25 @@ mod tests {
assert_eq!(state.storage_at(&a, &k).unwrap(), H256::from(U256::from(1)));
}

#[test]
fn create_contract_fail() {
let mut state = get_temp_state();
let orig_root = state.root().clone();
let a: Address = 1000.into();

state.checkpoint(); // c1
state.new_contract(&a, U256::zero(), U256::zero()).unwrap();
state.add_balance(&a, &U256::from(1), CleanupMode::ForceCreate).unwrap();
state.checkpoint(); // c2
state.add_balance(&a, &U256::from(1), CleanupMode::ForceCreate).unwrap();
state.discard_checkpoint(); // discard c2
state.revert_to_checkpoint(); // revert to c1
assert_eq!(state.exists(&a).unwrap(), false);

state.commit().unwrap();
assert_eq!(orig_root, state.root().clone());
}

#[test]
fn create_empty() {
let mut state = get_temp_state();
Expand Down

0 comments on commit 631df0f

Please sign in to comment.