Align ProcessInstruction error handling (#16232)

This commit is contained in:
Jack May
2021-03-30 13:41:04 -07:00
committed by GitHub
parent f84e88f0a2
commit ce7f7c2b6c

View File

@ -69,27 +69,6 @@ pub mod programs;
#[macro_use] #[macro_use]
extern crate solana_bpf_loader_program; extern crate solana_bpf_loader_program;
pub fn to_instruction_error(error: ProgramError) -> InstructionError {
match error {
ProgramError::Custom(err) => InstructionError::Custom(err),
ProgramError::InvalidArgument => InstructionError::InvalidArgument,
ProgramError::InvalidInstructionData => InstructionError::InvalidInstructionData,
ProgramError::InvalidAccountData => InstructionError::InvalidAccountData,
ProgramError::AccountDataTooSmall => InstructionError::AccountDataTooSmall,
ProgramError::InsufficientFunds => InstructionError::InsufficientFunds,
ProgramError::IncorrectProgramId => InstructionError::IncorrectProgramId,
ProgramError::MissingRequiredSignature => InstructionError::MissingRequiredSignature,
ProgramError::AccountAlreadyInitialized => InstructionError::AccountAlreadyInitialized,
ProgramError::UninitializedAccount => InstructionError::UninitializedAccount,
ProgramError::NotEnoughAccountKeys => InstructionError::NotEnoughAccountKeys,
ProgramError::AccountBorrowFailed => InstructionError::AccountBorrowFailed,
ProgramError::MaxSeedLengthExceeded => InstructionError::MaxSeedLengthExceeded,
ProgramError::InvalidSeeds => InstructionError::InvalidSeeds,
ProgramError::BorshIoError(err) => InstructionError::BorshIoError(err),
ProgramError::AccountNotRentExempt => InstructionError::AccountNotRentExempt,
}
}
/// Errors from the program test environment /// Errors from the program test environment
#[derive(Error, Debug, PartialEq)] #[derive(Error, Debug, PartialEq)]
pub enum ProgramTestError { pub enum ProgramTestError {
@ -169,10 +148,8 @@ pub fn builtin_process_instruction(
.collect(); .collect();
// Execute the program // Execute the program
let result = process_instruction(program_id, &account_infos, input).map_err(u64::from)?;
process_instruction(program_id, &account_infos, input).map_err(to_instruction_error);
if result.is_ok() {
// Commit AccountInfo changes back into KeyedAccounts // Commit AccountInfo changes back into KeyedAccounts
for keyed_account in keyed_accounts { for keyed_account in keyed_accounts {
let mut account = keyed_account.account.borrow_mut(); let mut account = keyed_account.account.borrow_mut();
@ -181,9 +158,8 @@ pub fn builtin_process_instruction(
account.lamports = **lamports.borrow(); account.lamports = **lamports.borrow();
account.set_data(data.borrow().to_vec()); account.set_data(data.borrow().to_vec());
} }
}
result Ok(())
} }
/// Converts a `solana-program`-style entrypoint into the runtime's entrypoint style, for /// Converts a `solana-program`-style entrypoint into the runtime's entrypoint style, for