Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix sbf sysvar test #32803

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use {
runtime_config::RuntimeConfig,
},
solana_sdk::{
account::{Account, AccountSharedData},
account::{create_account_shared_data_for_test, Account, AccountSharedData},
account_info::AccountInfo,
clock::Slot,
entrypoint::{deserialize, ProgramResult, SUCCESS},
Expand Down Expand Up @@ -587,6 +587,11 @@ impl ProgramTest {
);
}

pub fn add_sysvar_account<S: Sysvar>(&mut self, address: Pubkey, sysvar: &S) {
let account = create_account_shared_data_for_test(sysvar);
self.add_account(address, account.into());
}

/// Add a SBF program to the test environment.
///
/// `program_name` will also be used to locate the SBF shared object in the current or fixtures
Expand Down
10 changes: 3 additions & 7 deletions programs/sbf/rust/sysvar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,9 @@ pub fn process_instruction(
{
msg!("EpochRewards identifier:");
sysvar::epoch_rewards::id().log();
let epoch_rewards = EpochRewards::from_account_info(&accounts[11]);
// epoch_rewards sysvar should only be valid during epoch reward period. In this test case,
// the test bank is outside reward period. Therefore, we expect that the epoch_rewards
// sysvar doesn't exist.
assert!(epoch_rewards.is_err());
let got_epoch_rewards = EpochRewards::get();
assert!(got_epoch_rewards.is_err());
let epoch_rewards = EpochRewards::from_account_info(&accounts[11]).unwrap();
let got_epoch_rewards = EpochRewards::get()?;
assert_eq!(epoch_rewards, got_epoch_rewards);
}

Ok(())
Expand Down
10 changes: 9 additions & 1 deletion programs/sbf/rust/sysvar/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@ use {
async fn test_sysvars() {
let program_id = Pubkey::new_unique();

let program_test = ProgramTest::new(
let mut program_test = ProgramTest::new(
"solana_sbf_rust_sysvar",
program_id,
processor!(process_instruction),
);

let epoch_rewards = epoch_rewards::EpochRewards {
total_rewards: 100,
distributed_rewards: 50,
distribution_complete_block_height: 42,
};
program_test.add_sysvar_account(epoch_rewards::id(), &epoch_rewards);
let (mut banks_client, payer, recent_blockhash) = program_test.start().await;

let mut transaction = Transaction::new_with_payer(
Expand Down Expand Up @@ -59,6 +66,7 @@ async fn test_sysvars() {
processor!(process_instruction),
);
program_test.deactivate_feature(disable_fees_sysvar::id());
program_test.add_sysvar_account(epoch_rewards::id(), &epoch_rewards);
let (mut banks_client, payer, recent_blockhash) = program_test.start().await;

let mut transaction = Transaction::new_with_payer(
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3538,7 +3538,7 @@ impl Bank {
}
}

/// Create EpochRewards syavar with calculated rewards
/// Create EpochRewards sysvar with calculated rewards
fn create_epoch_rewards_sysvar(
&self,
total_rewards: u64,
Expand Down