Skip to content

test_set_code_to_contract_creator()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_set_code_to_contract_creator@83970623.

Generate fixtures for these test cases for Prague with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_set_code_to_contract_creator --fork Prague

Test the executing a contract-creating opcode in a set-code transaction.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
@pytest.mark.with_all_create_opcodes
def test_set_code_to_contract_creator(
    state_test: StateTestFiller,
    pre: Alloc,
    create_opcode: Op,
    evm_code_type: EVMCodeType,
):
    """Test the executing a contract-creating opcode in a set-code transaction."""
    storage = Storage()
    auth_signer = pre.fund_eoa(auth_account_start_balance)

    deployed_code: Bytecode | Container = Op.STOP
    initcode: Bytecode | Container

    if evm_code_type == EVMCodeType.LEGACY:
        initcode = Initcode(deploy_code=deployed_code)
    elif evm_code_type == EVMCodeType.EOF_V1:
        deployed_code = Container.Code(deployed_code)
        initcode = Container.Init(deploy_container=deployed_code)
    else:
        raise ValueError(f"Unsupported EVM code type: {evm_code_type}")

    salt = 0

    deployed_contract_address = compute_create_address(
        address=auth_signer,
        nonce=1,
        salt=salt,
        initcode=initcode,
        opcode=create_opcode,
    )

    creator_code: Bytecode | Container
    if evm_code_type == EVMCodeType.LEGACY:
        creator_code = Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE) + Op.SSTORE(
            storage.store_next(deployed_contract_address),
            create_opcode(value=0, offset=0, size=Op.CALLDATASIZE, salt=salt),
        )
    elif evm_code_type == EVMCodeType.EOF_V1:
        creator_code = Container(
            sections=[
                Section.Code(
                    code=Op.EOFCREATE[0](0, 0, 0, 0) + Op.STOP(),
                ),
                Section.Container(
                    container=initcode,
                ),
            ]
        )
    else:
        raise ValueError(f"Unsupported EVM code type: {evm_code_type}")

    creator_code_address = pre.deploy_contract(creator_code)

    tx = Transaction(
        gas_limit=10_000_000,
        to=auth_signer,
        value=0,
        data=initcode if evm_code_type == EVMCodeType.LEGACY else b"",
        authorization_list=[
            AuthorizationTuple(
                address=creator_code_address,
                nonce=0,
                signer=auth_signer,
            ),
        ],
        sender=pre.fund_eoa(),
    )

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post={
            creator_code_address: Account(storage={}),
            auth_signer: Account(
                nonce=2,
                code=Spec.delegation_designation(creator_code_address),
                storage=storage,
            ),
            deployed_contract_address: Account(
                code=deployed_code,
                storage={},
            ),
        },
    )

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) create_opcode evm_code_type
...fork_Prague-create_opcode_CREATE2-evm_code_type_LEGACY-blockchain_test CREATE2 LEGACY
...fork_Prague-create_opcode_CREATE2-evm_code_type_LEGACY-state_test CREATE2 LEGACY
...fork_Prague-create_opcode_CREATE-evm_code_type_LEGACY-blockchain_test CREATE LEGACY
...fork_Prague-create_opcode_CREATE-evm_code_type_LEGACY-state_test CREATE LEGACY
...fork_Osaka-create_opcode_CREATE2-evm_code_type_LEGACY-blockchain_test CREATE2 LEGACY
...fork_Osaka-create_opcode_CREATE2-evm_code_type_LEGACY-state_test CREATE2 LEGACY
...fork_Osaka-create_opcode_CREATE-evm_code_type_LEGACY-blockchain_test CREATE LEGACY
...fork_Osaka-create_opcode_CREATE-evm_code_type_LEGACY-state_test CREATE LEGACY