diff --git a/crates/blockifier/src/test_utils.rs b/crates/blockifier/src/test_utils.rs index 94ac0644891..b8b123be3c1 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 fe9fdebff55..932647ef408 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 8b1a0554624..d68df6d42eb 100644 --- a/crates/starknet_api/src/core.rs +++ b/crates/starknet_api/src/core.rs @@ -357,6 +357,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 e6ca53d1e1a..a434f1d76ca 100644 --- a/crates/starknet_batcher/src/batcher_test.rs +++ b/crates/starknet_batcher/src/batcher_test.rs @@ -4,17 +4,17 @@ 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::rstest; -use starknet_api::block::{BlockInfo, BlockNumber}; -use starknet_api::core::{ContractAddress, Nonce, StateDiffCommitment}; +use starknet_api::block::{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, tx_hash}; @@ -62,10 +62,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); - -fn initial_block_info() -> BlockInfo { - 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 { @@ -268,7 +272,7 @@ async fn validate_block_full_flow() { proposal_id: PROPOSAL_ID, deadline: deadline(), retrospective_block_hash: None, - block_info: initial_block_info(), + block_info: INITIAL_BLOCK_INFO, }; batcher.validate_block(validate_block_input).await.unwrap(); @@ -392,7 +396,7 @@ async fn send_finish_to_an_invalid_proposal() { proposal_id: PROPOSAL_ID, deadline: deadline(), retrospective_block_hash: None, - block_info: initial_block_info(), + block_info: INITIAL_BLOCK_INFO, }; batcher.validate_block(validate_block_input).await.unwrap(); @@ -429,7 +433,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(), + block_info: INITIAL_BLOCK_INFO, }) .await .unwrap();