def run_n_nodes(application: str, nodes_amount: int) -> ExonumNetwork: """Creates and runs a network with N validators and return an `ExonumNetwork` object with it.""" address = "127.0.0.1:{}" # Assign peer ports starting from 6331. available_peer_port = 6331 # Assign API ports starting from 8080. available_api_port = 8080 network = ExonumNetwork(application) network.generate_template(nodes_amount) for i in range(nodes_amount): network.generate_config(i, address.format(available_peer_port)) available_peer_port += 1 for i in range(nodes_amount): public_api_address = address.format(available_api_port) private_api_address = address.format(available_api_port + 1) network.finalize(i, public_api_address, private_api_address) available_api_port += 2 for i in range(nodes_amount): network.run_node(i) return network
def run_n_nodes(application: str, nodes_amount: int) -> ExonumNetwork: """Creates and runs a network with N validators and return an `ExonumNetwork` object with it.""" global available_peer_port, available_api_port address = "127.0.0.1:{}" network = ExonumNetwork(application) network.generate_template(nodes_amount) for i in range(nodes_amount): network.generate_config(i, address.format(available_peer_port)) available_peer_port += 1 if available_peer_port > MIN_PEER_PORT + PORT_RANGE: available_peer_port = MIN_PEER_PORT for i in range(nodes_amount): public_api_address = address.format(available_api_port) private_api_address = address.format(available_api_port + 1) network.finalize(i, public_api_address, private_api_address) available_api_port += 2 if available_api_port > MIN_API_PORT + PORT_RANGE: available_api_port = MIN_API_PORT for i in range(nodes_amount): network.run_node(i) return network