def test_did_resolver_library(publisher_account, metadata_instance, ddo_sample_2): did_registry = keeper().did_registry checksum_test = Web3.keccak(text='checksum') value_test = metadata_instance.root_url did_resolver = DIDResolver(keeper().did_registry) did_seed = generate_prefixed_id() asset_id = did_registry.hash_did(did_seed, publisher_account.address) asset1 = ddo_sample_2 asset1._did = DID.did(asset_id) did_registry.register(did_seed, checksum_test, url=value_test, account=publisher_account) metadata_instance.publish_asset_ddo(asset1) did_resolved = did_resolver.resolve(asset1.did) assert did_resolved assert did_resolved.did == asset1.did with pytest.raises(ValueError): did_resolver.resolve(asset1.asset_id) metadata_instance.retire_asset_ddo(asset1.did)
def test_get_resolve_url(metadata_instance, publisher_account): register_account = publisher_account did_registry = keeper().did_registry did_seed = generate_prefixed_id() asset_id = did_registry.hash_did(did_seed, register_account.address) did = DID.did(asset_id) value_test = metadata_instance.root_url did_resolver = DIDResolver(keeper().did_registry) did_registry.register(did_seed, b'test', url=value_test, account=register_account) url = did_resolver.get_resolve_url(Web3.toBytes(hexstr=asset_id)) assert url == value_test
def test_get_resolve_multiple_urls(publisher_account): register_account = publisher_account did_registry = keeper().did_registry did_resolver = DIDResolver(keeper().did_registry) iterations = 3 counter = 0 while counter < iterations: _seed = generate_prefixed_id() _asset_id = did_registry.hash_did(_seed, register_account.address) _url = 'http://localhost:5000/' + str(counter) did_registry.register(_seed, b'test', url=_url, account=register_account) assert did_resolver.get_resolve_url( Web3.toBytes(hexstr=_asset_id)) == _url counter = counter + 1
def setup_nft_sales_agreements_environment(): consumer_acc = get_consumer_account() publisher_acc = get_publisher_account() keeper = Keeper.get_instance() ddo = get_ddo_nft_sample() did_seed = generate_prefixed_id() asset_id = keeper.did_registry.hash_did(did_seed, publisher_acc.address) ddo._did = DID.did(asset_id) keeper.did_registry.register_mintable_did( did_seed, checksum=Web3Provider.get_web3().toBytes(hexstr=ddo.asset_id), url='http://172.17.0.1:5000', cap=10, royalties=10, account=publisher_acc, providers=None) keeper.did_registry.mint(ddo.asset_id, 10, account=publisher_acc) service_agreement = ServiceAgreement.from_ddo(ServiceTypes.NFT_SALES, ddo) agreement_id = ServiceAgreement.create_new_agreement_id() price = service_agreement.get_price() (access_cond_id, lock_cond_id, escrow_cond_id) = service_agreement.generate_agreement_condition_ids( agreement_id, asset_id, consumer_acc.address, keeper) nft_access_service_agreement = ServiceAgreement.from_ddo( ServiceTypes.NFT_ACCESS, ddo) nft_access_agreement_id = ServiceAgreement.create_new_agreement_id() (nft_access_cond_id, nft_holder_cond_id ) = nft_access_service_agreement.generate_agreement_condition_ids( nft_access_agreement_id, asset_id, consumer_acc.address, keeper) return (keeper, ddo, publisher_acc, consumer_acc, agreement_id, nft_access_agreement_id, asset_id, price, service_agreement, nft_access_service_agreement, (lock_cond_id, access_cond_id, escrow_cond_id), (nft_access_cond_id, nft_holder_cond_id))
def setup_did_sales_agreements_environment(): consumer_acc = get_consumer_account() publisher_acc = get_publisher_account() keeper = Keeper.get_instance() ddo = get_ddo_did_sales_sample() did_seed = generate_prefixed_id() asset_id = keeper.did_registry.hash_did(did_seed, publisher_acc.address) ddo._did = DID.did(asset_id) keeper.did_registry.register( did_seed, checksum=Web3Provider.get_web3().toBytes(hexstr=ddo.asset_id), url='metadata:5000', account=publisher_acc, providers=None) service_agreement = ServiceAgreement.from_ddo(ServiceTypes.DID_SALES, ddo) agreement_id = ServiceAgreement.create_new_agreement_id() price = service_agreement.get_price() (access_cond_id, lock_cond_id, escrow_cond_id) = service_agreement.generate_agreement_condition_ids( agreement_id, asset_id, consumer_acc.address, keeper) return ( keeper, ddo, publisher_acc, consumer_acc, agreement_id, asset_id, price, service_agreement, (lock_cond_id, access_cond_id, escrow_cond_id), )
def setup_agreements_environment(ddo_sample): consumer_acc = get_consumer_account() publisher_acc = get_publisher_account() keeper = Keeper.get_instance() ddo = ddo_sample ddo._did = DID.did({"0": generate_prefixed_id()}) keeper.did_registry.register( ddo.asset_id, checksum=Web3Provider.get_web3().toBytes(hexstr=ddo.asset_id), url='localhost:5000', account=publisher_acc, providers=None ) registered_ddo = ddo asset_id = registered_ddo.asset_id service_agreement = ServiceAgreement.from_ddo(ServiceTypes.ASSET_ACCESS, ddo) agreement_id = ServiceAgreement.create_new_agreement_id() price = service_agreement.get_price() access_cond_id, lock_cond_id, escrow_cond_id = \ service_agreement.generate_agreement_condition_ids( agreement_id, asset_id, consumer_acc.address, publisher_acc.address, keeper ) return ( keeper, publisher_acc, consumer_acc, agreement_id, asset_id, price, service_agreement, (lock_cond_id, access_cond_id, escrow_cond_id), )
def create_new_agreement_id(): """ :return: """ return generate_prefixed_id()