Skip to content

Commit ce47715

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

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

program/rust/src/tests/test_upd_aggregate.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,49 @@ fn test_upd_aggregate() {
7878
price_account.is_signer = false;
7979
PriceAccount::initialize(&price_account, PC_VERSION).unwrap();
8080

81+
// test same slot aggregation, aggregate price and conf should be updated but not twap and twac
82+
{
83+
let mut price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
84+
price_data.num_ = 1;
85+
price_data.last_slot_ = 1000;
86+
price_data.agg_.pub_slot_ = 1000;
87+
price_data.comp_[0].latest_ = p1;
88+
}
89+
unsafe {
90+
assert!(c_upd_aggregate(
91+
price_account.try_borrow_mut_data().unwrap().as_mut_ptr(),
92+
1000,
93+
1,
94+
));
95+
}
96+
97+
{
98+
let price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
99+
100+
assert_eq!(price_data.agg_.price_, 100);
101+
assert_eq!(price_data.agg_.conf_, 10);
102+
assert_eq!(price_data.twap_.val_, 0);
103+
assert_eq!(price_data.twac_.val_, 0);
104+
assert_eq!(price_data.num_qt_, 1);
105+
assert_eq!(price_data.timestamp_, 1);
106+
assert_eq!(price_data.prev_slot_, 0);
107+
assert_eq!(price_data.prev_price_, 0);
108+
assert_eq!(price_data.prev_conf_, 0);
109+
assert_eq!(price_data.prev_timestamp_, 0);
110+
}
111+
81112
// single publisher
82113
{
83114
let mut price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
84115
price_data.num_ = 1;
85116
price_data.last_slot_ = 1000;
86117
price_data.agg_.pub_slot_ = 1000;
87118
price_data.comp_[0].latest_ = p1;
119+
price_data.prev_slot_ = 0;
120+
price_data.prev_price_ = 0;
121+
price_data.prev_conf_ = 0;
122+
price_data.prev_timestamp_ = 0;
123+
price_data.agg_.status_ = PC_STATUS_UNKNOWN;
88124
}
89125

90126
unsafe {

0 commit comments

Comments
 (0)