Add BPF Sanity program-test based test (#19159)
This commit is contained in:
parent
446816de52
commit
9dfeee2993
|
@ -2717,6 +2717,8 @@ name = "solana-bpf-rust-sanity"
|
||||||
version = "1.8.0"
|
version = "1.8.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"solana-program 1.8.0",
|
"solana-program 1.8.0",
|
||||||
|
"solana-program-test",
|
||||||
|
"solana-sdk",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -9,11 +9,18 @@ homepage = "https://solana.com/"
|
||||||
documentation = "https://docs.rs/solana-bpf-rust-sanity"
|
documentation = "https://docs.rs/solana-bpf-rust-sanity"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
test-bpf = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
solana-program = { path = "../../../../sdk/program", version = "=1.8.0" }
|
solana-program = { path = "../../../../sdk/program", version = "=1.8.0" }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
solana-program-test = { path = "../../../../program-test", version = "=1.8.0" }
|
||||||
|
solana-sdk = { path = "../../../../sdk", version = "=1.8.0" }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib", "lib"]
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
targets = ["x86_64-unknown-linux-gnu"]
|
targets = ["x86_64-unknown-linux-gnu"]
|
||||||
|
|
|
@ -22,7 +22,7 @@ fn return_sstruct() -> SStruct {
|
||||||
|
|
||||||
entrypoint!(process_instruction);
|
entrypoint!(process_instruction);
|
||||||
#[allow(clippy::unnecessary_wraps)]
|
#[allow(clippy::unnecessary_wraps)]
|
||||||
fn process_instruction(
|
pub fn process_instruction(
|
||||||
program_id: &Pubkey,
|
program_id: &Pubkey,
|
||||||
accounts: &[AccountInfo],
|
accounts: &[AccountInfo],
|
||||||
instruction_data: &[u8],
|
instruction_data: &[u8],
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
#![cfg(feature = "test-bpf")]
|
||||||
|
|
||||||
|
use solana_bpf_rust_sanity::process_instruction;
|
||||||
|
use solana_program_test::*;
|
||||||
|
use solana_sdk::{
|
||||||
|
instruction::{AccountMeta, Instruction},
|
||||||
|
pubkey::Pubkey,
|
||||||
|
signature::{Keypair, Signer},
|
||||||
|
transaction::Transaction,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_sysvars() {
|
||||||
|
let program_id = Pubkey::new_unique();
|
||||||
|
let program_test = ProgramTest::new(
|
||||||
|
"solana_bpf_rust_sanity",
|
||||||
|
program_id,
|
||||||
|
processor!(process_instruction),
|
||||||
|
);
|
||||||
|
let (mut banks_client, payer_keypair, recent_blockhash) = program_test.start().await;
|
||||||
|
|
||||||
|
let mut transaction = Transaction::new_with_payer(
|
||||||
|
&[Instruction::new_with_bincode(
|
||||||
|
program_id,
|
||||||
|
&(),
|
||||||
|
vec![
|
||||||
|
AccountMeta::new(payer_keypair.pubkey(), true),
|
||||||
|
AccountMeta::new(Keypair::new().pubkey(), false),
|
||||||
|
],
|
||||||
|
)],
|
||||||
|
Some(&payer_keypair.pubkey()),
|
||||||
|
);
|
||||||
|
transaction.sign(&[&payer_keypair], recent_blockhash);
|
||||||
|
banks_client.process_transaction(transaction).await.unwrap();
|
||||||
|
}
|
|
@ -1,11 +1,13 @@
|
||||||
use solana_bpf_rust_sysvar::process_instruction;
|
use solana_bpf_rust_sysvar::process_instruction;
|
||||||
use solana_program_test::*;
|
use solana_program_test::*;
|
||||||
use solana_sdk::sysvar::recent_blockhashes;
|
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
instruction::{AccountMeta, Instruction},
|
instruction::{AccountMeta, Instruction},
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::Signer,
|
signature::Signer,
|
||||||
sysvar::{clock, epoch_schedule, instructions, rent, slot_hashes, slot_history, stake_history},
|
sysvar::{
|
||||||
|
clock, epoch_schedule, instructions, recent_blockhashes, rent, slot_hashes, slot_history,
|
||||||
|
stake_history,
|
||||||
|
},
|
||||||
transaction::Transaction,
|
transaction::Transaction,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1335,7 +1335,7 @@ fn assert_instruction_count() {
|
||||||
("solana_bpf_rust_noop", 478),
|
("solana_bpf_rust_noop", 478),
|
||||||
("solana_bpf_rust_param_passing", 46),
|
("solana_bpf_rust_param_passing", 46),
|
||||||
("solana_bpf_rust_rand", 481),
|
("solana_bpf_rust_rand", 481),
|
||||||
("solana_bpf_rust_sanity", 907),
|
("solana_bpf_rust_sanity", 922),
|
||||||
("solana_bpf_rust_secp256k1_recover", 301),
|
("solana_bpf_rust_secp256k1_recover", 301),
|
||||||
("solana_bpf_rust_sha", 32337),
|
("solana_bpf_rust_sha", 32337),
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Reference in New Issue