Skip to content

Commit

Permalink
add add_program helper
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Jun 23, 2024
1 parent 40747e6 commit 9122853
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
16 changes: 15 additions & 1 deletion harness/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};

Expand All @@ -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<Rent> {
self.sysvar_cache.get_rent().unwrap_or_default()
Expand Down
19 changes: 0 additions & 19 deletions harness/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9122853

Please sign in to comment.