Skip to content

test_create_opcode_emits_log()

Documentation for tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py::test_create_opcode_emits_log@a9abd46e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py::test_create_opcode_emits_log --fork Amsterdam

Test that CREATE/CREATE2 opcodes emit logs based on value.

Source code in tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
@pytest.mark.parametrize(
    "create_value",
    [
        pytest.param(1, id="with_value"),
        pytest.param(0, id="zero_value"),
    ],
)
@pytest.mark.with_all_create_opcodes
def test_create_opcode_emits_log(
    state_test: StateTestFiller,
    env: Environment,
    pre: Alloc,
    sender: EOA,
    fork: Fork,
    create_opcode: Op,
    create_value: int,
) -> None:
    """Test that CREATE/CREATE2 opcodes emit logs based on value."""
    initcode = Op.RETURN(0, 0)
    initcode_len = len(initcode)

    contract_code = Op.MSTORE(
        0, Op.PUSH32(bytes(initcode).rjust(32, b"\x00"))
    ) + Op.SSTORE(
        0,
        create_opcode(
            value=create_value, offset=32 - initcode_len, size=initcode_len
        ),
    )
    contract = pre.deploy_contract(contract_code, balance=create_value)
    created_address = compute_create_address(
        address=contract,
        nonce=1,
        salt=0,
        initcode=bytes(initcode),
        opcode=create_opcode,
    )

    expected_logs = [transfer_log(sender, contract, 1)]
    if create_value > 0:
        expected_logs.append(
            transfer_log(contract, created_address, create_value)
        )

    tx = Transaction(
        sender=sender,
        to=contract,
        value=1,
        expected_receipt=TransactionReceipt(logs=expected_logs),
    )

    post = {created_address: Account(balance=create_value)}
    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.