Add utility function to help get System error out of ProgramError

This commit is contained in:
Greg Fitzgerald 2019-03-13 11:55:43 -06:00
parent c14cce4c85
commit 6a89c68a1d
3 changed files with 11 additions and 7 deletions

View File

@ -447,7 +447,6 @@ mod tests {
use crate::poh_recorder::WorkingBank;
use solana_runtime::runtime::InstructionError;
use solana_sdk::genesis_block::GenesisBlock;
use solana_sdk::native_program::ProgramError;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::system_transaction::SystemTransaction;
use std::sync::mpsc::channel;
@ -685,7 +684,7 @@ mod tests {
// ProgramErrors should still be recorded
results[0] = Err(BankError::InstructionError(
1,
InstructionError::ProgramError(ProgramError::ResultWithNegativeLamports),
InstructionError::new_result_with_negative_lamports(),
));
BankingStage::record_transactions(&transactions, &results, &poh_recorder).unwrap();
let (_, entries) = entry_receiver.recv().unwrap();

View File

@ -888,7 +888,6 @@ mod tests {
use bincode::serialize;
use solana_sdk::genesis_block::{GenesisBlock, BOOTSTRAP_LEADER_LAMPORTS};
use solana_sdk::hash;
use solana_sdk::native_program::ProgramError;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::system_instruction::SystemInstruction;
use solana_sdk::system_program;
@ -1002,7 +1001,7 @@ mod tests {
bank.get_signature_status(&t1.signatures[0]),
Some(Err(BankError::InstructionError(
1,
InstructionError::ProgramError(ProgramError::ResultWithNegativeLamports)
InstructionError::new_result_with_negative_lamports(),
)))
);
}
@ -1050,7 +1049,7 @@ mod tests {
bank.process_transaction(&tx),
Err(BankError::InstructionError(
0,
InstructionError::ProgramError(ProgramError::ResultWithNegativeLamports)
InstructionError::new_result_with_negative_lamports(),
))
);
@ -1086,7 +1085,7 @@ mod tests {
bank.transfer(10_001, &mint_keypair, &pubkey, genesis_block.hash()),
Err(BankError::InstructionError(
0,
InstructionError::ProgramError(ProgramError::ResultWithNegativeLamports)
InstructionError::new_result_with_negative_lamports(),
))
);
assert_eq!(bank.transaction_count(), 1);
@ -1187,7 +1186,7 @@ mod tests {
Ok(()),
Err(BankError::InstructionError(
1,
InstructionError::ProgramError(ProgramError::ResultWithNegativeLamports),
InstructionError::new_result_with_negative_lamports(),
)),
];

View File

@ -24,6 +24,12 @@ pub enum InstructionError {
ExternalAccountUserdataModified,
}
impl InstructionError {
pub fn new_result_with_negative_lamports() -> Self {
InstructionError::ProgramError(ProgramError::ResultWithNegativeLamports)
}
}
/// Reasons the runtime might have rejected a transaction.
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum TransactionError {