Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow use major versions of Aleph SDK #27

Merged
merged 7 commits into from
Jan 31, 2024
8 changes: 4 additions & 4 deletions deployment/deploy_vrf_vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from tempfile import TemporaryDirectory
from typing import Optional, Tuple, Dict

from aleph.sdk import AuthenticatedAlephClient
from aleph.sdk.client import AuthenticatedAlephHttpClient
from aleph.sdk.chains.common import get_fallback_private_key
from aleph.sdk.chains.ethereum import ETHAccount
from aleph_message.models import ItemHash, ProgramMessage
Expand All @@ -30,7 +30,7 @@ def mksquashfs(path: Path, destination: Path) -> None:


async def upload_dir_as_volume(
aleph_client: AuthenticatedAlephClient,
aleph_client: AuthenticatedAlephHttpClient,
dir_path: Path,
channel: str,
volume_path: Optional[Path] = None,
Expand All @@ -52,7 +52,7 @@ async def upload_dir_as_volume(


async def deploy_python_program(
aleph_client: AuthenticatedAlephClient,
aleph_client: AuthenticatedAlephHttpClient,
code_volume_hash: ItemHash,
entrypoint: str,
venv_hash: ItemHash,
Expand Down Expand Up @@ -101,7 +101,7 @@ async def deploy_vrf(
account = ETHAccount(private_key)
channel = "vrf-tests"

async with AuthenticatedAlephClient(
async with AuthenticatedAlephHttpClient(
account=account, api_server=settings.API_HOST
) as aleph_client:
# Upload the code and venv volumes
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ package_dir =
# For more information, check out https://semver.org/.
install_requires =
aiohttp
aleph-sdk-python==0.7.0
aleph-sdk-python~=0.8.0
hexbytes
fastapi>=0.95.1
importlib-metadata; python_version<"3.8"
Expand Down
8 changes: 4 additions & 4 deletions src/aleph_vrf/coordinator/vrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import aiohttp
from aleph.sdk.chains.ethereum import ETHAccount
from aleph.sdk.client import AuthenticatedAlephClient
from aleph.sdk.client import AuthenticatedAlephHttpClient
from aleph_message.models import ItemHash
from aleph_message.status import MessageStatus
from hexbytes import HexBytes
Expand Down Expand Up @@ -67,7 +67,7 @@ async def post_executor_api_request(url: str, model: Type[M]) -> M:


async def _generate_vrf(
aleph_client: AuthenticatedAlephClient,
aleph_client: AuthenticatedAlephHttpClient,
nb_executors: int,
nb_bytes: int,
vrf_function: ItemHash,
Expand Down Expand Up @@ -144,7 +144,7 @@ async def generate_vrf(
):
vrf_function = vrf_function or settings.FUNCTION

async with AuthenticatedAlephClient(
async with AuthenticatedAlephHttpClient(
account=account,
api_server=aleph_api_server or settings.API_HOST,
# Avoid going through the VM connector on aleph.im CRNs
Expand Down Expand Up @@ -270,7 +270,7 @@ def generate_final_vrf(


async def publish_data(
aleph_client: AuthenticatedAlephClient,
aleph_client: AuthenticatedAlephHttpClient,
data: Union[VRFRequest, VRFResponse],
ref: str,
) -> ItemHash:
Expand Down
14 changes: 7 additions & 7 deletions src/aleph_vrf/executor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
logger = logging.getLogger(__name__)

logger.debug("import aleph_client")
from aleph.sdk.client import AlephClient, AuthenticatedAlephClient
from aleph.sdk.client import AlephHttpClient, AuthenticatedAlephHttpClient
from aleph.sdk.vm.app import AlephApp
from aleph_message.models import ItemHash, PostMessage
from aleph_message.status import MessageStatus
Expand Down Expand Up @@ -52,9 +52,9 @@
app = AlephApp(http_app=http_app)


async def authenticated_aleph_client() -> AuthenticatedAlephClient:
async def authenticated_aleph_client() -> AuthenticatedAlephHttpClient:
account = settings.aleph_account()
async with AuthenticatedAlephClient(
async with AuthenticatedAlephHttpClient(
account=account,
api_server=settings.API_HOST,
# Avoid going through the VM connector on aleph.im CRNs
Expand All @@ -71,7 +71,7 @@ async def index():
}


async def _get_message(client: AlephClient, item_hash: ItemHash) -> PostMessage:
async def _get_message(client: AlephHttpClient, item_hash: ItemHash) -> PostMessage:
try:
return await client.get_message(item_hash=item_hash, message_type=PostMessage)
except MessageNotFoundError:
Expand All @@ -93,7 +93,7 @@ async def _get_message(client: AlephClient, item_hash: ItemHash) -> PostMessage:
async def receive_generate(
vrf_request_hash: ItemHash,
aleph_client: Annotated[
AuthenticatedAlephClient, Depends(authenticated_aleph_client)
AuthenticatedAlephHttpClient, Depends(authenticated_aleph_client)
],
) -> APIResponse[PublishedVRFRandomNumberHash]:
"""
Expand Down Expand Up @@ -150,7 +150,7 @@ async def receive_generate(
async def receive_publish(
message_hash: ItemHash,
aleph_client: Annotated[
AuthenticatedAlephClient, Depends(authenticated_aleph_client)
AuthenticatedAlephHttpClient, Depends(authenticated_aleph_client)
],
) -> APIResponse[PublishedVRFRandomNumber]:
"""
Expand Down Expand Up @@ -195,7 +195,7 @@ async def receive_publish(


async def publish_data(
aleph_client: AuthenticatedAlephClient,
aleph_client: AuthenticatedAlephHttpClient,
data: Union[VRFRandomNumberHash, VRFRandomNumber],
ref: str,
) -> ItemHash:
Expand Down
4 changes: 2 additions & 2 deletions tests/coordinator/test_integration_lib.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Tuple, Dict, List

import pytest
from aleph.sdk import AlephClient
from aleph.sdk.client import AlephHttpClient
from aleph.sdk.chains.common import generate_key
from aleph.sdk.chains.ethereum import ETHAccount
from aleph_message.models import PostMessage, ItemHash
Expand Down Expand Up @@ -76,7 +76,7 @@ async def assert_aleph_message_matches_vrf_response(
) -> PostMessage:
assert vrf_response.message_hash

async with AlephClient(api_server=ccn_url) as client:
async with AlephHttpClient(api_server=ccn_url) as client:
message = await client.get_message(
vrf_response.message_hash, message_type=PostMessage
)
Expand Down
6 changes: 3 additions & 3 deletions tests/executor/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import aiohttp
import pytest
import pytest_asyncio
from aleph.sdk import AlephClient
from aleph.sdk.client import AlephHttpClient
from aleph_message.models import (
ItemType,
MessageType,
Expand Down Expand Up @@ -156,7 +156,7 @@ async def assert_aleph_message_matches_random_number_hash(
) -> PostMessage:
assert random_number_hash.message_hash

async with AlephClient(api_server=ccn_url) as client:
async with AlephHttpClient(api_server=ccn_url) as client:
message = await client.get_message(
random_number_hash.message_hash, message_type=PostMessage
)
Expand All @@ -182,7 +182,7 @@ async def assert_aleph_message_matches_random_number(
ccn_url: Any, # aiohttp does not expose its URL type
random_number: PublishedVRFRandomNumber,
) -> PostMessage:
async with AlephClient(api_server=ccn_url) as client:
async with AlephHttpClient(api_server=ccn_url) as client:
message = await client.get_message(
random_number.message_hash, message_type=PostMessage
)
Expand Down
6 changes: 3 additions & 3 deletions tests/malicious_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

logger = logging.getLogger(__name__)

from aleph.sdk.client import AuthenticatedAlephClient
from aleph.sdk.client import AuthenticatedAlephHttpClient
from aleph.sdk.vm.app import AlephApp
from aleph_message.models import ItemHash

Expand All @@ -36,7 +36,7 @@
async def receive_generate(
vrf_request_hash: ItemHash,
aleph_client: Annotated[
AuthenticatedAlephClient, Depends(authenticated_aleph_client)
AuthenticatedAlephHttpClient, Depends(authenticated_aleph_client)
],
) -> APIResponse[PublishedVRFRandomNumberHash]:
from aleph_vrf.executor.main import receive_generate as real_receive_generate
Expand All @@ -50,7 +50,7 @@ async def receive_generate(
async def receive_publish(
message_hash: ItemHash,
aleph_client: Annotated[
AuthenticatedAlephClient, Depends(authenticated_aleph_client)
AuthenticatedAlephHttpClient, Depends(authenticated_aleph_client)
],
) -> APIResponse[PublishedVRFRandomNumber]:
from aleph_vrf.executor.main import receive_publish as real_receive_publish
Expand Down
25 changes: 24 additions & 1 deletion tests/mock_ccn.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from aleph_message.models import ItemHash
from aleph_message.status import MessageStatus
from fastapi import FastAPI
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel, Field

logger = logging.getLogger(__name__)
Expand All @@ -22,6 +22,9 @@

@app.get("/api/v0/messages.json")
async def get_messages(hashes: Optional[str], page: int = 1, pagination: int = 20):
"""
Mock messages.json endpoint
"""
hashes = [ItemHash(h) for h in hashes.split(",")] if hashes is not None else []
messages = [MESSAGES[item_hash] for item_hash in hashes if item_hash in MESSAGES]
paginated_messages = messages[(page - 1) * pagination : page * pagination]
Expand All @@ -35,6 +38,26 @@ async def get_messages(hashes: Optional[str], page: int = 1, pagination: int = 2
}


class MessageResponse(BaseModel):
message: Dict[str, Any]
status: str


@app.get("/api/v0/messages/{item_hash}")
async def get_message(item_hash: str):
"""
Mock individual view message endpoint
"""
message = MESSAGES.get(ItemHash(item_hash))
if not message:
raise HTTPException(status_code=404, detail="Message not found")

return MessageResponse(
message=message,
status="processed"
)


class PubMessageRequest(BaseModel):
sync: bool = False
message_dict: Dict[str, Any] = Field(alias="message")
Expand Down