|
| 1 | +import pytest |
| 2 | + |
| 3 | +from aleph.sdk.client import AuthenticatedAlephHttpClient |
| 4 | +from aleph.sdk.query.filters import MessageFilter |
| 5 | +from tests.integration.toolkit import has_messages, try_until |
| 6 | + |
| 7 | +from .config import REFERENCE_NODE, TARGET_NODE |
| 8 | + |
| 9 | + |
| 10 | +async def create_store_on_target(account, emitter_node: str, receiver_node: str): |
| 11 | + """ |
| 12 | + Create a POST message on the target node, then fetch it from the reference node and download the file. |
| 13 | + """ |
| 14 | + with open("tests/integration/fixtures/testStore.txt", "rb") as f: |
| 15 | + file_content = f.read() |
| 16 | + async with AuthenticatedAlephHttpClient( |
| 17 | + account=account, api_server=emitter_node |
| 18 | + ) as tx_session: |
| 19 | + store_message, message_status = await tx_session.create_store( |
| 20 | + file_content=file_content, |
| 21 | + extra_fields={"test": "test"}, |
| 22 | + ) |
| 23 | + |
| 24 | + async with AuthenticatedAlephHttpClient( |
| 25 | + account=account, api_server=receiver_node |
| 26 | + ) as rx_session: |
| 27 | + responses = await try_until( |
| 28 | + rx_session.get_messages, |
| 29 | + has_messages, |
| 30 | + timeout=5, |
| 31 | + message_filter=MessageFilter( |
| 32 | + hashes=[store_message.item_hash], |
| 33 | + ), |
| 34 | + ) |
| 35 | + |
| 36 | + message_from_target = responses.messages[0] |
| 37 | + assert store_message.item_hash == message_from_target.item_hash |
| 38 | + |
| 39 | + async with AuthenticatedAlephHttpClient( |
| 40 | + account=account, api_server=receiver_node |
| 41 | + ) as rx_session: |
| 42 | + store_content = await rx_session.download_file(store_message.content.item_hash) |
| 43 | + assert store_content == file_content |
| 44 | + |
| 45 | + |
| 46 | +@pytest.mark.asyncio |
| 47 | +async def test_create_message_on_target(fixture_account): |
| 48 | + """ |
| 49 | + Attempts to create a new message on the target node and verifies if the message can be fetched from |
| 50 | + the reference node. |
| 51 | + """ |
| 52 | + await create_store_on_target( |
| 53 | + fixture_account, emitter_node=TARGET_NODE, receiver_node=REFERENCE_NODE |
| 54 | + ) |
| 55 | + |
| 56 | + |
| 57 | +@pytest.mark.asyncio |
| 58 | +async def test_create_message_on_reference(fixture_account): |
| 59 | + """ |
| 60 | + Attempts to create a new message on the reference node and verifies if the message can be fetched from |
| 61 | + the target node. |
| 62 | + """ |
| 63 | + await create_store_on_target( |
| 64 | + fixture_account, emitter_node=REFERENCE_NODE, receiver_node=TARGET_NODE |
| 65 | + ) |
0 commit comments