Skip to content

test_bal_create_in_static_context()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py::test_bal_create_in_static_context@a9abd46e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py::test_bal_create_in_static_context --fork Amsterdam

CREATE/CREATE2 in static context: created address NOT in BAL.

Static check must fire before balance check, address computation, or nonce increment.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
@pytest.mark.parametrize("value", [0, 1], ids=["no_value", "with_value"])
@pytest.mark.with_all_create_opcodes
def test_bal_create_in_static_context(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    create_opcode: Op,
    value: int,
) -> None:
    """
    CREATE/CREATE2 in static context: created address NOT in BAL.

    Static check must fire before balance check, address computation,
    or nonce increment.
    """
    init_code = Initcode(deploy_code=Op.STOP)
    init_code_bytes = bytes(init_code)

    caller = pre.deploy_contract(
        code=Op.MSTORE(0, Op.PUSH32(init_code_bytes))
        + create_opcode(
            value=value,
            offset=32 - len(init_code_bytes),
            size=len(init_code_bytes),
        )
        + Op.STOP,
        balance=value,
    )

    would_be_address = compute_create_address(
        address=caller,
        nonce=1,
        salt=0,
        initcode=init_code_bytes,
        opcode=create_opcode,
    )

    blockchain_test_under_static_call(
        pre,
        blockchain_test,
        static_call_target=caller,
        bal_expectations={would_be_address: None},
        post={
            caller: Account(nonce=1, balance=value),
            would_be_address: Account.NONEXISTENT,
        },
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.