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@ffe48572.

Generate fixtures for these test cases for Bogota with:

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

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
@EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
@pytest.mark.execute(
    pytest.mark.skip(reason="requires env.fee_recipient as block coinbase")
)
@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 = pre.fund_eoa()

    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_execution_gas(
        sends_value=bool(value),
        recipient_type=RecipientType.DELEGATION_7702,
        delegation_warm=True,
    )

    total_gas_cost = intrinsic_gas + top_frame_gas

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

    post = {
        sender: Account(
            nonce=1,
            balance_change=-value - GasFee(tx, gas=total_gas_cost),
        ),
        target: Account(balance=value, code=target_code),
        # The delegated coinbase receives only the priority fee.
        delegated_to: Account(balance_change=Tip(tx, gas=total_gas_cost)),
    }

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

Parametrized Test Cases

This test generates 2 parametrized test cases across 2 forks.