@@ -5,6 +5,7 @@ use pyth_sdk_solana::state::{
5
5
MAGIC ,
6
6
VERSION_2 ,
7
7
} ;
8
+ use pyth_sdk_solana:: VALID_SLOT_PERIOD ;
8
9
use solana_program_test:: * ;
9
10
use test_contract:: instruction;
10
11
@@ -25,6 +26,20 @@ fn price_account_all_zero() -> PriceAccount {
25
26
#[ tokio:: test]
26
27
async fn test_price_not_stale ( ) {
27
28
let mut price = price_account_all_zero ( ) ;
29
+ price. agg . pub_slot = 1000 - 10 ;
30
+ price. agg . status = PriceStatus :: Trading ;
31
+ test_instr_exec_ok ( instruction:: price_status_check (
32
+ & price,
33
+ PriceStatus :: Trading ,
34
+ ) )
35
+ . await ;
36
+ }
37
+
38
+
39
+ #[ tokio:: test]
40
+ async fn test_price_not_stale_future ( ) {
41
+ let mut price = price_account_all_zero ( ) ;
42
+ price. agg . pub_slot = 1000 + 10 ;
28
43
price. agg . status = PriceStatus :: Trading ;
29
44
test_instr_exec_ok ( instruction:: price_status_check (
30
45
& price,
@@ -38,10 +53,7 @@ async fn test_price_not_stale() {
38
53
async fn test_price_stale ( ) {
39
54
let mut price = price_account_all_zero ( ) ;
40
55
price. agg . status = PriceStatus :: Trading ;
41
- // Value 100 will cause an overflow because this is bigger than Solana slot in the test suite
42
- // (its ~1-5). As the check will be 5u - 100u ~= 1e18 > MAX_SLOT_DIFFERENCE. It can only
43
- // break when Solana slot in the test suite becomes between 100 and 100+MAX_SLOT_DIFFERENCE.
44
- price. agg . pub_slot = 100 ;
56
+ price. agg . pub_slot = 1000 - VALID_SLOT_PERIOD - 1 ;
45
57
46
58
#[ cfg( feature = "test-bpf" ) ] // Only in BPF the clock check is performed
47
59
let expected_status = PriceStatus :: Unknown ;
0 commit comments