Skip to content

Commit

Permalink
chore(starknet_api): use const fn create for testing block info
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Dec 17, 2024
1 parent 9896be8 commit bcbd6b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 8 additions & 0 deletions crates/starknet_api/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ impl From<u128> for ContractAddress {
}
}

pub const fn const_into_contract_address(val: &str) -> ContractAddress {
ContractAddress(const_into_patricia_key(val))
}

impl_from_through_intermediate!(u128, ContractAddress, u8, u16, u32, u64);

/// The maximal size of storage var.
Expand Down Expand Up @@ -367,6 +371,10 @@ impl From<u128> for PatriciaKey {

impl_from_through_intermediate!(u128, PatriciaKey, u8, u16, u32, u64);

pub const fn const_into_patricia_key(val: &str) -> PatriciaKey {
PatriciaKey(Felt::from_hex_unchecked(val))
}

impl TryFrom<StarkHash> for PatriciaKey {
type Error = StarknetApiError;

Expand Down
9 changes: 4 additions & 5 deletions crates/starknet_api/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use crate::block::{
GasPrices,
NonzeroGasPrice,
};
use crate::contract_address;
use crate::core::{ChainId, ContractAddress, Nonce};
use crate::core::{const_into_contract_address, ChainId, ContractAddress, Nonce};
use crate::execution_resources::GasAmount;
use crate::rpc_transaction::RpcTransaction;
use crate::transaction::fields::Fee;
Expand Down Expand Up @@ -179,17 +178,17 @@ pub const DEFAULT_GAS_PRICES: GasPrices = GasPrices {
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 {
pub const 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),
sequencer_address: const_into_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 {
pub const fn create_for_testing_with_kzg(use_kzg_da: bool) -> Self {
Self { use_kzg_da, ..Self::create_for_testing() }
}
}

0 comments on commit bcbd6b9

Please sign in to comment.