Skip to content

test_max_initcode_size_via_create_fork_transition()

Documentation for tests/amsterdam/eip7954_increase_max_contract_size/test_fork_transition.py::test_max_initcode_size_via_create_fork_transition@9c2813ee.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7954_increase_max_contract_size/test_fork_transition.py::test_max_initcode_size_via_create_fork_transition --fork Amsterdam

Ensure the new max initcode size limit activates at fork via opcodes.

Source code in tests/amsterdam/eip7954_increase_max_contract_size/test_fork_transition.py
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
@pytest.mark.parametrize("create_opcode", [Op.CREATE, Op.CREATE2])
def test_max_initcode_size_via_create_fork_transition(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: TransitionFork,
    create_opcode: Op,
) -> None:
    """Ensure the new max initcode size limit activates at fork via opcodes."""
    initcode = Initcode(
        deploy_code=Op.STOP,
        initcode_length=fork.transitions_to().max_initcode_size(),
    )
    initcode_bytes = bytes(initcode)

    alice = pre.fund_eoa()
    bob = pre.fund_eoa()

    create_call = (
        create_opcode(
            value=0, offset=0, size=Op.CALLDATASIZE, salt=CREATE2_SALT
        )
        if create_opcode == Op.CREATE2
        else create_opcode(value=0, offset=0, size=Op.CALLDATASIZE)
    )

    factory_code = (
        Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE)
        + Op.SSTORE(0, create_call)
        + Op.STOP
    )

    factory_pre = pre.deploy_contract(factory_code)
    factory_post = pre.deploy_contract(factory_code)

    create_address_pre = compute_create_address(
        address=factory_pre,
        nonce=1,
        salt=CREATE2_SALT,
        initcode=initcode,
        opcode=create_opcode,
    )
    create_address_post = compute_create_address(
        address=factory_post,
        nonce=1,
        salt=CREATE2_SALT,
        initcode=initcode,
        opcode=create_opcode,
    )

    blocks = [
        Block(
            timestamp=14_999,
            txs=[
                Transaction(
                    sender=alice,
                    to=factory_pre,
                    data=initcode_bytes,
                    gas_limit=fork.transitions_from().transaction_gas_limit_cap(),
                )
            ],
        ),
        Block(
            timestamp=15_000,
            txs=[
                Transaction(
                    sender=bob,
                    to=factory_post,
                    data=initcode_bytes,
                    gas_limit=fork.transitions_to().transaction_gas_limit_cap(),
                )
            ],
        ),
    ]

    # Pre-fork: CREATE returns 0 (initcode exceeds parent fork limit)
    # Post-fork: CREATE succeeds
    post: dict[Any, Account | None] = {
        factory_pre: Account(storage={0: 0}),
        create_address_pre: Account.NONEXISTENT,
        factory_post: Account(storage={0: create_address_post}),
        create_address_post: Account(code=Op.STOP),
    }

    blockchain_test(pre=pre, blocks=blocks, post=post)

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.