diff --git a/harness/src/lib.rs b/harness/src/lib.rs index eb70a5b5..e33016df 100644 --- a/harness/src/lib.rs +++ b/harness/src/lib.rs @@ -100,7 +100,7 @@ impl Mollusk { let mut mollusk = Self { program_id: *program_id, - program_account: program::program_account(program_id), + program_account: program::create_program_account(program_id), ..Default::default() }; @@ -115,6 +115,20 @@ impl Mollusk { mollusk } + /// Add a program to the test environment. + /// + /// If you intend to CPI to a program, this is likely what you want to use. + pub fn add_program(&mut self, program_id: &Pubkey, program_name: &'static str) { + let elf = file::load_program_elf(program_name); + program::add_program_to_cache( + &mut self.program_cache, + program_id, + &elf, + &self.compute_budget, + &self.feature_set, + ); + } + /// Get the current rent. pub fn get_rent(&self) -> Arc { self.sysvar_cache.get_rent().unwrap_or_default() diff --git a/harness/src/program.rs b/harness/src/program.rs index 3f36eede..cf24821c 100644 --- a/harness/src/program.rs +++ b/harness/src/program.rs @@ -131,25 +131,6 @@ pub fn create_program_accounts( ) } -pub fn program_account(program_id: &Pubkey) -> AccountSharedData { - let data = bincode::serialize(&UpgradeableLoaderState::Program { - programdata_address: Pubkey::find_program_address( - &[program_id.as_ref()], - &bpf_loader_upgradeable::id(), - ) - .0, - }) - .unwrap(); - let lamports = Rent::default().minimum_balance(data.len()); - AccountSharedData::from(Account { - lamports, - data, - owner: bpf_loader_upgradeable::id(), - executable: true, - rent_epoch: 0, - }) -} - /// Create a default program cache instance. pub fn default_program_cache() -> LoadedProgramsForTxBatch { let mut cache = LoadedProgramsForTxBatch::default();