state: test when contract creation fails, old storage values should re-appear (#9532)
Because more tests won't hurt. :) Add a test case for https://github.com/ethereum/py-evm/pull/1224#issuecomment-418775512 where if contract creation fails, old storage values (if ever existed) should re-appear.
This commit is contained in:
parent
61f4534e2a
commit
018e2403b1
@ -2472,6 +2472,33 @@ mod tests {
|
|||||||
assert_eq!(orig_root, state.root().clone());
|
assert_eq!(orig_root, state.root().clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn create_contract_fail_previous_storage() {
|
||||||
|
let mut state = get_temp_state();
|
||||||
|
let a: Address = 1000.into();
|
||||||
|
let k = H256::from(U256::from(0));
|
||||||
|
|
||||||
|
state.set_storage(&a, k, H256::from(U256::from(0xffff))).unwrap();
|
||||||
|
state.commit().unwrap();
|
||||||
|
state.clear();
|
||||||
|
|
||||||
|
let orig_root = state.root().clone();
|
||||||
|
assert_eq!(state.storage_at(&a, &k).unwrap(), H256::from(U256::from(0xffff)));
|
||||||
|
state.clear();
|
||||||
|
|
||||||
|
state.checkpoint(); // c1
|
||||||
|
state.new_contract(&a, U256::zero(), U256::zero()).unwrap();
|
||||||
|
state.checkpoint(); // c2
|
||||||
|
state.set_storage(&a, k, H256::from(U256::from(2))).unwrap();
|
||||||
|
state.revert_to_checkpoint(); // revert to c2
|
||||||
|
assert_eq!(state.storage_at(&a, &k).unwrap(), H256::from(U256::from(0)));
|
||||||
|
state.revert_to_checkpoint(); // revert to c1
|
||||||
|
assert_eq!(state.storage_at(&a, &k).unwrap(), H256::from(U256::from(0xffff)));
|
||||||
|
|
||||||
|
state.commit().unwrap();
|
||||||
|
assert_eq!(orig_root, state.root().clone());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn create_empty() {
|
fn create_empty() {
|
||||||
let mut state = get_temp_state();
|
let mut state = get_temp_state();
|
||||||
|
Loading…
Reference in New Issue
Block a user