Skip to content

Commit

Permalink
Merge pull request #627 from pinheadmz/miner-std-single
Browse files Browse the repository at this point in the history
scenarios: miner_std should accept single --tank option
  • Loading branch information
pinheadmz authored Oct 3, 2024
2 parents 6b3ed49 + ff4b8d7 commit 6299243
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
18 changes: 12 additions & 6 deletions resources/scenarios/miner_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 20 additions & 0 deletions test/conf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

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

0 comments on commit 6299243

Please sign in to comment.