コード例 #1
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
コード例 #2
0
def main(filename, pkey=None, storage_engine="IPFS", channel="TEST"):
    """Uploads or store FILENAME.
    
    If FILENAME is an IPFS multihash and IPFS is selected as an engine (default), don't try to upload, just pin it to the network.
    Else, uploads the file to the network before pining it.
    """
    if pkey is None:
        pkey = get_fallback_private_key()

    account = ETHAccount(private_key=pkey)

    upload_filename = None
    upload_hash = None

    if 46 <= len(filename) <= 48 and filename.startswith(
            "Q") and storage_engine == "IPFS":
        upload_hash = filename
    else:
        upload_filename = filename

    asyncio.run(
        do_upload(account,
                  storage_engine,
                  channel,
                  filename=upload_filename,
                  file_hash=upload_hash))
コード例 #3
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
コード例 #4
0
def test_sign_data_deprecated():
    """Test the data signature"""
    data = None
    signature = NulsSignature(data=data)

    delete_private_key_file()
    private_key = get_fallback_private_key()

    assert signature
    sign_deprecated: NulsSignatureSecp256k1 = (
        NulsSignatureSecp256k1.sign_data_deprecated(pri_key=private_key,
                                                    digest_bytes=b"x" *
                                                    (256 // 8)))
    assert sign_deprecated
コード例 #5
0
def main(host, port, channel, pkey=None, secret=None):
    app.add_routes(routes)
    loop = asyncio.get_event_loop()

    app['secret'] = secret
    app['channel'] = channel

    if pkey is None:
        pkey = get_fallback_private_key()

    account = ETHAccount(private_key=pkey)
    app['account'] = account

    web.run_app(app, host=host, port=port)
コード例 #6
0
ファイル: mqtt.py プロジェクト: antonioandara/aleph-client
async def gateway(loop,
                  host='api1.aleph.im',
                  port=1883,
                  ca_cert=None,
                  pkey=None,
                  keepalive=10,
                  transport='tcp',
                  auth=None):

    if pkey is None:
        pkey = get_fallback_private_key()

    account = ETHAccount(private_key=pkey)
    state = dict()
    userdata = {'account': account, 'state': state, 'received': False}
    client = aiomqtt.Client(loop, userdata=userdata, transport=transport)
    client.on_connect = on_connect
    client.on_disconnect = on_disconnect
    client.on_message = on_message

    if ca_cert is not None:
        client.tls_set(ca_cert)
    if auth is not None:
        client.username_pw_set(**auth)

    asyncio.ensure_future(client.loop_forever())

    await client.connect(host, port, keepalive)
    # client.loop_forever()
    while True:
        await asyncio.sleep(10)
        if not userdata['received']:
            await client.reconnect()

        for key, value in state.items():
            ret = create_aggregate(account, key, value, channel='IOT_TEST')
            print("sent", ret['item_hash'])
            userdata['received'] = False
コード例 #7
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
コード例 #8
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
コード例 #9
0
ファイル: conftest.py プロジェクト: aleph-im/aleph-client
def fixture_account():
    private_key = get_fallback_private_key()
    return ETHAccount(private_key)