Skip to content

Commit

Permalink
test(starknet_batcher): setup gas prices for testing (#2445)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware authored Dec 18, 2024
1 parent dd0473f commit 3fc110b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 28 deletions.
34 changes: 7 additions & 27 deletions crates/blockifier/src/test_utils/struct_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,12 @@ 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, NonzeroGasPrice};
use starknet_api::block::{BlockInfo, BlockNumber, BlockTimestamp};
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_ETH_L1_DATA_GAS_PRICE, DEFAULT_ETH_L1_GAS_PRICE};
use starknet_api::test_utils::DEFAULT_GAS_PRICES;

use super::{
update_json_value,
TEST_ERC20_CONTRACT_ADDRESS,
TEST_ERC20_CONTRACT_ADDRESS2,
TEST_SEQUENCER_ADDRESS,
};
use crate::blockifier::block::validated_gas_prices;
use crate::bouncer::{BouncerConfig, BouncerWeights, BuiltinCount};
use crate::context::{BlockContext, ChainInfo, FeeTokenAddresses, TransactionContext};
use crate::execution::call_info::{CallExecution, CallInfo, Retdata};
Expand All @@ -39,10 +32,12 @@ 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,
DEFAULT_STRK_L1_DATA_GAS_PRICE,
DEFAULT_STRK_L1_GAS_PRICE,
TEST_ERC20_CONTRACT_ADDRESS,
TEST_ERC20_CONTRACT_ADDRESS2,
TEST_SEQUENCER_ADDRESS,
};
use crate::transaction::objects::{
CurrentTransactionInfo,
Expand Down Expand Up @@ -156,22 +151,7 @@ impl BlockInfoExt for BlockInfo {
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: DEFAULT_GAS_PRICES,
use_kzg_da: false,
}
}
Expand Down
17 changes: 16 additions & 1 deletion crates/starknet_api/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
use serde_json::to_string_pretty;
use starknet_types_core::felt::Felt;

use crate::block::{BlockNumber, GasPrice, NonzeroGasPrice};
use crate::block::{BlockNumber, GasPrice, GasPriceVector, GasPrices, NonzeroGasPrice};
use crate::core::{ChainId, ContractAddress, Nonce};
use crate::execution_resources::GasAmount;
use crate::rpc_transaction::RpcTransaction;
Expand Down Expand Up @@ -132,8 +132,23 @@ 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 Fri.
pub const DEFAULT_ETH_L2_GAS_PRICE: NonzeroGasPrice =
NonzeroGasPrice::new_unchecked(GasPrice(u128::pow(10, 6)));
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);

0 comments on commit 3fc110b

Please sign in to comment.