Skip to content

Commit a57bce5

Browse files
committed
Refactor test_upd_aggregate.rs: Clean up imports and formatting, update test cases
1 parent f31f75b commit a57bce5

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

program/rust/src/tests/test_upd_aggregate.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,49 @@ fn test_upd_aggregate() {
6969
price_account.is_signer = false;
7070
PriceAccount::initialize(&price_account, PC_VERSION).unwrap();
7171

72+
// test same slot aggregation, aggregate price and conf should be updated but not twap and twac
73+
{
74+
let mut price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
75+
price_data.num_ = 1;
76+
price_data.last_slot_ = 1000;
77+
price_data.agg_.pub_slot_ = 1000;
78+
price_data.comp_[0].latest_ = p1;
79+
}
80+
unsafe {
81+
assert!(c_upd_aggregate(
82+
price_account.try_borrow_mut_data().unwrap().as_mut_ptr(),
83+
1000,
84+
1,
85+
));
86+
}
87+
88+
{
89+
let price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
90+
91+
assert_eq!(price_data.agg_.price_, 100);
92+
assert_eq!(price_data.agg_.conf_, 10);
93+
assert_eq!(price_data.twap_.val_, 0);
94+
assert_eq!(price_data.twac_.val_, 0);
95+
assert_eq!(price_data.num_qt_, 1);
96+
assert_eq!(price_data.timestamp_, 1);
97+
assert_eq!(price_data.prev_slot_, 0);
98+
assert_eq!(price_data.prev_price_, 0);
99+
assert_eq!(price_data.prev_conf_, 0);
100+
assert_eq!(price_data.prev_timestamp_, 0);
101+
}
102+
72103
// single publisher
73104
{
74105
let mut price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
75106
price_data.num_ = 1;
76107
price_data.last_slot_ = 1000;
77108
price_data.agg_.pub_slot_ = 1000;
78109
price_data.comp_[0].latest_ = p1;
110+
price_data.prev_slot_ = 0;
111+
price_data.prev_price_ = 0;
112+
price_data.prev_conf_ = 0;
113+
price_data.prev_timestamp_ = 0;
114+
price_data.agg_.status_ = PC_STATUS_UNKNOWN;
79115
}
80116
unsafe {
81117
assert!(c_upd_aggregate(
@@ -134,7 +170,6 @@ fn test_upd_aggregate() {
134170
assert_eq!(price_data.prev_timestamp_, 1);
135171
}
136172

137-
138173
// three publishers
139174
{
140175
let mut price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();

0 commit comments

Comments
 (0)