def register_test_list(pytestconfig, convex, provenance_contract, accounts): global test_event_list account_test = accounts[0] account_other = accounts[1] if not test_event_list: test_event_list = [] event_count = 10 topup_accounts(convex, accounts) register_account = account_other for index in range(0, event_count): if index % 2 == 0: asset_id_hex = secrets.token_hex(32) asset_id = f'0x{asset_id_hex}' if register_account.address == account_test.address: register_account = account_other else: register_account = account_test result = provenance_contract.send(f'(register {asset_id})', register_account) assert (result) record = result['value'] assert (record['owner'] == register_account.address) record['asset_id'] = asset_id test_event_list.append(record) return test_event_list
def test_bad_asset_id(convex, provenance_contract, accounts): account_test = accounts[0] topup_accounts(convex, account_test) bad_asset_id = '0x' + secrets.token_hex(20) with pytest.raises(ConvexAPIError, match='INVALID'): result = provenance_contract.send(f'(register {bad_asset_id})', account_test)
def test_contract_did_transfer(convex, did_contract, accounts): # register and transfer account_test = accounts[0] account_other = accounts[1] topup_accounts(convex, accounts) did_hex = secrets.token_hex(32) did = f'0x{did_hex}' ddo = 'test - ddo' command = f'(register {did} "{ddo}")' result = did_contract.send(command, account_test) assert (result['value']) assert (result['value'] == did_hex) # call owner? on owner account command = f'(owner? {did})' result = did_contract.query(command, account_test) assert (result['value']) # call owner? on account_other command = f'(owner? {did})' result = did_contract.query(command, account_other) assert (not result['value']) command = f'(transfer {did} {account_other.address})' result = did_contract.send(command, account_test) assert (result['value']) assert (result['value'][0] == did_hex) #check ownership to different accounts # call owner? on owner account command = f'(owner? {did})' result = did_contract.query(command, account_test) assert (not result['value']) # call owner? on account_other command = f'(owner? {did})' result = did_contract.query(command, account_other) assert (result['value']) # call unregister fail - from account_test (old owner) with pytest.raises(ConvexAPIError, match='NOT-OWNER'): command = f'(unregister {did})' result = did_contract.send(command, account_test) # call unregister from account_other ( new owner ) command = f'(unregister {did})' result = did_contract.send(command, account_other) assert (result['value']) assert (result['value'] == did_hex)
def accounts(config, convex): result = [] # load in the test accounts account_1 = config['accounts']['account1'] keypair_import = KeyPair.import_from_file(account_1['keyfile'], account_1['password']) accounts = [ convex.setup_account(account_1['name'], keypair_import), convex.create_account(keypair_import), ] topup_accounts(convex, accounts) return accounts
def test_contract_did_bulk_register(convex, did_contract, accounts): account_test = accounts[0] for index in range(0, 2): topup_accounts(convex, account_test) did_hex = secrets.token_hex(32) did = f'0x{did_hex}' # ddo = secrets.token_hex(51200) ddo = secrets.token_hex(1024) command = f'(register {did} "{ddo}")' result = did_contract.send(command, account_test) assert (result['value']) assert (result['value'] == did_hex)
def test_provenance_contract_event_owner_list(convex, provenance_contract, accounts, register_test_list): account_other = accounts[1] topup_accounts(convex, account_other) record = register_test_list[secrets.randbelow(len(register_test_list))] owner_count = 0 for item in register_test_list: if item['owner'] == record['owner']: owner_count += 1 owner_address = to_address(record['owner']) result = provenance_contract.query(f'(owner-list {owner_address})', account_other) asset_list = result['value'] assert (asset_list) assert (len(asset_list) >= owner_count)
def test_provenance_contract_event_list(convex, provenance_contract, accounts, register_test_list): account_test = accounts[0] topup_accounts(convex, account_test) record = register_test_list[secrets.randbelow(len(register_test_list))] asset_id = record['asset_id'] result = provenance_contract.query(f'(event-list {asset_id})', account_test) assert (result) event_list = result['value'] assert (event_list) assert (len(event_list) == 2) event_item = event_list[0] assert (event_item['owner'] == record['owner']) assert (event_item['timestamp'])
def test_contract_did_register_assert_did(convex, did_contract, accounts): topup_accounts(convex, accounts) account_test = accounts[0] did_bad = secrets.token_hex(20) did_valid = secrets.token_hex(32) ddo = 'test - ddo' command = f'(register "{did_bad}" "{ddo}")' with pytest.raises(ConvexAPIError, match='INVALID'): result = did_contract.send(command, account_test) command = f'(register "" "{ddo}")' with pytest.raises(ConvexAPIError, match='INVALID'): result = did_contract.send(command, account_test) command = f'(register 42 "{ddo}")' with pytest.raises(ConvexAPIError, match='INVALID'): result = did_contract.send(command, account_test) command = f'(register 0x{did_valid} "{ddo}")' result = did_contract.send(command, account_test) assert (result['value']) assert (result['value'] == did_valid)
def test_contract_did_owner_list(convex, did_contract, accounts): account_test = accounts[0] account_other = accounts[1] did_list = [] for index in range(0, 4): topup_accounts(convex, accounts) did_hex = secrets.token_hex(32) did = f'0x{did_hex}' did_list.append(did_hex) # ddo = secrets.token_hex(51200) ddo = f'ddo test - {index}' command = f'(register {did} "{ddo}")' result = did_contract.send(command, account_test) assert (result['value']) assert (result['value'] == did_hex) command = f'(owner-list {account_test.address})' result = did_contract.query(command) assert (result['value']) for did_value in did_list: assert (did_value in result['value'])
def test_contract_did_register_resolve(convex, did_contract, accounts): account_test = accounts[0] account_other = accounts[1] topup_accounts(convex, accounts) did_hex = secrets.token_hex(32) did = f'0x{did_hex}' ddo = 'test - ddo' # call register command = f'(register {did} "{ddo}")' result = did_contract.send(command, account_test) assert (result['value']) assert (result['value'] == did_hex) # call resolve did to ddo command = f'(resolve {did})' result = did_contract.query(command) assert (result['value']) assert (result['value'] == ddo) # call resolve did to ddo on other account command = f'(resolve {did})' result = did_contract.query(command) assert (result['value']) assert (result['value'] == ddo) # call owner? on owner account command = f'(owner? {did})' result = did_contract.query(command, account_test) assert (result['value']) # call owner? on owner account_other command = f'(owner? {did})' result = did_contract.query(command, account_other) assert (not result['value']) # call resolve unknown bad_did = f'0x{secrets.token_hex(32)}' command = f'(resolve {bad_did})' result = did_contract.query(command) assert (result['value'] is None) new_ddo = 'new - ddo' # call register - update command = f'(register {did} "{new_ddo}")' result = did_contract.send(command, account_test) assert (result['value']) assert (result['value'] == did_hex) # call register - update from other account with pytest.raises(ConvexAPIError, match='NOT-OWNER'): command = f'(register {did} "{ddo}")' result = did_contract.send(command, account_other) # call resolve did to new_ddo command = f'(resolve {did})' result = did_contract.query(command) assert (result['value']) assert (result['value'] == new_ddo) # call unregister fail - from other account with pytest.raises(ConvexAPIError, match='NOT-OWNER'): command = f'(unregister {did})' result = did_contract.send(command, account_other) # call unregister command = f'(unregister {did})' result = did_contract.send(command, account_test) assert (result['value']) assert (result['value'] == did_hex) # call resolve did to empty command = f'(resolve {did})' result = did_contract.query(command) assert (result['value'] is None) # call unregister - unknown did command = f'(unregister {bad_did})' result = did_contract.send(command, account_test) assert (result['value'] is None)