def test_heartbeat(dbsession, eth_network_id, eth_service): """Create Ethereum account on Ethereum node.""" update_heart_beat(dbsession, eth_network_id, 555, 555) with transaction.manager: network = dbsession.query(AssetNetwork).get(eth_network_id) assert is_network_alive(network, current_time=556) assert not is_network_alive(network, current_time=999)
def setup_house(request): """Setup different networks supported by the instance. Setup house wallets on each network. Setup ETH giveaway on testnet and private testnet. """ dbsession = request.dbsession services = ServiceCore.parse_network_config(request) networks = services.keys() for network_name in networks: print("Setting up house wallet on ", network_name) network = get_eth_network(dbsession, network_name) assert is_network_alive(network), "Network was dead when we started to create address {}".format(network) dbsession.flush() house_address = get_house_address(network) if not house_address: create_house_address(network) if not "initial_assets" in network.other_data: network.other_data["initial_assets"] = {} if network_name == "testnet": network.other_data["human_friendly_name"] = "Ethereum Testnet" # Setup testnet ETH give away if network_name in ("testnet", "private testnet"): network.other_data["initial_assets"]["eth_amount"] = "5.0"
def ensure_networks_online(request): """Give time to ethereum-service process to catch up. Don't go forward until we have confirmed that Ethereum service is alive and talking to us. """ services = ServiceCore.parse_network_config(request) networks = services.keys() while True: remaining_networks = [] network_stats = [] for network_name in networks: with transaction.manager: network = get_eth_network(request.dbsession, network_name) if not is_network_alive(network): remaining_networks.append(network_name) network_stats.append(dump_network_heartbeat(network)) if remaining_networks: print("Waiting ethereum-service to wake up for networks ", network_stats) time.sleep(15) networks = remaining_networks else: break print("All networks green")
def check_op_completion(id): op = dbsession.query(CryptoOperation).get(id) network = op.network if not is_network_alive(network): time.sleep(5) # Give some extra time to recover if not is_network_alive(network): raise RuntimeError("Tried to complete against dead network: {}, op {}".format(network, op)) # Cleared this item if op.completed_at: logger.info("Finished %s", op) return True if op.failed_at: raise RuntimeError("Op failed while waiting: {}".format(op)) return False
def check_op_completion(id): op = dbsession.query(CryptoOperation).get(id) network = op.network if not is_network_alive(network): time.sleep(5) # Give some extra time to recover if not is_network_alive(network): raise RuntimeError( "Tried to complete against dead network: {}, op {}".format( network, op)) # Cleared this item if op.completed_at: logger.info("Finished %s", op) return True if op.failed_at: raise RuntimeError("Op failed while waiting: {}".format(op)) return False