@@ -5,6 +5,7 @@ use pyth_sdk_solana::state::{
55 MAGIC ,
66 VERSION_2 ,
77} ;
8+ use pyth_sdk_solana:: VALID_SLOT_PERIOD ;
89use solana_program_test:: * ;
910use test_contract:: instruction;
1011
@@ -25,6 +26,20 @@ fn price_account_all_zero() -> PriceAccount {
2526#[ tokio:: test]
2627async fn test_price_not_stale ( ) {
2728 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 ;
2843 price. agg . status = PriceStatus :: Trading ;
2944 test_instr_exec_ok ( instruction:: price_status_check (
3045 & price,
@@ -38,10 +53,7 @@ async fn test_price_not_stale() {
3853async fn test_price_stale ( ) {
3954 let mut price = price_account_all_zero ( ) ;
4055 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 ;
4557
4658 #[ cfg( feature = "test-bpf" ) ] // Only in BPF the clock check is performed
4759 let expected_status = PriceStatus :: Unknown ;
0 commit comments