@@ -23,6 +23,7 @@ def make_state(
2323 return PublisherState (
2424 publisher_name = "publisher" ,
2525 symbol = "Crypto.BTC/USD" ,
26+ asset_type = "Crypto" ,
2627 public_key = SolanaPublicKey ("2hgu6Umyokvo8FfSDdMa9nDKhcdv9Q4VvGNhRCeSWeD3" ),
2728 status = PythPriceStatus .TRADING ,
2829 aggregate_status = PythPriceStatus .TRADING ,
@@ -62,8 +63,14 @@ def simulate_time_pass(seconds):
6263 current_time += seconds
6364 return current_time
6465
65- def setup_check (state , stall_time_limit ):
66- check = PublisherStalledCheck (state , {"stall_time_limit" : stall_time_limit })
66+ def setup_check (state , stall_time_limit , max_slot_distance ):
67+ check = PublisherStalledCheck (
68+ state ,
69+ {
70+ "stall_time_limit" : stall_time_limit ,
71+ "max_slot_distance" : max_slot_distance ,
72+ },
73+ )
6774 PUBLISHER_CACHE [(state .publisher_name , state .symbol )] = (
6875 state .price ,
6976 current_time ,
@@ -76,17 +83,17 @@ def run_check(check, seconds, expected):
7683
7784 PUBLISHER_CACHE .clear ()
7885 state_a = make_state (1 , 100.0 , 2.0 , 1 , 100.0 , 1.0 )
79- check_a = setup_check (state_a , 5 )
86+ check_a = setup_check (state_a , 5 , 25 )
8087 run_check (check_a , 5 , True ) # Should pass as it hits the limit exactly
8188
8289 PUBLISHER_CACHE .clear ()
8390 state_b = make_state (1 , 100.0 , 2.0 , 1 , 100.0 , 1.0 )
84- check_b = setup_check (state_b , 5 )
91+ check_b = setup_check (state_b , 5 , 25 )
8592 run_check (check_b , 6 , False ) # Should fail as it exceeds the limit
8693
8794 PUBLISHER_CACHE .clear ()
8895 state_c = make_state (1 , 100.0 , 2.0 , 1 , 100.0 , 1.0 )
89- check_c = setup_check (state_c , 5 )
96+ check_c = setup_check (state_c , 5 , 25 )
9097 run_check (check_c , 2 , True ) # Initial check should pass
9198 state_c .price = 105.0 # Change the price
9299 run_check (check_c , 3 , True ) # Should pass as price changes
@@ -95,3 +102,11 @@ def run_check(check, seconds, expected):
95102 run_check (
96103 check_c , 8 , False
97104 ) # Should fail as price stalls for too long after last change
105+
106+ # Adding a check for when the publisher is offline
107+ PUBLISHER_CACHE .clear ()
108+ state_d = make_state (1 , 100.0 , 2.0 , 1 , 100.0 , 1.0 )
109+ state_d .latest_block_slot = 25
110+ state_d .slot = 0
111+ check_d = setup_check (state_d , 5 , 25 )
112+ run_check (check_d , 10 , True ) # Should pass as the publisher is offline
0 commit comments