@@ -357,6 +357,56 @@ impl<S: FlowTestState> OsTestOutput<S> {
357357 }
358358}
359359
360+ /// Holds the data needed to run the OS and create the test output.
361+ pub ( crate ) struct TestRunner < S : FlowTestState > {
362+ pub ( crate ) os_hints : OsHints ,
363+ // Carries the writes of the entire execution in its cache.
364+ pub ( crate ) entire_cached_state : CachedState < S > ,
365+ pub ( crate ) messages_to_l1 : Vec < MessageToL1 > ,
366+ pub ( crate ) messages_to_l2 : Vec < MessageToL2 > ,
367+ pub ( crate ) private_keys : Option < Vec < Felt > > ,
368+ }
369+
370+ impl < S : FlowTestState > TestRunner < S > {
371+ /// Runs the OS and creates the test output.
372+ pub ( crate ) fn run ( mut self ) -> OsTestOutput < S > {
373+ // This cached state holds the diff of the entire execution.
374+ let entire_state_diff = self . entire_cached_state . to_state_diff ( ) . unwrap ( ) . state_maps ;
375+ let entire_initial_reads = get_extended_initial_reads ( & self . entire_cached_state ) ;
376+ self . entire_cached_state . state . apply_writes (
377+ & entire_state_diff,
378+ & self . entire_cached_state . class_hash_to_class . borrow ( ) ,
379+ ) ;
380+ let final_state = self . entire_cached_state . state ;
381+
382+ // Create expected values before running OS (os_hints is consumed by run_os_stateless).
383+ let expected_values = OsTestExpectedValues :: new (
384+ & self . os_hints ,
385+ self . messages_to_l1 ,
386+ self . messages_to_l2 ,
387+ create_committer_state_diff ( entire_state_diff. clone ( ) ) ,
388+ ) ;
389+ let layout = DEFAULT_OS_LAYOUT ;
390+ let os_output = run_os_stateless ( layout, self . os_hints ) . unwrap ( ) ;
391+
392+ let decompressed_state_diff =
393+ create_committer_state_diff ( TestManager :: < S > :: get_decompressed_state_diff (
394+ & os_output,
395+ & final_state,
396+ entire_initial_reads. alias_keys ( ) ,
397+ self . private_keys . as_ref ( ) ,
398+ ) ) ;
399+
400+ OsTestOutput {
401+ runner_output : os_output,
402+ private_keys : self . private_keys ,
403+ decompressed_state_diff,
404+ final_state,
405+ expected_values,
406+ }
407+ }
408+ }
409+
360410/// Manages the execution of flow tests by maintaining the initial state and transactions.
361411pub ( crate ) struct TestManager < S : FlowTestState > {
362412 pub ( crate ) initial_state : InitialState < S > ,
@@ -741,38 +791,14 @@ impl<S: FlowTestState> TestManager<S> {
741791 let os_hints =
742792 OsHints { os_input : starknet_os_input, os_hints_config : self . os_hints_config } ;
743793
744- // This cached state holds the diff of the entire execution.
745- let entire_state_diff = state. to_state_diff ( ) . unwrap ( ) . state_maps ;
746- let entire_initial_reads = state. get_initial_reads ( ) . unwrap ( ) ;
747-
748- state. state . apply_writes ( & entire_state_diff, & state. class_hash_to_class . borrow ( ) ) ;
749- let final_state = state. state ;
750-
751- // Create expected values before running OS (os_hints is consumed by run_os_stateless).
752- let expected_values = OsTestExpectedValues :: new (
753- & os_hints,
754- self . messages_to_l1 ,
755- self . messages_to_l2 ,
756- create_committer_state_diff ( entire_state_diff) ,
757- ) ;
758- let layout = DEFAULT_OS_LAYOUT ;
759- let os_output = run_os_stateless ( layout, os_hints) . unwrap ( ) ;
760-
761- let decompressed_state_diff =
762- create_committer_state_diff ( Self :: get_decompressed_state_diff (
763- & os_output,
764- & final_state,
765- entire_initial_reads. alias_keys ( ) ,
766- self . private_keys . as_ref ( ) ,
767- ) ) ;
768-
769- OsTestOutput {
770- runner_output : os_output,
794+ let test_runner = TestRunner {
795+ os_hints,
796+ entire_cached_state : state,
797+ messages_to_l1 : self . messages_to_l1 ,
798+ messages_to_l2 : self . messages_to_l2 ,
771799 private_keys : self . private_keys ,
772- decompressed_state_diff,
773- final_state,
774- expected_values,
775- }
800+ } ;
801+ test_runner. run ( )
776802 }
777803}
778804
0 commit comments