Skip to content

test_selfdestruct_alive_beneficiary_no_account_write()

Documentation for tests/amsterdam/eip8038_state_access_gas_cost_increase/test_selfdestruct_gas.py::test_selfdestruct_alive_beneficiary_no_account_write@343274cc.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8038_state_access_gas_cost_increase/test_selfdestruct_gas.py::test_selfdestruct_alive_beneficiary_no_account_write --fork Amsterdam

SELFDESTRUCT to an already-alive beneficiary charges no ACCOUNT_WRITE.

The beneficiary already exists, so no account is created: execution = OPCODE_SELFDESTRUCT_BASE + (COLD_ACCOUNT_ACCESS if cold) and no state gas is charged. The block header reflects the pure execution consumption.

Source code in tests/amsterdam/eip8038_state_access_gas_cost_increase/test_selfdestruct_gas.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
@EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
@pytest.mark.parametrize("warm", [False, True], ids=["cold", "warm"])
def test_selfdestruct_alive_beneficiary_no_account_write(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    warm: bool,
) -> None:
    """
    SELFDESTRUCT to an already-alive beneficiary charges no ACCOUNT_WRITE.

    The beneficiary already exists, so no account is created: execution =
    ``OPCODE_SELFDESTRUCT_BASE + (COLD_ACCOUNT_ACCESS if cold)`` and no
    state gas is charged. The block header reflects the pure execution
    consumption.
    """
    beneficiary = pre.fund_eoa(amount=1)  # alive

    destructor_code = _destructor_code(
        beneficiary, warm=warm, account_new=False
    )
    destructor = pre.deploy_contract(code=destructor_code, balance=1)

    caller_code = Op.POP(Op.CALL(gas=Op.GAS, address=destructor)) + Op.STOP
    caller = pre.deploy_contract(code=caller_code)

    access_list = (
        [AccessList(address=beneficiary, storage_keys=[])] if warm else None
    )
    # Intrinsic must include the access-list cost that warms the
    # beneficiary; pass the list so the calculator folds it in.
    intrinsic = fork.transaction_intrinsic_cost_calculator()(
        access_list=access_list
    )

    # Pure execution: intrinsic + caller frame + destructor frame (whose
    # execution_cost folds the SELFDESTRUCT charge and beneficiary PUSH).
    expected_gas_used = (
        intrinsic
        + caller_code.gas_cost(fork)
        + destructor_code.execution_cost(fork)
    )

    tx = Transaction(
        to=caller,
        sender=pre.fund_eoa(),
        access_list=access_list,
        state_gas_reservoir=0,
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=expected_gas_used,
        ),
    )

    state_test(
        pre=pre,
        # EIP-6780: the pre-deployed destructor is not same-tx-created,
        # so it is not deleted; its balance still transfers.
        post={
            destructor: Account(balance=0, code=destructor_code),
            beneficiary: Account(balance=2),
        },
        tx=tx,
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.