Skip to content

Commit da4eb87

Browse files
committed
test: fix old pyth tests
1 parent cd58b05 commit da4eb87

File tree

3 files changed

+57
-23
lines changed

3 files changed

+57
-23
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/src/bank/pyth_accumulator.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ use {
2020
pub const ACCUMULATOR_RING_SIZE: u32 = 10_000;
2121

2222
lazy_static! {
23-
static ref ORACLE_PUBKEY: Option<Pubkey> = match env::var("PYTH_ORACLE_PUBKEY") {
24-
Ok(value) => Some(
25-
value
26-
.parse()
27-
.expect("invalid value of PYTH_ORACLE_PUBKEY env var")
28-
),
29-
Err(VarError::NotPresent) => None,
23+
pub static ref ORACLE_PUBKEY: Pubkey = match env::var("PYTH_ORACLE_PUBKEY") {
24+
Ok(value) => value
25+
.parse()
26+
.expect("invalid value of PYTH_ORACLE_PUBKEY env var"),
27+
Err(VarError::NotPresent) => {
28+
// Pythnet oracle program address
29+
"FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epH".parse().unwrap()
30+
}
3031
Err(VarError::NotUnicode(err)) => {
3132
panic!("invalid value of PYTH_ORACLE_PUBKEY env var: {err:?}");
3233
}
@@ -51,9 +52,6 @@ pub enum AccumulatorUpdateErrorV1 {
5152

5253
#[error("could not parse Pubkey from environment")]
5354
InvalidEnvPubkey(#[from] solana_sdk::pubkey::ParsePubkeyError),
54-
55-
#[error("no oracle pubkey")]
56-
NoOraclePubkey,
5755
}
5856

5957
/// Updates the Accumulator Sysvar at the start of a new slot. See `update_clock` to see a similar
@@ -376,10 +374,8 @@ fn post_accumulator_attestation(
376374
}
377375

378376
pub fn update_v2(bank: &Bank) -> std::result::Result<(), AccumulatorUpdateErrorV1> {
379-
let oracle_pubkey = ORACLE_PUBKEY.ok_or(AccumulatorUpdateErrorV1::NoOraclePubkey)?;
380-
381377
let accounts = bank
382-
.get_program_accounts(&oracle_pubkey, &ScanConfig::new(true))
378+
.get_program_accounts(&ORACLE_PUBKEY, &ScanConfig::new(true))
383379
.map_err(AccumulatorUpdateErrorV1::GetProgramAccounts)?;
384380

385381
let mut any_v1_aggregations = false;
@@ -395,12 +391,10 @@ pub fn update_v2(bank: &Bank) -> std::result::Result<(), AccumulatorUpdateErrorV
395391
&pubkey.to_bytes().into(),
396392
&mut price_account_data,
397393
) {
398-
Ok(outcome) => {
399-
if outcome.commit {
400-
account.set_data(price_account_data);
401-
bank.store_account_and_update_capitalization(&pubkey, &account);
402-
}
403-
v2_messages.extend(outcome.messages);
394+
Ok(messages) => {
395+
account.set_data(price_account_data);
396+
bank.store_account_and_update_capitalization(&pubkey, &account);
397+
v2_messages.extend(messages);
404398
}
405399
Err(err) => match err {
406400
AggregationError::NotPriceFeedAccount => {}

runtime/src/bank/pyth_accumulator_tests.rs

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
use crate::{
22
bank::{
3-
pyth_accumulator::{get_accumulator_keys, ACCUMULATOR_RING_SIZE},
3+
pyth_accumulator::{get_accumulator_keys, ACCUMULATOR_RING_SIZE, ORACLE_PUBKEY},
44
Bank,
55
},
66
genesis_utils::{create_genesis_config_with_leader, GenesisConfigInfo},
77
};
88
use byteorder::ByteOrder;
99
use byteorder::{LittleEndian, ReadBytesExt};
1010
use itertools::Itertools;
11+
use pyth_oracle::solana_program::account_info::AccountInfo;
12+
use pyth_oracle::{PriceAccount, PythAccount};
1113
use pythnet_sdk::{
1214
accumulators::{merkle::MerkleAccumulator, Accumulator},
1315
hashers::{keccak256_160::Keccak160, Hasher},
@@ -17,6 +19,7 @@ use pythnet_sdk::{
1719
use solana_sdk::{
1820
account::{AccountSharedData, ReadableAccount, WritableAccount},
1921
borsh::{BorshDeserialize, BorshSerialize},
22+
clock::Epoch,
2023
epoch_schedule::EpochSchedule,
2124
feature::{self, Feature},
2225
feature_set,
@@ -25,7 +28,7 @@ use solana_sdk::{
2528
signature::keypair_from_seed,
2629
signer::Signer,
2730
};
28-
use std::{io::Read, sync::Arc};
31+
use std::{io::Read, mem::size_of, sync::Arc};
2932

3033
// Create Message Account Bytes
3134
//
@@ -125,6 +128,25 @@ fn test_update_accumulator_sysvar() {
125128
// Store Message account so the accumulator sysvar updater can find it.
126129
bank.store_account(&price_message_key.pubkey(), &price_message_account);
127130

131+
let (price_feed_key, _bump) = Pubkey::find_program_address(&[b"123"], &ORACLE_PUBKEY);
132+
let mut price_feed_account =
133+
AccountSharedData::new(42, size_of::<PriceAccount>(), &ORACLE_PUBKEY);
134+
PriceAccount::initialize(
135+
&AccountInfo::new(
136+
&price_feed_key.to_bytes().into(),
137+
false,
138+
true,
139+
&mut 0,
140+
&mut price_feed_account.data_mut(),
141+
&ORACLE_PUBKEY.to_bytes().into(),
142+
false,
143+
Epoch::default(),
144+
),
145+
0,
146+
)
147+
.unwrap();
148+
bank.store_account(&price_feed_key, &price_feed_account);
149+
128150
// Derive the Wormhole Message Account that will be generated by the sysvar updater.
129151
let (wormhole_message_pubkey, _bump) = Pubkey::find_program_address(
130152
&[b"AccumulatorMessage", &(bank.slot() as u32).to_be_bytes()],
@@ -396,6 +418,25 @@ fn test_update_accumulator_end_of_block() {
396418
// Store Message account so the accumulator sysvar updater can find it.
397419
bank.store_account(&price_message_key.pubkey(), &price_message_account);
398420

421+
let (price_feed_key, _bump) = Pubkey::find_program_address(&[b"123"], &ORACLE_PUBKEY);
422+
let mut price_feed_account =
423+
AccountSharedData::new(42, size_of::<PriceAccount>(), &ORACLE_PUBKEY);
424+
PriceAccount::initialize(
425+
&AccountInfo::new(
426+
&price_feed_key.to_bytes().into(),
427+
false,
428+
true,
429+
&mut 0,
430+
&mut price_feed_account.data_mut(),
431+
&ORACLE_PUBKEY.to_bytes().into(),
432+
false,
433+
Epoch::default(),
434+
),
435+
0,
436+
)
437+
.unwrap();
438+
bank.store_account(&price_feed_key, &price_feed_account);
439+
399440
// Derive the Wormhole Message Account that will be generated by the sysvar updater.
400441
let (wormhole_message_pubkey, _bump) = Pubkey::find_program_address(
401442
&[b"AccumulatorMessage", &(bank.slot() as u32).to_be_bytes()],
@@ -631,7 +672,6 @@ fn test_update_accumulator_end_of_block() {
631672
#[test]
632673
fn test_get_accumulator_keys() {
633674
use pythnet_sdk::{pythnet, ACCUMULATOR_EMITTER_ADDRESS, MESSAGE_BUFFER_PID};
634-
let leader_pubkey = solana_sdk::pubkey::new_rand();
635675
let accumulator_keys: Vec<Pubkey> = get_accumulator_keys()
636676
.iter()
637677
.map(|(_, pk_res)| *pk_res.as_ref().unwrap())

0 commit comments

Comments
 (0)