Skip to content

test_create_opcode_balance_only_target()

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

Generate fixtures for these test cases for Bogota with:

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

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
@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 17 forks.