Skip to content

test_creating_tx_to_contract_creator()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_creating_tx_to_contract_creator@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_creating_tx_to_contract_creator --fork Bogota

Test executing a contract-creating opcode in a 7702-context called from a creating transaction.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
@pytest.mark.with_all_create_opcodes
def test_creating_tx_to_contract_creator(
    state_test: StateTestFiller,
    pre: Alloc,
    create_opcode: Op,
) -> None:
    """
    Test executing a contract-creating opcode in a 7702-context called from a
    creating transaction.
    """
    creator_storage = Storage()
    initcode_storage = Storage()

    inner_create_result_slot = creator_storage.peek_slot()
    creator_code = Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE) + Op.SSTORE(
        creator_storage.store_next(0, hint="inner create result"),
        create_opcode(value=0, offset=0, size=Op.CALLDATASIZE),
    )

    creator_code_address = pre.deploy_contract(creator_code)

    auth_signer = pre.fund_eoa(delegation=creator_code_address)

    deployed_code = Op.STOP
    # pad right to ensure code size is multiple of 32 bytes to MSTORE
    inner_initcode = Initcode(deploy_code=deployed_code)
    inner_initcode_bytes = inner_initcode + b"\x00" * (
        32 - (len(inner_initcode) % 32)
    )

    test_bytes = b"\xde" * 32

    initcode = (
        Op.SSTORE(initcode_storage.store_next(1, hint="outer code worked"), 1)
        + Op.MSTORE(0, Op.PUSH32(bytes(inner_initcode_bytes)))
        + Op.SSTORE(
            initcode_storage.store_next(1, hint="outer call result"),
            Op.CALL(address=auth_signer, args_size=len(inner_initcode_bytes)),
        )
        + Op.MSTORE(32, Op.PUSH32(test_bytes))
        + Op.RETURN(32, len(test_bytes))
    )

    tx = Transaction(
        to=None,
        value=0,
        data=initcode,
        sender=auth_signer,
    )

    deployed_contract_address = tx.created_contract

    inner_create_code_address = compute_create_address(
        address=auth_signer,
        nonce=2,
        initcode=inner_initcode_bytes,
        opcode=create_opcode,
    )
    creator_storage[inner_create_result_slot] = inner_create_code_address

    state_test(
        pre=pre,
        tx=tx,
        post={
            creator_code_address: Account(storage={}),
            auth_signer: Account(
                nonce=3,
                code=Spec.delegation_designation(creator_code_address),
                storage=creator_storage,
            ),
            deployed_contract_address: Account(
                code=test_bytes, storage=initcode_storage
            ),
            inner_create_code_address: Account(code=deployed_code),
        },
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 4 forks.