diff --git a/crates/blockifier/src/test_utils/invoke.rs b/crates/blockifier/src/test_utils/invoke.rs index a5898d31fb..db5915d6cf 100644 --- a/crates/blockifier/src/test_utils/invoke.rs +++ b/crates/blockifier/src/test_utils/invoke.rs @@ -1,26 +1,13 @@ use starknet_api::test_utils::invoke::InvokeTxArgs; -use starknet_api::transaction::{InvokeTransactionV0, TransactionHash, TransactionVersion}; +use starknet_api::transaction::TransactionHash; -use crate::abi::abi_utils::selector_from_name; -use crate::transaction::constants::EXECUTE_ENTRY_POINT_NAME; use crate::transaction::transactions::InvokeTransaction; pub fn invoke_tx(invoke_args: InvokeTxArgs) -> InvokeTransaction { let default_tx_hash = TransactionHash::default(); let only_query = invoke_args.only_query; // TODO: Make TransactionVersion an enum and use match here. - let invoke_tx = if invoke_args.version == TransactionVersion::ZERO { - starknet_api::transaction::InvokeTransaction::V0(InvokeTransactionV0 { - max_fee: invoke_args.max_fee, - calldata: invoke_args.calldata, - contract_address: invoke_args.sender_address, - signature: invoke_args.signature, - // V0 transactions should always select the `__execute__` entry point. - entry_point_selector: selector_from_name(EXECUTE_ENTRY_POINT_NAME), - }) - } else { - starknet_api::test_utils::invoke::invoke_tx(invoke_args) - }; + let invoke_tx = starknet_api::test_utils::invoke::invoke_tx(invoke_args); match only_query { true => InvokeTransaction::new_for_query(invoke_tx, default_tx_hash), diff --git a/crates/starknet_api/src/test_utils/invoke.rs b/crates/starknet_api/src/test_utils/invoke.rs index 09f9f84721..d8c03994de 100644 --- a/crates/starknet_api/src/test_utils/invoke.rs +++ b/crates/starknet_api/src/test_utils/invoke.rs @@ -1,5 +1,6 @@ -use crate::calldata; -use crate::core::{ContractAddress, Nonce}; +use std::sync::OnceLock; + +use crate::core::{ContractAddress, EntryPointSelector, Nonce}; use crate::data_availability::DataAvailabilityMode; use crate::executable_transaction::InvokeTransaction as ExecutableInvokeTransaction; use crate::transaction::{ @@ -7,6 +8,7 @@ use crate::transaction::{ Calldata, Fee, InvokeTransaction, + InvokeTransactionV0, InvokeTransactionV1, InvokeTransactionV3, PaymasterData, @@ -16,6 +18,7 @@ use crate::transaction::{ TransactionVersion, ValidResourceBounds, }; +use crate::{calldata, felt}; #[derive(Clone)] pub struct InvokeTxArgs { @@ -71,15 +74,33 @@ macro_rules! invoke_tx_args { }; } +static EXECUTE_ENTRY_POINT_SELECTOR: OnceLock = OnceLock::new(); + +/// V0 transactions should always select the `__execute__` entry point. +/// The original code from the blockifier crate was: +/// +/// crate::abi::abi_utils::selector_from_name( +/// crate::transaction::constants::EXECUTE_ENTRY_POINT_NAME +/// ) +fn execute_entry_point_selector() -> EntryPointSelector { + // This is the result of hashing the string "__execute__" with the Starknet keccak function. + const EXECUTE_ENTRY_POINT_NAME_THROUGH_KECCAK: &str = + "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad"; + + *EXECUTE_ENTRY_POINT_SELECTOR + .get_or_init(|| EntryPointSelector(felt!(EXECUTE_ENTRY_POINT_NAME_THROUGH_KECCAK))) +} + pub fn invoke_tx(invoke_args: InvokeTxArgs) -> InvokeTransaction { // TODO: Make TransactionVersion an enum and use match here. if invoke_args.version == TransactionVersion::ZERO { - // TODO(Arni): Implement V0. See blockifier test utils for reference. There is an issue with - // the computation of the entry_point_selector. - panic!( - "This test util does not supported creation of transaction version: {:?}.", - invoke_args.version - ); + InvokeTransaction::V0(InvokeTransactionV0 { + max_fee: invoke_args.max_fee, + calldata: invoke_args.calldata, + contract_address: invoke_args.sender_address, + signature: invoke_args.signature, + entry_point_selector: execute_entry_point_selector(), + }) } else if invoke_args.version == TransactionVersion::ONE { InvokeTransaction::V1(InvokeTransactionV1 { max_fee: invoke_args.max_fee,