Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pgarg66 committed Mar 6, 2024
1 parent d13235c commit 193173b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
7 changes: 6 additions & 1 deletion ledger-tool/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ use {
},
solana_runtime::bank::Bank,
solana_sdk::{
account::AccountSharedData,
account::{create_account_shared_data_for_test, AccountSharedData},
account_utils::StateMut,
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
pubkey::Pubkey,
slot_history::Slot,
sysvar,
transaction_context::{IndexOfAccount, InstructionAccount},
},
std::{
Expand Down Expand Up @@ -510,6 +511,10 @@ pub fn program(ledger_path: &Path, matches: &ArgMatches<'_>) {
program_id, // ID of the loaded program. It can modify accounts with the same owner key
AccountSharedData::new(0, 0, &loader_id),
));
transaction_accounts.push((
sysvar::epoch_schedule::id(),
create_account_shared_data_for_test(bank.epoch_schedule()),
));
let interpreted = matches.value_of("mode").unwrap() != "jit";
with_mock_invoke_context!(invoke_context, transaction_context, transaction_accounts);

Expand Down
19 changes: 18 additions & 1 deletion program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ use {
vm::{Config, ContextObject, EbpfVm},
},
solana_sdk::{
account::AccountSharedData,
account::{create_account_shared_data_for_test, AccountSharedData},
bpf_loader_deprecated,
clock::Slot,
epoch_schedule::EpochSchedule,
feature_set::FeatureSet,
hash::Hash,
instruction::{AccountMeta, InstructionError},
native_loader,
pubkey::Pubkey,
saturating_add_assign,
stable_layout::stable_instruction::StableInstruction,
sysvar,
transaction_context::{
IndexOfAccount, InstructionAccount, TransactionAccount, TransactionContext,
},
Expand Down Expand Up @@ -727,6 +729,18 @@ pub fn mock_process_instruction<F: FnMut(&mut InvokeContext), G: FnMut(&mut Invo
program_indices.insert(0, transaction_accounts.len() as IndexOfAccount);
let processor_account = AccountSharedData::new(0, 0, &native_loader::id());
transaction_accounts.push((*loader_id, processor_account));
let pop_epoch_schedule_account = if !transaction_accounts
.iter()
.any(|(key, _)| *key == sysvar::epoch_schedule::id())
{
transaction_accounts.push((
sysvar::epoch_schedule::id(),
create_account_shared_data_for_test(&EpochSchedule::default()),
));
true
} else {
false
};
with_mock_invoke_context!(invoke_context, transaction_context, transaction_accounts);
let mut programs_loaded_for_tx_batch = LoadedProgramsForTxBatch::default();
programs_loaded_for_tx_batch.replenish(
Expand All @@ -745,6 +759,9 @@ pub fn mock_process_instruction<F: FnMut(&mut InvokeContext), G: FnMut(&mut Invo
assert_eq!(result, expected_result);
post_adjustments(&mut invoke_context);
let mut transaction_accounts = transaction_context.deconstruct_without_keys().unwrap();
if pop_epoch_schedule_account {
transaction_accounts.pop();
}
transaction_accounts.pop();
transaction_accounts
}
Expand Down
11 changes: 9 additions & 2 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,7 @@ mod tests {
},
account_utils::StateMut,
clock::Clock,
epoch_schedule::EpochSchedule,
instruction::{AccountMeta, InstructionError},
pubkey::Pubkey,
rent::Rent,
Expand Down Expand Up @@ -3793,7 +3794,10 @@ mod tests {

#[test]
fn test_program_usage_count_on_upgrade() {
let transaction_accounts = vec![];
let transaction_accounts = vec![(
sysvar::epoch_schedule::id(),
create_account_for_test(&EpochSchedule::default()),
)];
with_mock_invoke_context!(invoke_context, transaction_context, transaction_accounts);
let program_id = Pubkey::new_unique();
let env = Arc::new(BuiltinProgram::new_mock());
Expand Down Expand Up @@ -3833,7 +3837,10 @@ mod tests {

#[test]
fn test_program_usage_count_on_non_upgrade() {
let transaction_accounts = vec![];
let transaction_accounts = vec![(
sysvar::epoch_schedule::id(),
create_account_for_test(&EpochSchedule::default()),
)];
with_mock_invoke_context!(invoke_context, transaction_context, transaction_accounts);
let program_id = Pubkey::new_unique();
let env = Arc::new(BuiltinProgram::new_mock());
Expand Down

0 comments on commit 193173b

Please sign in to comment.