diff --git a/harness/src/lib.rs b/harness/src/lib.rs index 37a1136..0696f4e 100644 --- a/harness/src/lib.rs +++ b/harness/src/lib.rs @@ -35,7 +35,7 @@ pub mod sysvar; use { crate::{ result::{Check, InstructionResult}, - sysvar::MolluskSysvars, + sysvar::Sysvars, }, solana_program_runtime::{ compute_budget::ComputeBudget, invoke_context::InvokeContext, @@ -44,17 +44,11 @@ use { }, solana_sdk::{ account::AccountSharedData, - clock::Clock, - epoch_rewards::EpochRewards, - epoch_schedule::EpochSchedule, feature_set::FeatureSet, hash::Hash, instruction::Instruction, pubkey::Pubkey, rent::Rent, - slot_hashes::SlotHashes, - stake_history::StakeHistory, - sysvar::last_restart_slot::LastRestartSlot, transaction_context::{InstructionAccount, TransactionContext}, }, std::sync::Arc, @@ -73,7 +67,7 @@ pub struct Mollusk { pub program_account: AccountSharedData, pub program_cache: LoadedProgramsForTxBatch, pub program_id: Pubkey, - pub sysvars: MolluskSysvars, + pub sysvars: Sysvars, } impl Default for Mollusk { @@ -91,7 +85,7 @@ impl Default for Mollusk { program_account, program_cache: program::default_program_cache(), program_id, - sysvars: MolluskSysvars::default(), + sysvars: Sysvars::default(), } } } @@ -136,41 +130,6 @@ impl Mollusk { ); } - /// Get the `Clock` sysvar. - pub fn get_clock(&self) -> &Clock { - &self.sysvars.clock - } - - /// Get the `EpochRewards` sysvar. - pub fn get_epoch_rewards(&self) -> &EpochRewards { - &self.sysvars.epoch_rewards - } - - /// Get the `EpochSchedule` sysvar. - pub fn get_epoch_schedule(&self) -> &EpochSchedule { - &self.sysvars.epoch_schedule - } - - /// Get the `LastRestartSlot` sysvar. - pub fn get_last_restart_slot(&self) -> &LastRestartSlot { - &self.sysvars.last_restart_slot - } - - /// Get the `Rent` sysvar. - pub fn get_rent(&self) -> &Rent { - &self.sysvars.rent - } - - /// Get the `SlotHashes` sysvar. - pub fn get_slot_hashes(&self) -> &SlotHashes { - &self.sysvars.slot_hashes - } - - /// Get the `StakeHistory` sysvar. - pub fn get_stake_history(&self) -> &StakeHistory { - &self.sysvars.stake_history - } - /// Warp the test environment to a slot by updating sysvars. pub fn warp_to_slot(&mut self, slot: u64) { self.sysvars.warp_to_slot(slot) diff --git a/harness/src/result.rs b/harness/src/result.rs index c091666..294f287 100644 --- a/harness/src/result.rs +++ b/harness/src/result.rs @@ -116,7 +116,7 @@ impl InstructionResult { check_lamports, actual_lamports ); } - if let Some(check_owner) = &account.check_owner { + if let Some(check_owner) = account.check_owner { let actual_owner = resulting_account.owner(); assert_eq!( check_owner, actual_owner, @@ -200,7 +200,7 @@ struct AccountCheck<'a> { pubkey: Pubkey, check_data: Option<&'a [u8]>, check_lamports: Option, - check_owner: Option, + check_owner: Option<&'a Pubkey>, check_state: Option, } @@ -242,7 +242,7 @@ impl<'a> AccountCheckBuilder<'a> { self } - pub fn owner(mut self, owner: Pubkey) -> Self { + pub fn owner(mut self, owner: &'a Pubkey) -> Self { self.check.check_owner = Some(owner); self } diff --git a/harness/src/sysvar.rs b/harness/src/sysvar.rs index 37ef65c..6ba4cba 100644 --- a/harness/src/sysvar.rs +++ b/harness/src/sysvar.rs @@ -18,7 +18,7 @@ use { // around it for modifying its contents. /// Mollusk sysvars. #[derive(Default)] -pub struct MolluskSysvars { +pub struct Sysvars { pub clock: Clock, pub epoch_rewards: EpochRewards, pub epoch_schedule: EpochSchedule, @@ -28,7 +28,7 @@ pub struct MolluskSysvars { pub stake_history: StakeHistory, } -impl MolluskSysvars { +impl Sysvars { /// Warp the test environment to a slot by updating sysvars. pub fn warp_to_slot(&mut self, slot: Slot) { // First update `Clock`. @@ -54,8 +54,8 @@ impl MolluskSysvars { } } -impl From<&MolluskSysvars> for SysvarCache { - fn from(mollusk_cache: &MolluskSysvars) -> Self { +impl From<&Sysvars> for SysvarCache { + fn from(mollusk_cache: &Sysvars) -> Self { let mut sysvar_cache = SysvarCache::default(); sysvar_cache.fill_missing_entries(|pubkey, set_sysvar| { if pubkey.eq(&Clock::id()) { @@ -90,7 +90,7 @@ mod tests { #[test] fn test_warp_to_slot() { - let mut sysvars = MolluskSysvars::default(); + let mut sysvars = Sysvars::default(); assert_eq!(sysvars.clock.slot, 0); sysvars.warp_to_slot(200); @@ -133,7 +133,7 @@ mod tests { stake_history }; - let sysvars = MolluskSysvars { + let sysvars = Sysvars { clock, epoch_rewards, epoch_schedule, diff --git a/harness/tests/bpf_program.rs b/harness/tests/bpf_program.rs index cbfcc5d..1b5c390 100644 --- a/harness/tests/bpf_program.rs +++ b/harness/tests/bpf_program.rs @@ -25,7 +25,7 @@ fn test_write_data() { let data = &[1, 2, 3, 4, 5]; let space = data.len(); - let lamports = mollusk.get_rent().minimum_balance(space); + let lamports = mollusk.sysvars.rent.minimum_balance(space); let key = Pubkey::new_unique(); let account = AccountSharedData::new(lamports, space, &program_id); @@ -80,7 +80,7 @@ fn test_write_data() { Check::account(&key) .data(data) .lamports(lamports) - .owner(program_id) + .owner(&program_id) .build(), ], ); @@ -230,7 +230,7 @@ fn test_close_account() { Check::account(&key) .data(&[]) .lamports(0) - .owner(system_program::id()) + .owner(&system_program::id()) .closed() .build(), ], @@ -248,7 +248,7 @@ fn test_cpi() { let data = &[1, 2, 3, 4, 5]; let space = data.len(); - let lamports = mollusk.get_rent().minimum_balance(space); + let lamports = mollusk.sysvars.rent.minimum_balance(space); let key = Pubkey::new_unique(); let account = AccountSharedData::new(lamports, space, &cpi_target_program_id); @@ -362,7 +362,7 @@ fn test_cpi() { Check::account(&key) .data(data) .lamports(lamports) - .owner(cpi_target_program_id) + .owner(&cpi_target_program_id) .build(), ], );