Skip to content

test_sender_is_coinbase()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_warmth_invariants.py::test_sender_is_coinbase@87aba1a3.

Generate fixtures for these test cases for Amsterdam with:

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

Sender is the block coinbase. The intrinsic charge is unchanged by sender identity, but the priority-fee payment loops back to the sender, so the net gas cost reduces to gas_used * base_fee_per_gas.

The coinbase override is wired via a custom Environment whose fee_recipient matches the sender's address.

Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_warmth_invariants.py
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
@pytest.mark.parametrize(
    "value",
    [
        pytest.param(0, id="zero_value"),
        pytest.param(1, id="non-zero_value"),
    ],
)
def test_sender_is_coinbase(
    fork: Fork,
    pre: Alloc,
    state_test: StateTestFiller,
    value: int,
) -> None:
    """
    Sender is the block coinbase. The intrinsic charge is unchanged
    by sender identity, but the priority-fee payment loops back to
    the sender, so the net gas cost reduces to ``gas_used *
    base_fee_per_gas``.

    The coinbase override is wired via a custom ``Environment`` whose
    ``fee_recipient`` matches the sender's address.
    """
    sender_initial_balance = 10**18
    sender = pre.fund_eoa(sender_initial_balance)

    target_initial_balance = 100
    target = pre.fund_eoa(amount=target_initial_balance)

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

    base_fee = 7
    gas_price = 1_000_000_000
    gas_limit = intrinsic_gas + 1000
    # Sender pays the full gas fee upfront and is credited the
    # priority fee back as the coinbase: net cost is
    # ``gas_used * base_fee``.
    sender_final_balance = (
        sender_initial_balance - value - intrinsic_gas * base_fee
    )

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

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

    state_test(
        pre=pre,
        tx=tx,
        post=post,
        env=Environment(fee_recipient=sender, base_fee_per_gas=base_fee),
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.