2023-03-12 22:28:34 -07:00
|
|
|
#![cfg(feature = "test-bpf")]
|
|
|
|
|
2022-02-21 19:59:06 -08:00
|
|
|
use {
|
|
|
|
solana_program_test::*,
|
2022-10-10 12:43:53 -07:00
|
|
|
solana_sbf_rust_sysvar::process_instruction,
|
2022-02-21 19:59:06 -08:00
|
|
|
solana_sdk::{
|
2022-04-28 01:24:42 -07:00
|
|
|
feature_set::disable_fees_sysvar,
|
2022-02-21 19:59:06 -08:00
|
|
|
instruction::{AccountMeta, Instruction},
|
|
|
|
pubkey::Pubkey,
|
|
|
|
signature::Signer,
|
|
|
|
sysvar::{
|
2022-04-28 01:24:42 -07:00
|
|
|
clock, epoch_schedule, fees, instructions, recent_blockhashes, rent, slot_hashes,
|
2022-02-21 19:59:06 -08:00
|
|
|
slot_history, stake_history,
|
|
|
|
},
|
|
|
|
transaction::Transaction,
|
2021-08-11 12:07:15 -07:00
|
|
|
},
|
2021-04-07 01:47:15 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#[tokio::test]
|
2021-06-01 15:33:17 -07:00
|
|
|
async fn test_sysvars() {
|
2021-04-07 01:47:15 -07:00
|
|
|
let program_id = Pubkey::new_unique();
|
2022-04-28 01:24:42 -07:00
|
|
|
|
2021-04-07 01:47:15 -07:00
|
|
|
let program_test = ProgramTest::new(
|
2022-10-10 12:43:53 -07:00
|
|
|
"solana_sbf_rust_sysvar",
|
2021-04-07 01:47:15 -07:00
|
|
|
program_id,
|
|
|
|
processor!(process_instruction),
|
|
|
|
);
|
|
|
|
let (mut banks_client, payer, recent_blockhash) = program_test.start().await;
|
|
|
|
|
|
|
|
let mut transaction = Transaction::new_with_payer(
|
|
|
|
&[Instruction::new_with_bincode(
|
|
|
|
program_id,
|
2022-04-28 01:24:42 -07:00
|
|
|
&[0u8],
|
2021-04-07 01:47:15 -07:00
|
|
|
vec![
|
|
|
|
AccountMeta::new(payer.pubkey(), true),
|
|
|
|
AccountMeta::new(Pubkey::new_unique(), false),
|
|
|
|
AccountMeta::new_readonly(clock::id(), false),
|
|
|
|
AccountMeta::new_readonly(epoch_schedule::id(), false),
|
|
|
|
AccountMeta::new_readonly(instructions::id(), false),
|
2021-07-29 10:48:14 -07:00
|
|
|
#[allow(deprecated)]
|
2021-04-07 01:47:15 -07:00
|
|
|
AccountMeta::new_readonly(recent_blockhashes::id(), false),
|
|
|
|
AccountMeta::new_readonly(rent::id(), false),
|
|
|
|
AccountMeta::new_readonly(slot_hashes::id(), false),
|
|
|
|
AccountMeta::new_readonly(slot_history::id(), false),
|
|
|
|
AccountMeta::new_readonly(stake_history::id(), false),
|
2022-04-28 01:24:42 -07:00
|
|
|
#[allow(deprecated)]
|
|
|
|
AccountMeta::new_readonly(fees::id(), false),
|
|
|
|
],
|
|
|
|
)],
|
|
|
|
Some(&payer.pubkey()),
|
|
|
|
);
|
|
|
|
transaction.sign(&[&payer], recent_blockhash);
|
|
|
|
banks_client.process_transaction(transaction).await.unwrap();
|
|
|
|
|
|
|
|
let mut program_test = ProgramTest::new(
|
2022-10-10 12:43:53 -07:00
|
|
|
"solana_sbf_rust_sysvar",
|
2022-04-28 01:24:42 -07:00
|
|
|
program_id,
|
|
|
|
processor!(process_instruction),
|
|
|
|
);
|
|
|
|
program_test.deactivate_feature(disable_fees_sysvar::id());
|
|
|
|
let (mut banks_client, payer, recent_blockhash) = program_test.start().await;
|
|
|
|
|
|
|
|
let mut transaction = Transaction::new_with_payer(
|
|
|
|
&[Instruction::new_with_bincode(
|
|
|
|
program_id,
|
|
|
|
&[1u8],
|
|
|
|
vec![
|
|
|
|
AccountMeta::new(payer.pubkey(), true),
|
|
|
|
AccountMeta::new(Pubkey::new_unique(), false),
|
|
|
|
AccountMeta::new_readonly(clock::id(), false),
|
|
|
|
AccountMeta::new_readonly(epoch_schedule::id(), false),
|
|
|
|
AccountMeta::new_readonly(instructions::id(), false),
|
|
|
|
#[allow(deprecated)]
|
|
|
|
AccountMeta::new_readonly(recent_blockhashes::id(), false),
|
|
|
|
AccountMeta::new_readonly(rent::id(), false),
|
|
|
|
AccountMeta::new_readonly(slot_hashes::id(), false),
|
|
|
|
AccountMeta::new_readonly(slot_history::id(), false),
|
|
|
|
AccountMeta::new_readonly(stake_history::id(), false),
|
|
|
|
#[allow(deprecated)]
|
|
|
|
AccountMeta::new_readonly(fees::id(), false),
|
2021-04-07 01:47:15 -07:00
|
|
|
],
|
|
|
|
)],
|
|
|
|
Some(&payer.pubkey()),
|
|
|
|
);
|
|
|
|
transaction.sign(&[&payer], recent_blockhash);
|
|
|
|
banks_client.process_transaction(transaction).await.unwrap();
|
|
|
|
}
|