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@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

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

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
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
@pytest.mark.with_all_create_opcodes
@pytest.mark.slow()
def test_set_code_to_contract_creator(
    state_test: StateTestFiller,
    pre: Alloc,
    create_opcode: Op,
) -> None:
    """
    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 = Op.STOP
    initcode: Bytecode = Initcode(deploy_code=deployed_code)

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

    creator_code: Bytecode = Op.CALLDATACOPY(
        0, 0, Op.CALLDATASIZE
    ) + Op.SSTORE(
        storage.store_next(deployed_contract_address),
        create_opcode(value=0, offset=0, size=Op.CALLDATASIZE),
    )

    creator_code_address = pre.deploy_contract(creator_code)

    tx = Transaction(
        gas_limit=10_000_000,
        to=auth_signer,
        value=0,
        data=initcode,
        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

This test generates 2 parametrized test cases across 3 forks.