This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Return sysvars via syscalls (#16422) (cherry picked from commit fa83f3b) * bad merge * Fix branch diffs * nudge Co-authored-by: Jack May <jack@solana.com>
- Loading branch information
1 parent
31ed985
commit 6da4bec
Showing
18 changed files
with
725 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,72 @@ | ||
use { | ||
solana_program_test::{processor, ProgramTest}, | ||
solana_sdk::{ | ||
account_info::AccountInfo, | ||
clock::Clock, | ||
entrypoint::ProgramResult, | ||
epoch_schedule::EpochSchedule, | ||
fee_calculator::FeeCalculator, | ||
instruction::Instruction, | ||
msg, | ||
pubkey::Pubkey, | ||
rent::Rent, | ||
signature::Signer, | ||
sysvar::{fees::Fees, Sysvar}, | ||
transaction::Transaction, | ||
}, | ||
}; | ||
|
||
// Process instruction to invoke into another program | ||
fn sysvar_getter_process_instruction( | ||
_program_id: &Pubkey, | ||
_accounts: &[AccountInfo], | ||
_input: &[u8], | ||
) -> ProgramResult { | ||
msg!("sysvar_getter"); | ||
|
||
let clock = Clock::get()?; | ||
assert_eq!(42, clock.slot); | ||
|
||
let epoch_schedule = EpochSchedule::get()?; | ||
assert_eq!(epoch_schedule, EpochSchedule::default()); | ||
|
||
let fees = Fees::get()?; | ||
assert_eq!( | ||
fees.fee_calculator, | ||
FeeCalculator { | ||
lamports_per_signature: 5000 | ||
} | ||
); | ||
|
||
let rent = Rent::get()?; | ||
assert_eq!(rent, Rent::default()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn get_sysvar() { | ||
let program_id = Pubkey::new_unique(); | ||
let program_test = ProgramTest::new( | ||
"sysvar_getter", | ||
program_id, | ||
processor!(sysvar_getter_process_instruction), | ||
); | ||
|
||
let mut context = program_test.start_with_context().await; | ||
context.warp_to_slot(42).unwrap(); | ||
let instructions = vec![Instruction::new_with_bincode(program_id, &(), vec![])]; | ||
|
||
let transaction = Transaction::new_signed_with_payer( | ||
&instructions, | ||
Some(&context.payer.pubkey()), | ||
&[&context.payer], | ||
context.last_blockhash, | ||
); | ||
|
||
context | ||
.banks_client | ||
.process_transaction(transaction) | ||
.await | ||
.unwrap(); | ||
} |
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
Oops, something went wrong.