Skip to content

Commit

Permalink
test: make sure batch publish does not apply prices when price_index …
Browse files Browse the repository at this point in the history
…== 0
  • Loading branch information
Riateche committed Aug 29, 2024
1 parent ee765c5 commit 36e1c80
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions runtime/src/bank/pyth/accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,13 @@ pub fn update_v2(bank: &Bank) -> std::result::Result<(), AccumulatorUpdateErrorV
v2_messages.push(publisher_stake_caps_message);
}

let mut measure = Measure::start("extract_batch_publish_prices");
let mut new_prices = batch_publish::extract_batch_publish_prices(bank).unwrap_or_else(|err| {
warn!("extract_batch_publish_prices failed: {}", err);
HashMap::new()
});
measure.stop();
debug!("batch publish: loaded prices in {}us", measure.as_us());

let mut measure = Measure::start("update_v2_aggregate_price");
for (pubkey, mut account) in accounts {
Expand Down
15 changes: 14 additions & 1 deletion runtime/src/bank/pyth/tests/batch_publish_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ fn test_batch_publish() {
&[
PublisherPrice::new(1, 1, 10, 2).unwrap(),
PublisherPrice::new(2, 1, 20, 3).unwrap(),
// Attempt to publish with price_index == 0,
// but it will not be applied.
PublisherPrice {
trading_status_and_feed_index: 0,
price: 30,
confidence: 35,
},
],
),
generate_publisher(
Expand Down Expand Up @@ -129,7 +136,7 @@ fn test_batch_publish() {
generate_price(b"seeds_1", 1),
generate_price(b"seeds_2", 2),
generate_price(b"seeds_3", 3),
generate_price(b"seeds_4", 4),
generate_price(b"seeds_4", 0),
];

bank = new_from_parent(&Arc::new(bank)); // Advance slot 1.
Expand All @@ -138,10 +145,16 @@ fn test_batch_publish() {
let new_price_feed1_account = bank.get_account(&prices_with_messages[0].0).unwrap();
let new_price_feed1_data: &PriceAccount = from_bytes(new_price_feed1_account.data());
assert_eq!(new_price_feed1_data.comp_[0].latest_.price_, 10);
assert_eq!(new_price_feed1_data.comp_[0].latest_.conf_, 2);
assert_eq!(new_price_feed1_data.comp_[0].latest_.status_, 1);
assert_eq!(new_price_feed1_data.comp_[1].latest_.price_, 15);

let new_price_feed2_account = bank.get_account(&prices_with_messages[1].0).unwrap();
let new_price_feed2_data: &PriceAccount = from_bytes(new_price_feed2_account.data());
assert_eq!(new_price_feed2_data.comp_[0].latest_.price_, 20);
assert_eq!(new_price_feed2_data.comp_[1].latest_.price_, 25);

let new_price_feed4_account = bank.get_account(&prices_with_messages[3].0).unwrap();
let new_price_feed4_data: &PriceAccount = from_bytes(new_price_feed4_account.data());
assert_eq!(new_price_feed4_data.comp_[0].latest_.price_, 0);
}

0 comments on commit 36e1c80

Please sign in to comment.