fix sbf sysvar test (#32803)

* fix sbf sysvar test

* typo

---------

Co-authored-by: HaoranYi <haoran.yi@solana.com>
This commit is contained in:
HaoranYi 2023-08-21 10:49:48 -05:00 committed by GitHub
parent c6989189ef
commit 910b0f5d12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 10 deletions

View File

@ -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},
@ -591,6 +591,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

View File

@ -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(())

View File

@ -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(
@ -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(

View File

@ -3541,7 +3541,7 @@ impl Bank {
}
}
/// Create EpochRewards syavar with calculated rewards
/// Create EpochRewards sysvar with calculated rewards
fn create_epoch_rewards_sysvar(
&self,
total_rewards: u64,