@@ -109,6 +109,69 @@ TEST_F(state_transition, selfdestruct_double_revert)
109109TEST_F (state_transition, selfdestruct_initcode)
110110{
111111 tx.data = selfdestruct (0xbe_address);
112+
113+ expect.post [compute_create_address (tx.sender , tx.nonce )].exists = false ;
114+ expect.post [0xbe_address].exists = false ;
115+ }
116+
117+ TEST_F (state_transition, selfdestruct_initcode_amsterdam)
118+ {
119+ // A same-tx-created account that self-destructs ending with a zero balance must not be in the
120+ // final state (EIP-8246). In this test we use initcode.
121+ rev = EVMC_AMSTERDAM ;
122+ tx.data = selfdestruct (0xbe_address);
123+
124+ expect.post [compute_create_address (tx.sender , tx.nonce )].exists = false ;
125+ expect.post [0xbe_address].exists = false ;
126+ }
127+
128+ TEST_F (state_transition, selfdestruct_prefunded)
129+ {
130+ // Although burn is removed in EIP-8246, the deletion of a pre-funded account still happens.
131+ rev = EVMC_CANCUN ;
132+ const auto created = compute_create_address (tx.sender , tx.nonce );
133+ pre [created] = {.balance = 1 };
134+ tx.data = selfdestruct (0xbe_address); // Transfer to distinct beneficiary.
135+
136+ expect.post [created].exists = false ; // Removed, despite pre-existing in the state.
137+ expect.post [0xbe_address].balance = 1 ; // Pre-funded balance delivered to the beneficiary.
138+ }
139+
140+
141+ TEST_F (state_transition, selfdestruct_prefunded_amsterdam)
142+ {
143+ // Although burn is removed in EIP-8246, the deletion of a pre-funded account still happens.
144+ rev = EVMC_AMSTERDAM ;
145+ const auto created = compute_create_address (tx.sender , tx.nonce );
146+ pre [created] = {.balance = 1 };
147+ tx.data = selfdestruct (0xbe_address); // Transfer to distinct beneficiary.
148+
149+ expect.post [created].exists = false ; // Removed, despite pre-existing in the state.
150+ expect.post [0xbe_address].balance = 1 ; // Pre-funded balance delivered to the beneficiary.
151+ }
152+
153+ TEST_F (state_transition, selfdestruct_prefunded_burn)
154+ {
155+ // Burn pre-funded ETH by self-destruct to self.
156+ rev = EVMC_CANCUN ;
157+ const auto created = compute_create_address (tx.sender , tx.nonce );
158+ pre [created] = {.balance = 1 };
159+ tx.data = selfdestruct (created);
160+
161+ expect.post [created].exists = false ; // Removed, despite pre-existing in the state.
162+ }
163+
164+ TEST_F (state_transition, selfdestruct_prefunded_burn_amsterdam)
165+ {
166+ // Although burn is removed in EIP-8246, the deletion of a pre-funded account still happens.
167+ rev = EVMC_AMSTERDAM ;
168+ const auto created = compute_create_address (tx.sender , tx.nonce );
169+ pre [created] = {.balance = 1 };
170+ tx.data = selfdestruct (created);
171+
172+ expect.post [created].balance = 1 ; // Balance preserved.
173+ expect.post [created].nonce = 0 ;
174+ expect.post [created].code = {};
112175}
113176
114177TEST_F (state_transition, massdestruct_shanghai)
0 commit comments