2
2
crate :: {
3
3
compute_budget:: ComputeBudget ,
4
4
ic_msg,
5
- loaded_programs:: { LoadedProgram , LoadedProgramType , LoadedProgramsForTxBatch } ,
5
+ loaded_programs:: {
6
+ LoadedProgram , LoadedProgramType , LoadedProgramsForTxBatch , ProgramRuntimeEnvironments ,
7
+ } ,
6
8
log_collector:: LogCollector ,
7
9
stable_log,
8
10
sysvar_cache:: SysvarCache ,
@@ -17,15 +19,18 @@ use {
17
19
vm:: { Config , ContextObject , EbpfVm } ,
18
20
} ,
19
21
solana_sdk:: {
20
- account:: AccountSharedData ,
22
+ account:: { create_account_shared_data_for_test , AccountSharedData } ,
21
23
bpf_loader_deprecated,
24
+ clock:: Slot ,
25
+ epoch_schedule:: EpochSchedule ,
22
26
feature_set:: FeatureSet ,
23
27
hash:: Hash ,
24
28
instruction:: { AccountMeta , InstructionError } ,
25
29
native_loader,
26
30
pubkey:: Pubkey ,
27
31
saturating_add_assign,
28
32
stable_layout:: stable_instruction:: StableInstruction ,
33
+ sysvar,
29
34
transaction_context:: {
30
35
IndexOfAccount , InstructionAccount , TransactionAccount , TransactionContext ,
31
36
} ,
@@ -209,6 +214,17 @@ impl<'a> InvokeContext<'a> {
209
214
. or_else ( || self . programs_loaded_for_tx_batch . find ( pubkey) )
210
215
}
211
216
217
+ pub fn get_environments_for_slot (
218
+ & self ,
219
+ effective_slot : Slot ,
220
+ ) -> Result < & ProgramRuntimeEnvironments , InstructionError > {
221
+ let epoch_schedule = self . sysvar_cache . get_epoch_schedule ( ) ?;
222
+ let epoch = epoch_schedule. get_epoch ( effective_slot) ;
223
+ Ok ( self
224
+ . programs_loaded_for_tx_batch
225
+ . get_environments_for_epoch ( epoch) )
226
+ }
227
+
212
228
/// Push a stack frame onto the invocation stack
213
229
pub fn push ( & mut self ) -> Result < ( ) , InstructionError > {
214
230
let instruction_context = self
@@ -713,6 +729,18 @@ pub fn mock_process_instruction<F: FnMut(&mut InvokeContext), G: FnMut(&mut Invo
713
729
program_indices. insert ( 0 , transaction_accounts. len ( ) as IndexOfAccount ) ;
714
730
let processor_account = AccountSharedData :: new ( 0 , 0 , & native_loader:: id ( ) ) ;
715
731
transaction_accounts. push ( ( * loader_id, processor_account) ) ;
732
+ let pop_epoch_schedule_account = if !transaction_accounts
733
+ . iter ( )
734
+ . any ( |( key, _) | * key == sysvar:: epoch_schedule:: id ( ) )
735
+ {
736
+ transaction_accounts. push ( (
737
+ sysvar:: epoch_schedule:: id ( ) ,
738
+ create_account_shared_data_for_test ( & EpochSchedule :: default ( ) ) ,
739
+ ) ) ;
740
+ true
741
+ } else {
742
+ false
743
+ } ;
716
744
with_mock_invoke_context ! ( invoke_context, transaction_context, transaction_accounts) ;
717
745
let mut programs_loaded_for_tx_batch = LoadedProgramsForTxBatch :: default ( ) ;
718
746
programs_loaded_for_tx_batch. replenish (
@@ -731,6 +759,9 @@ pub fn mock_process_instruction<F: FnMut(&mut InvokeContext), G: FnMut(&mut Invo
731
759
assert_eq ! ( result, expected_result) ;
732
760
post_adjustments ( & mut invoke_context) ;
733
761
let mut transaction_accounts = transaction_context. deconstruct_without_keys ( ) . unwrap ( ) ;
762
+ if pop_epoch_schedule_account {
763
+ transaction_accounts. pop ( ) ;
764
+ }
734
765
transaction_accounts. pop ( ) ;
735
766
transaction_accounts
736
767
}
0 commit comments