def get_contract_dict_by_name(contract_name): """ Retrieve the Contract instance for a given contract name. :param contract_name: str :return: the smart contract's definition from the json abi file, dict """ network_name = Keeper.get_network_name(Keeper.get_network_id()).lower() artifacts_path = ConfigProvider.get_config().keeper_path # file_name = '{}.{}.json'.format(contract_name, network_name) # path = os.path.join(keeper.artifacts_path, file_name) path = ContractHandler._get_contract_file_path(artifacts_path, contract_name, network_name) if not (path and os.path.exists(path)): path = ContractHandler._get_contract_file_path( artifacts_path, contract_name, network_name.lower()) if not (path and os.path.exists(path)): path = ContractHandler._get_contract_file_path( artifacts_path, contract_name, Keeper.DEFAULT_NETWORK_NAME) if not (path and os.path.exists(path)): raise FileNotFoundError(f'Keeper contract {contract_name} file ' f'not found in {artifacts_path} ' f'using network name {network_name}') with open(path) as f: contract_dict = json.loads(f.read()) return contract_dict
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 = ConfigProvider.get_config().keeper_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 OceanKeeperContractsNotFound( 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.dispenser, keeper.token, keeper.did_registry, keeper.agreement_manager, keeper.template_manager, keeper.condition_manager, keeper.access_secret_store_condition, keeper.sign_condition, keeper.lock_reward_condition, keeper.escrow_access_secretstore_template, keeper.escrow_reward_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_keeper_networks(): keeper = Keeper() assert isinstance(keeper.get_network_id(), int) assert keeper.get_network_name(1) == Keeper._network_name_map.get(1) assert keeper.get_network_name(2) == Keeper._network_name_map.get(2) assert keeper.get_network_name(3) == Keeper._network_name_map.get(3) assert keeper.get_network_name(4) == Keeper._network_name_map.get(4) assert keeper.get_network_name(42) == Keeper._network_name_map.get(42) assert keeper.get_network_name(77) == Keeper._network_name_map.get(77) assert keeper.get_network_name(99) == Keeper._network_name_map.get(99) assert keeper.get_network_name(8995) == Keeper._network_name_map.get(8995) assert keeper.get_network_name(8996) == Keeper._network_name_map.get(8996) assert keeper.get_network_name(0) == 'development'