Skip to content

Commit 1a13ccc

Browse files
committed
test: verify aggregation output
1 parent d949c27 commit 1a13ccc

File tree

2 files changed

+63
-6
lines changed

2 files changed

+63
-6
lines changed

program/rust/src/processor/upd_price.rs

-2
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,6 @@ pub fn upd_price(
256256
]
257257
};
258258

259-
// Append a TWAP message if available
260-
261259
// anchor discriminator for "global:put_all"
262260
let discriminator: [u8; 8] = [212, 225, 193, 91, 151, 238, 20, 93];
263261
let create_inputs_ix = Instruction::new_with_borsh(

program/rust/src/tests/test_upd_price_with_validator.rs

+63-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use {
44
PriceAccount,
55
PriceAccountFlags,
66
PythAccount,
7+
PythOracleSerialize,
78
},
89
c_oracle_header::{
910
PC_STATUS_IGNORED,
@@ -26,6 +27,10 @@ use {
2627
},
2728
validator,
2829
},
30+
pythnet_sdk::messages::{
31+
PriceFeedMessage,
32+
TwapMessage,
33+
},
2934
solana_program::{
3035
program_error::ProgramError,
3136
pubkey::Pubkey,
@@ -120,12 +125,66 @@ fn test_upd_price_with_validator() {
120125
}
121126

122127
// 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+
125157
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);
126187

127-
validator::aggregate_price(2, 102, price_account.key, *price_account.data.borrow_mut())
128-
.unwrap();
129188
update_clock_slot(&mut clock_account, 3);
130189
// add next price in new slot triggering snapshot and aggregate calc
131190
populate_instruction(&mut instruction_data, 81, 2, 2);

0 commit comments

Comments
 (0)