def test_creating_ddo_from_scratch(): # create an empty ddo ddo = DDO() assert ddo.did is None assert ddo.asset_id is None assert ddo.created is not None did = DID.did("0x99999999999999999") ddo.assign_did(did) assert ddo.did == did pub_acc = get_publisher_account() ddo.add_service(TEST_SERVICE_TYPE, TEST_SERVICE_URL) # add a proof to the first public_key/authentication ddo.add_proof('checksum', pub_acc) ddo_text_proof = ddo.as_text() assert ddo_text_proof pub_acc = get_publisher_account() assert not ddo.public_keys ddo.add_public_key(did, pub_acc.address) assert len(ddo.public_keys) == 1 assert ddo.get_public_key(0) == ddo.public_keys[0] with pytest.raises(IndexError): ddo.get_public_key(1) assert ddo.get_public_key(did) == ddo.public_keys[0] assert ddo.get_public_key('0x32233') is None assert not ddo.authentications ddo.add_authentication(did, '') assert len(ddo.authentications) == 1
def test_nft(): register_account = get_publisher_account() did_registry = DIDRegistry.get_instance() nft_upgradeable = NFTUpgradeable.get_instance() w3 = Web3 did_seed = new_did() asset_id = did_registry.hash_did(did_seed, register_account.address) someone_address = "0x00a329c0648769A73afAc7F9381E08FB43dBEA72" checksum_test = w3.keccak(text='checksum') activity_id = new_did() cap = 10 royalties = 0 url = 'http://localhost:5000' test_address = w3.toChecksumAddress('068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0') assert did_registry.register_mintable_did(did_seed, checksum_test, url, cap, royalties, account=register_account, providers=[test_address], activity_id=activity_id) is True balance = nft_upgradeable.balance(register_account.address, asset_id) assert balance == 0 balance_consumer = nft_upgradeable.balance(someone_address, asset_id) assert balance_consumer == 0 did_registry.mint(asset_id, 10, account=register_account) assert balance + 10 == nft_upgradeable.balance(register_account.address, asset_id) assert nft_upgradeable.transfer_nft(asset_id, someone_address, 1, register_account) assert nft_upgradeable.balance(register_account.address, asset_id) == 9 assert nft_upgradeable.balance(someone_address, asset_id) == balance_consumer + 1 did_registry.burn(asset_id, 9, account=register_account) assert balance == nft_upgradeable.balance(register_account.address, asset_id)
def test_delegate_provenance(): register_account = get_publisher_account() delegated_account = get_consumer_account() did_registry = DIDRegistry.get_instance() w3 = Web3 did_seed = new_did() asset_id = did_registry.hash_did(did_seed, register_account.address) checksum_test = w3.keccak(text='checksum') activity_id = new_did() provenance_id = new_did() url = 'http://localhost:5000' test_address = w3.toChecksumAddress('068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0') assert did_registry.register(did_seed, checksum_test, url=url, account=register_account, providers=[test_address], activity_id=activity_id) is True assert did_registry.is_provenance_delegate(Web3.toBytes(hexstr=asset_id), register_account.address) is False assert did_registry.is_provenance_delegate(Web3.toBytes(hexstr=asset_id), delegated_account.address) is False assert did_registry.add_did_provenance_delegate(Web3.toBytes(hexstr=asset_id), delegated_account.address, register_account) is True assert did_registry.is_provenance_delegate(Web3.toBytes(hexstr=asset_id), delegated_account.address) is True assert did_registry.remove_did_provenance_delegate(Web3.toBytes(hexstr=asset_id), delegated_account.address, register_account) is True assert did_registry.is_provenance_delegate(Web3.toBytes(hexstr=asset_id), delegated_account.address) is False
def test_provenance_from_registry(): register_account = get_publisher_account() did_registry = DIDRegistry.get_instance() w3 = Web3 did_seed = new_did() asset_id = did_registry.hash_did(did_seed, register_account.address) checksum_test = w3.keccak(text='checksum') activity_id = new_did() provenance_id = new_did() url = 'http://localhost:5000' test_address = w3.toChecksumAddress('068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0') assert did_registry.register(did_seed, checksum_test, url=url, account=register_account, providers=[test_address], activity_id=activity_id) is True assert register_account.address == did_registry.get_provenance_owner(asset_id) did_registry.used(provenance_id, asset_id, test_address, activity_id, "", account=register_account, attributes="used test") provenance_entry = did_registry.get_provenance_entry(provenance_id) assert ("0x" + activity_id, provenance_entry['activity_id']) assert ("0x" + asset_id, provenance_entry['did']) assert (3, provenance_entry['method']) assert (register_account.address, provenance_entry['created_by'])
def test_grant_permissions(): register_account = get_publisher_account() did_registry = DIDRegistry.get_instance() w3 = Web3 did_seed = new_did() asset_id = did_registry.hash_did(did_seed, register_account.address) checksum_test = w3.keccak(text='checksum') value_test = 'http://localhost:5000' test_address = w3.toChecksumAddress('068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0') did_registry.register(did_seed, checksum_test, url=value_test, account=register_account, providers=[test_address]) assert not did_registry.get_permission(asset_id, test_address) did_registry.grant_permission(asset_id, test_address, register_account) assert did_registry.get_permission(asset_id, test_address) did_registry.revoke_permission(asset_id, test_address, register_account) assert not did_registry.get_permission(asset_id, test_address)
def test_store_token(): ocn_auth = OceanAuth(Keeper.get_instance(), ':memory:') acc = get_publisher_account() token = ocn_auth.store(acc) assert ocn_auth.check(token) == acc.address, 'invalid token, check failed.' # verify it is saved assert ocn_auth.restore(acc) == token, 'Restoring token failed.'
def setup_agreements_environment(): consumer_acc = get_consumer_account() publisher_acc = get_publisher_account() keeper = Keeper.get_instance() ddo = get_ddo_sample() ddo._did = DID.did({"0": "0x12341234"}) keeper.did_registry.register( ddo.asset_id, checksum=Web3Provider.get_web3().toBytes(hexstr=ddo.asset_id), url='aquarius: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() (lock_cond_id, access_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 test_get_did(): register_account = get_publisher_account() did_registry = DIDRegistry.get_instance() w3 = Web3 did_seed = new_did() asset_id = did_registry.hash_did(did_seed, register_account.address) checksum_test = w3.keccak(text='checksum') activity_id = new_did() someone_address = w3.toChecksumAddress('0x00a329c0648769A73afAc7F9381E08FB43dBEA72') url = 'http://localhost:5000' royalties = 20 cap = 0 assert did_registry.register_mintable_did(did_seed, checksum_test, url, cap, royalties, account=register_account, providers=[someone_address], activity_id=activity_id) is True registered_did = did_registry.get_did_register(asset_id) assert registered_did['owner'] == register_account.address assert registered_did['url'] == url assert registered_did['lastUpdatedBy'] == register_account.address assert registered_did['blockNumberUpdated'] > 0 assert len(registered_did['providers']) == 1 assert registered_did['nftSupply'] == 0 assert registered_did['mintCap'] == cap assert registered_did['royalties'] == royalties
def registered_ddo(): ocn = get_publisher_ocean_instance() aqua = AquariusProvider.get_aquarius(ocn.config.aquarius_url) for did in aqua.list_assets(): aqua.retire_asset_ddo(did) return get_registered_ddo(ocn, get_publisher_account())
def test_check_token(web3_instance): ocn_auth = OceanAuth(Keeper.get_instance(), ':memory:') acc = get_publisher_account() token = ocn_auth.get(acc) address = ocn_auth.check(token) assert address != '0x0', 'Verifying token failed.' sig = token.split('-')[0] assert ocn_auth.check(sig) == '0x0'
def test_restore_token(publisher_ocean_instance): ocn_auth = OceanAuth(Keeper.get_instance(), ':memory:') acc = get_publisher_account() assert ocn_auth.restore( acc) is None, 'Expecting None when restoring non-existing token.' token = ocn_auth.store(acc) assert ocn_auth.check(token) == acc.address, 'invalid token, check failed.' # verify it is saved assert ocn_auth.restore(acc) == token, 'Restoring token failed.'
def __init__(self, ocean_instance=None, account=None): self.ocean_instance = ocean_instance if not ocean_instance: from tests.resources.helper_functions import get_publisher_ocean_instance self.ocean_instance = get_publisher_ocean_instance( init_tokens=False, use_ss_mock=False, use_brizo_mock=False) self.account = account if not account: from tests.resources.helper_functions import get_publisher_account self.account = get_publisher_account(ConfigProvider.get_config())
def buy_asset(): """ Requires all ocean services running. """ ConfigProvider.set_config(ExampleConfig.get_config()) config = ConfigProvider.get_config() # make ocean instance ocn = Ocean() acc = get_publisher_account(config) if not acc: acc = ([acc for acc in ocn.accounts.list() if acc.password] or ocn.accounts.list())[0] # Register ddo ddo = ocn.assets.create(Metadata.get_example(), acc, providers=[acc.address]) logging.info(f'registered ddo: {ddo.did}') # ocn here will be used only to publish the asset. Handling the asset by the publisher # will be performed by the Brizo server running locally keeper = Keeper.get_instance() if 'TEST_LOCAL_NILE' in os.environ and os.environ['TEST_LOCAL_NILE'] == '1': provider = keeper.did_registry.to_checksum_address( '0x413c9ba0a05b8a600899b41b0c62dd661e689354' ) keeper.did_registry.add_provider(ddo.asset_id, provider, acc) logging.debug(f'is did provider: ' f'{keeper.did_registry.is_did_provider(ddo.asset_id, provider)}') cons_ocn = Ocean() consumer_account = get_account_from_config(config, 'parity.address1', 'parity.password1') # sign agreement using the registered asset did above service = ddo.get_service(service_type=ServiceTypes.ASSET_ACCESS) # This will send the purchase request to Brizo which in turn will execute the agreement on-chain cons_ocn.accounts.request_tokens(consumer_account, 100) sa = ServiceAgreement.from_service_dict(service.as_dictionary()) agreement_id = cons_ocn.assets.order( ddo.did, sa.service_definition_id, consumer_account) logging.info('placed order: %s, %s', ddo.did, agreement_id) i = 0 while ocn.agreements.is_access_granted( agreement_id, ddo.did, consumer_account.address) is not True and i < 30: time.sleep(1) i += 1 assert ocn.agreements.is_access_granted(agreement_id, ddo.did, consumer_account.address) ocn.assets.consume( agreement_id, ddo.did, sa.service_definition_id, consumer_account, config.downloads_path) logging.info('Success buying asset.')
def test_get_token(): ocn_auth = OceanAuth(Keeper.get_instance(), ':memory:') acc = get_publisher_account() token = ocn_auth.get(acc) assert isinstance(token, str), 'Invalid auth token type.' assert token.startswith('0x'), 'Invalid auth token.' parts = token.split('-') assert len(parts) == 2, 'Invalid token, timestamp separator is not found.' address = ocn_auth.check(token) assert address != '0x0', 'Verifying token failed.'
def __init__(self, ocean_instance=None, account=None): if not ocean_instance: from tests.resources.helper_functions import get_publisher_instance ocean_instance = get_publisher_instance(init_tokens=False, use_ss_mock=False, use_gateway_mock=True) self.ocean_instance = ocean_instance self.account = account if not account: from tests.resources.helper_functions import get_publisher_account self.account = get_publisher_account()
def test_create_ddo(metadata): pub_acc = get_publisher_account() ddo = DDO() ddo.add_service(ServiceTypes.METADATA, 'http://myaquarius.com', values=metadata, index='0') checksums = dict() for service in ddo.services: checksums[str(service.index)] = checksum(service.main) ddo.add_proof(checksums, pub_acc) did = ddo.assign_did(DID.did(ddo.proof['checksum'])) ddo.proof['signatureValue'] = Keeper.sign_hash(did_to_id_bytes(did), pub_acc) ddo.add_public_key(did, pub_acc.address) ddo.add_authentication(did, PUBLIC_KEY_TYPE_RSA)
def agreements(): publisher_acc = get_publisher_account() keeper = Keeper.get_instance() w3 = Web3Provider.get_web3() did_resolver = Mock() ddo = get_ddo_sample() service = ddo.get_service(ServiceTypes.ASSET_ACCESS) service.update_value(ServiceAgreementTemplate.TEMPLATE_ID_KEY, w3.toChecksumAddress(publisher_acc.address)) did_resolver.resolve = MagicMock(return_value=ddo) return Agreements(keeper, did_resolver, AssetConsumer, AssetExecutor, ConfigProvider.get_config())
def test_register(): register_account = get_publisher_account() did_registry = DIDRegistry.get_instance() w3 = Web3 did_seed = new_did() asset_id = did_registry.hash_did(did_seed, register_account.address) checksum_test = w3.keccak(text='checksum') value_test = 'http://localhost:5000' # register DID-> URL assert did_registry.register( did_seed, checksum_test, url=value_test, account=register_account ) is True with pytest.raises(Exception): did_registry.get_did_owner('did:nv' + asset_id) assert did_registry.get_did_owner(asset_id) == register_account.address
def test_search_multiple_provenance_event_tests(): register_account = get_publisher_account() did_registry = DIDRegistry.get_instance() w3 = Web3 did_seed = new_did() asset_id = did_registry.hash_did(did_seed, register_account.address) checksum_test = w3.keccak(text='checksum') activity_id = new_did() provenance_id = new_did() derived_did = new_did() url = 'http://localhost:5000' test_address = w3.toChecksumAddress('068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0') assert did_registry.register(did_seed, checksum_test, url=url, account=register_account, providers=[test_address], activity_id=activity_id) is True did_registry.used(provenance_id, asset_id, register_account.address, activity_id, "", account=register_account, attributes="used test") did_registry.was_derived_from(new_did(), derived_did, asset_id, register_account.address, activity_id, account=register_account, attributes="was derived from") did_registry.was_associated_with(new_did(), asset_id, register_account.address, activity_id, account=register_account, attributes="was associated with") did_registry.acted_on_behalf(new_did(), asset_id, register_account.address, register_account.address, activity_id, '', account=register_account, attributes="acted on behalf") assert len(did_registry.get_provenance_method_events('WAS_GENERATED_BY', Web3.toBytes(hexstr=asset_id))) == 1 assert len( did_registry.get_provenance_method_events('USED', Web3.toBytes(hexstr=asset_id))) == 1 assert len(did_registry.get_provenance_method_events('WAS_DERIVED_FROM', Web3.toBytes(hexstr=derived_did))) == 1 assert len(did_registry.get_provenance_method_events('WAS_ASSOCIATED_WITH', Web3.toBytes(hexstr=asset_id))) == 1 assert len(did_registry.get_provenance_method_events('ACTED_ON_BEHALF', Web3.toBytes(hexstr=asset_id))) == 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 test_providers(): register_account = get_publisher_account() consumer_account = get_consumer_account() did_registry = DIDRegistry.get_instance() w3 = Web3 did_seed = new_did() asset_id = did_registry.hash_did(did_seed, register_account.address) # asset_id = add_0x_prefix(asset_id) checksum_test = w3.keccak(text='checksum') value_test = 'http://localhost:5000' test_address = w3.toChecksumAddress('068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0') # register DID-> URL with pytest.raises(AssertionError): did_registry.register( did_seed, checksum_test, url=value_test, account=register_account, providers=consumer_account.address ) did_registry.register( did_seed, checksum_test, url=value_test, account=register_account, providers=[test_address] ) unknown_asset_id = add_0x_prefix(new_did()) providers = did_registry.get_did_providers(unknown_asset_id) assert len(providers) == 0 assert did_registry.is_did_provider(asset_id, register_account.address) is False providers = did_registry.get_did_providers(asset_id) assert len(providers) == 1 and providers[0] == test_address assert did_registry.is_did_provider(asset_id, test_address) is True removed = did_registry.remove_provider(asset_id, test_address, register_account) assert removed providers = did_registry.get_did_providers(asset_id) assert len(providers) == 0 assert did_registry.is_did_provider(asset_id, test_address) is False did_registry.add_provider(asset_id, test_address, register_account) providers = did_registry.get_did_providers(asset_id) assert len(providers) == 1 and providers[0] == test_address assert did_registry.is_did_provider(asset_id, test_address) is True
def test_transfer_ownership(): register_account = get_publisher_account() did_registry = DIDRegistry.get_instance() w3 = Web3 did_seed = new_did() asset_id = did_registry.hash_did(did_seed, register_account.address) checksum_test = w3.keccak(text='checksum') value_test = 'http://localhost:5000' test_address = w3.toChecksumAddress('068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0') did_registry.register(did_seed, checksum_test, url=value_test, account=register_account, providers=[test_address]) first_owner = did_registry.get_did_owner(asset_id) assert first_owner == register_account.address did_registry.transfer_did_ownership(asset_id, test_address, register_account) assert did_registry.get_did_owner(asset_id) == test_address
def test_provenance_events(): register_account = get_publisher_account() did_registry = DIDRegistry.get_instance() w3 = Web3 did_seed = new_did() asset_id = did_registry.hash_did(did_seed, register_account.address) checksum_test = w3.keccak(text='checksum') activity_id = new_did() provenance_id = new_did() url = 'http://localhost:5000' test_address = w3.toChecksumAddress('068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0') assert did_registry.register(did_seed, checksum_test, url=url, account=register_account, providers=[test_address], activity_id=activity_id) is True did_registry.used(provenance_id, asset_id, test_address, activity_id, "", account=register_account, attributes="used test") assert len(did_registry.get_did_provenance_events(Web3.toBytes(hexstr=asset_id))) == 2
def test_register_with_invalid_params(): register_account = get_publisher_account() did_registry = DIDRegistry.get_instance() w3 = Web3 did_seed = new_did() asset_id = did_registry.hash_did(did_seed, register_account.address) did_test = 'did:nv:' + asset_id checksum_test = w3.keccak(text='checksum') value_test = 'http://localhost:5000' # No checksum provided with pytest.raises(ValueError): did_registry.register(did_seed, '', url=value_test, account=None) # Invalid checksum provided with pytest.raises(ValueError): did_registry.register(did_seed, did_test, url=value_test, account=None) # No account provided with pytest.raises(ValueError): did_registry.register(did_seed, checksum_test, url=value_test, account=None)
def test_sign_and_recover(web3_instance): w3 = web3_instance account = get_publisher_account() msg = 'testing-signature-and-recovery-of-signer-address' msg_hash = w3.keccak(text=msg) signature = Keeper.sign_hash(msg_hash, account) address = w3.toChecksumAddress(Keeper.ec_recover(msg_hash, signature)) assert address == account.address # Signature created on msg with the ethereum prefix. `web3.eth.account.recoverHash` does NOT # add any prefixes to the message, so we have to add the prefix before the call. address = w3.eth.account.recoverHash(msg_hash, signature=signature) assert address == account.address # Now do the opposite, sign with eth.account.sign_hash() (using prefixed msg hash), # then recover address with Keeper.ec_recover() on the msg hash with no prefix. with open(get_resource_path('data', 'publisher_key_file.json')) as kf: key = kf.read() prvkey = w3.eth.account.decrypt(key, account.password) account_sig_prefixed = add_0x_prefix( w3.eth.account.signHash(msg_hash, prvkey)['signature'].hex()) assert Keeper.ec_recover( msg_hash, account_sig_prefixed).lower() == account.address.lower() # Test specific case where message is signed by some Wallet web3 such as Metamask or # burner wallet. Such signature uses the `web3.personal` `sign` method which adds # `Ethereum Signed Message` prefix in a generic way, see `add_ethereum_prefix_and_hash_msg` for details. sig = '0xa9e78d2c088c0b17a8c35b69e0dfa774692ccabed570e40502795bd41f561cf7677ed02bf4ee7967a55979d585bbf203b4a490e1d747e5a4d60a50859d816ac51b' publisher_address = '0x903322C7E45A60d7c8C3EA236c5beA9Af86310c7' doc_id = '028faa498d154388a89dc0dea908a4e27700920217a44abe8f1cdd64953125b8' prefixed_hash = add_ethereum_prefix_and_hash_msg(doc_id) recovered_address = w3.eth.account.recoverHash(prefixed_hash, signature=sig) assert recovered_address == publisher_address recovered_address = Keeper.ec_recover(prefixed_hash, sig) assert recovered_address == publisher_address recovered_address = Keeper.personal_ec_recover(doc_id, sig) assert recovered_address == publisher_address
def test_sign_tx(): # account_address = '0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e' account = get_publisher_account() wallet = Wallet(Web3Provider.get_web3(), account.key_file, account.password, address=account.address) tx_dict = { 'from': '0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e', 'to': '0xc354ba9AD5dF1023C2640b14A09E61a500F21546', 'gas': 153432, 'data': '0x534eb706ff3b98759dc7421dad1f42c4fbc00ceab99e4d849f884fa680398c8e65bcaf1a' '3f4b0356b3399ae841a2c6fce00787cf27dcf08e3b3e65065fea2498e621848f0000000000' '00000000000000000000000000000000000000000000000000008000000000000000000000' '000000000000000000000000000000000000000000a0000000000000000000000000000000' '00000000000000000000000000000000000000000000000000000000000000000000000000' '000000000000000000000078687474703a2f2f6c6f63616c686f73743a353030302f617069' '2f76312f61717561726975732f6173736574732f64646f2f6469643a6f703a666633623938' '37353964633734323164616431663432633466626330306365616239396534643834396638' '3834666136383033393863386536356263616631610000000000000000', 'nonce': 730, 'gasPrice': 1000000000 } Wallet._last_tx_count[account.address] = tx_dict['nonce'] - 1 tx_hash = ( '0xf901aa7d843b9aca008302575894c354ba9ad5df1023c2640b14a09e61a500f2154680b90144534eb706ff3b98759dc7421dad1f42c4fbc00ceab99e4d849f884fa680398c8e65bcaf1a3f4b0356b3399ae841a2c6fce00787cf27dcf08e3b3e65065fea2498e621848f000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000078687474703a2f2f6c6f63616c686f73743a353030302f6170692f76312f61717561726975732f6173736574732f64646f2f6469643a6f703a6666336239383735396463373432316461643166343263346662633030636561623939653464383439663838346661363830333938633865363562636166316100000000000000001ba07ff531911521dd7aab8ea4a96d219033f3b80447cdf5f94a930f10806dd1f8dca006ce5047b2f91a5d895ee0680e7da9168dc8f94899f2263ef26586028613342c' ) signed_tx = wallet.sign_tx(tx_dict) assert signed_tx.hex() == tx_hash
def setup_things(): config = ConfigProvider.get_config() consumer_acc = get_consumer_account(config) publisher_acc = get_publisher_account(config) keeper = Keeper.get_instance() service_definition_id = 'Access' ddo = get_ddo_sample() ddo._did = DID.did() keeper.did_registry.register(ddo.did, checksum=Web3Provider.get_web3().sha3( text=ddo.metadata['base']['checksum']), url='aquarius:5000', account=publisher_acc, providers=None) registered_ddo = ddo asset_id = registered_ddo.asset_id service_agreement = ServiceAgreement.from_ddo(service_definition_id, 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 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 test_royalties_are_valid(): register_account = get_publisher_account() did_registry = DIDRegistry.get_instance() w3 = Web3 did_seed = new_did() asset_id = did_registry.hash_did(did_seed, register_account.address) checksum_test = w3.keccak(text='checksum') activity_id = new_did() new_owner_address = w3.toChecksumAddress('068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0') someone_address = w3.toChecksumAddress('0x00a329c0648769A73afAc7F9381E08FB43dBEA72') url = 'http://localhost:5000' royalties = 20 cap = 0 assert did_registry.register_mintable_did(did_seed, checksum_test, url, cap, royalties, account=register_account, providers=[someone_address], activity_id=activity_id) is True did_registry.transfer_did_ownership(asset_id, new_owner_address, register_account) assert did_registry.are_royalties_valid(asset_id, [80, 20], [someone_address, register_account.address]) is True assert did_registry.are_royalties_valid(asset_id, [90], [someone_address]) is False assert did_registry.are_royalties_valid(asset_id, [90, 10], [someone_address, register_account.address]) is False
"""Test Token Contract.""" import pytest from web3 import Web3 from contracts_lib_py.conditions import LockPaymentCondition from contracts_lib_py.token import Token from contracts_lib_py.keeper import Keeper from tests.resources.helper_functions import get_consumer_account, get_publisher_account consumer_account = get_consumer_account() publisher_account = get_publisher_account() def test_token_contract(): token = Token.get_instance() assert token assert isinstance(token, Token) def test_get_balance(): token = Token.get_instance() assert isinstance(token.get_token_balance(consumer_account.address), int) def test_get_balance_invalid_address(): token = Token.get_instance() with pytest.raises(Exception): token.get_token_balance('not valid') def test_token_approve():