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@21507778.

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
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
@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.