diff --git a/crates/starknet_api/src/core.rs b/crates/starknet_api/src/core.rs index 8b1a055462..e13d1b35dc 100644 --- a/crates/starknet_api/src/core.rs +++ b/crates/starknet_api/src/core.rs @@ -135,6 +135,10 @@ impl From 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. @@ -367,6 +371,10 @@ impl From 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 for PatriciaKey { type Error = StarknetApiError; diff --git a/crates/starknet_api/src/test_utils.rs b/crates/starknet_api/src/test_utils.rs index abd8530075..5bbbab4d85 100644 --- a/crates/starknet_api/src/test_utils.rs +++ b/crates/starknet_api/src/test_utils.rs @@ -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; @@ -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() } } }