Skip to content

test_call_identity_precompile()

Documentation for tests/frontier/identity_precompile/test_identity.py::test_call_identity_precompile@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/frontier/identity_precompile/test_identity.py::test_call_identity_precompile --fork Bogota

Test identity precompile RETURNDATA is sized correctly based on the input size.

Source code in tests/frontier/identity_precompile/test_identity.py
@pytest.mark.ported_from(
    [
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CALLCODEIdentitiy_0Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CALLCODEIdentitiy_1Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CALLCODEIdentity_1_nonzeroValueFiller.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CALLCODEIdentity_2Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CALLCODEIdentity_3Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CALLCODEIdentity_4Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CALLCODEIdentity_4_gas17Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CALLCODEIdentity_4_gas18Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CallIdentitiy_0Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CallIdentitiy_1Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CallIdentity_1_nonzeroValueFiller.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CallIdentity_2Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CallIdentity_3Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CallIdentity_4Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CallIdentity_4_gas17Filler.json",
        "https://github.com/ethereum/tests/blob/v17.1/src/GeneralStateTestsFiller/stPreCompiledContracts2/CallIdentity_4_gas18Filler.json",
    ],
    pr=["https://github.com/ethereum/execution-spec-tests/pull/1344"],
    coverage_missed_reason="MPT related coverage lost, not relevant to test",
)
@pytest.mark.valid_from("Byzantium")
@pytest.mark.parametrize("call_type", [Op.CALL, Op.CALLCODE])
@pytest.mark.parametrize(
    [
        "call_args",
        "memory_values",
        "contract_balance",
        "call_succeeds",
    ],
    [
        pytest.param(CallArgs(gas=0xFF), (0x1,), 0x0, True, id="identity_0"),
        pytest.param(
            CallArgs(args_size=0x0),
            (0x0,),
            0x0,
            True,
            id="identity_1",
        ),
        pytest.param(
            CallArgs(gas=0x30D40, value=0x1, args_size=0x0),
            (0x1,),
            0x1,
            True,
            id="identity_1_nonzerovalue",
        ),
        pytest.param(
            CallArgs(gas=0x30D40, value=0x1, args_size=0x0),
            None,
            0x0,
            False,
            id="identity_1_nonzerovalue_insufficient_balance",
        ),
        pytest.param(
            CallArgs(args_size=0x25),
            (0xF34578907F,),
            0x0,
            True,
            id="identity_2",
        ),
        pytest.param(
            CallArgs(args_size=0x25),
            (0xF34578907F,),
            0x0,
            True,
            id="identity_3",
        ),
        pytest.param(
            CallArgs(gas=0x64),
            (
                0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
            ),
            0x0,
            True,
            id="identity_4",
        ),
        pytest.param(
            CallArgs(gas=0x11),
            (
                0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
            ),
            0x0,
            False,
            id="identity_4_insufficient_gas",
        ),
        pytest.param(
            CallArgs(gas=0x12),
            (
                0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
            ),
            0x0,
            True,
            id="identity_4_exact_gas",
        ),
    ],
)
@pytest.mark.eels_base_coverage
def test_call_identity_precompile(
    state_test: StateTestFiller,
    pre: Alloc,
    call_type: Op,
    call_args: CallArgs,
    memory_values: Tuple[int, ...],
    call_succeeds: bool,
    contract_balance: int,
) -> None:
    """
    Test identity precompile RETURNDATA is sized correctly based on the input
    size.
    """
    storage = Storage()

    contract_bytecode = generate_identity_call_bytecode(
        storage,
        call_type,
        memory_values,
        call_args,
        call_succeeds,
    )

    account = pre.deploy_contract(
        contract_bytecode,
        storage=storage.canary(),
        balance=contract_balance,
    )

    tx = Transaction(to=account, sender=pre.fund_eoa())

    post = {account: Account(storage=storage)}

    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 16 parametrized test cases across 13 forks.