@@ -69,7 +69,6 @@ pub use utils::CommonCreateInput;
6969
7070pub type Ecx < ' a , ' b , ' c > = & ' a mut EvmContext < & ' b mut ( dyn DatabaseExt + ' c ) > ;
7171pub type InnerEcx < ' a , ' b , ' c > = & ' a mut InnerEvmContext < & ' b mut ( dyn DatabaseExt + ' c ) > ;
72- pub type Strategy < ' a > = & ' a mut dyn CheatcodeInspectorStrategy ;
7372
7473/// Helper trait for obtaining complete [revm::Inspector] instance from mutable reference to
7574/// [Cheatcodes].
@@ -528,7 +527,7 @@ pub struct Cheatcodes {
528527 pub wallets : Option < Wallets > ,
529528
530529 /// The behavior strategy.
531- pub strategy : Option < Box < dyn CheatcodeInspectorStrategy > > ,
530+ pub strategy : CheatcodeInspectorStrategy ,
532531}
533532
534533impl Clone for Cheatcodes {
@@ -568,7 +567,7 @@ impl Clone for Cheatcodes {
568567 arbitrary_storage : self . arbitrary_storage . clone ( ) ,
569568 deprecated : self . deprecated . clone ( ) ,
570569 wallets : self . wallets . clone ( ) ,
571- strategy : self . strategy . as_ref ( ) . map ( |s| s . new_cloned ( ) ) ,
570+ strategy : self . strategy . clone ( ) ,
572571 }
573572 }
574573}
@@ -588,7 +587,7 @@ impl Cheatcodes {
588587 Self {
589588 fs_commit : true ,
590589 labels : config. labels . clone ( ) ,
591- strategy : Some ( config. strategy . clone ( ) ) ,
590+ strategy : config. strategy . clone ( ) ,
592591 config,
593592 block : Default :: default ( ) ,
594593 active_delegation : Default :: default ( ) ,
@@ -763,7 +762,8 @@ impl Cheatcodes {
763762 if ecx_inner. journaled_state . depth ( ) == broadcast. depth {
764763 input. set_caller ( broadcast. new_origin ) ;
765764
766- self . strategy . as_mut ( ) . unwrap ( ) . record_broadcastable_create_transactions (
765+ self . strategy . runner . record_broadcastable_create_transactions (
766+ self . strategy . context . as_mut ( ) ,
767767 self . config . clone ( ) ,
768768 & input,
769769 ecx_inner,
@@ -801,9 +801,9 @@ impl Cheatcodes {
801801 } ] ) ;
802802 }
803803
804- if let Some ( result) = self . with_strategy ( |strategy , cheatcodes| {
805- strategy. zksync_try_create ( cheatcodes , ecx, & input, executor)
806- } ) {
804+ if let Some ( result) =
805+ self . strategy . runner . clone ( ) . zksync_try_create ( self , ecx, & input, executor)
806+ {
807807 return Some ( result) ;
808808 }
809809
@@ -924,10 +924,7 @@ where {
924924 }
925925 }
926926
927- self . strategy
928- . as_mut ( )
929- . expect ( "failed acquiring strategy" )
930- . zksync_record_create_address ( & outcome) ;
927+ self . strategy . runner . zksync_record_create_address ( self . strategy . context . as_mut ( ) , & outcome) ;
931928
932929 outcome
933930 }
@@ -970,10 +967,12 @@ where {
970967 let prev = account. info . nonce ;
971968 let nonce = prev. saturating_sub ( 1 ) ;
972969 account. info . nonce = nonce;
973- self . strategy
974- . as_mut ( )
975- . expect ( "failed acquiring strategy" )
976- . zksync_sync_nonce ( sender, nonce, ecx) ;
970+ self . strategy . runner . zksync_sync_nonce (
971+ self . strategy . context . as_mut ( ) ,
972+ sender,
973+ nonce,
974+ ecx,
975+ ) ;
977976
978977 trace ! ( target: "cheatcodes" , %sender, nonce, prev, "corrected nonce" ) ;
979978 }
@@ -1007,10 +1006,7 @@ where {
10071006 return None ;
10081007 }
10091008
1010- self . strategy
1011- . as_mut ( )
1012- . expect ( "failed acquiring strategy" )
1013- . zksync_set_deployer_call_input ( call) ;
1009+ self . strategy . runner . zksync_set_deployer_call_input ( self . strategy . context . as_mut ( ) , call) ;
10141010
10151011 // Handle expected calls
10161012
@@ -1145,17 +1141,15 @@ where {
11451141 } )
11461142 }
11471143
1148- self . strategy
1149- . as_mut ( )
1150- . expect ( "failed acquiring strategy" )
1151- . record_broadcastable_call_transactions (
1152- self . config . clone ( ) ,
1153- call,
1154- ecx_inner,
1155- broadcast,
1156- & mut self . broadcastable_transactions ,
1157- & mut self . active_delegation ,
1158- ) ;
1144+ self . strategy . runner . record_broadcastable_call_transactions (
1145+ self . strategy . context . as_mut ( ) ,
1146+ self . config . clone ( ) ,
1147+ call,
1148+ ecx_inner,
1149+ broadcast,
1150+ & mut self . broadcastable_transactions ,
1151+ & mut self . active_delegation ,
1152+ ) ;
11591153
11601154 let account =
11611155 ecx_inner. journaled_state . state ( ) . get_mut ( & broadcast. new_origin ) . unwrap ( ) ;
@@ -1228,9 +1222,9 @@ where {
12281222 } ] ) ;
12291223 }
12301224
1231- if let Some ( result) = self . with_strategy ( |strategy , cheatcodes| {
1232- strategy. zksync_try_call ( cheatcodes , ecx, call, executor)
1233- } ) {
1225+ if let Some ( result) =
1226+ self . strategy . runner . clone ( ) . zksync_try_call ( self , ecx, call, executor)
1227+ {
12341228 return Some ( result) ;
12351229 }
12361230
@@ -1272,17 +1266,6 @@ where {
12721266 None => false ,
12731267 }
12741268 }
1275-
1276- pub fn with_strategy < F , R > ( & mut self , mut f : F ) -> R
1277- where
1278- F : FnMut ( Strategy , & mut Self ) -> R ,
1279- {
1280- let mut strategy = self . strategy . take ( ) ;
1281- let result = f ( strategy. as_mut ( ) . expect ( "failed acquiring strategy" ) . as_mut ( ) , self ) ;
1282- self . strategy = strategy;
1283-
1284- result
1285- }
12861269}
12871270
12881271impl Inspector < & mut dyn DatabaseExt > for Cheatcodes {
@@ -1302,10 +1285,11 @@ impl Inspector<&mut dyn DatabaseExt> for Cheatcodes {
13021285 self . gas_metering . paused_frames . push ( interpreter. gas ) ;
13031286 }
13041287
1305- self . strategy
1306- . as_mut ( )
1307- . expect ( "failed acquiring strategy" )
1308- . post_initialize_interp ( interpreter, ecx) ;
1288+ self . strategy . runner . post_initialize_interp (
1289+ self . strategy . context . as_mut ( ) ,
1290+ interpreter,
1291+ ecx,
1292+ ) ;
13091293 }
13101294
13111295 #[ inline]
@@ -1350,8 +1334,7 @@ impl Inspector<&mut dyn DatabaseExt> for Cheatcodes {
13501334
13511335 #[ inline]
13521336 fn step_end ( & mut self , interpreter : & mut Interpreter , ecx : Ecx ) {
1353- if self . strategy . as_mut ( ) . expect ( "failed acquiring strategy" ) . pre_step_end ( interpreter, ecx)
1354- {
1337+ if self . strategy . runner . pre_step_end ( self . strategy . context . as_mut ( ) , interpreter, ecx) {
13551338 return ;
13561339 }
13571340
0 commit comments