77use {
88 crate :: {
99 accounts:: { compile_accounts, CompiledAccounts } ,
10- result:: { Check , InstructionResult } ,
10+ result:: InstructionResult ,
1111 Mollusk , DEFAULT_LOADER_KEY ,
1212 } ,
1313 mollusk_svm_fuzz_fixture_firedancer:: {
2222 solana_compute_budget:: compute_budget:: ComputeBudget ,
2323 solana_sdk:: {
2424 account:: Account ,
25+ feature_set:: FeatureSet ,
2526 instruction:: { AccountMeta , Instruction , InstructionError } ,
2627 pubkey:: Pubkey ,
2728 } ,
@@ -66,17 +67,12 @@ fn num_to_instr_err(num: i32, custom_code: u32) -> InstructionError {
6667}
6768
6869fn build_fixture_context (
69- mollusk : & Mollusk ,
70- instruction : & Instruction ,
7170 accounts : & [ ( Pubkey , Account ) ] ,
71+ compute_budget : & ComputeBudget ,
72+ feature_set : & FeatureSet ,
73+ instruction : & Instruction ,
74+ slot : u64 ,
7275) -> FuzzContext {
73- let Mollusk {
74- compute_budget,
75- feature_set,
76- slot, // FD-Fuzz feature only.
77- ..
78- } = mollusk;
79-
8076 let loader_key = if BUILTIN_PROGRAM_IDS . contains ( & instruction. program_id ) {
8177 solana_sdk:: native_loader:: id ( )
8278 } else {
@@ -100,14 +96,22 @@ fn build_fixture_context(
10096 instruction_accounts,
10197 instruction_data : instruction. data . clone ( ) ,
10298 compute_units_available : compute_budget. compute_unit_limit ,
103- slot_context : FuzzSlotContext { slot : * slot } ,
99+ slot_context : FuzzSlotContext { slot } ,
104100 epoch_context : FuzzEpochContext {
105101 feature_set : feature_set. clone ( ) ,
106102 } ,
107103 }
108104}
109105
110- fn parse_fixture_context ( context : & FuzzContext ) -> ( Mollusk , Instruction , Vec < ( Pubkey , Account ) > ) {
106+ pub struct ParsedFixtureContext {
107+ pub accounts : Vec < ( Pubkey , Account ) > ,
108+ pub compute_budget : ComputeBudget ,
109+ pub feature_set : FeatureSet ,
110+ pub instruction : Instruction ,
111+ pub slot : u64 ,
112+ }
113+
114+ pub ( crate ) fn parse_fixture_context ( context : & FuzzContext ) -> ParsedFixtureContext {
111115 let FuzzContext {
112116 program_id,
113117 accounts,
@@ -128,13 +132,6 @@ fn parse_fixture_context(context: &FuzzContext) -> (Mollusk, Instruction, Vec<(P
128132 . map ( |( key, acct, _) | ( * key, acct. clone ( ) ) )
129133 . collect :: < Vec < _ > > ( ) ;
130134
131- let mollusk = Mollusk {
132- compute_budget,
133- feature_set : epoch_context. feature_set . clone ( ) ,
134- slot : slot_context. slot ,
135- ..Default :: default ( )
136- } ;
137-
138135 let metas = instruction_accounts
139136 . iter ( )
140137 . map ( |ia| {
@@ -152,7 +149,13 @@ fn parse_fixture_context(context: &FuzzContext) -> (Mollusk, Instruction, Vec<(P
152149
153150 let instruction = Instruction :: new_with_bytes ( * program_id, instruction_data, metas) ;
154151
155- ( mollusk, instruction, accounts)
152+ ParsedFixtureContext {
153+ accounts,
154+ compute_budget,
155+ feature_set : epoch_context. feature_set . clone ( ) ,
156+ instruction,
157+ slot : slot_context. slot ,
158+ }
156159}
157160
158161fn build_fixture_effects ( context : & FuzzContext , result : & InstructionResult ) -> FuzzEffects {
@@ -195,9 +198,9 @@ fn build_fixture_effects(context: &FuzzContext, result: &InstructionResult) -> F
195198 }
196199}
197200
198- fn parse_fixture_effects (
199- mollusk : & Mollusk ,
201+ pub ( crate ) fn parse_fixture_effects (
200202 accounts : & [ ( Pubkey , Account ) ] ,
203+ compute_unit_limit : u64 ,
201204 effects : & FuzzEffects ,
202205) -> InstructionResult {
203206 let raw_result = if effects. program_result == 0 {
@@ -229,10 +232,7 @@ fn parse_fixture_effects(
229232 program_result,
230233 raw_result,
231234 execution_time : 0 , // TODO: Omitted for now.
232- compute_units_consumed : mollusk
233- . compute_budget
234- . compute_unit_limit
235- . saturating_sub ( effects. compute_units_available ) ,
235+ compute_units_consumed : compute_unit_limit. saturating_sub ( effects. compute_units_available ) ,
236236 return_data,
237237 resulting_accounts,
238238 }
@@ -250,9 +250,14 @@ pub fn build_fixture_from_mollusk_test(
250250 instruction : & Instruction ,
251251 accounts : & [ ( Pubkey , Account ) ] ,
252252 result : & InstructionResult ,
253- _checks : & [ Check ] ,
254253) -> FuzzFixture {
255- let input = build_fixture_context ( mollusk, instruction, accounts) ;
254+ let input = build_fixture_context (
255+ accounts,
256+ & mollusk. compute_budget ,
257+ & mollusk. feature_set ,
258+ instruction,
259+ mollusk. slot , // FD-fuzz feature only.
260+ ) ;
256261 // This should probably be built from the checks, but there's currently no
257262 // mechanism to enforce full check coverage on a result.
258263 let output = build_fixture_effects ( & input, result) ;
@@ -265,15 +270,14 @@ pub fn build_fixture_from_mollusk_test(
265270
266271pub fn load_firedancer_fixture (
267272 fixture : & mollusk_svm_fuzz_fixture_firedancer:: Fixture ,
268- ) -> (
269- Mollusk ,
270- Instruction ,
271- Vec < ( Pubkey , Account ) > ,
272- InstructionResult ,
273- ) {
274- let ( mollusk, instruction, accounts) = parse_fixture_context ( & fixture. input ) ;
275- let result = parse_fixture_effects ( & mollusk, & accounts, & fixture. output ) ;
276- ( mollusk, instruction, accounts, result)
273+ ) -> ( ParsedFixtureContext , InstructionResult ) {
274+ let parsed = parse_fixture_context ( & fixture. input ) ;
275+ let result = parse_fixture_effects (
276+ & parsed. accounts ,
277+ parsed. compute_budget . compute_unit_limit ,
278+ & fixture. output ,
279+ ) ;
280+ ( parsed, result)
277281}
278282
279283#[ test]
0 commit comments