-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8027f98
commit 9d1536d
Showing
3 changed files
with
103 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,34 @@ | ||
import hashlib | ||
import json | ||
from pathlib import Path | ||
from tempfile import NamedTemporaryFile | ||
|
||
import pytest | ||
from aleph_message.status import MessageStatus | ||
|
||
from aleph.sdk import AlephClient | ||
from aleph.sdk import AuthenticatedAlephClient | ||
from aleph.sdk.chains.common import get_fallback_private_key | ||
from aleph.sdk.chains.ethereum import ETHAccount | ||
from examples.store import do_upload_with_message | ||
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) | ||
|
||
content = "Test Py Aleph upload\n" | ||
content_bytes = content.encode("utf-8") | ||
|
||
with NamedTemporaryFile(mode="w", delete=False) as temp_file: | ||
temp_file.write(content) | ||
|
||
file_name = Path(temp_file.name) | ||
actual_item_hash = hashlib.sha256( | ||
content.encode() | ||
).hexdigest() # Calculate the hash of the content | ||
|
||
test = await do_upload_with_message( | ||
account=account, | ||
engine="STORAGE", | ||
channel="Test", | ||
filename=file_name, | ||
item_hash=actual_item_hash, | ||
) | ||
async with AlephClient(api_server="http://0.0.0.0:4024") as client: | ||
file_content = await client.download_file(test["hash"]) | ||
assert file_content == content_bytes | ||
content = b"Test pyaleph upload\n" | ||
file_hash = hashlib.sha256(content).hexdigest() | ||
|
||
async with AuthenticatedAlephClient( | ||
account=account, api_server="http://0.0.0.0:8000" | ||
) as client: | ||
message, status = await client.create_store( | ||
address=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 client.download_file(file_hash=file_hash) | ||
assert server_content == content |