11use std:: collections:: { BTreeMap , HashMap } ;
22use std:: env;
3- use std:: fs:: read_to_string;
43use std:: sync:: { Arc , LazyLock } ;
54
65use apollo_gateway_config:: config:: RpcStateReaderConfig ;
@@ -15,26 +14,19 @@ use blockifier::state::state_api::StateResult;
1514use indexmap:: IndexMap ;
1615use pretty_assertions:: assert_eq;
1716use serde:: { Deserialize , Serialize } ;
18- use serde_json:: Value ;
1917use starknet_api:: block:: BlockNumber ;
2018use starknet_api:: contract_class:: ContractClass ;
2119use starknet_api:: core:: { ChainId , ClassHash , CompiledClassHash , ContractAddress , Nonce } ;
2220use starknet_api:: state:: { SierraContractClass , StorageKey } ;
23- use starknet_api:: transaction:: TransactionHash ;
2421use starknet_types_core:: felt:: Felt ;
2522
26- use crate :: state_reader:: cli:: TransactionInput ;
27- use crate :: state_reader:: errors:: { ReexecutionError , ReexecutionResult } ;
23+ use crate :: state_reader:: errors:: ReexecutionError ;
2824use crate :: state_reader:: offline_state_reader:: {
2925 OfflineConsecutiveStateReaders ,
3026 SerializableDataPrevBlock ,
3127 SerializableOfflineReexecutionData ,
3228} ;
33- use crate :: state_reader:: reexecution_state_reader:: {
34- ConsecutiveReexecutionStateReaders ,
35- ReexecutionStateReader ,
36- } ;
37- use crate :: state_reader:: serde_utils:: deserialize_transaction_json_to_starknet_api_tx;
29+ use crate :: state_reader:: reexecution_state_reader:: ConsecutiveReexecutionStateReaders ;
3830use crate :: state_reader:: test_state_reader:: ConsecutiveTestStateReaders ;
3931
4032pub static RPC_NODE_URL : LazyLock < String > = LazyLock :: new ( || {
@@ -313,71 +305,6 @@ pub fn write_block_reexecution_data_to_file(
313305 println ! ( "RPC replies required for reexecuting block {block_number} written to json file." ) ;
314306}
315307
316- /// Executes a single transaction from a JSON file or given a transaction hash, using RPC to fetch
317- /// block context. Does not assert correctness, only prints the execution result.
318- pub fn execute_single_transaction (
319- block_number : BlockNumber ,
320- node_url : String ,
321- chain_id : ChainId ,
322- tx_input : TransactionInput ,
323- contract_class_manager : ContractClassManager ,
324- ) -> ReexecutionResult < ( ) > {
325- // Create RPC config.
326- let config = RpcStateReaderConfig :: from_url ( node_url) ;
327-
328- // Create ConsecutiveTestStateReaders first.
329- let consecutive_state_readers = ConsecutiveTestStateReaders :: new (
330- block_number. prev ( ) . expect ( "Should not run with block 0" ) ,
331- Some ( config) ,
332- chain_id. clone ( ) ,
333- false , // dump_mode = false
334- contract_class_manager,
335- ) ;
336-
337- // Get transaction and hash based on input method.
338- let ( transaction, transaction_hash) = match tx_input {
339- TransactionInput :: FromHash { tx_hash } => {
340- // Fetch transaction from the next block (the block containing the transaction to
341- // execute).
342- let transaction =
343- consecutive_state_readers. next_block_state_reader . get_tx_by_hash ( & tx_hash) ?;
344- let transaction_hash = TransactionHash ( Felt :: from_hex_unchecked ( & tx_hash) ) ;
345-
346- ( transaction, transaction_hash)
347- }
348- TransactionInput :: FromFile { tx_path } => {
349- // Load the transaction from a local JSON file.
350- let json_content = read_to_string ( & tx_path)
351- . unwrap_or_else ( |_| panic ! ( "Failed to read transaction JSON file: {}." , tx_path) ) ;
352- let json_value: Value = serde_json:: from_str ( & json_content) ?;
353- let transaction = deserialize_transaction_json_to_starknet_api_tx ( json_value) ?;
354- let transaction_hash = transaction. calculate_transaction_hash ( & chain_id) ?;
355-
356- ( transaction, transaction_hash)
357- }
358- } ;
359-
360- // Convert transaction to BlockifierTransaction using api_txs_to_blockifier_txs_next_block.
361- let blockifier_tx = consecutive_state_readers
362- . next_block_state_reader
363- . api_txs_to_blockifier_txs_next_block ( vec ! [ ( transaction, transaction_hash) ] ) ?;
364-
365- // Create transaction executor.
366- let mut transaction_executor =
367- consecutive_state_readers. pre_process_and_create_executor ( None ) ?;
368-
369- // Execute transaction (should be single element).
370- let execution_results = transaction_executor. execute_txs ( & blockifier_tx, None ) ;
371-
372- // We expect exactly one execution result since we executed a single transaction.
373- let res =
374- execution_results. first ( ) . expect ( "Expected exactly one execution result, but got none" ) ;
375-
376- println ! ( "Execution result: {:?}" , res) ;
377-
378- Ok ( ( ) )
379- }
380-
381308/// Asserts equality between two `CommitmentStateDiff` structs, ignoring insertion order.
382309#[ macro_export]
383310macro_rules! assert_eq_state_diff {
0 commit comments