From c9eb289de8bc52930c109e0fba128d08e4948352 Mon Sep 17 00:00:00 2001 From: Yihau Chen Date: Tue, 20 Feb 2024 22:48:07 +0800 Subject: [PATCH] get 'map_transaction_error' return value consistent (#6277) --- governance/test-sdk/src/tools.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/governance/test-sdk/src/tools.rs b/governance/test-sdk/src/tools.rs index 8705f8fb9ca..c929467e689 100644 --- a/governance/test-sdk/src/tools.rs +++ b/governance/test-sdk/src/tools.rs @@ -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), } }