From 6a89c68a1dd46cbad21dc2bf166ff5d021a30910 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Wed, 13 Mar 2019 11:55:43 -0600 Subject: [PATCH] Add utility function to help get System error out of ProgramError --- core/src/banking_stage.rs | 3 +-- runtime/src/bank.rs | 9 ++++----- runtime/src/runtime.rs | 6 ++++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/core/src/banking_stage.rs b/core/src/banking_stage.rs index f9ba714bd5..3fc2038e7a 100644 --- a/core/src/banking_stage.rs +++ b/core/src/banking_stage.rs @@ -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(); diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index bcecb5e45c..9b789ebc1c 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -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(), )), ]; diff --git a/runtime/src/runtime.rs b/runtime/src/runtime.rs index c11ab2a444..06f2ff49ea 100644 --- a/runtime/src/runtime.rs +++ b/runtime/src/runtime.rs @@ -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 {