Skip to content

test_bal_withdrawal_and_transaction()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip4895.py::test_bal_withdrawal_and_transaction@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_and_transaction --fork Amsterdam

Ensure BAL captures both transaction and withdrawal balance changes.

Alice starts with 1 ETH, Bob starts with 0, Charlie starts with 0. Alice sends 5 wei to Bob. Charlie receives 10 gwei withdrawal. Bob ends with 5 wei, Charlie ends with 10 gwei.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip4895.py
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
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
@EIPChecklist.BlockLevelConstraint.Test.Content.Withdrawals()
def test_bal_withdrawal_and_transaction(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
) -> None:
    """
    Ensure BAL captures both transaction and withdrawal balance changes.

    Alice starts with 1 ETH, Bob starts with 0, Charlie starts with 0.
    Alice sends 5 wei to Bob.
    Charlie receives 10 gwei withdrawal.
    Bob ends with 5 wei, Charlie ends with 10 gwei.
    """
    alice = pre.fund_eoa()
    bob = pre.fund_eoa(amount=0)
    charlie = pre.fund_eoa(amount=0)

    tx = Transaction(
        sender=alice,
        to=bob,
        value=5,
        max_fee_per_gas=50,
        max_priority_fee_per_gas=5,
    )

    block = Block(
        txs=[tx],
        withdrawals=[
            Withdrawal(
                index=0,
                validator_index=0,
                address=charlie,
                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)
                    ],
                ),
                charlie: BalAccountExpectation(
                    balance_changes=[
                        BalBalanceChange(
                            block_access_index=2, post_balance=10 * GWEI
                        )
                    ],
                ),
            }
        ),
    )

    blockchain_test(
        pre=pre,
        blocks=[block],
        post={
            alice: Account(nonce=1),
            bob: Account(balance=5),
            charlie: Account(balance=10 * GWEI),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.