diff --git a/crates/blockifier/src/test_utils.rs b/crates/blockifier/src/test_utils.rs index 94ac064489..b8b123be3c 100644 --- a/crates/blockifier/src/test_utils.rs +++ b/crates/blockifier/src/test_utils.rs @@ -17,7 +17,15 @@ use std::path::PathBuf; use cairo_vm::types::builtin_name::BuiltinName; use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use starknet_api::abi::abi_utils::{get_fee_token_var_address, selector_from_name}; -use starknet_api::block::{BlockHash, BlockHashAndNumber, BlockNumber, GasPrice, NonzeroGasPrice}; +use starknet_api::block::{ + BlockHash, + BlockHashAndNumber, + BlockNumber, + GasPrice, + GasPriceVector, + GasPrices, + NonzeroGasPrice, +}; use starknet_api::core::{ClassHash, ContractAddress}; use starknet_api::execution_resources::{GasAmount, GasVector}; use starknet_api::hash::StarkHash; @@ -149,9 +157,25 @@ pub const DEFAULT_ETH_L1_DATA_GAS_PRICE: NonzeroGasPrice = NonzeroGasPrice::new_unchecked(GasPrice(u128::pow(10, 6))); // Given in units of Wei. pub const DEFAULT_STRK_L1_DATA_GAS_PRICE: NonzeroGasPrice = NonzeroGasPrice::new_unchecked(GasPrice(u128::pow(10, 9))); // Given in units of STRK. +pub const DEFAULT_ETH_L2_GAS_PRICE: NonzeroGasPrice = + NonzeroGasPrice::new_unchecked(GasPrice(25 * u128::pow(10, 5))); +// TODO(Arni): Fix to: 25 * u128::pow(10, 5) when the gas price is given in STRK. pub const DEFAULT_STRK_L2_GAS_PRICE: NonzeroGasPrice = NonzeroGasPrice::new_unchecked(GasPrice(u128::pow(10, 9))); +pub const DEFAULT_GAS_PRICES: GasPrices = GasPrices { + eth_gas_prices: GasPriceVector { + l1_gas_price: DEFAULT_ETH_L1_GAS_PRICE, + l2_gas_price: DEFAULT_ETH_L2_GAS_PRICE, + l1_data_gas_price: DEFAULT_ETH_L1_DATA_GAS_PRICE, + }, + strk_gas_prices: GasPriceVector { + l1_gas_price: DEFAULT_STRK_L1_GAS_PRICE, + l2_gas_price: DEFAULT_STRK_L2_GAS_PRICE, + l1_data_gas_price: DEFAULT_STRK_L1_DATA_GAS_PRICE, + }, +}; + // Deprecated transactions: pub const MAX_FEE: Fee = DEFAULT_L1_GAS_AMOUNT.nonzero_saturating_mul(DEFAULT_ETH_L1_GAS_PRICE); diff --git a/crates/blockifier/src/test_utils/struct_impls.rs b/crates/blockifier/src/test_utils/struct_impls.rs index 134d396f61..75fbceb06b 100644 --- a/crates/blockifier/src/test_utils/struct_impls.rs +++ b/crates/blockifier/src/test_utils/struct_impls.rs @@ -153,26 +153,28 @@ pub trait BlockInfoExt { impl BlockInfoExt for BlockInfo { fn create_for_testing() -> Self { + let gas_prices = validated_gas_prices( + DEFAULT_ETH_L1_GAS_PRICE, + DEFAULT_STRK_L1_GAS_PRICE, + DEFAULT_ETH_L1_DATA_GAS_PRICE, + DEFAULT_STRK_L1_DATA_GAS_PRICE, + NonzeroGasPrice::new( + VersionedConstants::latest_constants() + .convert_l1_to_l2_gas_price_round_up(DEFAULT_ETH_L1_GAS_PRICE.into()), + ) + .unwrap(), + NonzeroGasPrice::new( + VersionedConstants::latest_constants() + .convert_l1_to_l2_gas_price_round_up(DEFAULT_STRK_L1_GAS_PRICE.into()), + ) + .unwrap(), + ); + // TODO(Arni): assert_eq!(gas_prices, crate::test_utils::DEFAULT_GAS_PRICES); Self { block_number: BlockNumber(CURRENT_BLOCK_NUMBER), block_timestamp: BlockTimestamp(CURRENT_BLOCK_TIMESTAMP), sequencer_address: contract_address!(TEST_SEQUENCER_ADDRESS), - gas_prices: validated_gas_prices( - DEFAULT_ETH_L1_GAS_PRICE, - DEFAULT_STRK_L1_GAS_PRICE, - DEFAULT_ETH_L1_DATA_GAS_PRICE, - DEFAULT_STRK_L1_DATA_GAS_PRICE, - NonzeroGasPrice::new( - VersionedConstants::latest_constants() - .convert_l1_to_l2_gas_price_round_up(DEFAULT_ETH_L1_GAS_PRICE.into()), - ) - .unwrap(), - NonzeroGasPrice::new( - VersionedConstants::latest_constants() - .convert_l1_to_l2_gas_price_round_up(DEFAULT_STRK_L1_GAS_PRICE.into()), - ) - .unwrap(), - ), + gas_prices, use_kzg_da: false, } } diff --git a/crates/starknet_api/src/core.rs b/crates/starknet_api/src/core.rs index 4841e01a91..a04189de5d 100644 --- a/crates/starknet_api/src/core.rs +++ b/crates/starknet_api/src/core.rs @@ -358,6 +358,10 @@ impl PatriciaKey { pub fn key(&self) -> &StarkHash { &self.0 } + + pub const fn new_unchecked(key: StarkHash) -> Self { + PatriciaKey(key) + } } impl From for PatriciaKey { diff --git a/crates/starknet_batcher/src/batcher_test.rs b/crates/starknet_batcher/src/batcher_test.rs index 06dadf99d8..5a9f400e09 100644 --- a/crates/starknet_batcher/src/batcher_test.rs +++ b/crates/starknet_batcher/src/batcher_test.rs @@ -1,20 +1,20 @@ use std::collections::{HashMap, HashSet}; -use std::sync::{Arc, LazyLock}; +use std::sync::Arc; use assert_matches::assert_matches; use async_trait::async_trait; use blockifier::abi::constants; -use blockifier::test_utils::struct_impls::BlockInfoExt; +use blockifier::test_utils::{CURRENT_BLOCK_TIMESTAMP, DEFAULT_GAS_PRICES}; use chrono::Utc; use futures::future::BoxFuture; use futures::FutureExt; use mockall::automock; use mockall::predicate::{always, eq}; use rstest::{fixture, rstest}; -use starknet_api::block::{BlockHashAndNumber, BlockInfo, BlockNumber}; -use starknet_api::core::{ContractAddress, Nonce, StateDiffCommitment}; +use starknet_api::block::{BlockHashAndNumber, BlockInfo, BlockNumber, BlockTimestamp}; +use starknet_api::core::{ContractAddress, Nonce, PatriciaKey, StateDiffCommitment}; use starknet_api::executable_transaction::Transaction; -use starknet_api::hash::PoseidonHash; +use starknet_api::hash::{PoseidonHash, StarkHash}; use starknet_api::state::ThinStateDiff; use starknet_api::transaction::TransactionHash; use starknet_api::{contract_address, felt, nonce}; @@ -55,9 +55,14 @@ const INITIAL_HEIGHT: BlockNumber = BlockNumber(3); const STREAMING_CHUNK_SIZE: usize = 3; const BLOCK_GENERATION_TIMEOUT: tokio::time::Duration = tokio::time::Duration::from_secs(1); const PROPOSAL_ID: ProposalId = ProposalId(0); - -static INITIAL_BLOCK_INFO: LazyLock = - LazyLock::new(|| BlockInfo { block_number: INITIAL_HEIGHT, ..BlockInfo::create_for_testing() }); +const INITIAL_BLOCK_INFO: BlockInfo = BlockInfo { + block_number: INITIAL_HEIGHT, + block_timestamp: BlockTimestamp(CURRENT_BLOCK_TIMESTAMP), + // TODO: Use test sequencer address. + sequencer_address: ContractAddress(PatriciaKey::new_unchecked(StarkHash::ONE)), + gas_prices: DEFAULT_GAS_PRICES, + use_kzg_da: false, +}; fn proposal_commitment() -> ProposalCommitment { ProposalCommitment { @@ -118,7 +123,7 @@ fn mock_proposal_manager_validate_flow() -> MockProposalManagerTraitWrapper { proposal_manager .expect_wrap_validate_block() .times(1) - .with(eq(INITIAL_BLOCK_INFO.clone()), eq(PROPOSAL_ID), eq(None), always(), always()) + .with(eq(INITIAL_BLOCK_INFO), eq(PROPOSAL_ID), eq(None), always(), always()) .return_once(|_, _, _, _, tx_provider| { { async move { @@ -235,7 +240,7 @@ async fn validate_block_full_flow() { proposal_id: PROPOSAL_ID, deadline: deadline(), retrospective_block_hash: None, - block_info: INITIAL_BLOCK_INFO.clone(), + block_info: INITIAL_BLOCK_INFO, }; batcher.validate_block(validate_block_input).await.unwrap(); @@ -335,7 +340,7 @@ async fn send_finish_to_an_invalid_proposal() { proposal_manager .expect_wrap_validate_block() .times(1) - .with(eq(INITIAL_BLOCK_INFO.clone()), eq(PROPOSAL_ID), eq(None), always(), always()) + .with(eq(INITIAL_BLOCK_INFO), eq(PROPOSAL_ID), eq(None), always(), always()) .return_once(|_, _, _, _, _| { async move { Ok(()) } }.boxed()); let proposal_error = GetProposalResultError::BlockBuilderError(Arc::new( @@ -354,7 +359,7 @@ async fn send_finish_to_an_invalid_proposal() { proposal_id: PROPOSAL_ID, deadline: deadline(), retrospective_block_hash: None, - block_info: INITIAL_BLOCK_INFO.clone(), + block_info: INITIAL_BLOCK_INFO, }; batcher.validate_block(validate_block_input).await.unwrap(); @@ -387,7 +392,7 @@ async fn propose_block_full_flow() { proposal_id: PROPOSAL_ID, retrospective_block_hash: None, deadline: chrono::Utc::now() + chrono::Duration::seconds(1), - block_info: INITIAL_BLOCK_INFO.clone(), + block_info: INITIAL_BLOCK_INFO, }) .await .unwrap();