diff --git a/crates/blockifier_reexecution/resources/raw_rpc_json_objects/transactions.json b/crates/blockifier_reexecution/resources/raw_rpc_json_objects/transactions.json index f29c46ae043..2979d5afefe 100644 --- a/crates/blockifier_reexecution/resources/raw_rpc_json_objects/transactions.json +++ b/crates/blockifier_reexecution/resources/raw_rpc_json_objects/transactions.json @@ -183,5 +183,21 @@ "account_deployment_data": [], "nonce_data_availability_mode": "L1", "fee_data_availability_mode": "L1" + }, + "l1_handler": { + "transaction_hash": "0x2315145ae0290b7d49ea3f509b1084b5fcd70d0fea8bed04b83aa8af33e4d7e", + "type": "L1_HANDLER", + "version": "0x0", + "nonce": "0x1961fb", + "contract_address": "0x73314940630fd6dcda0d772d4c972c4e0a9946bef9dabf4ef84eda8ef542b82", + "calldata": [ + "0xae0ee0a63a2ce6baeeffe56e7714fb4efe48d419", + "0x455448", + "0xc2da4fdceac12352751fb90eca6821107563d743", + "0x622dc4bd4723f8b058196db0be5e7b89bbe01f0e55730a51c45480ba229a373", + "0xe35fa931a0000", + "0x0" + ], + "entry_point_selector": "0x1b64b1b3b690b43b9b514fb81377518f4039cd3e4f4914d8a6bdf01d679fb19" } } \ No newline at end of file diff --git a/crates/blockifier_reexecution/src/state_reader/raw_rpc_json_test.rs b/crates/blockifier_reexecution/src/state_reader/raw_rpc_json_test.rs index fc19ff217c5..0fdd100f81e 100644 --- a/crates/blockifier_reexecution/src/state_reader/raw_rpc_json_test.rs +++ b/crates/blockifier_reexecution/src/state_reader/raw_rpc_json_test.rs @@ -125,6 +125,16 @@ fn deserialize_declare_txs( } } +#[test] +fn deserialize_l1_handler_tx() { + let l1_handler_tx = deserialize_transaction_json_to_starknet_api_tx( + read_json_file("raw_rpc_json_objects/transactions.json")["l1_handler"].clone(), + ) + .expect("Failed to deserialize l1 handler tx"); + + assert_matches!(l1_handler_tx, Transaction::L1Handler(..)); +} + #[rstest] fn serialize_state_maps() { let nonces = HashMap::from([(contract_address!(1_u8), nonce!(1_u8))]); diff --git a/crates/blockifier_reexecution/src/state_reader/reexecution_state_reader.rs b/crates/blockifier_reexecution/src/state_reader/reexecution_state_reader.rs index e0b1b677341..58fc50f199f 100644 --- a/crates/blockifier_reexecution/src/state_reader/reexecution_state_reader.rs +++ b/crates/blockifier_reexecution/src/state_reader/reexecution_state_reader.rs @@ -3,7 +3,7 @@ use blockifier::state::state_api::StateResult; use blockifier::transaction::transaction_execution::Transaction as BlockifierTransaction; use papyrus_execution::DEPRECATED_CONTRACT_SIERRA_SIZE; use starknet_api::core::ClassHash; -use starknet_api::transaction::{Transaction, TransactionHash}; +use starknet_api::transaction::{Fee, Transaction, TransactionHash}; use starknet_core::types::ContractClass as StarknetContractClass; use super::compile::{legacy_to_contract_class_v0, sierra_to_contact_class_v1}; @@ -41,28 +41,34 @@ pub(crate) trait ReexecutionStateReader { .into_iter() .map(|(tx, tx_hash)| match tx { Transaction::Invoke(_) | Transaction::DeployAccount(_) => { - BlockifierTransaction::from_api(tx, tx_hash, None, None, None, false) - .map_err(ReexecutionError::from) + Ok(BlockifierTransaction::from_api(tx, tx_hash, None, None, None, false)?) } Transaction::Declare(ref declare_tx) => { let class_info = self .get_class_info(declare_tx.class_hash()) .map_err(ReexecutionError::from)?; - BlockifierTransaction::from_api( + Ok(BlockifierTransaction::from_api( tx, tx_hash, Some(class_info), None, None, false, - ) - .map_err(ReexecutionError::from) + )?) } - Transaction::L1Handler(_) => todo!("Implement L1Handler transaction converter"), + Transaction::L1Handler(_) => Ok(BlockifierTransaction::from_api( + tx, + tx_hash, + None, + Some(Fee(u128::MAX)), + None, + false, + )?), + Transaction::Deploy(_) => { panic!("Reexecution not supported for Deploy transactions.") } }) - .collect::, _>>() + .collect() } } diff --git a/crates/blockifier_reexecution/src/state_reader/rpc_https_test.rs b/crates/blockifier_reexecution/src/state_reader/rpc_https_test.rs index dbecf79a3fe..cf059779726 100644 --- a/crates/blockifier_reexecution/src/state_reader/rpc_https_test.rs +++ b/crates/blockifier_reexecution/src/state_reader/rpc_https_test.rs @@ -45,6 +45,10 @@ const EXAMPLE_DECLARE_V3_BLOCK_NUMBER: u64 = 825013; const EXAMPLE_DECLARE_V3_TX_HASH: &str = "0x03ab43c0913f95b901b49ed1aa6009b31ebe0ad7ba62da49fc6de7f3854b496f"; +const EXAMPLE_L1_HANDLER_BLOCK_NUMBER: u64 = 868429; +const EXAMPLE_L1_HANDLER_TX_HASH: &str = + "0x02315145ae0290b7d49ea3f509b1084b5fcd70d0fea8bed04b83aa8af33e4d7e"; + #[fixture] pub fn test_block_number() -> BlockNumber { BlockNumber(EXAMPLE_BLOCK_NUMBER) @@ -176,6 +180,15 @@ pub fn test_get_declare_tx_by_hash( } } +#[test] +pub fn test_get_l1_handler_tx_by_hash() { + // Create StateReader with block number that contain the l1 handler tx. + let state_reader = + TestStateReader::new_for_testing(BlockNumber(EXAMPLE_L1_HANDLER_BLOCK_NUMBER)); + let actual_tx = state_reader.get_tx_by_hash(EXAMPLE_L1_HANDLER_TX_HASH).unwrap(); + assert_matches!(actual_tx, Transaction::L1Handler(..)) +} + #[rstest] pub fn test_get_statediff_rpc(test_state_reader: TestStateReader) { assert!(test_state_reader.get_state_diff().is_ok());