Skip to content

Conversation

guibescos
Copy link
Contributor

@guibescos guibescos commented Apr 24, 2023

This PR aims to move the last python tests to rust.
I had to refactor parts of pyth_simulator.rs to support moving the clock and to support sending multiple instruction in one transaction.
The tests imitate what was happening in Python but with some extra assertions.
I will delete the python tests once this gets merged.

@guibescos guibescos force-pushed the move-tests-to-rust branch from a12ab92 to cfb076b Compare April 24, 2023 19:55
// Try to update the publisher's price
if is_component_update(cmd_args)? {
let mut status: u32 = cmd_args.status;
let mut threshold_conf = cmd_args.price / MAX_CI_DIVISOR;
Copy link
Contributor Author

@guibescos guibescos Apr 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code gets refactored so I can use it in test_publish_batch.rs.

@@ -64,7 +76,7 @@ use {
/// this struct to test how pyth instructions execute in the Solana runtime.
pub struct PythSimulator {
program_id: Pubkey,
banks_client: BanksClient,
context: ProgramTestContext,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need this refactor to be able to advance the clock in the simulator

/// `payer` is used to pay for and sign the transaction.
async fn process_ix(
async fn process_ixs(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function got updated to support multiple instructions in the same transaction

@@ -0,0 +1,164 @@
use {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will replace test_update_price.py

@@ -0,0 +1,128 @@
use {
crate::{
accounts::PriceAccount,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will replace test_update_price.py


sim.warp_to_slot(2).await.unwrap();

let mut new_quotes: HashMap<String, Quote> = HashMap::new();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In test_update_price.py, the second set of quotes are (1,1,"TRADING"). I changed the second set of quotes to be random here.

@guibescos guibescos marked this pull request as ready for review April 24, 2023 21:18
Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool. i left you a very minor comment. feel free to merge this and rename that function in whatever your next pr is.

@@ -195,6 +199,25 @@ pub fn is_component_update(cmd_args: &UpdPriceArgs) -> Result<bool, OracleError>
}
}

// Return PC_STATUS_IGNORED if confidence is bigger than price divided by MAX_CI_DIVISOR else returns status
pub fn check_confidence_too_big(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function name sounds like it's going to error if the confidence is too big. something more like get_status_for_update would be better. (I don't love that name either, but the point being the name should indicate that this returns a status)

@guibescos guibescos merged commit 458e49b into main Apr 24, 2023
@guibescos guibescos deleted the move-tests-to-rust branch April 24, 2023 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants