def test_14_view_asset_listing(resources, remote_agent_surfer):
    test_data = "Test listing searching by listing id"
    asset_data = DataAsset.create('TestAsset', test_data)
    asset = remote_agent_surfer.register_asset(asset_data)
    assert (asset)
    listing = remote_agent_surfer.create_listing(resources.listing_data,
                                                 asset.did)
    listing.set_published(True)
    logging.debug("view_asset_listing for listing_id: " + listing.listing_id)
    listing2 = remote_agent_surfer.get_listing(listing.listing_id)
    assert (listing2.listing_id == listing.listing_id)
    # view all listings
    listings = remote_agent_surfer.get_listings()
    logging.debug("listings: " + str(listings))
    assert (listings)
    assert (isinstance(listings, list))
    assert (len(listings) > 0)
    # found = False
    # FIXME: the remote agent call to get all listings does NOT return this listing!?
    found = True
    for listing in listings:
        logging.debug("checking: " + str(listing.listing_id) + " == " +
                      str(listing.listing_id == listing2.listing_id))
        if listing.listing_id == listing2.listing_id:
            found = True
            break
    assert (found)
def test_10_asset_upload(resources, remote_agent_surfer):
    test_data = secrets.token_hex(1024)
    asset_data = DataAsset.create('TestAsset', test_data)
    asset = remote_agent_surfer.register_asset(asset_data)
    assert (asset)

    assert (remote_agent_surfer.upload_asset(asset))
示例#3
0
def register_upload_data(remote_agent: AgentBase, name: str, data_stream: Any, chunk_size_value: int = None) -> Any:

    if chunk_size_value is None:
        chunk_size_value = DEFAULT_CHUNK_SIZE

    chunk_size = chunk_size_value
    if isinstance(chunk_size_value, str):
        chunk_size = decode_readable_size(chunk_size_value)
    if not isinstance(chunk_size, int):
        raise ValueError(f'invalid chunk size "{chunk_size_value}", must be int or str')

    bundle_asset = BundleAsset.create(name)
    index = 0
    asset = None
    while True:
        data = data_stream.read(chunk_size)
        if data:
            asset_name = f'{name}:{index}'
            data_asset = DataAsset.create(asset_name, data)
            asset = remote_agent.register_asset(data_asset)
            remote_agent.upload_asset(asset)
            bundle_asset = bundle_asset.add(asset_name, asset)
            index += 1
        else:
            break
    if index > 0:
        asset = remote_agent.register_asset(bundle_asset)
    return asset
def test_07_metadata_access(resources, remote_agent_surfer):
    test_data = secrets.token_bytes(1024)
    asset_data = DataAsset.create('TestAsset', test_data)
    asset = remote_agent_surfer.register_asset(asset_data)
    assert (asset.asset_id)
    assert (asset.metadata)
    assert (asset.metadata == asset_data.metadata)
示例#5
0
def register_asset_for_sale(agent, resources, account):

    asset = DataAsset.create('TestAsset', secrets.token_hex(256))
    asset = agent.register_asset(asset)
    listing = agent.create_listing(resources.listing_data, asset.did)
    assert listing
    assert listing.asset_did
    return listing
示例#6
0
def test_13_asset_listing_search(resources, remote_agent_surfer):
    test_data = secrets.token_hex(1024)
    asset_data = DataAsset.create('TestAsset', test_data)
    asset = remote_agent_surfer.register_asset(asset_data)
    assert (asset)
    listing = remote_agent_surfer.create_listing(resources.listing_data,
                                                 asset.did)
    assert (listing)
    assert (listing.asset_did)
示例#7
0
def test_create_from_bytes():
    asset_name = secrets.token_hex(8)
    test_data = secrets.token_bytes(1024)
    asset = DataAsset.create(asset_name, test_data)
    assert(asset)
    assert(isinstance(asset, DataAsset))
    assert(asset.name == asset_name)
    assert(asset.type_name == 'dataset')
    assert(asset.metadata['contentType'] ==  'application/octet-stream')
示例#8
0
def test_create_from_text():
    asset_name = secrets.token_hex(8)
    test_data = str(secrets.token_bytes(1024))
    asset = DataAsset.create(asset_name, test_data)
    assert(asset)
    assert(isinstance(asset, DataAsset))
    assert(asset.name == asset_name)
    assert(asset.type_name == 'dataset')
    assert(asset.metadata['contentType'] ==  'text/plain')
def test_08_asset_registration(resources, remote_agent_surfer):
    test_data = secrets.token_hex(1024)
    description = secrets.token_hex(16)
    asset_data_1 = DataAsset.create('TestAsset_08', test_data, {'description': description})
    asset_1 = remote_agent_surfer.register_asset(asset_data_1)
    assert(asset_1)

    asset_data_2 = DataAsset.create('TestAsset_08', test_data,  {'description': description})
    asset_2 = remote_agent_surfer.register_asset(asset_data_2)
    assert(asset_2)

    assert(asset_1.asset_id == asset_2.asset_id)

    asset_list = remote_agent_surfer.search_asset({
        'name': 'TestAsset_08',
         'description': description,
    })
    assert(asset_list)
    assert(len(asset_list) > 0)
    assert(asset_list[0] == asset_1.asset_id)
示例#10
0
def test_create_from_json_text():
    asset_name = secrets.token_hex(8)
    values = {
        'name': 'value',
        'key1': secrets.randbelow(100000)
    }
    test_data = json.dumps(values)
    asset = DataAsset.create(asset_name, test_data)
    assert(asset)
    assert(isinstance(asset, DataAsset))
    assert(asset.name == asset_name)
    assert(asset.type_name == 'dataset')
    assert(asset.metadata['contentType'] ==  'application/json')
示例#11
0
def test_19_asset_download(resources, remote_agent_surfer):
    test_data = secrets.token_hex(1024)
    asset_data = DataAsset.create('TestAsset', test_data)

    asset = remote_agent_surfer.register_asset(asset_data)

    remote_agent_surfer.upload_asset(asset)

    # now download
    store_asset = remote_agent_surfer.download_asset(asset.asset_id)

    assert (store_asset)
    assert (store_asset.data == asset.data)
    assert (store_asset.asset_id == asset.asset_id)
示例#12
0
def test_17_asset_purchase(resources, config, remote_agent_surfer,
                           convex_accounts):
    purchaser_account = convex_accounts
    test_data = secrets.token_bytes(1024)
    asset_data = DataAsset.create('TestAsset', test_data)
    asset = remote_agent_surfer.register_asset(asset_data)
    assert (asset)
    listing = remote_agent_surfer.create_listing(resources.listing_data,
                                                 asset.did)
    listing.set_published(True)
    logging.debug("create_purchase for listing_id: " + listing.listing_id)
    purchase = remote_agent_surfer.purchase_asset(listing, purchaser_account)
    assert (purchase['listingid'] == listing.listing_id)
    assert (purchase['status'] == 'wishlist')
    logging.debug("purchase: " + json.dumps(purchase))
def test_bundle_asset_add_access_remove(config):
    bundle = BundleAsset.create('name')
    asset_list = {}

    assert (bundle.is_bundle)
    # add a set of memory assets

    for index in range(0, TEST_ASSET_COUNT):
        test_data = secrets.token_hex(1024)
        name = f'name_{index}'
        asset_list[name] = DataAsset.create(f'Asset_{index}', test_data)
        bundle.add(name, asset_list[name])
        assert (bundle[name])
        assert (bundle.asset_count == index + 1)

    # using the iterator
    for name, asset_id in bundle:
        assert (name)
        assert (asset_id)
        assert (asset_id == asset_list[name].asset_id)

    # using the get_asset and __getitem__
    for index in range(0, bundle.asset_count):
        asset_id = bundle.get_asset_id(index)
        name = list(asset_list.keys())[index]
        assert (asset_id == asset_list[name].asset_id)
        asset_id = bundle.get_asset_id(name)
        assert (asset_id)
        assert (asset_id == asset_list[name].asset_id)
        asset = bundle[name]
        assert (asset_id)
        assert (asset_id == asset_list[name].asset_id)

        items = dict(bundle.asset_items)
        asset_id = items[name]
        assert (asset_id)
        assert (asset_id == asset_list[name].asset_id)

    # test remove
    for name in bundle.asset_names:
        asset_id = bundle.asset_remove(name)
        assert (asset_id)

    assert (bundle.asset_count == 0)
def test_18_confirm_purchase(resources, config, remote_agent_surfer,
                             convex_accounts):
    purchaser_account = convex_accounts
    test_data = secrets.token_bytes(1024)
    asset_data = DataAsset.create('TestAsset', test_data)
    asset = remote_agent_surfer.register_asset(asset_data)
    assert (asset)
    listing = remote_agent_surfer.create_listing(resources.listing_data,
                                                 asset.did)
    listing.set_published(True)
    logging.debug("confirm_purchase for listingid: " + listing.listing_id)
    response = remote_agent_surfer.update_listing(listing)
    logging.debug("update_listing response: " + str(response))
    assert (response)
    status = 'ordered'
    purchase = remote_agent_surfer.purchase_asset(listing, purchaser_account,
                                                  None, status)
    assert (purchase['listingid'] == listing.listing_id)
    assert (purchase['status'] == status)
def test_12_listing_publish(resources, remote_agent_surfer):
    test_data = secrets.token_hex(1024)
    asset_data = DataAsset.create('TestAsset', test_data)
    asset = remote_agent_surfer.register_asset(asset_data)
    assert (asset)
    listing = remote_agent_surfer.create_listing(resources.listing_data,
                                                 asset.did)
    assert (listing)
    assert (listing.asset_did)

    assert (not listing.is_published)

    listing.set_published(True)
    assert (listing.is_published)

    assert (remote_agent_surfer.update_listing(listing))

    read_listing = remote_agent_surfer.get_listing(listing.listing_id)
    assert (read_listing)
    assert (read_listing.is_published)
def main():

    # Create a new convex network instance.
    network = ConvexNetwork('https://convex.world')

    # Create a remote agent to do the work.
    agent_url = 'http://localhost:3030'

    authentication = AuthenticationBasic('Aladdin', 'OpenSesame')

    # find an agent based on it's url, you can also use an agent did or asset did instead
    agent = RemoteAgent.load(agent_url, network, authentication=authentication)
    if not agent:
        print('failed to find the agent')

    # create a listing specifying the information about the asset
    listing_data = {
        'name': 'The white paper',
        'author': 'Datacraft',
        'license': 'CC0: Public Domain',
        'price': '0'
    }

    # Now create a memory asset
    asset = DataAsset.create(
        'TestAsset', 'Some test data that I want to save for this asset')
    asset = create_asset_provenance_publish(asset, agent.did)

    # Print the asset data
    print('my asset:', asset.data)

    asset = agent.register_asset(asset)
    print(asset.did)
    listing = agent.create_listing(listing_data, asset.did)
    print(listing.did, listing.data)

    # now upload the asset data to Surfer
    agent.upload_asset(asset)
def test_02_asset_upload(remote_agent_surfer, resources):
    testData = secrets.token_bytes(1024)
    asset_data = DataAsset.create('TestAsset', testData)
    asset = remote_agent_surfer.register_asset(asset_data)
    remote_agent_surfer.upload_asset(asset)
def test_02_asset_register(remote_agent_surfer, resources):
    testData = secrets.token_bytes(1024)
    asset1 = DataAsset.create('TestAsset1', testData)
    asset2 = DataAsset.create('TestAsset2', testData)
    asset = remote_agent_surfer.register_asset(asset2)
    assert(asset.data == asset2.data)
示例#19
0
def test_init():
    asset = DataAsset.create('test data asset', TEST_DATA)
    assert(asset)
    assert(isinstance(asset, DataAsset))
    assert(asset.type_name == 'dataset')
    assert(asset.data == TEST_DATA.encode('utf-8'))