Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
build:
strategy:
matrix:
os: [ macos-11, macos-12, ubuntu-20.04, ubuntu-22.04 ]
runs-on: ${{matrix.os}}
os: [macos-11, macos-12, ubuntu-20.04, ubuntu-22.04]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
Expand All @@ -22,6 +22,12 @@ jobs:
if: startsWith(matrix.os, 'ubuntu-')
run: sudo echo RESET grub-efi/install_devices | sudo debconf-communicate grub-pc

- name: Set up Python
if: startsWith(matrix.os, 'macos')
uses: actions/setup-python@v2
with:
python-version: 3.11

- name: Cache dependencies
uses: actions/cache@v3
with:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ $ apt-get install -y python3-pip libsecp256k1-dev
```
Using some chains may also require installing `libgmp3-dev`.

### macOs
### macOs
This project does not support Python 3.12 on macOS. Please use Python 3.11 instead.
```shell
$ brew tap cuber/homebrew-libsecp256k1
$ brew install libsecp256k1
Expand Down
71 changes: 46 additions & 25 deletions tests/unit/test_upload.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,60 @@
import hashlib
from unittest.mock import AsyncMock, patch

import pytest
from aleph_message.models import AlephMessage, StoreMessage
from aleph_message.models import StoreMessage
from aleph_message.status import MessageStatus

from aleph.sdk import AuthenticatedAlephHttpClient
from aleph.sdk.chains.common import get_fallback_private_key
from aleph.sdk.chains.ethereum import ETHAccount
from aleph.sdk.types import StorageEnum


@pytest.mark.asyncio
async def test_upload_with_message():
pkey = get_fallback_private_key()
account = ETHAccount(private_key=pkey)
@pytest.fixture
def mock_authenticated_aleph_http_client():
with patch(
"aleph.sdk.AuthenticatedAlephHttpClient", autospec=True
) as MockHttpClient:
pkey = get_fallback_private_key()
account = ETHAccount(private_key=pkey)

http_session = AsyncMock()
mock_client = MockHttpClient.return_value
mock_client.http_session = http_session
mock_client.account = account
return mock_client


@pytest.mark.asyncio
async def test_upload_with_message(mock_authenticated_aleph_http_client):
content = b"Test pyaleph upload\n"
file_hash = hashlib.sha256(content).hexdigest()

async with AuthenticatedAlephHttpClient(account=account, api_server=None) as client:
message, status = await client.create_store(
address=account.get_address(),
file_content=content,
storage_engine=StorageEnum.storage,
sync=True,
)
print(message, status)

assert status == MessageStatus.PROCESSED
assert message.content.item_hash == file_hash

server_content = await client.download_file(file_hash=file_hash)
assert server_content == content

server_message: AlephMessage = await client.get_message(
item_hash=message.item_hash, message_type=StoreMessage
)
assert server_message.content.item_hash == file_hash
message = AsyncMock()
message.content.item_hash = file_hash
status = MessageStatus.PROCESSED
mock_authenticated_aleph_http_client.create_store.return_value = (message, status)

mock_authenticated_aleph_http_client.download_file.return_value = content

mock_authenticated_aleph_http_client.get_message.return_value = message

message, status = await mock_authenticated_aleph_http_client.create_store(
address=mock_authenticated_aleph_http_client.account.get_address(),
file_content=content,
storage_engine=StorageEnum.storage,
sync=True,
)

assert status == MessageStatus.PROCESSED
assert message.content.item_hash == file_hash

server_content = await mock_authenticated_aleph_http_client.download_file(
file_hash=file_hash
)
assert server_content == content

server_message = await mock_authenticated_aleph_http_client.get_message(
item_hash=message.item_hash, message_type=StoreMessage
)
assert server_message.content.item_hash == file_hash