Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions program/rust/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ pub enum OracleError {
UnknownCError = 602,
#[error("UnrecognizedInstruction")]
UnrecognizedInstruction = 603,
#[error("InvalidFundingAccount")]
InvalidFundingAccount = 604,
#[error("InvalidSignableAccount")]
InvalidSignableAccount = 605,
#[error("InvalidSystemAccount")]
InvalidSystemAccount = 606,
#[error("InvalidWritableAccount")]
InvalidWritableAccount = 607,
#[error("InvalidWritableAccount")]
InvalidFreshAccount = 608,
}

impl From<OracleError> for ProgramError {
Expand Down
9 changes: 6 additions & 3 deletions program/rust/src/rust_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ fn valid_funding_account(account: &AccountInfo) -> bool {
fn check_valid_funding_account(account: &AccountInfo) -> Result<(), ProgramError> {
pyth_assert(
valid_funding_account(account),
ProgramError::InvalidArgument,
OracleError::InvalidFundingAccount.into(),
)
}

Expand All @@ -375,7 +375,7 @@ fn check_valid_signable_account(
) -> Result<(), ProgramError> {
pyth_assert(
valid_signable_account(program_id, account, minimum_size),
ProgramError::InvalidArgument,
OracleError::InvalidSignableAccount.into(),
)
}

Expand All @@ -390,7 +390,10 @@ fn valid_fresh_account(account: &AccountInfo) -> bool {
}

fn check_valid_fresh_account(account: &AccountInfo) -> Result<(), ProgramError> {
pyth_assert(valid_fresh_account(account), ProgramError::InvalidArgument)
pyth_assert(
valid_fresh_account(account),
OracleError::InvalidFreshAccount.into(),
)
}

/// Sets the data of account to all-zero
Expand Down
5 changes: 3 additions & 2 deletions program/rust/src/tests/test_add_price.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::error::OracleError;
use crate::tests::test_utils::AccountSetup;
use bytemuck::bytes_of;
use solana_program::program_error::ProgramError;
Expand Down Expand Up @@ -146,7 +147,7 @@ fn test_add_price() {
],
instruction_data_add_price
),
Err(ProgramError::InvalidArgument)
Err(OracleError::InvalidFreshAccount.into())
);

clear_account(&price_account).unwrap();
Expand Down Expand Up @@ -195,7 +196,7 @@ fn test_add_price() {
],
instruction_data_add_price
),
Err(ProgramError::InvalidArgument)
Err(OracleError::InvalidSignableAccount.into())
);

// Fresh product account
Expand Down
3 changes: 2 additions & 1 deletion program/rust/src/tests/test_add_product.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::mem::size_of;

use crate::error::OracleError;
use crate::tests::test_utils::AccountSetup;
use bytemuck::bytes_of;
use solana_program::account_info::AccountInfo;
Expand Down Expand Up @@ -123,7 +124,7 @@ fn test_add_product() {
],
instruction_data
),
Err(ProgramError::InvalidArgument)
Err(OracleError::InvalidSignableAccount.into())
);

// test fill up of mapping table
Expand Down
3 changes: 2 additions & 1 deletion program/rust/src/tests/test_add_publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::rust_oracle::{
load_checked,
pubkey_equal,
};
use crate::OracleError;

#[test]
fn test_add_publisher() {
Expand Down Expand Up @@ -53,7 +54,7 @@ fn test_add_publisher() {
&[funding_account.clone(), price_account.clone(),],
instruction_data
),
Err(ProgramError::InvalidArgument)
Err(OracleError::InvalidSignableAccount.into())
);

// Now give the price account enough lamports to be rent exempt
Expand Down
15 changes: 8 additions & 7 deletions program/rust/src/tests/test_init_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::c_oracle_header::{
PC_VERSION,
};
use crate::deserialize::load_account_as;
use crate::error::OracleError;
use crate::rust_oracle::{
clear_account,
init_mapping,
Expand Down Expand Up @@ -57,7 +58,7 @@ fn test_init_mapping() {
&[funding_account.clone(), mapping_account.clone()],
instruction_data
),
Err(ProgramError::InvalidArgument)
Err(OracleError::InvalidFreshAccount.into())
);

clear_account(&mapping_account).unwrap();
Expand All @@ -75,7 +76,7 @@ fn test_init_mapping() {
&[funding_account.clone(), mapping_account.clone()],
instruction_data
),
Err(ProgramError::InvalidArgument)
Err(OracleError::InvalidFundingAccount.into())
);

funding_account.is_signer = true;
Expand All @@ -87,7 +88,7 @@ fn test_init_mapping() {
&[funding_account.clone(), mapping_account.clone()],
instruction_data
),
Err(ProgramError::InvalidArgument)
Err(OracleError::InvalidSignableAccount.into())
);

mapping_account.is_signer = true;
Expand All @@ -99,7 +100,7 @@ fn test_init_mapping() {
&[funding_account.clone(), mapping_account.clone()],
instruction_data
),
Err(ProgramError::InvalidArgument)
Err(OracleError::InvalidFundingAccount.into())
);

funding_account.is_writable = true;
Expand All @@ -111,7 +112,7 @@ fn test_init_mapping() {
&[funding_account.clone(), mapping_account.clone()],
instruction_data
),
Err(ProgramError::InvalidArgument)
Err(OracleError::InvalidSignableAccount.into())
);

mapping_account.is_writable = true;
Expand All @@ -123,7 +124,7 @@ fn test_init_mapping() {
&[funding_account.clone(), mapping_account.clone()],
instruction_data
),
Err(ProgramError::InvalidArgument)
Err(OracleError::InvalidSignableAccount.into())
);

mapping_account.owner = &program_id;
Expand All @@ -136,7 +137,7 @@ fn test_init_mapping() {
&[funding_account.clone(), mapping_account.clone()],
instruction_data
),
Err(ProgramError::InvalidArgument)
Err(OracleError::InvalidSignableAccount.into())
);

mapping_account.data = prev_data;
Expand Down
2 changes: 1 addition & 1 deletion program/rust/src/tests/test_upd_product.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::mem::size_of;

use crate::rust_oracle::try_convert;
use crate::tests::test_utils::AccountSetup;
use solana_program::account_info::AccountInfo;
use solana_program::program_error::ProgramError;
Expand All @@ -19,7 +20,6 @@ use crate::rust_oracle::{
initialize_checked,
load_checked,
read_pc_str_t,
try_convert,
upd_product,
};

Expand Down