@@ -1155,6 +1155,7 @@ impl Mollusk {
11551155 MolluskContext {
11561156 mollusk : self ,
11571157 account_store : Rc :: new ( RefCell :: new ( account_store) ) ,
1158+ hydrate_store : true , // <-- Default
11581159 }
11591160 }
11601161}
@@ -1179,22 +1180,42 @@ impl Mollusk {
11791180pub struct MolluskContext < AS : AccountStore > {
11801181 pub mollusk : Mollusk ,
11811182 pub account_store : Rc < RefCell < AS > > ,
1183+ pub hydrate_store : bool ,
11821184}
11831185
11841186impl < AS : AccountStore > MolluskContext < AS > {
11851187 fn load_accounts_for_instructions < ' a > (
11861188 & self ,
11871189 instructions : impl Iterator < Item = & ' a Instruction > ,
11881190 ) -> Vec < ( Pubkey , Account ) > {
1189- let mut seen = HashSet :: new ( ) ;
11901191 let mut accounts = Vec :: new ( ) ;
1192+
1193+ // If hydration is enabled, add sysvars and program accounts regardless
1194+ // of whether or not they exist already.
1195+ if self . hydrate_store {
1196+ self . mollusk
1197+ . program_cache
1198+ . get_all_keyed_program_accounts ( )
1199+ . into_iter ( )
1200+ . chain ( self . mollusk . sysvars . get_all_keyed_sysvar_accounts ( ) )
1201+ . for_each ( |( pubkey, account) | {
1202+ accounts. push ( ( pubkey, account) ) ;
1203+ } ) ;
1204+ }
1205+
1206+ // Regardless of hydration, only add an account if the caller hasn't
1207+ // already loaded it into the store.
1208+ let mut seen = HashSet :: new ( ) ;
11911209 let store = self . account_store . borrow ( ) ;
11921210 instructions. for_each ( |instruction| {
11931211 instruction
11941212 . accounts
11951213 . iter ( )
11961214 . for_each ( |AccountMeta { pubkey, .. } | {
11971215 if seen. insert ( * pubkey) {
1216+ // First try to load theirs, then see if it's a sysvar,
1217+ // then see if it's a cached program, then apply the
1218+ // default.
11981219 let account = store. get_account ( pubkey) . unwrap_or_else ( || {
11991220 self . mollusk
12001221 . sysvars
0 commit comments