Skip to content

test_factory_address_collision_reverts()

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

Generate fixtures for these test cases for Amsterdam with:

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

A second deployment to the same CREATE2 target reverts. CREATE2 fails when the destination already has code, returns 0, and the factory reverts with the (empty) creation-frame return data.

Source code in tests/amsterdam/eip7997_deterministic_factory_predeploy/test_factory.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
def test_factory_address_collision_reverts(
    state_test: StateTestFiller,
    pre: Alloc,
) -> None:
    """
    A second deployment to the same `CREATE2` target reverts. `CREATE2`
    fails when the destination already has code, returns 0, and the factory
    reverts with the (empty) creation-frame return data.
    """
    salt = 0x77
    runtime_code = Op.STOP
    initcode = Initcode(deploy_code=runtime_code)
    target = compute_create2_address(FACTORY, salt, initcode)

    storage = Storage()
    caller = pre.deploy_contract(
        Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE)
        + Op.SSTORE(
            storage.store_next(1, "first_call_success"),
            Op.CALL(
                gas=Op.GAS,
                address=FACTORY,
                value=0,
                args_offset=0,
                args_size=Op.CALLDATASIZE,
                ret_offset=0x100,
                ret_size=32,
            ),
        )
        + Op.SSTORE(
            storage.store_next(0, "second_call_failed"),
            Op.CALL(
                gas=Op.GAS,
                address=FACTORY,
                value=0,
                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),
            target: Account(nonce=1, code=bytes(runtime_code)),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.