diff --git a/resources/scenarios/ln_init.py b/resources/scenarios/ln_init.py index e915ee721..59df5e38e 100644 --- a/resources/scenarios/ln_init.py +++ b/resources/scenarios/ln_init.py @@ -9,14 +9,14 @@ from resources.scenarios.commander import Commander -def cli_help(): - return "Fund LN wallets and open channels" - - class LNInit(Commander): def set_test_params(self): self.num_nodes = None + def add_options(self, parser): + parser.description = "Fund LN wallets and open channels" + parser.usage = "warnet run /path/to/ln_init.py" + def run_test(self): self.log.info("Lock out of IBD") miner = self.ensure_miner(self.nodes[0]) diff --git a/resources/scenarios/miner_std.py b/resources/scenarios/miner_std.py index fcfea9841..5aa368d40 100755 --- a/resources/scenarios/miner_std.py +++ b/resources/scenarios/miner_std.py @@ -9,10 +9,6 @@ from resources.scenarios.commander import Commander -def cli_help(): - return "Generate blocks over time. Options: [--allnodes | --interval= | --mature ]" - - class Miner: def __init__(self, node, mature): self.node = node @@ -28,6 +24,8 @@ def set_test_params(self): self.miners = [] def add_options(self, parser): + parser.description = "Generate blocks over time" + parser.usage = "warnet run /path/to/miner_std.py [options]" parser.add_argument( "--allnodes", dest="allnodes", diff --git a/resources/scenarios/reconnaissance.py b/resources/scenarios/reconnaissance.py index 1440b119b..3fc2269e4 100755 --- a/resources/scenarios/reconnaissance.py +++ b/resources/scenarios/reconnaissance.py @@ -14,11 +14,6 @@ from test_framework.p2p import MAGIC_BYTES, P2PInterface -# This message is provided to the user when they describe the scenario -def cli_help(): - return "Demonstrate network reconnaissance using a scenario and P2PInterface" - - def get_signet_network_magic_from_node(node): template = node.getblocktemplate({"rules": ["segwit", "signet"]}) challenge = template["signet_challenge"] @@ -37,6 +32,10 @@ def set_test_params(self): # a sub-class of BitcoinTestFramework self.num_nodes = 1 + def add_options(self, parser): + parser.description = "Demonstrate network reconnaissance using a scenario and P2PInterface" + parser.usage = "warnet run /path/to/reconnaissance.py" + # Scenario entrypoint def run_test(self): self.log.info("Getting peer info") diff --git a/resources/scenarios/sens_relay.py b/resources/scenarios/sens_relay.py deleted file mode 100644 index 210b43760..000000000 --- a/resources/scenarios/sens_relay.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python3 - -# The base class exists inside the commander container -try: - from commander import Commander -except ImportError: - from resources.scenarios.commander import Commander - - -def cli_help(): - return "Send a transaction using sensitive relay" - - -class MinerStd(Commander): - def set_test_params(self): - self.num_nodes = 12 - - def run_test(self): - # PR branch node - test_node = self.nodes[11] - test_wallet = self.ensure_miner(test_node) - addr = test_wallet.getnewaddress() - - self.log.info("generating 110 blocks...") - self.generatetoaddress(test_node, 110, addr, sync_fun=self.no_op) - - self.log.info("adding onion addresses from all peers...") - for i in range(11): - info = self.nodes[i].getnetworkinfo() - for addr in info["localaddresses"]: - if "onion" in addr["address"]: - self.log.info(f"adding {addr['address']}:{addr['port']}") - test_node.addpeeraddress(addr["address"], addr["port"]) - - self.log.info("getting address from recipient...") - # some other node - recip = self.nodes[5] - recip_wallet = self.ensure_miner(recip) - recip_addr = recip_wallet.getnewaddress() - - self.log.info("sending transaction...") - self.log.info(test_wallet.sendtoaddress(recip_addr, 0.5)) - - -if __name__ == "__main__": - MinerStd().main() diff --git a/resources/scenarios/signet_miner.py b/resources/scenarios/signet_miner.py index 2a09b1f0c..0edc635e3 100644 --- a/resources/scenarios/signet_miner.py +++ b/resources/scenarios/signet_miner.py @@ -46,6 +46,8 @@ def set_test_params(self): self.num_nodes = 1 def add_options(self, parser): + parser.description = "Generate blocks on a signet network" + parser.usage = "warnet run /path/to/signet_miner.py [options]" parser.add_argument( "--tank", dest="tank", diff --git a/resources/scenarios/tx_flood.py b/resources/scenarios/tx_flood.py index 5da5f8b53..a4896e958 100755 --- a/resources/scenarios/tx_flood.py +++ b/resources/scenarios/tx_flood.py @@ -10,10 +10,6 @@ from resources.scenarios.commander import Commander -def cli_help(): - return "Make a big transaction mess. Options: [--interval=]" - - class TXFlood(Commander): def set_test_params(self): self.num_nodes = 1 @@ -21,6 +17,10 @@ def set_test_params(self): self.threads = [] def add_options(self, parser): + parser.description = ( + "Sends random transactions between all nodes with available balance in their wallet" + ) + parser.usage = "warnet run /path/to/tx_flood.py [options]" parser.add_argument( "--interval", dest="interval", diff --git a/src/warnet/control.py b/src/warnet/control.py index aa5991a92..c2a115fa4 100644 --- a/src/warnet/control.py +++ b/src/warnet/control.py @@ -2,6 +2,7 @@ import json import os import subprocess +import sys import time from concurrent.futures import ThreadPoolExecutor, as_completed from pathlib import Path @@ -188,7 +189,10 @@ def get_active_network(namespace): @click.argument("scenario_file", type=click.Path(exists=True, file_okay=True, dir_okay=False)) @click.argument("additional_args", nargs=-1, type=click.UNPROCESSED) def run(scenario_file: str, additional_args: tuple[str]): - """Run a scenario from a file""" + """ + Run a scenario from a file. + Pass `-- --help` to get individual scenario help + """ scenario_path = Path(scenario_file).resolve() scenario_name = scenario_path.stem @@ -233,6 +237,8 @@ def run(scenario_file: str, additional_args: tuple[str]): # Add additional arguments if additional_args: helm_command.extend(["--set", f"args={' '.join(additional_args)}"]) + if "--help" in additional_args or "-h" in additional_args: + return subprocess.run([sys.executable, scenario_path, "--help"]) helm_command.extend([name, COMMANDER_CHART])