def pytest_sessionstart(session): """ Start the test session by sending initial test funds. Will block until transactions are confirmed on-chain. """ assert util.is_active_shard(endpoints[0], delay_tolerance=20), "Shard 0 is not making progress..." assert util.is_active_shard(endpoints[1], delay_tolerance=20), "Shard 1 is not making progress..." # Send all txs. Note that this is the only place to break the txs invariant. for tx in initial_funding: response = base_request('hmy_sendRawTransaction', params=[tx["signed-raw-tx"]], endpoint=endpoints[tx["from-shard"]]) assert is_valid_json_rpc(response), f"Invalid JSON response: {response}" # Do not check for errors since resending initial txs is fine & failed txs will be caught in confirm timeout. # Confirm all txs within 2x timeout window (since all initial txs could be in 2 blocks). start_time = time.time() while time.time() - start_time <= 2 * tx_timeout: sent_txs = [] for tx in initial_funding: tx_response = get_transaction(tx["hash"], tx["from-shard"]) if (tx_response is not None): sent_txs.append(tx_response['blockNumber'] is not None) else: sent_txs.append(tx_response is not None) if all(sent_txs): return raise AssertionError("Could not confirm initial transactions on-chain.")
def fn(machine): # returning None marks success for this function try: node_metadata = blockchain.get_node_metadata( f"http://{machine['ip']}:9500/", timeout=15) sharding_structure = blockchain.get_sharding_structure( f"http://{machine['ip']}:9500/", timeout=15) except (rpc_exceptions.RPCError, rpc_exceptions.RequestsTimeoutError, rpc_exceptions.RequestsError) as e: log.error(traceback.format_exc()) return f"error on RPC from {machine['ip']}. Error {e}" shard, role, network = node_metadata['shard-id'], node_metadata[ 'role'], node_metadata['network'] is_leader, is_archival = node_metadata['is-leader'], node_metadata[ 'is-archival'] if int(shard) != int(machine['shard']): return f"configured shard {machine['shard']} != actual node shard of {shard}. (ip: {machine['ip']})" if condition['role'] != role: return f"configured node role {condition['role']} != actual node role of {role}. (ip: {machine['ip']})" if condition['network'] != network: return f"configured node network {condition['network']} != actual node network of {network}. (ip: {machine['ip']})" if condition['is_leader'] != is_leader: return f"configured node is_leader {condition['is_leader']} != actual node is_leader {is_leader}. (ip: {machine['ip']})" if condition['is_archival'] != is_archival: return f"configured node is_archival {condition['is_archival']} != actual node is_archival {is_archival}. (ip: {machine['ip']})" if not is_active_shard(f"http://{machine['ip']}:9500/", condition['max_seconds_since_last_block']): return f"configured node is either offline or latest block is" \ f" older than {condition['max_seconds_since_last_block']} seconds. (ip: {machine['ip']})" if _is_dns_node(machine, sharding_structure): return f"machine is a DNS node, which cannot be offline. (ip: {machine['ip']})" if _is_rclone_running(machine): return f"machine is running rclone, possibly another snapshot is running. (ip: {machine['ip']})" return None # indicate success
def test_is_active_shard(): assert isinstance(util.is_active_shard(''), bool)
f"{util.Typgpy.HEADER}Transaction for shard {shard}:\n{util.Typgpy.OKGREEN}" f"{cli.single_call(command, timeout=int(args.timeout) * len(endpoints) * len(accounts_info))}" f"{util.Typgpy.ENDC}") return total_amt if __name__ == "__main__": args = parse_args() assert os.path.isfile(args.config), f"`{args.config}` is not a file." setup() net_config = get_network_config() chain_id = get_chain_id(net_config) endpoints = get_endpoints(net_config) if not args.force: for ep in endpoints: assert util.is_active_shard( ep, delay_tolerance=200), f"`{ep}` is not an active endpoint" if os.environ['HMY_PROFILE'] is None: raise RuntimeError("Profile is not set, exiting...") print(f"{util.Typgpy.BOLD}Importing keys{util.Typgpy.ENDC}") accounts_info = load_accounts() init_bal = 0 for bal in get_balance_from_node_ip(args.dest_address, endpoints): init_bal += bal["amount"] print( f"{util.Typgpy.OKBLUE}Consolidating funds to: {util.Typgpy.OKGREEN}{args.dest_address}{util.Typgpy.ENDC}" ) print( f"{util.Typgpy.OKBLUE}Consolidating using endpoints: {util.Typgpy.OKGREEN}{endpoints}{util.Typgpy.ENDC}" )