Skip to content

test_intrinsic_charges_recipient_is_coinbase()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_warmth_invariants.py::test_intrinsic_charges_recipient_is_coinbase@5c024cbb.

Generate fixtures for these test cases for Amsterdam with:

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

Recipient is the block coinbase, which is implicitly warm before transaction execution. The intrinsic charge still includes COLD_ACCOUNT_ACCESS for the recipient.

Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_warmth_invariants.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
@pytest.mark.parametrize(
    "value",
    [
        pytest.param(0, id="zero_value"),
        pytest.param(1, id="non-zero_value"),
    ],
)
def test_intrinsic_charges_recipient_is_coinbase(
    env: Environment,
    fork: Fork,
    pre: Alloc,
    state_test: StateTestFiller,
    value: int,
) -> None:
    """
    Recipient is the block coinbase, which is implicitly warm before
    transaction execution. The intrinsic charge still includes
    ``COLD_ACCOUNT_ACCESS`` for the recipient.
    """
    sender_initial_balance = 10**18
    sender = pre.fund_eoa(sender_initial_balance)
    target = Address(env.fee_recipient)
    # Pre-fund coinbase so it is alive at top-frame check time; this
    # isolates the test to the intrinsic charge invariant and avoids
    # the orthogonal ``NEW_ACCOUNT`` top-frame state charge that would
    # otherwise fire for value transfer to an empty recipient.
    pre.fund_address(target, amount=1)

    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
        sends_value=bool(value),
        recipient_type=RecipientType.EOA,
        return_cost_deducted_prior_execution=True,
    )

    gas_price = 1_000_000_000
    gas_limit = intrinsic_gas + 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; verifying the sender balance is sufficient to
    # pin the intrinsic charge.
    sender_final_balance = (
        sender_initial_balance - value - intrinsic_gas * gas_price
    )

    post = {
        sender: Account(nonce=1, balance=sender_final_balance),
    }

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

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.