Skip to content

test_create_opcode_balance_only_target()

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

Generate fixtures for these test cases for Amsterdam with:

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

Test that a contract creation opcode succeeds when the target address has only a balance: an account with zero nonce, no code and no storage is not a collision (EIP-684).

Source code in tests/frontier/create/test_create_collision.py
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
@pytest.mark.with_all_create_opcodes
def test_create_opcode_balance_only_target(
    state_test: StateTestFiller,
    pre: Alloc,
    create_opcode: Op,
) -> None:
    """
    Test that a contract creation opcode succeeds when the target
    address has only a balance: an account with zero nonce, no code and
    no storage is not a collision (EIP-684).
    """
    initcode = CORRECT_INITCODE
    assert len(initcode) <= 32
    contract_creator_code = (
        # Stores the created address, which is non-zero on success.
        Op.MSTORE(0, Op.PUSH32(bytes(initcode).ljust(32, b"\0")))
        + Op.SSTORE(0x01, create_opcode(value=0, offset=0, size=len(initcode)))
        + Op.STOP
    )
    contract_creator_address = pre.deploy_contract(contract_creator_code)

    created_contract_address = compute_create_address(
        address=contract_creator_address,
        nonce=1,
        salt=0,
        initcode=initcode,
        opcode=create_opcode,
    )

    tx = Transaction(
        sender=pre.fund_eoa(),
        to=contract_creator_address,
        protected=False,
    )

    pre[created_contract_address] = Account(balance=1)

    state_test(
        pre=pre,
        post={
            created_contract_address: Account(
                balance=1,
                code=CORRECT_INITCODE.deploy_code,
                storage={0x00: 0x01},
            ),
            contract_creator_address: Account(
                storage={0x01: created_contract_address}
            ),
        },
        tx=tx,
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 16 forks.