From 57b6ffe0edbe08d428759ea9a6f8bcee14f7921a Mon Sep 17 00:00:00 2001 From: Olivier Desenfans Date: Fri, 22 Sep 2023 18:02:02 +0200 Subject: [PATCH] Fix: use UUID types for request/execution IDs Problem: older versions of aleph-sdk-python do not support serializing UUID objects. Solution: use the latest version of aleph-sdk-python. --- setup.cfg | 2 +- src/aleph_vrf/coordinator/vrf.py | 2 +- src/aleph_vrf/models.py | 2 +- src/aleph_vrf/types.py | 5 ++--- tests/executor/test_integration.py | 3 ++- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/setup.cfg b/setup.cfg index 5498224..d993155 100644 --- a/setup.cfg +++ b/setup.cfg @@ -49,7 +49,7 @@ package_dir = # For more information, check out https://semver.org/. install_requires = aiohttp - aleph-sdk-python==0.7.0 + aleph-sdk-python@git+https://github.com/aleph-im/aleph-sdk-python@28a10519a5dce4d1f25fb5d9d08c077eb60690e5 fastapi importlib-metadata; python_version<"3.8" utilitybelt diff --git a/src/aleph_vrf/coordinator/vrf.py b/src/aleph_vrf/coordinator/vrf.py index 016a295..e8d58bc 100644 --- a/src/aleph_vrf/coordinator/vrf.py +++ b/src/aleph_vrf/coordinator/vrf.py @@ -133,7 +133,7 @@ async def generate_vrf(account: ETHAccount) -> VRFResponse: nb_executors=nb_executors, nonce=nonce, vrf_function=ItemHash(settings.FUNCTION), - request_id=RequestId(str(uuid4())), + request_id=RequestId(uuid4()), node_list_hash=sha3_256(selected_node_list).hexdigest(), ) diff --git a/src/aleph_vrf/models.py b/src/aleph_vrf/models.py index ce877bc..f112a75 100644 --- a/src/aleph_vrf/models.py +++ b/src/aleph_vrf/models.py @@ -29,7 +29,7 @@ class VRFGenerationRequest(BaseModel): nb_bytes: int nonce: Nonce request_id: RequestId - execution_id: ExecutionId = Field(default_factory=lambda: str(uuid4())) + execution_id: ExecutionId = Field(default_factory=uuid4) vrf_function: ItemHash diff --git a/src/aleph_vrf/types.py b/src/aleph_vrf/types.py index 6ad0dc8..f2bfeb4 100644 --- a/src/aleph_vrf/types.py +++ b/src/aleph_vrf/types.py @@ -4,6 +4,5 @@ from pydantic import UUID4 Nonce = NewType("Nonce", int) -# TODO: use UUID once https://github.com/aleph-im/aleph-sdk-python/pull/61 is merged -RequestId = NewType("RequestId", str) -ExecutionId = NewType("ExecutionId", str) +RequestId = NewType("RequestId", UUID4) +ExecutionId = NewType("ExecutionId", UUID4) diff --git a/tests/executor/test_integration.py b/tests/executor/test_integration.py index 53ad5bb..b8a783b 100644 --- a/tests/executor/test_integration.py +++ b/tests/executor/test_integration.py @@ -1,6 +1,7 @@ import datetime as dt from hashlib import sha256 from typing import Dict, Any, Union, Tuple +from uuid import UUID import aiohttp import pytest @@ -70,7 +71,7 @@ def make_post_message( @pytest.fixture def mock_vrf_request() -> VRFRequest: - request_id = RequestId("513eb52c-cb74-463a-b40e-0e2adedafb8b") + request_id = RequestId(UUID("513eb52c-cb74-463a-b40e-0e2adedafb8b")) vrf_request = VRFRequest( nb_bytes=32,