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@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_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
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
563
564
565
566
567
568
569
570
571
572
573
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,
        gas_limit=1_000_000,
        gas_price=0xA,
    )

    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.