Exemplo n.º 1
0
async def test_get_messages():
    _get_fallback_session.cache_clear()

    response = await get_messages(
        pagination=2,
    )

    assert response.keys() == {
        "messages",
        "pagination_page",
        "pagination_total",
        "pagination_per_page",
        "pagination_item",
    }

    messages = response["messages"]
    assert set(messages[0].keys()).issuperset(
        {
            "_id",
            "chain",
            "item_hash",
            "sender",
            "type",
            "channel",
            "confirmed",
            "content",
            "item_content",
            "item_type",
            "signature",
            "size",
            "time",
            # 'confirmations',
        }
    )
Exemplo n.º 2
0
async def test_fetch_aggregate():
    _get_fallback_session.cache_clear()

    response = await fetch_aggregate(
        address="0xa1B3bb7d2332383D96b7796B908fB7f7F3c2Be10", key="corechannel"
    )
    assert response.keys() == {"nodes", "resource_nodes"}
Exemplo n.º 3
0
async def test_create_aggregate():
    _get_fallback_session.cache_clear()

    if os.path.exists(PRIVATE_KEY_FILE):
        os.remove(PRIVATE_KEY_FILE)

    private_key = get_fallback_private_key()
    account: ETHAccount = ETHAccount(private_key=private_key)

    content = {"Hello": "World"}

    mock_session = MagicMock()

    await create_aggregate(
        account=account,
        key='hello',
        content=content,
        channel="TEST",
        session=mock_session,
    )

    await create_aggregate(
        account=account,
        key='hello',
        content='world',
        channel="TEST",
        session=mock_session,
        api_server="https://example.org",
    )

    assert mock_session.post.called
Exemplo n.º 4
0
async def test_create_store():
    _get_fallback_session.cache_clear()

    if os.path.exists(PRIVATE_KEY_FILE):
        os.remove(PRIVATE_KEY_FILE)

    private_key = get_fallback_private_key()
    account: ETHAccount = ETHAccount(private_key=private_key)

    content = {"Hello": "World"}

    mock_session = MagicMock()

    mock_ipfs_push_file = AsyncMock()
    mock_ipfs_push_file.return_value = "FAKE-HASH"

    with patch('aleph_client.asynchronous.ipfs_push_file',
               mock_ipfs_push_file):

        await create_store(
            account=account,
            file_content=b"HELLO",
            # file_hash="abcde",
            channel="TEST",
            storage_engine=StorageEnum.ipfs,
            session=mock_session,
            api_server="https://example.org",
        )

        await create_store(
            account=account,
            # file_content=b"HELLO",
            file_hash="FAKE-HASH",
            channel="TEST",
            storage_engine=StorageEnum.ipfs,
            session=mock_session,
            api_server="https://example.org",
        )

    mock_storage_push_file = AsyncMock()
    mock_storage_push_file.return_value = "FAKE-HASH"

    with patch('aleph_client.asynchronous.storage_push_file',
               mock_storage_push_file):

        await create_store(
            account=account,
            file_content=b"HELLO",
            channel="TEST",
            storage_engine=StorageEnum.storage,
            session=mock_session,
            api_server="https://example.org",
        )

    assert mock_session.post.called
Exemplo n.º 5
0
async def test_forget():
    _get_fallback_session.cache_clear()

    if os.path.exists(PRIVATE_KEY_FILE):
        os.remove(PRIVATE_KEY_FILE)

    private_key = get_fallback_private_key()
    account: ETHAccount = ETHAccount(private_key=private_key)

    content = {"Hello": "World"}

    mock_session = MagicMock()

    await forget(
        account=account,
        hashes=["FAKE-HASH"],
        reason="GDPR",
        channel="TEST",
        session=mock_session,
        api_server="https://example.org",
    )

    assert mock_session.post.called
Exemplo n.º 6
0
async def test_create_program():
    _get_fallback_session.cache_clear()

    if os.path.exists(PRIVATE_KEY_FILE):
        os.remove(PRIVATE_KEY_FILE)

    private_key = get_fallback_private_key()
    account: ETHAccount = ETHAccount(private_key=private_key)

    content = {"Hello": "World"}

    mock_session = MagicMock()

    await create_program(
        account=account,
        program_ref="FAKE-HASH",
        entrypoint="main:app",
        runtime="FAKE-HASH",
        channel="TEST",
        session=mock_session,
        api_server="https://example.org",
    )

    assert mock_session.post.called