Skip to content

Commit

Permalink
test(batcher): setup gas prices for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Dec 4, 2024
1 parent 0dcf39a commit 862c770
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 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
8 changes: 7 additions & 1 deletion crates/blockifier/src/versioned_constants_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ use glob::{glob, Paths};
use pretty_assertions::assert_eq;
use rstest::rstest;
use starknet_api::block::NonzeroGasPrice;
use starknet_api::test_utils::{DEFAULT_STRK_L1_GAS_PRICE, DEFAULT_STRK_L2_GAS_PRICE};
use starknet_api::test_utils::{
DEFAULT_ETH_L1_GAS_PRICE,
DEFAULT_ETH_L2_GAS_PRICE,
DEFAULT_STRK_L1_GAS_PRICE,
DEFAULT_STRK_L2_GAS_PRICE,
};

use super::*;

Expand Down Expand Up @@ -198,6 +203,7 @@ fn test_syscall_gas_cost_calculation() {
}

#[rstest]
#[case::eth(DEFAULT_ETH_L1_GAS_PRICE, DEFAULT_ETH_L2_GAS_PRICE)]
#[case::strk(DEFAULT_STRK_L1_GAS_PRICE, DEFAULT_STRK_L2_GAS_PRICE)]
fn test_convert_l1_to_l2_gas_price_round_up(
#[case] l1_gas_price: NonzeroGasPrice,
Expand Down
6 changes: 3 additions & 3 deletions crates/starknet_api/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ impl GasPrice {

/// Utility struct representing a non-zero gas price. Useful when a gas amount must be computed by
/// taking a fee amount and dividing by the gas price.
#[derive(Copy, Clone, Debug, Deserialize, Serialize, derive_more::Display)]
#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq, Serialize, derive_more::Display)]
pub struct NonzeroGasPrice(GasPrice);

impl NonzeroGasPrice {
Expand Down Expand Up @@ -439,7 +439,7 @@ macro_rules! impl_try_from_uint_for_nonzero_gas_price {

impl_try_from_uint_for_nonzero_gas_price!(u8, u16, u32, u64, u128);

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct GasPriceVector {
pub l1_gas_price: NonzeroGasPrice,
pub l1_data_gas_price: NonzeroGasPrice,
Expand All @@ -453,7 +453,7 @@ pub enum FeeType {
}

// TODO(Arni): Remove derive of Default. Gas prices should always be set.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct GasPrices {
pub eth_gas_prices: GasPriceVector, // In wei.
pub strk_gas_prices: GasPriceVector, // In fri.
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 @@ -135,8 +135,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 STRK.
pub const DEFAULT_ETH_L2_GAS_PRICE: NonzeroGasPrice =
NonzeroGasPrice::new_unchecked(GasPrice(25 * u128::pow(10, 5)));
pub const DEFAULT_STRK_L2_GAS_PRICE: NonzeroGasPrice =
NonzeroGasPrice::new_unchecked(GasPrice(25 * u128::pow(10, 5)));

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 862c770

Please sign in to comment.