Skip to content

test_bal_withdrawal_and_new_contract()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip4895.py::test_bal_withdrawal_and_new_contract@5c024cbb.

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_new_contract --fork Amsterdam

Ensure BAL captures withdrawal to newly created contract.

Alice deploys Oracle contract with 5 gwei initial balance. Oracle receives withdrawal of 10 gwei in same block. Oracle ends with 15 gwei (5 from deployment + 10 from withdrawal).

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip4895.py
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
def test_bal_withdrawal_and_new_contract(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
) -> None:
    """
    Ensure BAL captures withdrawal to newly created contract.

    Alice deploys Oracle contract with 5 gwei initial balance.
    Oracle receives withdrawal of 10 gwei in same block.
    Oracle ends with 15 gwei (5 from deployment + 10 from withdrawal).
    """
    alice = pre.fund_eoa()

    code = Op.STOP
    initcode = Initcode(deploy_code=code)
    oracle = compute_create_address(address=alice)

    tx = Transaction(
        sender=alice,
        to=None,
        data=initcode,
        value=5 * GWEI,
    )

    block = Block(
        txs=[tx],
        withdrawals=[
            Withdrawal(
                index=0,
                validator_index=0,
                address=oracle,
                amount=10,
            )
        ],
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations={
                alice: BalAccountExpectation(
                    nonce_changes=[
                        BalNonceChange(block_access_index=1, post_nonce=1)
                    ],
                ),
                oracle: BalAccountExpectation(
                    code_changes=[
                        BalCodeChange(block_access_index=1, new_code=code)
                    ],
                    balance_changes=[
                        BalBalanceChange(
                            block_access_index=1, post_balance=5 * GWEI
                        ),
                        BalBalanceChange(
                            block_access_index=2, post_balance=15 * GWEI
                        ),
                    ],
                ),
            }
        ),
    )

    blockchain_test(
        pre=pre,
        blocks=[block],
        post={
            alice: Account(nonce=1),
            oracle: Account(balance=15 * GWEI, code=code),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.