Skip to content

test_create_tx_collision()

Documentation for tests/frontier/create/test_create_collision.py::test_create_tx_collision@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/frontier/create/test_create_collision.py::test_create_tx_collision --fork Bogota

Test that a contract creation transaction exceptionally aborts when the target address has non-empty code or nonce, leaving the existing account untouched.

Source code in tests/frontier/create/test_create_collision.py
@PORTED_FROM
@pytest.mark.parametrize_by_fork(
    "collision_nonce,collision_code,collision_storage,collision_balance,initcode",
    collision_params,
)
@pytest.mark.with_all_contract_creating_tx_types
@pytest.mark.eels_base_coverage
def test_create_tx_collision(
    state_test: StateTestFiller,
    pre: Alloc,
    tx_type: int,
    collision_nonce: int,
    collision_code: bytes,
    collision_storage: Dict[int, int],
    collision_balance: int,
    initcode: Bytecode,
    fork: Fork,
) -> None:
    """
    Test that a contract creation transaction exceptionally aborts when
    the target address has non-empty code or nonce, leaving the existing
    account untouched.
    """
    tx = Transaction(
        sender=pre.fund_eoa(),
        ty=tx_type,
        to=None,
        data=initcode,
        protected=False,
    )

    created_contract_address = tx.created_contract

    # This is the collision
    pre[created_contract_address] = Account(
        nonce=collision_nonce,
        code=collision_code,
        storage=collision_storage,
        balance=collision_balance,
    )

    expected_block_access_list = None
    if fork.is_eip_enabled(7928):
        expected_block_access_list = BlockAccessListExpectation(
            account_expectations={
                created_contract_address: BalAccountExpectation.empty()
            }
        )

    state_test(
        pre=pre,
        post={
            created_contract_address: Account(
                nonce=collision_nonce,
                code=collision_code,
                storage=collision_storage,
                balance=collision_balance,
            ),
        },
        tx=tx,
        expected_block_access_list=expected_block_access_list,
    )

Parametrized Test Cases

This test generates 36 parametrized test cases across 17 forks.