|
4 | 4 | PriceAccount, |
5 | 5 | PriceAccountFlags, |
6 | 6 | PythAccount, |
| 7 | + PythOracleSerialize, |
7 | 8 | }, |
8 | 9 | c_oracle_header::{ |
9 | 10 | PC_STATUS_IGNORED, |
|
26 | 27 | }, |
27 | 28 | validator, |
28 | 29 | }, |
| 30 | + pythnet_sdk::messages::{ |
| 31 | + PriceFeedMessage, |
| 32 | + TwapMessage, |
| 33 | + }, |
29 | 34 | solana_program::{ |
30 | 35 | program_error::ProgramError, |
31 | 36 | pubkey::Pubkey, |
@@ -120,12 +125,66 @@ fn test_upd_price_with_validator() { |
120 | 125 | } |
121 | 126 |
|
122 | 127 | // We aggregate the price at the end of each slot now. |
123 | | - validator::aggregate_price(1, 101, price_account.key, *price_account.data.borrow_mut()) |
124 | | - .unwrap(); |
| 128 | + let messages1 = |
| 129 | + validator::aggregate_price(1, 101, price_account.key, *price_account.data.borrow_mut()) |
| 130 | + .unwrap(); |
| 131 | + let expected_messages1 = [ |
| 132 | + PriceFeedMessage { |
| 133 | + id: price_account.key.to_bytes(), |
| 134 | + price: 42, |
| 135 | + conf: 2, |
| 136 | + exponent: 0, |
| 137 | + publish_time: 101, |
| 138 | + prev_publish_time: 0, |
| 139 | + ema_price: 42, |
| 140 | + ema_conf: 2, |
| 141 | + } |
| 142 | + .to_bytes(), |
| 143 | + TwapMessage { |
| 144 | + id: price_account.key.to_bytes(), |
| 145 | + cumulative_price: 42, |
| 146 | + cumulative_conf: 2, |
| 147 | + num_down_slots: 0, |
| 148 | + exponent: 0, |
| 149 | + publish_time: 101, |
| 150 | + prev_publish_time: 0, |
| 151 | + publish_slot: 1, |
| 152 | + } |
| 153 | + .to_bytes(), |
| 154 | + ]; |
| 155 | + assert_eq!(messages1, expected_messages1); |
| 156 | + |
125 | 157 | update_clock_slot(&mut clock_account, 2); |
| 158 | + let messages2 = |
| 159 | + validator::aggregate_price(2, 102, price_account.key, *price_account.data.borrow_mut()) |
| 160 | + .unwrap(); |
| 161 | + |
| 162 | + let expected_messages2 = [ |
| 163 | + PriceFeedMessage { |
| 164 | + id: price_account.key.to_bytes(), |
| 165 | + price: 42, |
| 166 | + conf: 2, |
| 167 | + exponent: 0, |
| 168 | + publish_time: 102, |
| 169 | + prev_publish_time: 101, |
| 170 | + ema_price: 41, |
| 171 | + ema_conf: 2, |
| 172 | + } |
| 173 | + .to_bytes(), |
| 174 | + TwapMessage { |
| 175 | + id: price_account.key.to_bytes(), |
| 176 | + cumulative_price: 84, |
| 177 | + cumulative_conf: 4, |
| 178 | + num_down_slots: 0, |
| 179 | + exponent: 0, |
| 180 | + publish_time: 102, |
| 181 | + prev_publish_time: 101, |
| 182 | + publish_slot: 2, |
| 183 | + } |
| 184 | + .to_bytes(), |
| 185 | + ]; |
| 186 | + assert_eq!(messages2, expected_messages2); |
126 | 187 |
|
127 | | - validator::aggregate_price(2, 102, price_account.key, *price_account.data.borrow_mut()) |
128 | | - .unwrap(); |
129 | 188 | update_clock_slot(&mut clock_account, 3); |
130 | 189 | // add next price in new slot triggering snapshot and aggregate calc |
131 | 190 | populate_instruction(&mut instruction_data, 81, 2, 2); |
|
0 commit comments