Skip to content

test_create_tx_collision()

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

Generate fixtures for these test cases for Amsterdam with:

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

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
119
120
121
122
123
124
125
126
127
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
@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 16 forks.