forked from anza-xyz/agave
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Program-Test: Add test for BPF programs (anza-xyz#1416)
- Loading branch information
1 parent
4178c69
commit 1a37631
Showing
1 changed file
with
43 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use { | ||
solana_program_test::ProgramTest, | ||
solana_sdk::{ | ||
bpf_loader, instruction::Instruction, pubkey::Pubkey, signature::Signer, | ||
transaction::Transaction, | ||
}, | ||
}; | ||
|
||
#[tokio::test] | ||
async fn test_add_bpf_program() { | ||
let program_id = Pubkey::new_unique(); | ||
|
||
std::env::set_var("SBF_OUT_DIR", "../programs/bpf_loader/test_elfs/out"); | ||
|
||
let mut program_test = ProgramTest::default(); | ||
program_test.prefer_bpf(true); | ||
program_test.add_program("noop_aligned", program_id, None); | ||
|
||
let mut context = program_test.start_with_context().await; | ||
|
||
// Assert the program is a BPF Loader 2 program. | ||
let program_account = context | ||
.banks_client | ||
.get_account(program_id) | ||
.await | ||
.unwrap() | ||
.unwrap(); | ||
assert_eq!(program_account.owner, bpf_loader::id()); | ||
|
||
// Invoke the program. | ||
let instruction = Instruction::new_with_bytes(program_id, &[], Vec::new()); | ||
let transaction = Transaction::new_signed_with_payer( | ||
&[instruction], | ||
Some(&context.payer.pubkey()), | ||
&[&context.payer], | ||
context.last_blockhash, | ||
); | ||
context | ||
.banks_client | ||
.process_transaction(transaction) | ||
.await | ||
.unwrap(); | ||
} |