Review comments
This commit is contained in:
committed by
Greg Fitzgerald
parent
1a9ef37251
commit
fe1676bc3a
@ -108,13 +108,7 @@ fn execute_instruction(
|
||||
program_accounts,
|
||||
tick_height,
|
||||
)
|
||||
.map_err(|err| match err {
|
||||
ProgramError::CustomError(mut error) => {
|
||||
error.truncate(32);
|
||||
ProgramError::CustomError(error)
|
||||
}
|
||||
e => e,
|
||||
})?;
|
||||
.map_err(verify_error)?;
|
||||
|
||||
// Verify the instruction
|
||||
for ((pre_program_id, pre_lamports, pre_userdata), post_account) in
|
||||
@ -233,6 +227,16 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn verify_error(err: ProgramError) -> ProgramError {
|
||||
match err {
|
||||
ProgramError::CustomError(mut error) => {
|
||||
error.truncate(32);
|
||||
ProgramError::CustomError(error)
|
||||
}
|
||||
e => e,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@ -312,4 +316,18 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_verify_error() {
|
||||
let short_error = ProgramError::CustomError(vec![1, 2, 3]);
|
||||
let expected_short_error = short_error.clone(); // short CustomError errors should be untouched
|
||||
assert_eq!(verify_error(short_error), expected_short_error);
|
||||
|
||||
let long_error = ProgramError::CustomError(vec![8; 40]);
|
||||
let expected_long_error = ProgramError::CustomError(vec![8; 32]); // long CustomError errors should be truncated
|
||||
assert_eq!(verify_error(long_error), expected_long_error);
|
||||
|
||||
let other_error = ProgramError::GenericError;
|
||||
let expected_other_error = other_error.clone(); // non-CustomError errors should be untouched
|
||||
assert_eq!(verify_error(other_error), expected_other_error);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user