Skip to content

Commit 4c613db

Browse files
authored
Merge pull request #589 from pinheadmz/scenario-help
fix scenario help
2 parents 1d27e21 + 14c9ca0 commit 4c613db

File tree

7 files changed

+23
-64
lines changed

7 files changed

+23
-64
lines changed

resources/scenarios/ln_init.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
from resources.scenarios.commander import Commander
1010

1111

12-
def cli_help():
13-
return "Fund LN wallets and open channels"
14-
15-
1612
class LNInit(Commander):
1713
def set_test_params(self):
1814
self.num_nodes = None
1915

16+
def add_options(self, parser):
17+
parser.description = "Fund LN wallets and open channels"
18+
parser.usage = "warnet run /path/to/ln_init.py"
19+
2020
def run_test(self):
2121
self.log.info("Lock out of IBD")
2222
miner = self.ensure_miner(self.nodes[0])

resources/scenarios/miner_std.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
from resources.scenarios.commander import Commander
1010

1111

12-
def cli_help():
13-
return "Generate blocks over time. Options: [--allnodes | --interval=<number> | --mature ]"
14-
15-
1612
class Miner:
1713
def __init__(self, node, mature):
1814
self.node = node
@@ -28,6 +24,8 @@ def set_test_params(self):
2824
self.miners = []
2925

3026
def add_options(self, parser):
27+
parser.description = "Generate blocks over time"
28+
parser.usage = "warnet run /path/to/miner_std.py [options]"
3129
parser.add_argument(
3230
"--allnodes",
3331
dest="allnodes",

resources/scenarios/reconnaissance.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
from test_framework.p2p import MAGIC_BYTES, P2PInterface
1515

1616

17-
# This message is provided to the user when they describe the scenario
18-
def cli_help():
19-
return "Demonstrate network reconnaissance using a scenario and P2PInterface"
20-
21-
2217
def get_signet_network_magic_from_node(node):
2318
template = node.getblocktemplate({"rules": ["segwit", "signet"]})
2419
challenge = template["signet_challenge"]
@@ -37,6 +32,10 @@ def set_test_params(self):
3732
# a sub-class of BitcoinTestFramework
3833
self.num_nodes = 1
3934

35+
def add_options(self, parser):
36+
parser.description = "Demonstrate network reconnaissance using a scenario and P2PInterface"
37+
parser.usage = "warnet run /path/to/reconnaissance.py"
38+
4039
# Scenario entrypoint
4140
def run_test(self):
4241
self.log.info("Getting peer info")

resources/scenarios/sens_relay.py

Lines changed: 0 additions & 46 deletions
This file was deleted.

resources/scenarios/signet_miner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def set_test_params(self):
4646
self.num_nodes = 1
4747

4848
def add_options(self, parser):
49+
parser.description = "Generate blocks on a signet network"
50+
parser.usage = "warnet run /path/to/signet_miner.py [options]"
4951
parser.add_argument(
5052
"--tank",
5153
dest="tank",

resources/scenarios/tx_flood.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
from resources.scenarios.commander import Commander
1111

1212

13-
def cli_help():
14-
return "Make a big transaction mess. Options: [--interval=<number>]"
15-
16-
1713
class TXFlood(Commander):
1814
def set_test_params(self):
1915
self.num_nodes = 1
2016
self.addrs = []
2117
self.threads = []
2218

2319
def add_options(self, parser):
20+
parser.description = (
21+
"Sends random transactions between all nodes with available balance in their wallet"
22+
)
23+
parser.usage = "warnet run /path/to/tx_flood.py [options]"
2424
parser.add_argument(
2525
"--interval",
2626
dest="interval",

src/warnet/control.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import os
44
import subprocess
5+
import sys
56
import time
67
from concurrent.futures import ThreadPoolExecutor, as_completed
78
from pathlib import Path
@@ -188,7 +189,10 @@ def get_active_network(namespace):
188189
@click.argument("scenario_file", type=click.Path(exists=True, file_okay=True, dir_okay=False))
189190
@click.argument("additional_args", nargs=-1, type=click.UNPROCESSED)
190191
def run(scenario_file: str, additional_args: tuple[str]):
191-
"""Run a scenario from a file"""
192+
"""
193+
Run a scenario from a file.
194+
Pass `-- --help` to get individual scenario help
195+
"""
192196
scenario_path = Path(scenario_file).resolve()
193197
scenario_name = scenario_path.stem
194198

@@ -233,6 +237,8 @@ def run(scenario_file: str, additional_args: tuple[str]):
233237
# Add additional arguments
234238
if additional_args:
235239
helm_command.extend(["--set", f"args={' '.join(additional_args)}"])
240+
if "--help" in additional_args or "-h" in additional_args:
241+
return subprocess.run([sys.executable, scenario_path, "--help"])
236242

237243
helm_command.extend([name, COMMANDER_CHART])
238244

0 commit comments

Comments
 (0)