Skip to content

test_bal_withdrawal_to_coinbase()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip4895.py::test_bal_withdrawal_to_coinbase@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip4895.py::test_bal_withdrawal_to_coinbase --fork Amsterdam

Ensure BAL captures withdrawal to coinbase address.

Block with 1 transaction and 1 withdrawal to coinbase/fee recipient. Coinbase receives both transaction fees and withdrawal.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip4895.py
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
def test_bal_withdrawal_to_coinbase(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    fork: Fork,
) -> None:
    """
    Ensure BAL captures withdrawal to coinbase address.

    Block with 1 transaction and 1 withdrawal to coinbase/fee recipient.
    Coinbase receives both transaction fees and withdrawal.
    """
    alice = pre.fund_eoa()
    bob = pre.fund_eoa(amount=0)
    coinbase = pre.fund_eoa(amount=0)

    intrinsic_gas_calculator = fork.transaction_intrinsic_cost_calculator()
    intrinsic_gas = intrinsic_gas_calculator()
    tx_gas_limit = intrinsic_gas + 1000
    gas_price = 0xA

    tx = Transaction(
        sender=alice,
        to=bob,
        value=5,
        gas_limit=tx_gas_limit,
        gas_price=gas_price,
    )

    # Calculate tip to coinbase
    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,
    )
    tip_to_coinbase = (gas_price - base_fee_per_gas) * intrinsic_gas
    coinbase_final_balance = tip_to_coinbase + (10 * GWEI)

    block = Block(
        txs=[tx],
        fee_recipient=coinbase,
        header_verify=Header(base_fee_per_gas=base_fee_per_gas),
        withdrawals=[
            Withdrawal(
                index=0,
                validator_index=0,
                address=coinbase,
                amount=10,
            )
        ],
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations={
                alice: BalAccountExpectation(
                    nonce_changes=[
                        BalNonceChange(block_access_index=1, post_nonce=1)
                    ],
                ),
                bob: BalAccountExpectation(
                    balance_changes=[
                        BalBalanceChange(block_access_index=1, post_balance=5)
                    ],
                ),
                coinbase: BalAccountExpectation(
                    balance_changes=[
                        BalBalanceChange(
                            block_access_index=1, post_balance=tip_to_coinbase
                        ),
                        BalBalanceChange(
                            block_access_index=2,
                            post_balance=coinbase_final_balance,
                        ),
                    ],
                ),
            }
        ),
    )

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.