Skip to content

Commit 5be3e09

Browse files
committed
address comments
1 parent 6b539db commit 5be3e09

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

program/rust/src/tests/test_ema.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ fn test_ema_multiple_publishers_same_slot() -> Result<(), Box<dyn std::error::Er
126126
let price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
127127
assert_eq!(price_data.prev_twap_.val_, 10);
128128
assert_eq!(price_data.prev_twac_.val_, 1);
129+
// The EMA value decreases to 12 despite an increase in the aggregate price due to the higher confidence associated with the new price.
130+
// The EMA calculation considers the weight of 1/confidence for the new price, leading to a lower weighted average when the confidence is high.
129131
assert_eq!(price_data.twap_.val_, 12);
130132
assert_eq!(price_data.twac_.val_, 1);
131133
}

program/rust/src/tests/test_upd_price.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ fn test_upd_price() {
348348
assert_eq!(price_data.prev_price_, -100);
349349
assert_eq!(price_data.prev_conf_, 1);
350350
assert_eq!(price_data.prev_timestamp_, 4);
351+
assert_eq!(price_data.twap_.numer_, 1677311098);
352+
assert_eq!(price_data.twap_.denom_, 1279419481);
353+
assert_eq!(price_data.price_cumulative.price, 86);
351354
}
352355

353356
// reset twap_.denom_ to 0 to simulate program upgrade in the same slot and make sure agg_.price_ is not updated again
@@ -381,6 +384,9 @@ fn test_upd_price() {
381384
assert_eq!(price_data.prev_price_, -100);
382385
assert_eq!(price_data.prev_conf_, 1);
383386
assert_eq!(price_data.prev_timestamp_, 4);
387+
assert_eq!(price_data.twap_.numer_, 1677311098); // twap_.numer_ should not be updated
388+
assert_eq!(price_data.twap_.denom_, 1279419481); // twap_.denom_ should not be updated
389+
assert_eq!(price_data.price_cumulative.price, 86); // price_cumulative should not be updated
384390
}
385391
}
386392

0 commit comments

Comments
 (0)