Skip to content

test_bal_coinbase_zero_tip()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py::test_bal_coinbase_zero_tip@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py::test_bal_coinbase_zero_tip --fork Amsterdam

Ensure BAL includes coinbase even when priority fee is zero.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
def test_bal_coinbase_zero_tip(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    fork: Fork,
) -> None:
    """Ensure BAL includes coinbase even when priority fee is zero."""
    bob = pre.fund_eoa(amount=0)
    coinbase = pre.fund_eoa(amount=0)  # fee recipient

    intrinsic_gas_calculator = fork.transaction_intrinsic_cost_calculator()
    intrinsic_gas = intrinsic_gas_calculator(
        calldata=b"",
        contract_creation=False,
        access_list=[],
        recipient_type=RecipientType.EMPTY_ACCOUNT,
        sends_value=True,
    )
    top_frame_state_gas = fork.transaction_top_frame_state_gas(
        sends_value=True,
        recipient_type=RecipientType.EMPTY_ACCOUNT,
    )
    tx_gas_limit = intrinsic_gas + top_frame_state_gas + 1000

    # Calculate base fee
    genesis_env = Environment(base_fee_per_gas=0x7)
    base_fee_per_gas = fork.base_fee_per_gas_calculator()(
        parent_base_fee_per_gas=int(genesis_env.base_fee_per_gas or 0),
        parent_gas_used=0,
        parent_gas_limit=genesis_env.gas_limit,
    )

    # Set gas_price equal to base_fee so tip = 0
    tx_value = 5
    alice_initial_balance = (tx_gas_limit * base_fee_per_gas) + tx_value
    alice = pre.fund_eoa(amount=alice_initial_balance)
    tx = Transaction(
        sender=alice,
        to=bob,
        value=tx_value,
        gas_limit=tx_gas_limit,
        gas_price=base_fee_per_gas,
    )

    alice_final_balance = (
        alice_initial_balance
        - tx_value
        - ((intrinsic_gas + top_frame_state_gas) * base_fee_per_gas)
    )

    block = Block(
        txs=[tx],
        fee_recipient=coinbase,
        header_verify=Header(base_fee_per_gas=base_fee_per_gas),
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations={
                alice: BalAccountExpectation(
                    nonce_changes=[
                        BalNonceChange(block_access_index=1, post_nonce=1)
                    ],
                    balance_changes=[
                        BalBalanceChange(
                            block_access_index=1,
                            post_balance=alice_final_balance,
                        )
                    ],
                ),
                bob: BalAccountExpectation(
                    balance_changes=[
                        BalBalanceChange(block_access_index=1, post_balance=5)
                    ]
                ),
                # Coinbase must be included even with zero tip
                coinbase: BalAccountExpectation.empty(),
            }
        ),
    )

    blockchain_test(
        pre=pre,
        blocks=[block],
        post={
            alice: Account(nonce=1, balance=alice_final_balance),
            bob: Account(balance=5),
        },
        genesis_environment=genesis_env,
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.