Skip to content

test_factory_deploys_to_pre_funded_address()

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

Generate fixtures for these test cases for Amsterdam with:

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

CREATE2 to an address that has only a balance (no code, no storage, nonce 0) succeeds and preserves the existing balance.

Source code in tests/amsterdam/eip7997_deterministic_factory_predeploy/test_factory.py
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
def test_factory_deploys_to_pre_funded_address(
    state_test: StateTestFiller,
    pre: Alloc,
) -> None:
    """
    `CREATE2` to an address that has only a balance (no code, no storage,
    nonce 0) succeeds and preserves the existing balance.
    """
    salt = 0x66
    runtime_code = Op.STOP
    initcode = Initcode(deploy_code=runtime_code)
    expected_address = compute_create2_address(FACTORY, salt, initcode)
    pre_balance = 1

    storage = Storage()
    caller = pre.deploy_contract(
        Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE)
        + Op.POP(
            Op.CALL(
                gas=Op.GAS,
                address=expected_address,
                value=pre_balance,
            )
        )
        + Op.SSTORE(
            storage.store_next(1, "factory_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.STOP,
        balance=pre_balance,
    )

    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(
                nonce=1,
                balance=pre_balance,
                code=bytes(runtime_code),
            ),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.