Пример #1
0
def test_update_trusted_algorithms():
    setup = Setup()

    config = ConfigProvider.get_config()
    ddo_address = get_contracts_addresses(
        "ganache", config)[MetadataContract.CONTRACT_NAME]
    ddo_registry = MetadataContract(ddo_address)

    # Setup algorithm meta to run raw algorithm
    algorithm_ddo = get_registered_algorithm_ddo(
        setup.publisher_ocean_instance, setup.publisher_wallet)
    # verify the ddo is available in Aquarius
    _ = setup.publisher_ocean_instance.assets.resolve(algorithm_ddo.did)

    # Dataset with compute service
    compute_ddo = get_registered_ddo_with_compute_service(
        setup.publisher_ocean_instance,
        setup.publisher_wallet,
        trusted_algorithms=[algorithm_ddo.did],
    )
    # verify the ddo is available in Aquarius
    _ = setup.publisher_ocean_instance.assets.resolve(compute_ddo.did)
    trusted_algo_list = create_publisher_trusted_algorithms(
        [algorithm_ddo.did],
        setup.publisher_ocean_instance.config.aquarius_url)
    compute_ddo.update_compute_privacy(trusted_algorithms=trusted_algo_list,
                                       allow_all=False,
                                       allow_raw_algorithm=False)

    tx_id = setup.publisher_ocean_instance.assets.update(
        compute_ddo, setup.publisher_wallet)

    tx_receipt = ddo_registry.get_tx_receipt(tx_id)
    logs = ddo_registry.event_MetadataUpdated.processReceipt(tx_receipt)
    assert logs[0].args.dataToken == compute_ddo.data_token_address

    wait_for_update(
        setup.publisher_ocean_instance,
        compute_ddo.did,
        "privacy",
        {"publisherTrustedAlgorithms": [algorithm_ddo.did]},
    )

    compute_ddo_updated = setup.publisher_ocean_instance.assets.resolve(
        compute_ddo.did)

    run_compute_test(
        setup.consumer_ocean_instance,
        setup.publisher_wallet,
        setup.consumer_wallet,
        [compute_ddo_updated],
        algo_ddo=algorithm_ddo,
    )
Пример #2
0
def test_update_trusted_algorithms(config, web3, algorithm_ddo,
                                   asset_with_trusted):
    setup = Setup()

    ddo_address = get_contracts_addresses(
        config.address_file, "ganache")[MetadataContract.CONTRACT_NAME]
    ddo_registry = MetadataContract(web3, ddo_address)

    trusted_algo_list = create_publisher_trusted_algorithms(
        [algorithm_ddo.did],
        setup.publisher_ocean_instance.config.metadata_cache_uri)
    asset_with_trusted.update_compute_privacy(
        trusted_algorithms=trusted_algo_list,
        trusted_algo_publishers=[],
        allow_all=False,
        allow_raw_algorithm=False,
    )

    tx_id = setup.publisher_ocean_instance.assets.update(
        asset_with_trusted, setup.publisher_wallet)

    tx_receipt = ddo_registry.get_tx_receipt(web3, tx_id)
    logs = ddo_registry.event_MetadataUpdated.processReceipt(tx_receipt,
                                                             errors=DISCARD)
    assert logs[0].args.dataToken == asset_with_trusted.data_token_address

    wait_for_update(
        setup.publisher_ocean_instance,
        asset_with_trusted.did,
        "privacy",
        {"publisherTrustedAlgorithms": [algorithm_ddo.did]},
    )

    compute_ddo_updated = setup.publisher_ocean_instance.assets.resolve(
        asset_with_trusted.did)

    run_compute_test(
        setup.consumer_ocean_instance,
        setup.publisher_wallet,
        setup.consumer_wallet,
        [compute_ddo_updated],
        algo_ddo=algorithm_ddo,
    )
Пример #3
0
def test_register_asset(publisher_ocean_instance):
    """Test various paths for asset registration."""
    ocn = publisher_ocean_instance
    ddo_reg = ocn.assets.ddo_registry()
    block = ocn.web3.eth.blockNumber
    alice = get_publisher_wallet()
    bob = get_consumer_wallet()

    def _get_num_assets(_minter):
        dids = [
            add_0x_prefix(did_to_id(a))
            for a in ocn.assets.owner_assets(_minter)
        ]
        dids = [a for a in dids if len(a) == 42]
        return len([
            a for a in dids if DataToken(a).contract_concise.isMinter(_minter)
        ])

    num_assets_owned = _get_num_assets(alice.address)

    original_ddo = create_asset(ocn, alice)
    assert original_ddo, "create asset failed."

    # try to resolve new asset
    did = original_ddo.did
    asset_id = original_ddo.asset_id
    log = ddo_reg.get_event_log(ddo_reg.EVENT_METADATA_CREATED, block,
                                asset_id, 30)
    assert log, "no ddo created event."

    ddo = wait_for_ddo(ocn, did)
    assert ddo, "ddo is not found in cache."
    ddo_dict = ddo.as_dictionary()
    original = original_ddo.as_dictionary()
    assert ddo_dict["publicKey"] == original["publicKey"]
    assert ddo_dict["authentication"] == original["authentication"]
    assert ddo_dict["service"]
    assert original["service"]
    metadata = ddo_dict["service"][0]["attributes"]
    if "datePublished" in metadata["main"]:
        metadata["main"].pop("datePublished")
    assert (ddo_dict["service"][0]["attributes"]["main"]["name"] ==
            original["service"][0]["attributes"]["main"]["name"])
    assert ddo_dict["service"][1] == original["service"][1]

    # Can't resolve unregistered asset
    unregistered_did = DID.did({"0": "0x00112233445566"})
    with pytest.raises(ValueError):
        ocn.assets.resolve(unregistered_did)

    # Raise error on bad did
    invalid_did = "did:op:0123456789"
    with pytest.raises(ValueError):
        ocn.assets.resolve(invalid_did)

    meta_data_assets = ocn.assets.search("")
    if meta_data_assets:
        print("Currently registered assets:")
        print(meta_data_assets)

    # Publish the metadata
    _ = ddo.metadata["main"]["name"]
    _name = "updated name"
    ddo.metadata["main"]["name"] = _name
    assert ddo.metadata["main"]["name"] == _name
    with pytest.raises(ValueError):
        ocn.assets.update(ddo, bob)

    _ = ocn.assets.update(ddo, alice)
    log = ddo_reg.get_event_log(ddo_reg.EVENT_METADATA_UPDATED, block,
                                asset_id, 30)
    assert log, "no ddo updated event"
    _asset = wait_for_update(ocn, ddo.did, "name", _name)
    assert _asset, "Cannot read asset after update."
    assert (_asset.metadata["main"]["name"] == _name
            ), "updated asset does not have the new updated name !!!"

    assert (ocn.assets.owner(
        ddo.did) == alice.address), "asset owner does not seem correct."

    assert _get_num_assets(alice.address) == num_assets_owned + 1