Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit c9eb289

Browse files
authored
get 'map_transaction_error' return value consistent (#6277)
1 parent 655e294 commit c9eb289

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

governance/test-sdk/src/tools.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,25 @@ pub fn map_transaction_error(transport_error: TransportError) -> ProgramError {
2929
TransportError::TransactionError(TransactionError::InstructionError(
3030
_,
3131
instruction_error,
32-
)) => ProgramError::try_from(instruction_error).unwrap_or_else(|ie| match ie {
32+
)) => match instruction_error {
33+
// In solana-sdk v1.19.0, there is a ProgramError for
34+
// InstructionError::IncorrectAuthority. This results in the error mapping
35+
// returning two different values: one for sdk < v1.19 and another for sdk >= v1.19.0.
36+
// To avoid this situation, handle InstructionError::IncorrectAuthority earlier.
37+
// Can be removed when Solana v1.19.0 becomes a stable channel (also need to update the
38+
// test assert for
39+
// `test_create_program_governance_with_incorrect_upgrade_authority_error`)
3340
InstructionError::IncorrectAuthority => {
3441
ProgramInstructionError::IncorrectAuthority.into()
3542
}
36-
InstructionError::PrivilegeEscalation => {
37-
ProgramInstructionError::PrivilegeEscalation.into()
38-
}
39-
_ => panic!("TEST-INSTRUCTION-ERROR {:?}", ie),
40-
}),
41-
43+
_ => ProgramError::try_from(instruction_error).unwrap_or_else(|ie| match ie {
44+
InstructionError::IncorrectAuthority => unreachable!(),
45+
InstructionError::PrivilegeEscalation => {
46+
ProgramInstructionError::PrivilegeEscalation.into()
47+
}
48+
_ => panic!("TEST-INSTRUCTION-ERROR {:?}", ie),
49+
}),
50+
},
4251
_ => panic!("TEST-TRANSPORT-ERROR: {:?}", transport_error),
4352
}
4453
}

0 commit comments

Comments
 (0)