@@ -47,6 +47,43 @@ TEST_F(state_transition, selfdestruct_same_tx_cancun)
4747 expect.post [0xbe_address].balance = 0x4e ;
4848}
4949
50+ TEST_F (state_transition, selfdestruct_same_create_cancun)
51+ {
52+ // Use CREATE to temporarily create an account using initcode with SELFDESTRUCT.
53+ // The CREATE should succeed by returning proper address, but the created account
54+ // should not be in the post state.
55+ rev = EVMC_CANCUN ;
56+ static constexpr auto BENEFICIARY = 0x4a0000be_address;
57+ const auto initcode = selfdestruct (BENEFICIARY );
58+
59+ tx.to = To;
60+ pre [To] = {
61+ .balance = 0x4e ,
62+ .code = mstore (0 , push (initcode)) +
63+ create ().input (32 - initcode.size (), initcode.size ()).value (0x0e ) + sstore (0 ),
64+ };
65+
66+ expect.post [To].balance = 0x40 ;
67+ expect.post [To].storage [0x00_bytes32] = to_bytes32 (compute_create_address (To, pre [To].nonce ));
68+ expect.post [BENEFICIARY ].balance = 0x0e ;
69+ }
70+
71+ TEST_F (state_transition, selfdestruct_beneficiary_with_code)
72+ {
73+ // Send ETH via SELFDESTRUCT to an account with code.
74+ // This test checks if the beneficiary's code in the state is not somehow disturbed
75+ // by this action as we likely don't load the code from database.
76+ rev = EVMC_CANCUN ;
77+ static constexpr auto BENEFICIARY = 0x4a0000be_address;
78+
79+ tx.to = To;
80+ pre [To] = {.balance = 1 , .code = selfdestruct (BENEFICIARY )};
81+ pre [BENEFICIARY ] = {.code = bytecode{OP_STOP }};
82+
83+ expect.post [To].balance = 0 ;
84+ expect.post [BENEFICIARY ].code = pre [BENEFICIARY ].code ;
85+ }
86+
5087TEST_F (state_transition, selfdestruct_double_revert)
5188{
5289 rev = EVMC_SHANGHAI ;
0 commit comments