def test_etherscan_url_mainnet(): # address url = get_etherscan_url(network=NetworksInventory.MAINNET, url_type=EtherscanURLType.ADDRESS, address_or_tx_hash=ADDRESS_OR_TX_HASH) assert url == f"https://etherscan.io/address/{ADDRESS_OR_TX_HASH}" # transaction url = get_etherscan_url(network=NetworksInventory.MAINNET, url_type=EtherscanURLType.TRANSACTION, address_or_tx_hash=ADDRESS_OR_TX_HASH) assert url == f"https://etherscan.io/tx/{ADDRESS_OR_TX_HASH}"
def test_etherscan_url_goerli(chain_id_func): # address url = get_etherscan_url( network='rando-goerli', # name irrelevant because of patch url_type=EtherscanURLType.ADDRESS, address_or_tx_hash=ADDRESS_OR_TX_HASH) assert url == f"https://goerli.etherscan.io/address/{ADDRESS_OR_TX_HASH}" # transaction url = get_etherscan_url( network='rando-goerli', # name irrelevant because of patch url_type=EtherscanURLType.TRANSACTION, address_or_tx_hash=ADDRESS_OR_TX_HASH) assert url == f"https://goerli.etherscan.io/tx/{ADDRESS_OR_TX_HASH}"
def make_contract_row(network: str, agent, balance: NU = None): contract_name = agent.contract_name contract_address = agent.contract_address cells = [ html.A(f'{contract_name} {contract_address} ({agent.contract.version})', id=f"{contract_name}-contract-address", href=get_etherscan_url(network, EtherscanURLType.ADDRESS, contract_address)) ] if balance is not None: cells.append(html.Span(balance)) row = html.Tr(cells) return row
def generate_node_row(network: str, node_info: dict) -> dict: staker_address = node_info['staker_address'] etherscan_url = get_etherscan_url(network, EtherscanURLType.ADDRESS, staker_address) slang_last_seen = get_last_seen(node_info) status = node_info['status']['status'] status_image_path = STATUS_IMAGE_PATHS[status] node_row = { NODE_TABLE_COLUMNS[0]: f'![{status}]({status_image_path})', NODE_TABLE_COLUMNS[1]: f'[{staker_address[:10]}...]({etherscan_url})', NODE_TABLE_COLUMNS[2]: f'[{node_info["nickname"]}]({NODE_STATUS_URL_TEMPLATE.format(node_info["rest_url"])})', NODE_TABLE_COLUMNS[3]: node_info['uptime'], NODE_TABLE_COLUMNS[4]: slang_last_seen, NODE_TABLE_COLUMNS[5]: node_info['fleet_state_icon'], #'Peers ': html.Td(node_info['peers']), # TODO } return node_row
def test_etherscan_url_invalid_inputs(): # no network with pytest.raises(ValueError): get_etherscan_url(network=None, url_type=EtherscanURLType.ADDRESS, address_or_tx_hash=ADDRESS_OR_TX_HASH) with pytest.raises(ValueError): get_etherscan_url(network='', url_type=EtherscanURLType.ADDRESS, address_or_tx_hash=ADDRESS_OR_TX_HASH) # unknown network with pytest.raises(ValueError): get_etherscan_url(network='pandora', url_type=EtherscanURLType.TRANSACTION, address_or_tx_hash=ADDRESS_OR_TX_HASH) # None url type with pytest.raises(ValueError): get_etherscan_url(network=NetworksInventory.IBEX, url_type=None, address_or_tx_hash=ADDRESS_OR_TX_HASH) # no hash with pytest.raises(ValueError): get_etherscan_url(network=NetworksInventory.IBEX, url_type=EtherscanURLType.TRANSACTION, address_or_tx_hash=None) with pytest.raises(ValueError): get_etherscan_url(network=NetworksInventory.IBEX, url_type=EtherscanURLType.TRANSACTION, address_or_tx_hash='')