Skip to content

test_contract_creation_transaction()

Documentation for tests/osaka/eip7951_p256verify_precompiles/test_p256verify.py::test_contract_creation_transaction@88e9fb8f.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7951_p256verify_precompiles/test_p256verify.py::test_contract_creation_transaction --fork Osaka

Test the contract creation for the P256VERIFY precompile.

Source code in tests/osaka/eip7951_p256verify_precompiles/test_p256verify.py
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
@pytest.mark.parametrize(
    "input_data,expected_output",
    [
        pytest.param(
            Spec.H0 + Spec.R0 + Spec.S0 + Spec.X0 + Spec.Y0,
            Spec.SUCCESS_RETURN_VALUE,
            id="valid_input",
        ),
        pytest.param(
            b"\x00" * 160,
            Spec.INVALID_RETURN_VALUE,
            id="invalid_input",
        ),
    ],
)
@pytest.mark.parametrize("precompile_address", [Spec.P256VERIFY], ids=[""])
@EIPChecklist.Precompile.Test.CallContexts.Initcode.Tx()
def test_contract_creation_transaction(
    state_test: StateTestFiller,
    pre: Alloc,
    tx: Transaction,
    input_data: bytes,
    expected_output: bytes,
) -> None:
    """Test the contract creation for the P256VERIFY precompile."""
    sender = pre.fund_eoa()

    storage = Storage()
    contract_address = compute_create_address(address=sender, nonce=0)
    contract_bytecode = (
        Op.CODECOPY(0, Op.SUB(Op.CODESIZE, len(input_data)), len(input_data))
        + Op.CALL(
            gas=Spec.P256VERIFY_GAS,
            address=Spec.P256VERIFY,
            value=0,
            args_offset=0,
            args_size=len(input_data),
            ret_offset=0,
            ret_size=32,
        )
        + Op.SSTORE(storage.store_next(True), Op.DUP1())
        + Op.SSTORE(storage.store_next(expected_output), Op.MLOAD(0))
        + Op.SSTORE(storage.store_next(len(expected_output)), Op.RETURNDATASIZE())
        + Op.STOP
    )

    tx = Transaction(
        sender=sender,
        gas_limit=1000000,
        to=None,
        value=0,
        data=contract_bytecode + input_data,
    )

    post = {
        contract_address: {
            "storage": storage,
        }
    }
    state_test(env=Environment(), pre=pre, post=post, tx=tx)

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) precompile_address input_data expected_output
...fork_Osaka-state_test--valid_input 256 bb5a52f42f9c9261ed4361f59422a1e3 0036e7c32b270c8807a419feca605023 2ba3a8be6b94d5ec80a6d9d1190a436e ffe50d85a1eee859b8cc6af9bd5c2e18 4cd60b855d442f5b3c7b11eb6c4e0ae7 525fe710fab9aa7c77a67f79e6fadd76 2927b10512bae3eddcfe467828128bad 2903269919f7086069c8c4df6c732838 c7787964eaac00e5921fb1498a60f460 6766b3d9685001558d1a974e7341513e 00000000000000000000000000000000 00000000000000000000000000000001
...fork_Osaka-state_test--invalid_input 256 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000
...fork_Osaka-blockchain_test_from_state_test--valid_input 256 bb5a52f42f9c9261ed4361f59422a1e3 0036e7c32b270c8807a419feca605023 2ba3a8be6b94d5ec80a6d9d1190a436e ffe50d85a1eee859b8cc6af9bd5c2e18 4cd60b855d442f5b3c7b11eb6c4e0ae7 525fe710fab9aa7c77a67f79e6fadd76 2927b10512bae3eddcfe467828128bad 2903269919f7086069c8c4df6c732838 c7787964eaac00e5921fb1498a60f460 6766b3d9685001558d1a974e7341513e 00000000000000000000000000000000 00000000000000000000000000000001
...fork_Osaka-blockchain_test_from_state_test--invalid_input 256 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000