Skip to content

Commit

Permalink
Merge pull request #589 from pinheadmz/scenario-help
Browse files Browse the repository at this point in the history
fix scenario help
  • Loading branch information
pinheadmz authored Sep 12, 2024
2 parents 1d27e21 + 14c9ca0 commit 4c613db
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 64 deletions.
8 changes: 4 additions & 4 deletions resources/scenarios/ln_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
6 changes: 2 additions & 4 deletions resources/scenarios/miner_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
from resources.scenarios.commander import Commander


def cli_help():
return "Generate blocks over time. Options: [--allnodes | --interval=<number> | --mature ]"


class Miner:
def __init__(self, node, mature):
self.node = node
Expand All @@ -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",
Expand Down
9 changes: 4 additions & 5 deletions resources/scenarios/reconnaissance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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")
Expand Down
46 changes: 0 additions & 46 deletions resources/scenarios/sens_relay.py

This file was deleted.

2 changes: 2 additions & 0 deletions resources/scenarios/signet_miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions resources/scenarios/tx_flood.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
from resources.scenarios.commander import Commander


def cli_help():
return "Make a big transaction mess. Options: [--interval=<number>]"


class TXFlood(Commander):
def set_test_params(self):
self.num_nodes = 1
self.addrs = []
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",
Expand Down
8 changes: 7 additions & 1 deletion src/warnet/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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])

Expand Down

0 comments on commit 4c613db

Please sign in to comment.