@@ -23,6 +23,7 @@ def make_state(
23
23
return PublisherState (
24
24
publisher_name = "publisher" ,
25
25
symbol = "Crypto.BTC/USD" ,
26
+ asset_type = "Crypto" ,
26
27
public_key = SolanaPublicKey ("2hgu6Umyokvo8FfSDdMa9nDKhcdv9Q4VvGNhRCeSWeD3" ),
27
28
status = PythPriceStatus .TRADING ,
28
29
aggregate_status = PythPriceStatus .TRADING ,
@@ -62,8 +63,14 @@ def simulate_time_pass(seconds):
62
63
current_time += seconds
63
64
return current_time
64
65
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
+ )
67
74
PUBLISHER_CACHE [(state .publisher_name , state .symbol )] = (
68
75
state .price ,
69
76
current_time ,
@@ -76,17 +83,17 @@ def run_check(check, seconds, expected):
76
83
77
84
PUBLISHER_CACHE .clear ()
78
85
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 )
80
87
run_check (check_a , 5 , True ) # Should pass as it hits the limit exactly
81
88
82
89
PUBLISHER_CACHE .clear ()
83
90
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 )
85
92
run_check (check_b , 6 , False ) # Should fail as it exceeds the limit
86
93
87
94
PUBLISHER_CACHE .clear ()
88
95
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 )
90
97
run_check (check_c , 2 , True ) # Initial check should pass
91
98
state_c .price = 105.0 # Change the price
92
99
run_check (check_c , 3 , True ) # Should pass as price changes
@@ -95,3 +102,11 @@ def run_check(check, seconds, expected):
95
102
run_check (
96
103
check_c , 8 , False
97
104
) # 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