Skip to content

test_sender_is_coinbase()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_warmth_invariants.py::test_sender_is_coinbase@622620d8.

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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
@EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
@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.