Skip to content

test_initcode_calls_with_value()

Documentation for tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py::test_initcode_calls_with_value@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py::test_initcode_calls_with_value --fork Bogota

Test that CALL with value during initcode emits correct log.

Initcode performs CALL with value before returning deployed code. Log should show the being-created contract as sender.

Source code in tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py
@pytest.mark.with_all_create_opcodes
def test_initcode_calls_with_value(
    state_test: StateTestFiller,
    env: Environment,
    pre: Alloc,
    sender: EOA,
    create_opcode: Op,
) -> None:
    """
    Test that CALL with value during initcode emits correct log.

    Initcode performs CALL with value before returning deployed code.
    Log should show the being-created contract as sender.
    """
    recipient = pre.deploy_contract(Op.STOP)

    # Initcode: CALL recipient with value, then RETURN empty code
    initcode = Op.CALL(address=recipient, value=1) + Op.RETURN(0, 0)
    initcode_bytes = bytes(initcode)

    # Store initcode in memory using code copy approach
    factory_code = (
        Op.CODECOPY(
            0,
            Op.SUB(Op.CODESIZE, len(initcode_bytes)),
            len(initcode_bytes),
        )
        + create_op(create_opcode, value=1, size=len(initcode_bytes))
        + Op.STOP
    ) + initcode

    factory = pre.deploy_contract(factory_code, balance=2)

    created_address = compute_create_address(
        address=factory,
        nonce=1,
        salt=0,
        initcode=initcode_bytes,
        opcode=create_opcode,
    )

    tx = Transaction(
        sender=sender,
        to=factory,
        value=0,
        expected_receipt=TransactionReceipt(
            logs=[
                # CREATE transfers value to new contract
                transfer_log(factory, created_address, 1),
                # Initcode CALLs recipient with value
                transfer_log(created_address, recipient, 1),
            ]
        ),
    )

    post = {recipient: Account(balance=1)}
    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 2 parametrized test cases across 2 forks.