-
Notifications
You must be signed in to change notification settings - Fork 116
Prove that new publishing slots work in a full-pubset test #385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9605443
2c26361
fd551da
074c8f2
1106962
ca56832
530ab60
437f57e
5abdebf
1dab1fa
533ee45
a7ed16e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use { | ||
crate::{ | ||
accounts::PriceAccount, | ||
c_oracle_header::{ | ||
PC_NUM_COMP, | ||
PC_STATUS_TRADING, | ||
}, | ||
tests::pyth_simulator::{ | ||
PythSimulator, | ||
Quote, | ||
}, | ||
}, | ||
solana_sdk::{ | ||
signature::Keypair, | ||
signer::Signer, | ||
}, | ||
}; | ||
|
||
// Verify that the whole publisher set participates in aggregate | ||
// calculation. This is important for verifying that extra | ||
// publisher slots on Pythnet are working. Here's how this works: | ||
// | ||
// * Fill all publisher slots on a price | ||
// * Divide the price component array into two even halves: first_half, second_half | ||
// * Publish two distinct price values to either half | ||
// * Verify that the aggregate averages out to an expected value in the middle | ||
#[tokio::test] | ||
async fn test_full_publisher_set() -> Result<(), Box<dyn std::error::Error>> { | ||
let mut sim = PythSimulator::new().await; | ||
let pub_keypairs: Vec<_> = (0..PC_NUM_COMP).map(|_idx| Keypair::new()).collect(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you sure this constant has the right value on each network? (i think you may have added a separate test toggled by the feature flag that it does have the expected value, but i forget) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a couple potential problems to discuss:
|
||
let pub_pubkeys: Vec<_> = pub_keypairs.iter().map(|kp| kp.pubkey()).collect(); | ||
|
||
let security_authority = Keypair::new(); | ||
let price_accounts = sim | ||
.setup_product_fixture(pub_pubkeys.as_slice(), security_authority.pubkey()) | ||
.await; | ||
let price = price_accounts["LTC"]; | ||
|
||
|
||
let n_pubs = pub_keypairs.len(); | ||
|
||
// Divide publishers into two even parts (assuming the max PC_NUM_COMP size is even) | ||
let (first_half, second_half) = pub_keypairs.split_at(n_pubs / 2); | ||
|
||
// Starting with the first publisher in each half, publish an update | ||
for (first_kp, second_kp) in first_half.iter().zip(second_half.iter()) { | ||
let first_quote = Quote { | ||
price: 100, | ||
confidence: 30, | ||
status: PC_STATUS_TRADING, | ||
}; | ||
|
||
sim.upd_price(first_kp, price, first_quote).await?; | ||
|
||
let second_quote = Quote { | ||
price: 120, | ||
confidence: 30, | ||
status: PC_STATUS_TRADING, | ||
}; | ||
|
||
sim.upd_price(second_kp, price, second_quote).await?; | ||
} | ||
|
||
// Advance slot once from 1 to 2 | ||
sim.warp_to_slot(2).await?; | ||
|
||
// Final price update to trigger aggregation | ||
let first_kp = pub_keypairs.first().unwrap(); | ||
let first_quote = Quote { | ||
price: 100, | ||
confidence: 30, | ||
status: PC_STATUS_TRADING, | ||
}; | ||
sim.upd_price(first_kp, price, first_quote).await?; | ||
|
||
{ | ||
let price_data = sim | ||
.get_account_data_as::<PriceAccount>(price) | ||
.await | ||
.unwrap(); | ||
|
||
assert_eq!(price_data.agg_.price_, 110); | ||
assert_eq!(price_data.agg_.conf_, 20); | ||
} | ||
|
||
Ok(()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: comment should say
publishers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this comment is correct. there's stuff like symbol name in the test case assets, but we only make it available for lookup to distinguish symbols human-readably, without filling in the relevant field in the metadata k/v/ store.