@@ -18,7 +18,9 @@ def __init__(self):
1818 def run_test (self ):
1919 try :
2020 self .setup_network ()
21- self .test_scenarios ()
21+ self .run_and_check_miner_scenario_from_file ()
22+ self .run_and_check_scenario_from_file ()
23+ self .check_regtest_recon ()
2224 finally :
2325 self .cleanup ()
2426
@@ -28,42 +30,29 @@ def setup_network(self):
2830 self .wait_for_all_tanks_status (target = "running" )
2931 self .wait_for_all_edges ()
3032
31- def test_scenarios (self ):
32- self .run_and_check_miner_scenario_from_file ()
33- self .run_and_check_scenario_from_file ()
34- self .check_regtest_recon ()
35-
3633 def scenario_running (self , scenario_name : str ):
3734 """Check that we are only running a single scenario of the correct name"""
3835 active = scenarios_active ()
3936 assert len (active ) == 1
4037 return scenario_name in active [0 ]["name" ]
4138
42- def run_and_check_scenario_from_file (self ):
43- scenario_file = "test/data/scenario_p2p_interface.py"
44- self .log .info (f"Running scenario from: { scenario_file } " )
45- self .warnet (f"run { scenario_file } " )
46- self .wait_for_predicate (self .check_scenario_clean_exit )
47-
48- def run_and_check_miner_scenario_from_file (self ):
49- scenario_file = "resources/scenarios/miner_std.py"
50- self .log .info (f"Running scenario from file: { scenario_file } " )
51- self .warnet (f"run { scenario_file } --allnodes --interval=1" )
52- start = int (self .warnet ("bitcoin rpc tank-0000 getblockcount" ))
53- self .wait_for_predicate (lambda : self .scenario_running ("commander-minerstd" ))
54- self .wait_for_predicate (lambda : self .check_blocks (2 , start = start ))
55- self .stop_scenario ()
56-
57- def check_regtest_recon (self ):
58- scenario_file = "resources/scenarios/reconnaissance.py"
59- self .log .info (f"Running scenario from file: { scenario_file } " )
60- self .warnet (f"run { scenario_file } " )
61- self .wait_for_predicate (self .check_scenario_clean_exit )
39+ def check_scenario_stopped (self ):
40+ running = scenarios_active ()
41+ self .log .debug (f"Checking if scenario stopped. Running scenarios: { len (running )} " )
42+ return len (running ) == 0
6243
6344 def check_scenario_clean_exit (self ):
6445 active = scenarios_active ()
6546 return all (scenario ["status" ] == "succeeded" for scenario in active )
6647
48+ def stop_scenario (self ):
49+ self .log .info ("Stopping running scenario" )
50+ running = scenarios_active ()
51+ assert len (running ) == 1 , f"Expected one running scenario, got { len (running )} "
52+ assert running [0 ]["status" ] == "running" , "Scenario should be running"
53+ stop_scenario (running [0 ]["name" ])
54+ self .wait_for_predicate (self .check_scenario_stopped )
55+
6756 def check_blocks (self , target_blocks , start : int = 0 ):
6857 count = int (self .warnet ("bitcoin rpc tank-0000 getblockcount" ))
6958 self .log .debug (f"Current block count: { count } , target: { start + target_blocks } " )
@@ -80,18 +69,26 @@ def check_blocks(self, target_blocks, start: int = 0):
8069
8170 return count >= start + target_blocks
8271
83- def stop_scenario (self ):
84- self .log .info ("Stopping running scenario" )
85- running = scenarios_active ()
86- assert len (running ) == 1 , f"Expected one running scenario, got { len (running )} "
87- assert running [0 ]["status" ] == "running" , "Scenario should be running"
88- stop_scenario (running [0 ]["name" ])
89- self .wait_for_predicate (self .check_scenario_stopped )
72+ def run_and_check_miner_scenario_from_file (self ):
73+ scenario_file = "resources/scenarios/miner_std.py"
74+ self .log .info (f"Running scenario from file: { scenario_file } " )
75+ self .warnet (f"run { scenario_file } --allnodes --interval=1" )
76+ start = int (self .warnet ("bitcoin rpc tank-0000 getblockcount" ))
77+ self .wait_for_predicate (lambda : self .scenario_running ("commander-minerstd" ))
78+ self .wait_for_predicate (lambda : self .check_blocks (2 , start = start ))
79+ self .stop_scenario ()
9080
91- def check_scenario_stopped (self ):
92- running = scenarios_active ()
93- self .log .debug (f"Checking if scenario stopped. Running scenarios: { len (running )} " )
94- return len (running ) == 0
81+ def run_and_check_scenario_from_file (self ):
82+ scenario_file = "test/data/scenario_p2p_interface.py"
83+ self .log .info (f"Running scenario from: { scenario_file } " )
84+ self .warnet (f"run { scenario_file } " )
85+ self .wait_for_predicate (self .check_scenario_clean_exit )
86+
87+ def check_regtest_recon (self ):
88+ scenario_file = "resources/scenarios/reconnaissance.py"
89+ self .log .info (f"Running scenario from file: { scenario_file } " )
90+ self .warnet (f"run { scenario_file } " )
91+ self .wait_for_predicate (self .check_scenario_clean_exit )
9592
9693
9794if __name__ == "__main__" :
0 commit comments