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@b47f0253.

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
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
@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)
        )

    gas_limit = 200_000
    if fork.is_eip_enabled(8037):
        gas_limit = 1_000_000

    tx = Transaction(
        sender=sender,
        to=contract,
        value=1,
        gas_limit=gas_limit,
        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.