forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Program Test: Fix invoke_builtin_function unwinding (#2632)
- Loading branch information
1 parent
1588bca
commit 52e7329
Showing
2 changed files
with
62 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use { | ||
solana_program_test::{processor, ProgramTest}, | ||
solana_sdk::{ | ||
account_info::AccountInfo, | ||
entrypoint::ProgramResult, | ||
instruction::{Instruction, InstructionError}, | ||
pubkey::Pubkey, | ||
signature::Signer, | ||
transaction::{Transaction, TransactionError}, | ||
}, | ||
}; | ||
|
||
fn panic(_program_id: &Pubkey, _accounts: &[AccountInfo], _input: &[u8]) -> ProgramResult { | ||
panic!("I panicked"); | ||
} | ||
|
||
#[tokio::test] | ||
async fn panic_test() { | ||
let program_id = Pubkey::new_unique(); | ||
|
||
let program_test = ProgramTest::new("panic", program_id, processor!(panic)); | ||
|
||
let context = program_test.start_with_context().await; | ||
|
||
let instruction = Instruction::new_with_bytes(program_id, &[], vec![]); | ||
|
||
let transaction = Transaction::new_signed_with_payer( | ||
&[instruction], | ||
Some(&context.payer.pubkey()), | ||
&[&context.payer], | ||
context.last_blockhash, | ||
); | ||
assert_eq!( | ||
context | ||
.banks_client | ||
.process_transaction(transaction) | ||
.await | ||
.unwrap_err() | ||
.unwrap(), | ||
TransactionError::InstructionError(0, InstructionError::ProgramFailedToComplete) | ||
); | ||
} |