Skip to content

test_balance_within_block()

Documentation for tests/shanghai/eip4895_withdrawals/test_withdrawals.py::test_balance_within_block@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/shanghai/eip4895_withdrawals/test_withdrawals.py::test_balance_within_block --fork Bogota

Test withdrawal balance increase within the same block in a contract call.

Source code in tests/shanghai/eip4895_withdrawals/test_withdrawals.py
def test_balance_within_block(
    blockchain_test: BlockchainTestFiller, pre: Alloc
) -> None:
    """
    Test withdrawal balance increase within the same block in a contract call.
    """
    save_balance_on_block_number = Op.SSTORE(
        Op.NUMBER,
        Op.BALANCE(Op.CALLDATALOAD(0)),
    )
    sender = pre.fund_eoa()
    recipient = pre.fund_eoa(ONE_GWEI)
    contract_address = pre.deploy_contract(save_balance_on_block_number)

    blocks = [
        Block(
            txs=[
                Transaction(
                    sender=sender,
                    to=contract_address,
                    data=Hash(recipient, left_padding=True),
                )
            ],
            withdrawals=[
                Withdrawal(
                    index=0,
                    validator_index=0,
                    address=recipient,
                    amount=1,
                )
            ],
        ),
        Block(
            txs=[
                Transaction(
                    sender=sender,
                    to=contract_address,
                    data=Hash(recipient, left_padding=True),
                )
            ]
        ),
    ]

    post = {
        contract_address: Account(
            storage={
                1: ONE_GWEI,
                2: 2 * ONE_GWEI,
            }
        )
    }

    blockchain_test(pre=pre, post=post, blocks=blocks)

Parametrized Test Cases

This test generates 1 parametrized test case across 6 forks.