Skip to content

test_bal_invalid_missing_account()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_invalid.py::test_bal_invalid_missing_account@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_invalid.py::test_bal_invalid_missing_account --fork Amsterdam

Test that clients reject blocks where BAL omits an account that was touched during block execution.

Covers both the case where the omitted account has a balance change (value transfer recipient) and the access-only case (account read via BALANCE with no state change).

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_invalid.py
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
@pytest.mark.valid_from("Amsterdam")
@pytest.mark.exception_test
@pytest.mark.parametrize(
    "scenario",
    ["balance_change", "access_only"],
)
def test_bal_invalid_missing_account(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    scenario: str,
) -> None:
    """
    Test that clients reject blocks where BAL omits an account that was
    touched during block execution.

    Covers both the case where the omitted account has a balance change
    (value transfer recipient) and the access-only case (account read via
    ``BALANCE`` with no state change).
    """
    sender = pre.fund_eoa(amount=10**18)
    sender_expectation = BalAccountExpectation(
        nonce_changes=[BalNonceChange(block_access_index=1, post_nonce=1)],
    )

    if scenario == "balance_change":
        omitted = pre.fund_eoa(amount=0)
        tx = Transaction(
            sender=sender,
            to=omitted,
            value=10**15,
            gas_limit=21_000,
        )
        post: dict = {
            sender: Account(balance=10**18, nonce=0),
            omitted: None,
        }
        account_expectations: dict = {
            sender: sender_expectation,
            omitted: BalAccountExpectation(
                balance_changes=[
                    BalBalanceChange(block_access_index=1, post_balance=10**15)
                ],
            ),
        }
    elif scenario == "access_only":
        omitted = pre.fund_eoa(amount=1)
        checker = pre.deploy_contract(code=Op.BALANCE(omitted))
        tx = Transaction(
            sender=sender,
            to=checker,
            gas_limit=100_000,
        )
        post = {
            sender: Account(balance=10**18, nonce=0),
            omitted: Account(balance=1),
            checker: Account(),
        }
        account_expectations = {
            sender: sender_expectation,
            checker: BalAccountExpectation.empty(),
            omitted: BalAccountExpectation.empty(),
        }
    else:
        raise ValueError(f"Unknown scenario: {scenario}")

    blockchain_test(
        pre=pre,
        post=post,
        blocks=[
            Block(
                txs=[tx],
                exception=BlockException.INVALID_BLOCK_ACCESS_LIST,
                expected_block_access_list=BlockAccessListExpectation(
                    account_expectations=account_expectations,
                ).modify(remove_accounts(omitted)),
            )
        ],
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.