Generalize error codes
This commit is contained in:
parent
1de5ae1ef0
commit
296415945a
|
@ -85,7 +85,7 @@ pub fn entrypoint(
|
|||
// All system instructions require that accounts_keys[0] be a signer
|
||||
if keyed_accounts[FROM_ACCOUNT_INDEX].signer_key().is_none() {
|
||||
info!("account[from] is unsigned");
|
||||
Err(ProgramError::InvalidArgument)?;
|
||||
Err(ProgramError::MissingRequiredSignature)?;
|
||||
}
|
||||
|
||||
match instruction {
|
||||
|
@ -96,7 +96,7 @@ pub fn entrypoint(
|
|||
} => create_system_account(keyed_accounts, lamports, space, &program_id),
|
||||
SystemInstruction::Assign { program_id } => {
|
||||
if !system_program::check_id(&keyed_accounts[FROM_ACCOUNT_INDEX].account.owner) {
|
||||
Err(ProgramError::AssignOfUnownedAccount)?;
|
||||
Err(ProgramError::IncorrectProgramId)?;
|
||||
}
|
||||
assign_account_to_program(keyed_accounts, &program_id)
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ mod tests {
|
|||
};
|
||||
let data = serialize(&instruction).unwrap();
|
||||
let result = entrypoint(&system_program::id(), &mut keyed_accounts, &data, 0);
|
||||
assert_eq!(result, Err(ProgramError::AssignOfUnownedAccount));
|
||||
assert_eq!(result, Err(ProgramError::IncorrectProgramId));
|
||||
assert_eq!(from_account.owner, new_program_owner);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ fn test_system_unsigned_transaction() {
|
|||
system_bank.bank.process_transaction(&tx),
|
||||
Err(BankError::InstructionError(
|
||||
0,
|
||||
InstructionError::ProgramError(ProgramError::InvalidArgument)
|
||||
InstructionError::ProgramError(ProgramError::MissingRequiredSignature)
|
||||
))
|
||||
);
|
||||
assert_eq!(system_bank.bank.get_balance(&from_keypair.pubkey()), 50);
|
||||
|
|
|
@ -17,8 +17,11 @@ pub enum ProgramError {
|
|||
/// An account's userdata was too small
|
||||
UserdataTooSmall,
|
||||
|
||||
/// SystemInstruction::Assign was attempted on an account unowned by the system program
|
||||
AssignOfUnownedAccount,
|
||||
/// The account did not have the expected program id
|
||||
IncorrectProgramId,
|
||||
|
||||
/// A signature was required but not found
|
||||
MissingRequiredSignature,
|
||||
|
||||
/// CustomError allows on-chain programs to implement program-specific error types and see
|
||||
/// them returned by the Solana runtime. A CustomError may be any type that is serialized
|
||||
|
|
Loading…
Reference in New Issue