@@ -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
@@ -917,10 +917,7 @@ where {
917917 }
918918 }
919919
920- self . strategy
921- . as_mut ( )
922- . expect ( "failed acquiring strategy" )
923- . zksync_record_create_address ( & outcome) ;
920+ self . strategy . runner . zksync_record_create_address ( self . strategy . context . as_mut ( ) , & outcome) ;
924921
925922 outcome
926923 }
@@ -963,10 +960,12 @@ where {
963960 let prev = account. info . nonce ;
964961 let nonce = prev. saturating_sub ( 1 ) ;
965962 account. info . nonce = nonce;
966- self . strategy
967- . as_mut ( )
968- . expect ( "failed acquiring strategy" )
969- . zksync_sync_nonce ( sender, nonce, ecx) ;
963+ self . strategy . runner . zksync_sync_nonce (
964+ self . strategy . context . as_mut ( ) ,
965+ sender,
966+ nonce,
967+ ecx,
968+ ) ;
970969
971970 trace ! ( target: "cheatcodes" , %sender, nonce, prev, "corrected nonce" ) ;
972971 }
@@ -1000,10 +999,7 @@ where {
1000999 return None ;
10011000 }
10021001
1003- self . strategy
1004- . as_mut ( )
1005- . expect ( "failed acquiring strategy" )
1006- . zksync_set_deployer_call_input ( call) ;
1002+ self . strategy . runner . zksync_set_deployer_call_input ( self . strategy . context . as_mut ( ) , call) ;
10071003
10081004 // Handle expected calls
10091005
@@ -1137,17 +1133,15 @@ where {
11371133 } )
11381134 }
11391135
1140- self . strategy
1141- . as_mut ( )
1142- . expect ( "failed acquiring strategy" )
1143- . record_broadcastable_call_transactions (
1144- self . config . clone ( ) ,
1145- call,
1146- ecx_inner,
1147- broadcast,
1148- & mut self . broadcastable_transactions ,
1149- & mut self . active_delegation ,
1150- ) ;
1136+ self . strategy . runner . record_broadcastable_call_transactions (
1137+ self . strategy . context . as_mut ( ) ,
1138+ self . config . clone ( ) ,
1139+ call,
1140+ ecx_inner,
1141+ broadcast,
1142+ & mut self . broadcastable_transactions ,
1143+ & mut self . active_delegation ,
1144+ ) ;
11511145
11521146 let account =
11531147 ecx_inner. journaled_state . state ( ) . get_mut ( & broadcast. new_origin ) . unwrap ( ) ;
@@ -1220,9 +1214,9 @@ where {
12201214 } ] ) ;
12211215 }
12221216
1223- if let Some ( result) = self . with_strategy ( |strategy , cheatcodes| {
1224- strategy. zksync_try_call ( cheatcodes , ecx, call, executor)
1225- } ) {
1217+ if let Some ( result) =
1218+ self . strategy . runner . clone ( ) . zksync_try_call ( self , ecx, call, executor)
1219+ {
12261220 return Some ( result) ;
12271221 }
12281222
@@ -1264,17 +1258,6 @@ where {
12641258 None => false ,
12651259 }
12661260 }
1267-
1268- pub fn with_strategy < F , R > ( & mut self , mut f : F ) -> R
1269- where
1270- F : FnMut ( Strategy , & mut Self ) -> R ,
1271- {
1272- let mut strategy = self . strategy . take ( ) ;
1273- let result = f ( strategy. as_mut ( ) . expect ( "failed acquiring strategy" ) . as_mut ( ) , self ) ;
1274- self . strategy = strategy;
1275-
1276- result
1277- }
12781261}
12791262
12801263impl Inspector < & mut dyn DatabaseExt > for Cheatcodes {
@@ -1294,10 +1277,11 @@ impl Inspector<&mut dyn DatabaseExt> for Cheatcodes {
12941277 self . gas_metering . paused_frames . push ( interpreter. gas ) ;
12951278 }
12961279
1297- self . strategy
1298- . as_mut ( )
1299- . expect ( "failed acquiring strategy" )
1300- . post_initialize_interp ( interpreter, ecx) ;
1280+ self . strategy . runner . post_initialize_interp (
1281+ self . strategy . context . as_mut ( ) ,
1282+ interpreter,
1283+ ecx,
1284+ ) ;
13011285 }
13021286
13031287 #[ inline]
@@ -1342,8 +1326,7 @@ impl Inspector<&mut dyn DatabaseExt> for Cheatcodes {
13421326
13431327 #[ inline]
13441328 fn step_end ( & mut self , interpreter : & mut Interpreter , ecx : Ecx ) {
1345- if self . strategy . as_mut ( ) . expect ( "failed acquiring strategy" ) . pre_step_end ( interpreter, ecx)
1346- {
1329+ if self . strategy . runner . pre_step_end ( self . strategy . context . as_mut ( ) , interpreter, ecx) {
13471330 return ;
13481331 }
13491332
0 commit comments