Skip to content

test_top_frame_charges_delegation_is_coinbase()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_warmth_invariants.py::test_top_frame_charges_delegation_is_coinbase@2119b382.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_warmth_invariants.py::test_top_frame_charges_delegation_is_coinbase --fork Amsterdam

Recipient holds a pre-existing EIP-7702 delegation whose target is the block coinbase. Coinbase is implicitly warm before execution, so the top-frame charges WARM_ACCESS for the delegation target.

Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_warmth_invariants.py
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
@pytest.mark.parametrize(
    "value",
    [
        pytest.param(0, id="zero_value"),
        pytest.param(1, id="non-zero_value"),
    ],
)
def test_top_frame_charges_delegation_is_coinbase(
    env: Environment,
    fork: Fork,
    pre: Alloc,
    state_test: StateTestFiller,
    value: int,
) -> None:
    """
    Recipient holds a pre-existing EIP-7702 delegation whose target is
    the block coinbase. Coinbase is implicitly warm before execution,
    so the top-frame charges ``WARM_ACCESS`` for the delegation target.
    """
    sender_initial_balance = 10**18
    sender = pre.fund_eoa(sender_initial_balance)

    delegated_to = Address(env.fee_recipient)
    target_code = Spec7702.delegation_designation(delegated_to)
    target = pre.deploy_contract(code=target_code)

    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
        sends_value=bool(value),
        recipient_type=RecipientType.DELEGATION_7702,
        return_cost_deducted_prior_execution=True,
    )
    top_frame_gas = fork.transaction_top_frame_gas_calculator()(
        sends_value=bool(value),
        recipient_type=RecipientType.DELEGATION_7702,
        delegation_warm=True,
    )

    total_gas_cost = intrinsic_gas + top_frame_gas
    gas_price = 1_000_000_000
    gas_limit = total_gas_cost + 1000

    tx = Transaction(
        sender=sender,
        to=target,
        value=value,
        gas_limit=gas_limit,
        gas_price=gas_price,
    )

    # Coinbase also receives miner fees, so its post-tx balance is not
    # asserted exactly.
    sender_final_balance = (
        sender_initial_balance - value - total_gas_cost * gas_price
    )

    post = {
        sender: Account(nonce=1, balance=sender_final_balance),
        target: Account(balance=value, code=target_code),
    }

    state_test(pre=pre, tx=tx, post=post)

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.