@@ -26,8 +26,9 @@ def setup_network(self):
26
26
27
27
def test_scenarios (self ):
28
28
self .check_available_scenarios ()
29
- self .run_and_check_scenario ("miner_std" )
30
- self .run_and_check_scenario_from_file ("src/warnet/scenarios/miner_std.py" )
29
+ self .run_and_check_miner_scenario ("miner_std" )
30
+ self .run_and_check_miner_scenario_from_file ("src/warnet/scenarios/miner_std.py" )
31
+ self .run_and_check_scenario_from_file ("test/data/scenario_p2p_interface.py" )
31
32
32
33
def check_available_scenarios (self ):
33
34
self .log .info ("Checking available scenarios" )
@@ -42,22 +43,46 @@ def scenario_running(self, scenario_name: str):
42
43
running = scenario_name in active [0 ]["cmd" ]
43
44
return running and len (active ) == 1
44
45
45
- def run_and_check_scenario (self , scenario_name ):
46
+ def run_and_check_scenario_from_file (self , scenario_file ):
47
+ scenario_name = self .get_scenario_name_from_path (scenario_file )
48
+
49
+ def check_scenario_clean_exit ():
50
+ running = self .rpc ("scenarios_list_running" )
51
+ scenarios = [s for s in running if s ["cmd" ].strip () == scenario_name ]
52
+ if not scenarios :
53
+ return False
54
+ scenario = scenarios [0 ]
55
+ if scenario ["active" ]:
56
+ return False
57
+ if scenario ["return_code" ] != 0 :
58
+ raise Exception (
59
+ f"Scenario { scenario_name } failed with return code { scenario ['return_code' ]} "
60
+ )
61
+ return True
62
+
63
+ self .log .info (f"Running scenario: { scenario_name } " )
64
+ self .warcli (f"scenarios run-file { scenario_file } " )
65
+ self .wait_for_predicate (lambda : check_scenario_clean_exit ())
66
+
67
+ def run_and_check_miner_scenario (self , scenario_name ):
46
68
self .log .info (f"Running scenario: { scenario_name } " )
47
69
self .warcli (f"scenarios run { scenario_name } --allnodes --interval=1" )
48
70
self .wait_for_predicate (lambda : self .scenario_running (scenario_name ))
49
71
self .wait_for_predicate (lambda : self .check_blocks (30 ))
50
72
self .stop_scenario ()
51
73
52
- def run_and_check_scenario_from_file (self , scenario_file ):
74
+ def run_and_check_miner_scenario_from_file (self , scenario_file ):
53
75
self .log .info (f"Running scenario from file: { scenario_file } " )
54
76
self .warcli (f"scenarios run-file { scenario_file } --allnodes --interval=1" )
55
77
start = int (self .warcli ("bitcoin rpc 0 getblockcount" ))
56
- scenario_name = os . path . splitext ( os . path . basename ( scenario_file ))[ 0 ]
78
+ scenario_name = self . get_scenario_name_from_path ( scenario_file )
57
79
self .wait_for_predicate (lambda : self .scenario_running (scenario_name ))
58
80
self .wait_for_predicate (lambda : self .check_blocks (2 , start = start ))
59
81
self .stop_scenario ()
60
82
83
+ def get_scenario_name_from_path (self , scenario_file ):
84
+ return os .path .splitext (os .path .basename (scenario_file ))[0 ]
85
+
61
86
def check_blocks (self , target_blocks , start : int = 0 ):
62
87
running = self .rpc ("scenarios_list_running" )
63
88
assert len (running ) == 1 , f"Expected one running scenario, got { len (running )} "
0 commit comments