diff --git a/crates/blockifier/src/concurrency/worker_logic_test.rs b/crates/blockifier/src/concurrency/worker_logic_test.rs index 4370e43d170..4e6dae5a220 100644 --- a/crates/blockifier/src/concurrency/worker_logic_test.rs +++ b/crates/blockifier/src/concurrency/worker_logic_test.rs @@ -4,7 +4,7 @@ use std::sync::Mutex; use rstest::rstest; use starknet_api::abi::abi_utils::get_fee_token_var_address; use starknet_api::core::{ContractAddress, Nonce}; -use starknet_api::test_utils::NonceManager; +use starknet_api::test_utils::{NonceManager, TEST_ERC20_CONTRACT_ADDRESS2}; use starknet_api::transaction::constants::DEPLOY_CONTRACT_FUNCTION_ENTRY_POINT_NAME; use starknet_api::transaction::fields::{ContractAddressSalt, Fee, ValidResourceBounds}; use starknet_api::transaction::TransactionVersion; @@ -25,13 +25,7 @@ use crate::state::state_api::StateReader; use crate::test_utils::contracts::FeatureContract; use crate::test_utils::declare::declare_tx; use crate::test_utils::initial_test_state::test_state; -use crate::test_utils::{ - create_calldata, - create_trivial_calldata, - CairoVersion, - BALANCE, - TEST_ERC20_CONTRACT_ADDRESS2, -}; +use crate::test_utils::{create_calldata, create_trivial_calldata, CairoVersion, BALANCE}; use crate::transaction::account_transaction::AccountTransaction; use crate::transaction::objects::HasRelatedFeeType; use crate::transaction::test_utils::{ diff --git a/crates/blockifier/src/execution/deprecated_syscalls/deprecated_syscalls_test.rs b/crates/blockifier/src/execution/deprecated_syscalls/deprecated_syscalls_test.rs index 7f04bb9abd4..fc244c67191 100644 --- a/crates/blockifier/src/execution/deprecated_syscalls/deprecated_syscalls_test.rs +++ b/crates/blockifier/src/execution/deprecated_syscalls/deprecated_syscalls_test.rs @@ -7,6 +7,13 @@ use rstest::rstest; use starknet_api::abi::abi_utils::selector_from_name; use starknet_api::core::{calculate_contract_address, ChainId}; use starknet_api::state::StorageKey; +use starknet_api::test_utils::{ + CURRENT_BLOCK_NUMBER, + CURRENT_BLOCK_NUMBER_FOR_VALIDATE, + CURRENT_BLOCK_TIMESTAMP, + CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE, + TEST_SEQUENCER_ADDRESS, +}; use starknet_api::transaction::fields::{Calldata, ContractAddressSalt, Fee}; use starknet_api::transaction::{ EventContent, @@ -34,11 +41,6 @@ use crate::test_utils::{ get_syscall_resources, trivial_external_entry_point_new, CairoVersion, - CURRENT_BLOCK_NUMBER, - CURRENT_BLOCK_NUMBER_FOR_VALIDATE, - CURRENT_BLOCK_TIMESTAMP, - CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE, - TEST_SEQUENCER_ADDRESS, }; use crate::transaction::objects::{ CommonAccountFields, diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/get_block_hash.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/get_block_hash.rs index 37ef06006fe..d86d25e1623 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/get_block_hash.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/get_block_hash.rs @@ -2,6 +2,7 @@ use pretty_assertions::assert_eq; use starknet_api::abi::abi_utils::selector_from_name; use starknet_api::execution_utils::format_panic_data; use starknet_api::state::StorageKey; +use starknet_api::test_utils::CURRENT_BLOCK_NUMBER; use starknet_api::{calldata, felt}; use starknet_types_core::felt::Felt; use test_case::test_case; @@ -15,12 +16,7 @@ use crate::state::state_api::State; use crate::test_utils::contracts::FeatureContract; use crate::test_utils::dict_state_reader::DictStateReader; use crate::test_utils::initial_test_state::test_state; -use crate::test_utils::{ - trivial_external_entry_point_new, - CairoVersion, - BALANCE, - CURRENT_BLOCK_NUMBER, -}; +use crate::test_utils::{trivial_external_entry_point_new, CairoVersion, BALANCE}; use crate::versioned_constants::VersionedConstants; use crate::{check_entry_point_execution_error_for_custom_hint, retdata}; diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/get_execution_info.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/get_execution_info.rs index c7657beaec0..8026c5d2c2a 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/get_execution_info.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/get_execution_info.rs @@ -3,6 +3,13 @@ use starknet_api::block::GasPrice; use starknet_api::core::ChainId; use starknet_api::data_availability::DataAvailabilityMode; use starknet_api::execution_resources::GasAmount; +use starknet_api::test_utils::{ + CURRENT_BLOCK_NUMBER, + CURRENT_BLOCK_NUMBER_FOR_VALIDATE, + CURRENT_BLOCK_TIMESTAMP, + CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE, + TEST_SEQUENCER_ADDRESS, +}; use starknet_api::transaction::fields::{ AccountDeploymentData, Calldata, @@ -23,16 +30,7 @@ use crate::execution::common_hints::ExecutionMode; use crate::execution::entry_point::CallEntryPoint; use crate::test_utils::contracts::FeatureContract; use crate::test_utils::initial_test_state::test_state; -use crate::test_utils::{ - trivial_external_entry_point_with_address, - CairoVersion, - BALANCE, - CURRENT_BLOCK_NUMBER, - CURRENT_BLOCK_NUMBER_FOR_VALIDATE, - CURRENT_BLOCK_TIMESTAMP, - CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE, - TEST_SEQUENCER_ADDRESS, -}; +use crate::test_utils::{trivial_external_entry_point_with_address, CairoVersion, BALANCE}; use crate::transaction::objects::{ CommonAccountFields, CurrentTransactionInfo, diff --git a/crates/blockifier/src/test_utils.rs b/crates/blockifier/src/test_utils.rs index 31c737980ff..636996f81fc 100644 --- a/crates/blockifier/src/test_utils.rs +++ b/crates/blockifier/src/test_utils.rs @@ -30,6 +30,7 @@ use starknet_api::test_utils::{ DEFAULT_STRK_L1_GAS_PRICE, DEFAULT_STRK_L2_GAS_PRICE, MAX_FEE, + TEST_SEQUENCER_ADDRESS, }; use starknet_api::transaction::fields::{ Calldata, @@ -52,13 +53,6 @@ use crate::test_utils::contracts::FeatureContract; use crate::transaction::transaction_types::TransactionType; use crate::utils::{const_max, u64_from_usize}; use crate::versioned_constants::VersionedConstants; -// TODO(Dori, 1/2/2024): Remove these constants once all tests use the `contracts` and -// `initial_test_state` modules for testing. -// Addresses. -pub const TEST_SEQUENCER_ADDRESS: &str = "0x1000"; -pub const TEST_ERC20_CONTRACT_ADDRESS: &str = "0x1001"; -pub const TEST_ERC20_CONTRACT_ADDRESS2: &str = "0x1002"; - // Class hashes. // TODO(Adi, 15/01/2023): Remove and compute the class hash corresponding to the ERC20 contract in // starkgate once we use the real ERC20 contract. @@ -157,14 +151,6 @@ pub const BALANCE: Fee = Fee(10 MAX_FEE.0, )); -// The block number of the BlockContext being used for testing. -pub const CURRENT_BLOCK_NUMBER: u64 = 2001; -pub const CURRENT_BLOCK_NUMBER_FOR_VALIDATE: u64 = 2000; - -// The block timestamp of the BlockContext being used for testing. -pub const CURRENT_BLOCK_TIMESTAMP: u64 = 1072023; -pub const CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE: u64 = 1069200; - #[derive(Default)] pub struct SaltManager { next_salt: u8, diff --git a/crates/blockifier/src/test_utils/struct_impls.rs b/crates/blockifier/src/test_utils/struct_impls.rs index 61d67bb3177..e53f672cad6 100644 --- a/crates/blockifier/src/test_utils/struct_impls.rs +++ b/crates/blockifier/src/test_utils/struct_impls.rs @@ -10,11 +10,11 @@ use cairo_lang_starknet_classes::contract_class::ContractClass as SierraContract #[cfg(feature = "cairo_native")] use cairo_native::executor::AotContractExecutor; use serde_json::Value; -use starknet_api::block::{BlockInfo, BlockNumber, BlockTimestamp}; +use starknet_api::block::BlockInfo; use starknet_api::contract_address; use starknet_api::core::{ChainId, ClassHash}; use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; -use starknet_api::test_utils::DEFAULT_GAS_PRICES; +use starknet_api::test_utils::{TEST_ERC20_CONTRACT_ADDRESS, TEST_ERC20_CONTRACT_ADDRESS2}; use crate::bouncer::{BouncerConfig, BouncerWeights, BuiltinCount}; use crate::context::{BlockContext, ChainInfo, FeeTokenAddresses, TransactionContext}; @@ -30,15 +30,7 @@ use crate::execution::entry_point::{ #[cfg(feature = "cairo_native")] use crate::execution::native::contract_class::NativeCompiledClassV1; use crate::state::state_api::State; -use crate::test_utils::{ - get_raw_contract_class, - update_json_value, - CURRENT_BLOCK_NUMBER, - CURRENT_BLOCK_TIMESTAMP, - TEST_ERC20_CONTRACT_ADDRESS, - TEST_ERC20_CONTRACT_ADDRESS2, - TEST_SEQUENCER_ADDRESS, -}; +use crate::test_utils::{get_raw_contract_class, update_json_value}; use crate::transaction::objects::{ CurrentTransactionInfo, DeprecatedTransactionInfo, @@ -145,22 +137,6 @@ pub trait BlockInfoExt { fn create_for_testing_with_kzg(use_kzg_da: bool) -> Self; } -impl BlockInfoExt for BlockInfo { - fn create_for_testing() -> Self { - Self { - block_number: BlockNumber(CURRENT_BLOCK_NUMBER), - block_timestamp: BlockTimestamp(CURRENT_BLOCK_TIMESTAMP), - sequencer_address: contract_address!(TEST_SEQUENCER_ADDRESS), - gas_prices: DEFAULT_GAS_PRICES, - use_kzg_da: false, - } - } - - fn create_for_testing_with_kzg(use_kzg_da: bool) -> Self { - Self { use_kzg_da, ..Self::create_for_testing() } - } -} - impl BlockContext { pub fn create_for_testing() -> Self { Self { diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index e45f4c8ca22..11997b64f54 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -22,6 +22,10 @@ use starknet_api::state::StorageKey; use starknet_api::test_utils::invoke::InvokeTxArgs; use starknet_api::test_utils::{ NonceManager, + CURRENT_BLOCK_NUMBER, + CURRENT_BLOCK_NUMBER_FOR_VALIDATE, + CURRENT_BLOCK_TIMESTAMP, + CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE, DEFAULT_L1_DATA_GAS_MAX_AMOUNT, DEFAULT_L1_GAS_AMOUNT, DEFAULT_L2_GAS_MAX_AMOUNT, @@ -29,6 +33,7 @@ use starknet_api::test_utils::{ DEFAULT_STRK_L1_GAS_PRICE, DEFAULT_STRK_L2_GAS_PRICE, MAX_FEE, + TEST_SEQUENCER_ADDRESS, }; use starknet_api::transaction::fields::Resource::{L1DataGas, L1Gas, L2Gas}; use starknet_api::transaction::fields::{ @@ -112,11 +117,6 @@ use crate::test_utils::{ CairoVersion, SaltManager, BALANCE, - CURRENT_BLOCK_NUMBER, - CURRENT_BLOCK_NUMBER_FOR_VALIDATE, - CURRENT_BLOCK_TIMESTAMP, - CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE, - TEST_SEQUENCER_ADDRESS, }; use crate::transaction::account_transaction::AccountTransaction; use crate::transaction::errors::{ diff --git a/crates/starknet_api/src/test_utils.rs b/crates/starknet_api/src/test_utils.rs index 2f4d53c7afc..5837c900355 100644 --- a/crates/starknet_api/src/test_utils.rs +++ b/crates/starknet_api/src/test_utils.rs @@ -7,7 +7,16 @@ use serde::{Deserialize, Serialize}; use serde_json::to_string_pretty; use starknet_types_core::felt::Felt; -use crate::block::{BlockNumber, GasPrice, GasPriceVector, GasPrices, NonzeroGasPrice}; +use crate::block::{ + BlockInfo, + BlockNumber, + BlockTimestamp, + GasPrice, + GasPriceVector, + GasPrices, + NonzeroGasPrice, +}; +use crate::contract_address; use crate::core::{ChainId, ContractAddress, Nonce}; use crate::execution_resources::GasAmount; use crate::rpc_transaction::RpcTransaction; @@ -21,6 +30,21 @@ pub mod l1_handler; generate_get_package_dir!(); +// TODO(Dori, 1/2/2024): Remove these constants once all tests use the `contracts` and +// `initial_test_state` modules for testing. +// Addresses. +pub const TEST_SEQUENCER_ADDRESS: &str = "0x1000"; +pub const TEST_ERC20_CONTRACT_ADDRESS: &str = "0x1001"; +pub const TEST_ERC20_CONTRACT_ADDRESS2: &str = "0x1002"; + +// The block number of the BlockContext being used for testing. +pub const CURRENT_BLOCK_NUMBER: u64 = 2001; +pub const CURRENT_BLOCK_NUMBER_FOR_VALIDATE: u64 = 2000; + +// The block timestamp of the BlockContext being used for testing. +pub const CURRENT_BLOCK_TIMESTAMP: u64 = 1072023; +pub const CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE: u64 = 1069200; + /// Returns the path to a file in the resources directory. This assumes the package directory has a /// `resources` folder. The value for file_path should be the path to the required file in the /// folder "resources". @@ -155,3 +179,19 @@ pub const DEFAULT_GAS_PRICES: GasPrices = GasPrices { // Deprecated transactions: pub const MAX_FEE: Fee = DEFAULT_L1_GAS_AMOUNT.nonzero_saturating_mul(DEFAULT_ETH_L1_GAS_PRICE); + +impl BlockInfo { + pub fn create_for_testing() -> Self { + Self { + block_number: BlockNumber(CURRENT_BLOCK_NUMBER), + block_timestamp: BlockTimestamp(CURRENT_BLOCK_TIMESTAMP), + sequencer_address: contract_address!(TEST_SEQUENCER_ADDRESS), + gas_prices: DEFAULT_GAS_PRICES, + use_kzg_da: false, + } + } + + pub fn create_for_testing_with_kzg(use_kzg_da: bool) -> Self { + Self { use_kzg_da, ..Self::create_for_testing() } + } +} diff --git a/crates/starknet_integration_tests/src/state_reader.rs b/crates/starknet_integration_tests/src/state_reader.rs index 27e11b124c2..c1d415bb8b9 100644 --- a/crates/starknet_integration_tests/src/state_reader.rs +++ b/crates/starknet_integration_tests/src/state_reader.rs @@ -4,12 +4,7 @@ use std::sync::Arc; use assert_matches::assert_matches; use blockifier::context::{BlockContext, ChainInfo}; use blockifier::test_utils::contracts::FeatureContract; -use blockifier::test_utils::{ - CairoVersion, - BALANCE, - CURRENT_BLOCK_TIMESTAMP, - TEST_SEQUENCER_ADDRESS, -}; +use blockifier::test_utils::{CairoVersion, BALANCE}; use blockifier::versioned_constants::VersionedConstants; use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; use indexmap::IndexMap; @@ -36,7 +31,12 @@ use starknet_api::block::{ use starknet_api::core::{ChainId, ClassHash, ContractAddress, Nonce, SequencerContractAddress}; use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; use starknet_api::state::{StorageKey, ThinStateDiff}; -use starknet_api::test_utils::{DEFAULT_ETH_L1_GAS_PRICE, DEFAULT_STRK_L1_GAS_PRICE}; +use starknet_api::test_utils::{ + CURRENT_BLOCK_TIMESTAMP, + DEFAULT_ETH_L1_GAS_PRICE, + DEFAULT_STRK_L1_GAS_PRICE, + TEST_SEQUENCER_ADDRESS, +}; use starknet_api::transaction::fields::Fee; use starknet_api::{contract_address, felt}; use starknet_client::reader::PendingData;