Skip to content

Commit

Permalink
get 'map_transaction_error' return value consistent (#6277)
Browse files Browse the repository at this point in the history
  • Loading branch information
yihau authored Feb 20, 2024
1 parent 655e294 commit c9eb289
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions governance/test-sdk/src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,25 @@ pub fn map_transaction_error(transport_error: TransportError) -> ProgramError {
TransportError::TransactionError(TransactionError::InstructionError(
_,
instruction_error,
)) => ProgramError::try_from(instruction_error).unwrap_or_else(|ie| match ie {
)) => match instruction_error {
// In solana-sdk v1.19.0, there is a ProgramError for
// InstructionError::IncorrectAuthority. This results in the error mapping
// returning two different values: one for sdk < v1.19 and another for sdk >= v1.19.0.
// To avoid this situation, handle InstructionError::IncorrectAuthority earlier.
// Can be removed when Solana v1.19.0 becomes a stable channel (also need to update the
// test assert for
// `test_create_program_governance_with_incorrect_upgrade_authority_error`)
InstructionError::IncorrectAuthority => {
ProgramInstructionError::IncorrectAuthority.into()
}
InstructionError::PrivilegeEscalation => {
ProgramInstructionError::PrivilegeEscalation.into()
}
_ => panic!("TEST-INSTRUCTION-ERROR {:?}", ie),
}),

_ => ProgramError::try_from(instruction_error).unwrap_or_else(|ie| match ie {
InstructionError::IncorrectAuthority => unreachable!(),
InstructionError::PrivilegeEscalation => {
ProgramInstructionError::PrivilegeEscalation.into()
}
_ => panic!("TEST-INSTRUCTION-ERROR {:?}", ie),
}),
},
_ => panic!("TEST-TRANSPORT-ERROR: {:?}", transport_error),
}
}
Expand Down

0 comments on commit c9eb289

Please sign in to comment.