def test_ec_recover(): test_values = [ ('0xe2DD09d719Da89e5a3D0F2549c7E24566e947260', 'c80996119e884cb38599bcd96a22ad3eea3a4734bcfb47959a5d41ecdcbdfe67', '0xa50427a9d5beccdea3eeabecfc1014096b35cd05965e772e8ea32477d2f217' 'c30d0ec5dbf6b14de1d6eeff45011d17490fe5126576b20d2cbada828cb068c9f801' ), ('0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e', 'd77c3a84cafe4cb8bc28bf41a99c63fd530c10da33a54acf94e8d1369d09fbb2', '0x9076b561e554cf657af333d9680ba118d556c5b697622636bce4b02f4d5632' '5a0ea6a474ca85291252c8c1b8637174ee32072bef357bb0c21b0db4c25b379e781b' ), ('0xe2DD09d719Da89e5a3D0F2549c7E24566e947260', '8d5c1065a9c74da59fbb9e41d1f196e40517e92d81b14c3a8143d6887f3f4438', '0x662f6cffd96ada4b6ce5497d444c92126bd053ab131915332edf0dbba716ba' '82662275670c95eb2a4d65245cac70313c25e34f594d7c0fbca5232c3d5701a57e00' ) ] for expected_address, document_id, signed_document_id in test_values: rec_address = Keeper.get_instance().ec_recover(document_id, signed_document_id) if expected_address.lower() == rec_address.lower(): msg_hsh = prepare_prefixed_hash(document_id) rec_address = Keeper.get_instance().ec_recover( msg_hsh, signed_document_id) assert expected_address.lower() == rec_address.lower()
def verify_contracts(): """ Verify that the contracts are deployed correctly in the network. :raise Exception: raise exception if the contracts are not deployed correctly. """ artifacts_path = Keeper.get_instance().artifacts_path logger.info( f'Keeper contract artifacts (JSON abi files) at: {artifacts_path}') if os.environ.get('KEEPER_NETWORK_NAME'): logger.warning( f'The `KEEPER_NETWORK_NAME` env var is set to ' f'{os.environ.get("KEEPER_NETWORK_NAME")}. ' f'This enables the user to override the method of how the network name ' f'is inferred from network id.') # try to find contract with this network name contract_name = Diagnostics.TEST_CONTRACT_NAME network_id = Keeper.get_network_id() network_name = Keeper.get_network_name(network_id) logger.info(f'Using keeper contracts from network {network_name}, ' f'network id is {network_id}') logger.info( f'Looking for keeper contracts ending with ".{network_name}.json", ' f'e.g. "{contract_name}.{network_name}.json".') existing_contract_names = os.listdir(artifacts_path) try: ContractHandler.get(contract_name) except Exception as e: logger.error(e) logger.error( f'Cannot find the keeper contracts. \n' f'Current network id is {network_id} and network name is {network_name}.' f'Expected to find contracts ending with ".{network_name}.json",' f' e.g. "{contract_name}.{network_name}.json"') raise ContractsNotFound( f'Keeper contracts for keeper network {network_name} were not found ' f'in {artifacts_path}. \n' f'Found the following contracts: \n\t{existing_contract_names}' ) keeper = Keeper.get_instance() contracts = [ keeper.token, keeper.did_registry, keeper.agreement_manager, keeper.template_manager, keeper.condition_manager, keeper.access_condition, keeper.sign_condition, keeper.lock_payment_condition, keeper.access_template, keeper.escrow_payment_condition, keeper.hash_lock_condition ] addresses = '\n'.join([f'\t{c.name}: {c.address}' for c in contracts]) logging.info('Finished loading keeper contracts:\n' '%s', addresses)
def test_load_external_contract(external_contract): address, abi, name = external_contract keeper = Keeper.get_instance(external_contracts=[external_contract]) contract = keeper.get_contract(name) assert contract is not None assert contract.address == address assert contract.CONTRACT_NAME == name
def test_artifacts_path(): artifacts_path = '/some/other/path' keeper = Keeper.get_instance(artifacts_path) assert keeper.artifacts_path == artifacts_path
def test_keeper_instance(): keeper = Keeper(ContractHandler.artifacts_path) assert keeper assert isinstance(keeper.get_instance(), Keeper)
def keeper(): return Keeper.get_instance()
def init_ocn_tokens(ocn, account, amount=100): ocn.accounts.request_tokens(account, amount) Keeper.get_instance().token.token_approve( Keeper.get_instance().dispenser.address, amount, account)
def get_network_name(): return Keeper.get_instance().get_network_name( Keeper.get_instance().get_network_id())
def setup_keeper(): Web3Provider._web3 = Web3(CustomHTTPProvider(get_keeper_url())) ContractHandler.artifacts_path = os.path.expanduser( '~/.nevermined/nevermined-contracts/artifacts') Keeper.get_instance(artifacts_path=ContractHandler.artifacts_path)
def keeper_instance(): # Init web3 before fetching keeper instance. web3() external_contracts = get_config().external_contracts return Keeper.get_instance(external_contracts=external_contracts)