11#![ allow( dead_code) ]
2- use std:: collections:: HashMap ;
2+ use std:: collections:: { HashMap , HashSet } ;
33use std:: sync:: LazyLock ;
44
55use blockifier:: abi:: constants:: STORED_BLOCK_HASH_BUFFER ;
66use blockifier:: blockifier_versioned_constants:: VersionedConstants ;
77use blockifier:: bouncer:: BouncerConfig ;
88use blockifier:: context:: { BlockContext , ChainInfo , FeeTokenAddresses } ;
9+ use blockifier:: state:: cached_state:: StateMaps ;
10+ use blockifier:: state:: stateful_compression_test_utils:: decompress;
11+ use blockifier:: test_utils:: ALIAS_CONTRACT_ADDRESS ;
912use blockifier:: transaction:: transaction_execution:: Transaction as BlockifierTransaction ;
1013use starknet_api:: block:: { BlockHash , BlockInfo , BlockNumber } ;
1114use starknet_api:: contract_class:: ContractClass ;
@@ -26,7 +29,7 @@ use starknet_os::io::os_input::{
2629 OsHintsConfig ,
2730 StarknetOsInput ,
2831} ;
29- use starknet_os:: io:: os_output:: StarknetOsRunnerOutput ;
32+ use starknet_os:: io:: os_output:: { OsStateDiff , StarknetOsRunnerOutput } ;
3033use starknet_os:: runner:: { run_os_stateless, DEFAULT_OS_LAYOUT } ;
3134use starknet_patricia_storage:: map_storage:: BorrowedMapStorage ;
3235use starknet_types_core:: felt:: Felt ;
@@ -68,6 +71,11 @@ pub(crate) struct TestManager<S: FlowTestState> {
6871 per_block_transactions : Vec < Vec < BlockifierTransaction > > ,
6972}
7073
74+ pub ( crate ) struct OsTestOutput {
75+ pub ( crate ) os_output : StarknetOsRunnerOutput ,
76+ pub ( crate ) decompressed_state_diff : StateMaps ,
77+ }
78+
7179impl < S : FlowTestState > TestManager < S > {
7280 /// Creates a new `TestManager` with the provided initial state data.
7381 pub ( crate ) fn new_with_initial_state_data ( initial_state_data : InitialStateData < S > ) -> Self {
@@ -154,7 +162,7 @@ impl<S: FlowTestState> TestManager<S> {
154162 pub ( crate ) async fn execute_test_with_default_block_contexts (
155163 self ,
156164 initial_block_number : u64 ,
157- ) -> StarknetOsRunnerOutput {
165+ ) -> OsTestOutput {
158166 let n_blocks = self . per_block_transactions . len ( ) ;
159167 let block_contexts: Vec < BlockContext > = ( 0 ..n_blocks)
160168 . map ( |i| {
@@ -171,7 +179,7 @@ impl<S: FlowTestState> TestManager<S> {
171179 pub ( crate ) async fn execute_test_with_block_contexts (
172180 self ,
173181 block_contexts : Vec < BlockContext > ,
174- ) -> StarknetOsRunnerOutput {
182+ ) -> OsTestOutput {
175183 assert_eq ! (
176184 block_contexts. len( ) ,
177185 self . per_block_transactions. len( ) ,
@@ -193,10 +201,7 @@ impl<S: FlowTestState> TestManager<S> {
193201 }
194202
195203 // Private method which executes the flow test.
196- async fn execute_flow_test (
197- mut self ,
198- block_contexts : Vec < BlockContext > ,
199- ) -> StarknetOsRunnerOutput {
204+ async fn execute_flow_test ( mut self , block_contexts : Vec < BlockContext > ) -> OsTestOutput {
200205 let per_block_txs = self . per_block_transactions ;
201206 let mut os_block_inputs = vec ! [ ] ;
202207 let mut cached_state_inputs = vec ! [ ] ;
@@ -209,6 +214,7 @@ impl<S: FlowTestState> TestManager<S> {
209214 contracts_trie_root_hash : self . initial_state . contracts_trie_root_hash ,
210215 classes_trie_root_hash : self . initial_state . classes_trie_root_hash ,
211216 } ;
217+ let mut alias_keys = HashSet :: new ( ) ;
212218 for ( block_txs, block_context) in per_block_txs. into_iter ( ) . zip ( block_contexts. into_iter ( ) )
213219 {
214220 // Clone the block info for later use.
@@ -220,6 +226,7 @@ impl<S: FlowTestState> TestManager<S> {
220226 // Update the wrapped state.
221227 let state_diff = final_state. to_state_diff ( ) . unwrap ( ) ;
222228 state = final_state. state ;
229+ alias_keys. extend ( state_diff. state_maps . alias_keys ( ) ) ;
223230 state. apply_writes ( & state_diff. state_maps , & final_state. class_hash_to_class . borrow ( ) ) ;
224231 // Commit the state diff.
225232 let committer_state_diff = create_committer_state_diff ( block_summary. state_diff ) ;
@@ -290,10 +297,18 @@ impl<S: FlowTestState> TestManager<S> {
290297 chain_id : CHAIN_ID_FOR_TESTS . clone ( ) ,
291298 strk_fee_token_address : * STRK_FEE_TOKEN_ADDRESS ,
292299 } ;
293- let os_hints_config = OsHintsConfig { full_output : true , chain_info, ..Default :: default ( ) } ;
300+ let os_hints_config = OsHintsConfig { chain_info, ..Default :: default ( ) } ;
294301 let os_hints = OsHints { os_input : starknet_os_input, os_hints_config } ;
295302 let layout = DEFAULT_OS_LAYOUT ;
296- run_os_stateless ( layout, os_hints) . unwrap ( )
303+ let os_output = run_os_stateless ( layout, os_hints) . unwrap ( ) ;
304+ let OsStateDiff :: Partial ( ref partial_os_state_diff) = os_output. os_output . state_diff else {
305+ panic ! ( "Expected a partial state diff in the output because of the OS config." ) ;
306+ } ;
307+ let compressed_state_diff = partial_os_state_diff. as_state_maps ( ) ;
308+ let decompressed_state_diff =
309+ decompress ( & compressed_state_diff, & state, * ALIAS_CONTRACT_ADDRESS , alias_keys) ;
310+
311+ OsTestOutput { os_output, decompressed_state_diff }
297312 }
298313}
299314
0 commit comments