Skip to content

test_bal_nonexistent_account_access_value_transfer()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py::test_bal_nonexistent_account_access_value_transfer@87aba1a3.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py::test_bal_nonexistent_account_access_value_transfer --fork Amsterdam

Ensure BAL captures non-existent account access via CALL/CALLCODE with value.

Alice calls Oracle contract which uses CALL or CALLCODE to access non-existent Bob with value transfer. - CALL: Transfers value from Oracle to Bob - CALLCODE: Self-transfer (net zero), Bob accessed for code

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
@pytest.mark.parametrize(
    "opcode",
    [
        pytest.param(Op.CALL),
        pytest.param(Op.CALLCODE),
    ],
)
@pytest.mark.parametrize(
    "value",
    [
        pytest.param(0, id="zero_value"),
        pytest.param(10**18, id="positive_value"),
    ],
)
def test_bal_nonexistent_account_access_value_transfer(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    opcode: Op,
    value: int,
) -> None:
    """
    Ensure BAL captures non-existent account access via CALL/CALLCODE
    with value.

    Alice calls Oracle contract which uses CALL or CALLCODE to access
    non-existent Bob with value transfer.
    - CALL: Transfers value from Oracle to Bob
    - CALLCODE: Self-transfer (net zero), Bob accessed for code
    """
    alice = pre.fund_eoa()
    bob = pre.nonexistent_account()
    oracle_balance = value + 10**18

    oracle_code = opcode(gas=0, address=bob, value=value)

    oracle = pre.deploy_contract(code=oracle_code, balance=oracle_balance)

    tx = Transaction(sender=alice, to=oracle)

    # Calculate expected balances
    if opcode == Op.CALL and value > 0:
        # CALL: Oracle loses value, Bob gains value
        oracle_final_balance = oracle_balance - value
        bob_final_balance = value
        bob_has_balance_change = True
        oracle_has_balance_change = True
    elif opcode == Op.CALLCODE and value > 0:
        # CALLCODE: Self-transfer (net zero), Bob just accessed for code
        oracle_final_balance = oracle_balance
        bob_final_balance = 0
        bob_has_balance_change = False
        oracle_has_balance_change = False
    else:
        # Zero value
        oracle_final_balance = oracle_balance
        bob_final_balance = 0
        bob_has_balance_change = False
        oracle_has_balance_change = False

    block = Block(
        txs=[tx],
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations={
                alice: BalAccountExpectation(
                    nonce_changes=[
                        BalNonceChange(block_access_index=1, post_nonce=1)
                    ],
                ),
                oracle: BalAccountExpectation(
                    balance_changes=[
                        BalBalanceChange(
                            block_access_index=1,
                            post_balance=oracle_final_balance,
                        )
                    ]
                    if oracle_has_balance_change
                    else [],
                ),
                bob: BalAccountExpectation(
                    balance_changes=[
                        BalBalanceChange(
                            block_access_index=1,
                            post_balance=bob_final_balance,
                        )
                    ]
                    if bob_has_balance_change
                    else [],
                ),
            }
        ),
    )

    blockchain_test(
        pre=pre,
        blocks=[block],
        post={
            alice: Account(nonce=1),
            oracle: Account(balance=oracle_final_balance),
            bob: Account(balance=bob_final_balance)
            if bob_has_balance_change
            else Account.NONEXISTENT,
        },
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.