Skip to content

test_factory_rejects_oversized_initcode()

Documentation for tests/amsterdam/eip7997_deterministic_factory_predeploy/test_factory.py::test_factory_rejects_oversized_initcode@2119b382.

Generate fixtures for these test cases for Amsterdam with:

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

EIP-3860: initcode larger than the fork's max initcode size is rejected. The factory's CREATE2 fails for oversized initcode and the factory reverts.

Source code in tests/amsterdam/eip7997_deterministic_factory_predeploy/test_factory.py
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
def test_factory_rejects_oversized_initcode(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    EIP-3860: initcode larger than the fork's max initcode size is
    rejected. The factory's `CREATE2` fails for oversized initcode and
    the factory reverts.
    """
    salt = 0x55
    initcode = Initcode(
        deploy_code=Op.STOP,
        initcode_length=fork.max_initcode_size() + 1,
    )
    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, "factory_call_failed"),
            Op.CALL(
                gas=Op.GAS,
                address=FACTORY,
                value=0,
                args_offset=0,
                args_size=Op.CALLDATASIZE,
            ),
        )
        + 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.