@@ -18,7 +18,9 @@ def __init__(self):
18
18
def run_test (self ):
19
19
try :
20
20
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 ()
22
24
finally :
23
25
self .cleanup ()
24
26
@@ -28,42 +30,29 @@ def setup_network(self):
28
30
self .wait_for_all_tanks_status (target = "running" )
29
31
self .wait_for_all_edges ()
30
32
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
-
36
33
def scenario_running (self , scenario_name : str ):
37
34
"""Check that we are only running a single scenario of the correct name"""
38
35
active = scenarios_active ()
39
36
assert len (active ) == 1
40
37
return scenario_name in active [0 ]["name" ]
41
38
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
62
43
63
44
def check_scenario_clean_exit (self ):
64
45
active = scenarios_active ()
65
46
return all (scenario ["status" ] == "succeeded" for scenario in active )
66
47
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
+
67
56
def check_blocks (self , target_blocks , start : int = 0 ):
68
57
count = int (self .warnet ("bitcoin rpc tank-0000 getblockcount" ))
69
58
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):
80
69
81
70
return count >= start + target_blocks
82
71
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 ()
90
80
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 )
95
92
96
93
97
94
if __name__ == "__main__" :
0 commit comments