Skip to content

test_contract_creation_tx()

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

Generate fixtures for these test cases for Amsterdam with:

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

Test that contract creation transactions emit logs based on value.

Source code in tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
@pytest.mark.parametrize(
    "tx_value,expect_log",
    [
        pytest.param(1000, True, id="with_value"),
        pytest.param(0, False, id="zero_value"),
    ],
)
def test_contract_creation_tx(
    state_test: StateTestFiller,
    env: Environment,
    pre: Alloc,
    sender: EOA,
    fork: Fork,
    tx_value: int,
    expect_log: bool,
) -> None:
    """Test that contract creation transactions emit logs based on value."""
    initcode = Op.RETURN(0, 0)
    created_address = compute_create_address(address=sender, nonce=0)

    expected_logs = (
        [transfer_log(sender, created_address, tx_value)] if expect_log else []
    )
    tx = Transaction(
        sender=sender,
        to=None,
        value=tx_value,
        data=bytes(initcode),
        expected_receipt=TransactionReceipt(logs=expected_logs),
    )

    post = {created_address: Account(balance=tx_value)} if tx_value > 0 else {}
    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.