Skip to content

test_factory_staticcall_reverts()

Documentation for tests/amsterdam/eip7997_deterministic_factory_predeploy/test_factory.py::test_factory_staticcall_reverts@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7997_deterministic_factory_predeploy/test_factory.py::test_factory_staticcall_reverts --fork Amsterdam

Calling the factory via STATICCALL fails because CREATE2 requires a writable context. No contract is deployed.

Source code in tests/amsterdam/eip7997_deterministic_factory_predeploy/test_factory.py
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
def test_factory_staticcall_reverts(
    state_test: StateTestFiller,
    pre: Alloc,
) -> None:
    """
    Calling the factory via `STATICCALL` fails because `CREATE2` requires a
    writable context. No contract is deployed.
    """
    salt = 0x33
    runtime_code = Op.STOP
    initcode = Initcode(deploy_code=runtime_code)
    expected_address = compute_create2_address(FACTORY, salt, initcode)

    storage = Storage()
    caller = pre.deploy_contract(
        Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE)
        + Op.SSTORE(
            storage.store_next(0, "staticcall_failed"),
            Op.STATICCALL(
                gas=Op.GAS,
                address=FACTORY,
                args_offset=0,
                args_size=Op.CALLDATASIZE,
                ret_offset=0x100,
                ret_size=32,
            ),
        )
        + Op.STOP,
    )

    state_test(
        pre=pre,
        tx=Transaction(
            sender=pre.fund_eoa(),
            to=caller,
            data=Hash(salt) + bytes(initcode),
        ),
        post={
            caller: Account(storage=storage),
            expected_address: Account.NONEXISTENT,
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.