diff --git a/program/rust/src/deserialize.rs b/program/rust/src/deserialize.rs index 6af073aad..e7772168e 100644 --- a/program/rust/src/deserialize.rs +++ b/program/rust/src/deserialize.rs @@ -89,7 +89,7 @@ pub fn load_checked<'a, T: PythAccount>( account_header.magic_number == PC_MAGIC && account_header.version == version && account_header.account_type == T::ACCOUNT_TYPE, - ProgramError::InvalidArgument, + OracleError::InvalidAccountHeader.into(), )?; } diff --git a/program/rust/src/error.rs b/program/rust/src/error.rs index 9be5c9710..87878045e 100644 --- a/program/rust/src/error.rs +++ b/program/rust/src/error.rs @@ -40,6 +40,10 @@ pub enum OracleError { InvalidUpgradeAuthority = 614, #[error("FailedPdaVerification")] InvalidPda = 615, + #[error("InvalidAccountHeader")] + InvalidAccountHeader = 616, + #[error("InvalidNumberOfAccounts")] + InvalidNumberOfAccounts = 617, } impl From for ProgramError { diff --git a/program/rust/src/rust_oracle.rs b/program/rust/src/rust_oracle.rs index 1645cc807..1258563f8 100644 --- a/program/rust/src/rust_oracle.rs +++ b/program/rust/src/rust_oracle.rs @@ -91,7 +91,7 @@ pub fn resize_price_account( ) -> ProgramResult { let [funding_account_info, price_account_info, system_program] = match accounts { [x, y, z] => Ok([x, y, z]), - _ => Err(ProgramError::InvalidArgument), + _ => Err(OracleError::InvalidNumberOfAccounts), }?; check_valid_funding_account(funding_account_info)?; @@ -148,7 +148,7 @@ pub fn init_mapping( ) -> ProgramResult { let [funding_account, fresh_mapping_account] = match accounts { [x, y] => Ok([x, y]), - _ => Err(ProgramError::InvalidArgument), + _ => Err(OracleError::InvalidNumberOfAccounts), }?; check_valid_funding_account(funding_account)?; @@ -168,7 +168,7 @@ pub fn add_mapping( ) -> ProgramResult { let [funding_account, cur_mapping, next_mapping] = match accounts { [x, y, z] => Ok([x, y, z]), - _ => Err(ProgramError::InvalidArgument), + _ => Err(OracleError::InvalidNumberOfAccounts), }?; check_valid_funding_account(funding_account)?; @@ -203,7 +203,7 @@ pub fn upd_price( let [funding_account, price_account, clock_account] = match accounts { [x, y, z] => Ok([x, y, z]), [x, y, _, z] => Ok([x, y, z]), - _ => Err(ProgramError::InvalidArgument), + _ => Err(OracleError::InvalidNumberOfAccounts), }?; check_valid_funding_account(funding_account)?; @@ -319,7 +319,7 @@ pub fn add_price( let [funding_account, product_account, price_account] = match accounts { [x, y, z] => Ok([x, y, z]), - _ => Err(ProgramError::InvalidArgument), + _ => Err(OracleError::InvalidNumberOfAccounts), }?; check_valid_funding_account(funding_account)?; @@ -354,7 +354,7 @@ pub fn del_price( ) -> ProgramResult { let [funding_account, product_account, price_account] = match accounts { [w, x, y] => Ok([w, x, y]), - _ => Err(ProgramError::InvalidArgument), + _ => Err(OracleError::InvalidNumberOfAccounts), }?; check_valid_funding_account(funding_account)?; @@ -399,7 +399,7 @@ pub fn init_price( let [funding_account, price_account] = match accounts { [x, y] => Ok([x, y]), - _ => Err(ProgramError::InvalidArgument), + _ => Err(OracleError::InvalidNumberOfAccounts), }?; check_valid_funding_account(funding_account)?; @@ -469,7 +469,7 @@ pub fn add_publisher( let [funding_account, price_account] = match accounts { [x, y] => Ok([x, y]), - _ => Err(ProgramError::InvalidArgument), + _ => Err(OracleError::InvalidNumberOfAccounts), }?; check_valid_funding_account(funding_account)?; @@ -519,7 +519,7 @@ pub fn del_publisher( let [funding_account, price_account] = match accounts { [x, y] => Ok([x, y]), - _ => Err(ProgramError::InvalidArgument), + _ => Err(OracleError::InvalidNumberOfAccounts), }?; check_valid_funding_account(funding_account)?; @@ -555,7 +555,7 @@ pub fn add_product( ) -> ProgramResult { let [funding_account, tail_mapping_account, new_product_account] = match accounts { [x, y, z] => Ok([x, y, z]), - _ => Err(ProgramError::InvalidArgument), + _ => Err(OracleError::InvalidNumberOfAccounts), }?; check_valid_funding_account(funding_account)?; @@ -592,7 +592,7 @@ pub fn upd_product( ) -> ProgramResult { let [funding_account, product_account] = match accounts { [x, y] => Ok([x, y]), - _ => Err(ProgramError::InvalidArgument), + _ => Err(OracleError::InvalidNumberOfAccounts), }?; check_valid_funding_account(funding_account)?; @@ -657,7 +657,7 @@ pub fn set_min_pub( let [funding_account, price_account] = match accounts { [x, y] => Ok([x, y]), - _ => Err(ProgramError::InvalidArgument), + _ => Err(OracleError::InvalidNumberOfAccounts), }?; check_valid_funding_account(funding_account)?; @@ -683,7 +683,7 @@ pub fn del_product( ) -> ProgramResult { let [funding_account, mapping_account, product_account] = match accounts { [w, x, y] => Ok([w, x, y]), - _ => Err(ProgramError::InvalidArgument), + _ => Err(OracleError::InvalidNumberOfAccounts), }?; check_valid_funding_account(funding_account)?; @@ -751,7 +751,7 @@ pub fn upd_permissions( let [funding_account, program_account, programdata_account, permissions_account, system_program] = match accounts { [v, w, x, y, z] => Ok([v, w, x, y, z]), - _ => Err(ProgramError::InvalidArgument), + _ => Err(OracleError::InvalidNumberOfAccounts), }?; let cmd_args = load::(instruction_data)?; diff --git a/program/rust/src/tests/test_add_mapping.rs b/program/rust/src/tests/test_add_mapping.rs index ac56f969b..ddb6f2f47 100644 --- a/program/rust/src/tests/test_add_mapping.rs +++ b/program/rust/src/tests/test_add_mapping.rs @@ -9,6 +9,7 @@ use crate::deserialize::{ load_account_as_mut, load_checked, }; +use crate::error::OracleError; use crate::instruction::{ CommandHeader, OracleCommand, @@ -98,7 +99,7 @@ fn test_add_mapping() { ], instruction_data ), - Err(ProgramError::InvalidArgument) + Err(OracleError::InvalidAccountHeader.into()) ); { diff --git a/program/rust/src/tests/test_add_price.rs b/program/rust/src/tests/test_add_price.rs index 882ae74bc..a384221a7 100644 --- a/program/rust/src/tests/test_add_price.rs +++ b/program/rust/src/tests/test_add_price.rs @@ -111,7 +111,7 @@ fn test_add_price() { &[funding_account.clone(), product_account.clone()], instruction_data_add_price ), - Err(ProgramError::InvalidArgument) + Err(OracleError::InvalidNumberOfAccounts.into()) ); // Price account is already initialized @@ -191,6 +191,6 @@ fn test_add_price() { ], instruction_data_add_price ), - Err(ProgramError::InvalidArgument) + Err(OracleError::InvalidAccountHeader.into()) ); } diff --git a/program/rust/src/tests/test_add_publisher.rs b/program/rust/src/tests/test_add_publisher.rs index 36859af95..8f2c1c103 100644 --- a/program/rust/src/tests/test_add_publisher.rs +++ b/program/rust/src/tests/test_add_publisher.rs @@ -95,7 +95,7 @@ fn test_add_publisher() { &[funding_account.clone(), price_account.clone(),], instruction_data ), - Err(ProgramError::InvalidArgument) + Err(OracleError::InvalidAccountHeader.into()) ); initialize_pyth_account_checked::(&price_account, PC_VERSION).unwrap(); diff --git a/program/rust/src/tests/test_init_mapping.rs b/program/rust/src/tests/test_init_mapping.rs index 298453be4..384483f6c 100644 --- a/program/rust/src/tests/test_init_mapping.rs +++ b/program/rust/src/tests/test_init_mapping.rs @@ -14,7 +14,6 @@ use crate::processor::process_instruction; use crate::tests::test_utils::AccountSetup; use crate::utils::clear_account; use bytemuck::bytes_of; -use solana_program::program_error::ProgramError; use solana_program::pubkey::Pubkey; use std::cell::RefCell; use std::rc::Rc; @@ -62,7 +61,7 @@ fn test_init_mapping() { assert_eq!( process_instruction(&program_id, &[funding_account.clone()], instruction_data), - Err(ProgramError::InvalidArgument) + Err(OracleError::InvalidNumberOfAccounts.into()) ); funding_account.is_signer = false; diff --git a/program/rust/src/tests/test_init_price.rs b/program/rust/src/tests/test_init_price.rs index e180ec2c2..1449b2ea2 100644 --- a/program/rust/src/tests/test_init_price.rs +++ b/program/rust/src/tests/test_init_price.rs @@ -50,7 +50,7 @@ fn test_init_price() { &[funding_account.clone(), price_account.clone()], instruction_data ), - Err(ProgramError::InvalidArgument) + Err(OracleError::InvalidAccountHeader.into()) ); initialize_pyth_account_checked::(&price_account, PC_VERSION).unwrap();