Skip to content

test_contract_creation_tx_collision()

Documentation for tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py::test_contract_creation_tx_collision@c74f1a67.

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_collision --fork Amsterdam

Test that a contract-creating transaction with an address collision emits no log.

Per EIP-7610, contract creation aborts when the target address already has non-empty code or nonce. The collision check happens before any value transfer, so EIP-7708 emits no Transfer log.

Source code in tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
@pytest.mark.parametrize(
    "collision_nonce,collision_code",
    [
        pytest.param(0, b"\x00", id="non_empty_code"),
        pytest.param(1, b"", id="non_empty_nonce"),
    ],
)
@pytest.mark.pre_alloc_mutable
def test_contract_creation_tx_collision(
    state_test: StateTestFiller,
    env: Environment,
    pre: Alloc,
    collision_nonce: int,
    collision_code: bytes,
) -> None:
    """
    Test that a contract-creating transaction with an address collision
    emits no log.

    Per EIP-7610, contract creation aborts when the target address already
    has non-empty code or nonce. The collision check happens before any
    value transfer, so EIP-7708 emits no Transfer log.
    """
    sender = pre.fund_eoa()
    tx = Transaction(
        sender=sender,
        to=None,
        value=1000,
        data=bytes(Op.RETURN(0, 0)),
        expected_receipt=TransactionReceipt(logs=[]),
    )

    collision_address = tx.created_contract
    pre[collision_address] = Account(
        nonce=collision_nonce,
        code=collision_code,
    )

    post = {
        collision_address: Account(
            nonce=collision_nonce,
            code=collision_code,
        ),
    }
    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.