From ff4b8d7e9ca2cfd4a4ce7a78fe96be3dcb729c20 Mon Sep 17 00:00:00 2001 From: Matthew Zipkin Date: Wed, 2 Oct 2024 09:45:38 -0400 Subject: [PATCH] scenarios: miner_std should accept single --tank option --- resources/scenarios/miner_std.py | 18 ++++++++++++------ src/warnet/bitcoin.py | 3 +-- test/conf_test.py | 20 ++++++++++++++++++++ 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/resources/scenarios/miner_std.py b/resources/scenarios/miner_std.py index 568934e67..3fa06c7d3 100755 --- a/resources/scenarios/miner_std.py +++ b/resources/scenarios/miner_std.py @@ -41,15 +41,21 @@ def add_options(self, parser): action="store_true", help="When true, generate 101 blocks ONCE per miner", ) + parser.add_argument( + "--tank", + dest="tank", + type=str, + help="Select one tank by name as the only miner", + ) def run_test(self): self.log.info("Starting miners.") - - max_miners = 1 - if self.options.allnodes: - max_miners = len(self.nodes) - for index in range(max_miners): - self.miners.append(Miner(self.nodes[index], self.options.mature)) + if self.options.tank: + self.miners = [Miner(self.tanks[self.options.tank], self.options.mature)] + else: + max_miners = len(self.nodes) if self.options.allnodes else 1 + for index in range(max_miners): + self.miners.append(Miner(self.nodes[index], self.options.mature)) while True: for miner in self.miners: diff --git a/src/warnet/bitcoin.py b/src/warnet/bitcoin.py index a27da3bc7..8942662e9 100644 --- a/src/warnet/bitcoin.py +++ b/src/warnet/bitcoin.py @@ -5,10 +5,9 @@ from io import BytesIO import click -from urllib3.exceptions import MaxRetryError - from test_framework.messages import ser_uint256 from test_framework.p2p import MESSAGEMAP +from urllib3.exceptions import MaxRetryError from .k8s import get_default_namespace, get_mission from .process import run_command diff --git a/test/conf_test.py b/test/conf_test.py index bc717a732..fc3c8f4b9 100755 --- a/test/conf_test.py +++ b/test/conf_test.py @@ -7,18 +7,22 @@ from test_base import TestBase +from warnet.control import stop_scenario from warnet.k8s import get_mission +from warnet.status import _get_deployed_scenarios as scenarios_deployed class ConfTest(TestBase): def __init__(self): super().__init__() self.network_dir = Path(os.path.dirname(__file__)) / "data" / "bitcoin_conf" + self.scen_dir = Path(os.path.dirname(__file__)).parent / "resources" / "scenarios" def run_test(self): try: self.setup_network() self.check_uacomment() + self.check_single_miner() finally: self.cleanup() @@ -52,6 +56,22 @@ def get_uacomment(): self.wait_for_predicate(get_uacomment) + def check_single_miner(self): + scenario_file = self.scen_dir / "miner_std.py" + self.log.info(f"Running scenario from: {scenario_file}") + # Mine from a tank that is not first or last and + # is one of the only few in the network that even + # has rpc reatewallet method! + self.warnet(f"run {scenario_file} --tank=tank-0026 --interval=1") + self.wait_for_predicate( + lambda: int(self.warnet("bitcoin rpc tank-0026 getblockcount")) >= 10 + ) + running = scenarios_deployed() + assert len(running) == 1, f"Expected one running scenario, got {len(running)}" + assert running[0]["status"] == "running", "Scenario should be running" + stop_scenario(running[0]["name"]) + self.wait_for_all_scenarios() + if __name__ == "__main__": test = ConfTest()