@@ -64,9 +64,7 @@ pub struct Mollusk {
6464 pub compute_budget : ComputeBudget ,
6565 pub feature_set : FeatureSet ,
6666 pub fee_structure : FeeStructure ,
67- pub program_account : AccountSharedData ,
6867 pub program_cache : ProgramCache ,
69- pub program_id : Pubkey ,
7068 pub sysvars : Sysvars ,
7169}
7270
@@ -78,63 +76,36 @@ impl Default for Mollusk {
7876 solana_runtime::message_processor=debug,\
7977 solana_runtime::system_instruction_processor=trace",
8078 ) ;
81- let ( program_id, program_account) = program:: keyed_account_for_system_program ( ) ;
8279 Self {
8380 compute_budget : ComputeBudget :: default ( ) ,
8481 feature_set : FeatureSet :: all_enabled ( ) ,
8582 fee_structure : FeeStructure :: default ( ) ,
86- program_account,
8783 program_cache : ProgramCache :: default ( ) ,
88- program_id,
8984 sysvars : Sysvars :: default ( ) ,
9085 }
9186 }
9287}
9388
9489impl Mollusk {
95- /// Create a new Mollusk instance for the provided program.
90+ /// Create a new Mollusk instance containing the provided program.
9691 ///
9792 /// Attempts the load the program's ELF file from the default search paths.
98- /// Once loaded, adds the program to the program cache and updates the
99- /// Mollusk instance with the program's ID and account .
93+ /// Once loaded, adds the program to the program cache and returns the
94+ /// newly created Mollusk instance .
10095 pub fn new ( program_id : & Pubkey , program_name : & str ) -> Self {
101- let mut mollusk = Self {
102- program_id : * program_id,
103- program_account : program:: create_program_account_loader_v3 ( program_id) ,
104- ..Default :: default ( )
105- } ;
106- mollusk. add_program ( program_id, program_name) ;
96+ let mut mollusk = Self :: default ( ) ;
97+ mollusk. add_program ( program_id, program_name, & DEFAULT_LOADER_KEY ) ;
10798 mollusk
10899 }
109100
110101 /// Add a program to the test environment.
111102 ///
112103 /// If you intend to CPI to a program, this is likely what you want to use.
113- pub fn add_program ( & mut self , program_id : & Pubkey , program_name : & str ) {
114- let elf = file:: load_program_elf ( program_name) ;
115- self . add_program_with_elf ( program_id, & elf) ;
116- }
117-
118- /// Add a program to the test environment under a specific loader.
119- ///
120- /// If you intend to CPI to a program, this is likely what you want to use.
121- pub fn add_program_with_loader (
122- & mut self ,
123- program_id : & Pubkey ,
124- program_name : & str ,
125- loader_key : & Pubkey ,
126- ) {
104+ pub fn add_program ( & mut self , program_id : & Pubkey , program_name : & str , loader_key : & Pubkey ) {
127105 let elf = file:: load_program_elf ( program_name) ;
128106 self . add_program_with_elf_and_loader ( program_id, & elf, loader_key) ;
129107 }
130108
131- /// Add a program to the test environment using a provided ELF.
132- ///
133- /// If you intend to CPI to a program, this is likely what you want to use.
134- pub fn add_program_with_elf ( & mut self , program_id : & Pubkey , elf : & [ u8 ] ) {
135- self . add_program_with_elf_and_loader ( program_id, elf, & DEFAULT_LOADER_KEY ) ;
136- }
137-
138109 /// Add a program to the test environment using a provided ELF under a
139110 /// specific loader.
140111 ///
@@ -154,32 +125,6 @@ impl Mollusk {
154125 ) ;
155126 }
156127
157- /// Switch the target program to a different program.
158- ///
159- /// Note: The program must already be contained in the program cache.
160- pub fn switch_target_program ( & mut self , program_id : & Pubkey ) {
161- let loader_key: Pubkey = self
162- . program_cache
163- . cache ( )
164- . read ( )
165- . unwrap ( )
166- . find ( program_id)
167- . expect ( "Program not found in cache" )
168- . account_owner
169- . into ( ) ;
170- if loader_key != DEFAULT_LOADER_KEY {
171- panic ! ( "Loader not supported for target program: {:?}" , loader_key) ;
172- }
173- self . program_id = * program_id;
174- self . program_account = program:: create_program_account_loader_v3 ( program_id) ;
175- }
176-
177- /// Add a program to the cache and make it the target program.
178- pub fn add_and_switch_target_program ( & mut self , program_id : & Pubkey , program_name : & str ) {
179- self . add_program ( program_id, program_name) ;
180- self . switch_target_program ( program_id) ;
181- }
182-
183128 /// Warp the test environment to a slot by updating sysvars.
184129 pub fn warp_to_slot ( & mut self , slot : u64 ) {
185130 self . sysvars . warp_to_slot ( slot)
0 commit comments