diff --git a/crates/blockifier/src/blockifier/block.rs b/crates/blockifier/src/blockifier/block.rs index 0ac14eecb6..7fdf2fb30a 100644 --- a/crates/blockifier/src/blockifier/block.rs +++ b/crates/blockifier/src/blockifier/block.rs @@ -1,5 +1,6 @@ use std::num::NonZeroU128; +use log::warn; use starknet_api::block::{BlockHash, BlockNumber, BlockTimestamp}; use starknet_api::core::ContractAddress; use starknet_api::state::StorageKey; @@ -9,7 +10,7 @@ use crate::abi::constants; use crate::state::errors::StateError; use crate::state::state_api::{State, StateResult}; use crate::transaction::objects::FeeType; -use crate::versioned_constants::{VersionedConstants, VersionedConstantsOverrides}; +use crate::versioned_constants::VersionedConstants; #[cfg(test)] #[path = "block_test.rs"] @@ -42,26 +43,27 @@ impl GasPrices { strk_l1_gas_price: NonZeroU128, eth_l1_data_gas_price: NonZeroU128, strk_l1_data_gas_price: NonZeroU128, + eth_l2_gas_price: NonZeroU128, + strk_l2_gas_price: NonZeroU128, ) -> Self { - // TODO(Aner): get gas prices from python. - let eth_l2_gas_price = NonZeroU128::new( - VersionedConstants::get_versioned_constants(VersionedConstantsOverrides { - validate_max_n_steps: 0, - max_recursion_depth: 0, - versioned_constants_base_overrides: None, - }) - .l1_to_l2_gas_price_conversion(eth_l1_gas_price.into()), - ) - .expect("L1 to L2 price conversion error (Rust side)."); - let strk_l2_gas_price = NonZeroU128::new( - VersionedConstants::get_versioned_constants(VersionedConstantsOverrides { - validate_max_n_steps: 0, - max_recursion_depth: 0, - versioned_constants_base_overrides: None, - }) - .l1_to_l2_gas_price_conversion(strk_l1_gas_price.into()), - ) - .expect("L1 to L2 price conversion error (Rust side)."); + // TODO(Aner): fix backwards compatibility. + let expected_eth_l2_gas_price = VersionedConstants::latest_constants() + .l1_to_l2_gas_price_conversion(eth_l1_gas_price.into()); + if u128::from(eth_l2_gas_price) != expected_eth_l2_gas_price { + warn!( + "eth_l2_gas_price does not match expected! eth_l2_gas_price:{eth_l2_gas_price}, \ + expected:{expected_eth_l2_gas_price}." + ) + } + let expected_strk_l2_gas_price = VersionedConstants::latest_constants() + .l1_to_l2_gas_price_conversion(strk_l1_gas_price.into()); + if u128::from(strk_l2_gas_price) != expected_strk_l2_gas_price { + warn!( + "strk_l2_gas_price does not match expected! \ + strk_l2_gas_price:{strk_l2_gas_price}, expected:{expected_strk_l2_gas_price}." + ) + } + GasPrices { eth_l1_gas_price, strk_l1_gas_price, diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs index f3517e1f9d..c61ea66120 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs @@ -14,8 +14,8 @@ use crate::test_utils::contracts::FeatureContract; use crate::test_utils::initial_test_state::test_state; use crate::test_utils::{calldata_for_deploy_test, trivial_external_entry_point_new, CairoVersion}; -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1);"VM")] -fn no_constructor(deployer_contract: FeatureContract) { +#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1), 204260;"VM")] +fn no_constructor(deployer_contract: FeatureContract, expected_gas: u64) { // TODO(Yoni): share the init code of the tests in this file. let empty_contract = FeatureContract::Empty(CairoVersion::Cairo1); @@ -33,6 +33,17 @@ fn no_constructor(deployer_contract: FeatureContract) { calldata, ..trivial_external_entry_point_new(deployer_contract) }; + + let deploy_call = &entry_point_call.execute_directly(&mut state).unwrap(); + assert_eq!( + deploy_call.execution, + CallExecution { + retdata: retdata![], + gas_consumed: expected_gas, + ..CallExecution::default() + } + ); + let deployed_contract_address = calculate_contract_address( ContractAddressSalt::default(), class_hash, @@ -41,11 +52,11 @@ fn no_constructor(deployer_contract: FeatureContract) { ) .unwrap(); - let deploy_call = &entry_point_call.execute_directly(&mut state).unwrap().inner_calls[0]; + let constructor_call = &deploy_call.inner_calls[0]; - assert_eq!(deploy_call.call.storage_address, deployed_contract_address); + assert_eq!(constructor_call.call.storage_address, deployed_contract_address); assert_eq!( - deploy_call.execution, + constructor_call.execution, CallExecution { retdata: retdata![], gas_consumed: 0, ..CallExecution::default() } ); assert_eq!(state.get_class_hash_at(deployed_contract_address).unwrap(), class_hash); @@ -77,8 +88,12 @@ fn no_constructor_nonempty_calldata(deployer_contract: FeatureContract) { )); } -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1), 5210;"VM")] -fn with_constructor(deployer_contract: FeatureContract, expected_gas: u64) { +#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1),214210, 5210;"VM")] +fn with_constructor( + deployer_contract: FeatureContract, + expected_gas: u64, + expected_constructor_gas: u64, +) { let empty_contract = FeatureContract::Empty(CairoVersion::Cairo1); let mut state = test_state( &ChainInfo::create_for_testing(), @@ -108,17 +123,27 @@ fn with_constructor(deployer_contract: FeatureContract, expected_gas: u64) { deployer_contract.get_instance_address(0), ) .unwrap(); - // Note, this is the call info of the constructor call (inner call). - let deploy_call = &entry_point_call.execute_directly(&mut state).unwrap().inner_calls[0]; - assert_eq!(deploy_call.call.storage_address, contract_address); + let deploy_call = &entry_point_call.execute_directly(&mut state).unwrap(); assert_eq!( deploy_call.execution, + CallExecution { + retdata: retdata![], + gas_consumed: expected_gas, + ..CallExecution::default() + } + ); + + let constructor_call = &deploy_call.inner_calls[0]; + + assert_eq!(constructor_call.call.storage_address, contract_address); + assert_eq!( + constructor_call.execution, CallExecution { // The test contract constructor returns its first argument. retdata: retdata![constructor_calldata[0]], // This reflects the gas cost of storage write syscall. - gas_consumed: expected_gas, + gas_consumed: expected_constructor_gas, ..CallExecution::default() } ); diff --git a/crates/blockifier/src/fee/fee_test.rs b/crates/blockifier/src/fee/fee_test.rs index 52ce692290..9c86e5f9d3 100644 --- a/crates/blockifier/src/fee/fee_test.rs +++ b/crates/blockifier/src/fee/fee_test.rs @@ -133,6 +133,14 @@ fn test_discounted_gas_overdraft( gas_price.try_into().unwrap(), DEFAULT_ETH_L1_DATA_GAS_PRICE.try_into().unwrap(), data_gas_price.try_into().unwrap(), + VersionedConstants::latest_constants() + .l1_to_l2_gas_price_conversion(DEFAULT_ETH_L1_GAS_PRICE) + .try_into() + .unwrap(), + VersionedConstants::latest_constants() + .l1_to_l2_gas_price_conversion(gas_price) + .try_into() + .unwrap(), ); let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo0); diff --git a/crates/blockifier/src/test_utils/struct_impls.rs b/crates/blockifier/src/test_utils/struct_impls.rs index 6b6e83b859..03e64465a1 100644 --- a/crates/blockifier/src/test_utils/struct_impls.rs +++ b/crates/blockifier/src/test_utils/struct_impls.rs @@ -163,6 +163,14 @@ impl BlockInfo { DEFAULT_STRK_L1_GAS_PRICE.try_into().unwrap(), DEFAULT_ETH_L1_DATA_GAS_PRICE.try_into().unwrap(), DEFAULT_STRK_L1_DATA_GAS_PRICE.try_into().unwrap(), + VersionedConstants::latest_constants() + .l1_to_l2_gas_price_conversion(DEFAULT_ETH_L1_GAS_PRICE) + .try_into() + .unwrap(), + VersionedConstants::latest_constants() + .l1_to_l2_gas_price_conversion(DEFAULT_STRK_L1_GAS_PRICE) + .try_into() + .unwrap(), ), use_kzg_da: false, } diff --git a/crates/gateway/src/compilation.rs b/crates/gateway/src/compilation.rs index 950ba41dca..aab1affc40 100644 --- a/crates/gateway/src/compilation.rs +++ b/crates/gateway/src/compilation.rs @@ -56,9 +56,8 @@ impl GatewayCompiler { ) -> GatewayResult { match self.sierra_to_casm_compiler.compile(cairo_lang_contract_class) { Ok(casm_contract_class) => Ok(casm_contract_class), - Err(starknet_sierra_compile::errors::CompilationUtilError::CompilationPanic) => { - // TODO(Arni): Log the panic. - error!("Compilation panicked."); + Err(starknet_sierra_compile::errors::CompilationUtilError::UnexpectedError(error)) => { + error!("Compilation panicked. Error: {:?}", error); Err(GatewaySpecError::UnexpectedError { data: "Internal server error.".to_owned() }) } Err(e) => { diff --git a/crates/gateway/src/compilation_test.rs b/crates/gateway/src/compilation_test.rs index b1efcef23a..8c41913c12 100644 --- a/crates/gateway/src/compilation_test.rs +++ b/crates/gateway/src/compilation_test.rs @@ -1,7 +1,4 @@ use assert_matches::assert_matches; -use cairo_lang_sierra_to_casm::compiler::CompilationError; -use cairo_lang_starknet_classes::allowed_libfuncs::AllowedLibfuncsError; -use cairo_lang_starknet_classes::casm_contract_class::StarknetSierraCompilationError; use mempool_test_utils::starknet_api_test_utils::{ compiled_class_hash as test_contract_compiled_class_hash, declare_tx as rpc_declare_tx, @@ -67,11 +64,8 @@ fn test_compile_contract_class_bytecode_size_validation(declare_tx_v3: RpcDeclar let result = gateway_compiler.process_declare_tx(&RpcDeclareTransaction::V3(declare_tx_v3)); assert_matches!(result.unwrap_err(), GatewaySpecError::CompilationFailed); - let expected_compilation_error = CompilationUtilError::StarknetSierraCompilationError( - StarknetSierraCompilationError::CompilationError(Box::new( - CompilationError::CodeSizeLimitExceeded, - )), - ); + let expected_compilation_error = + CompilationUtilError::CompilationError("Code size limit exceeded.".to_owned()); assert!(logs_contain(format!("Compilation failed: {:?}", expected_compilation_error).as_str())); } @@ -90,7 +84,7 @@ fn test_compile_contract_class_bad_sierra( assert_eq!(err, GatewaySpecError::CompilationFailed); let expected_compilation_error = - CompilationUtilError::AllowedLibfuncsError(AllowedLibfuncsError::SierraProgramError); + CompilationUtilError::CompilationError("Invalid Sierra program.".to_owned()); assert!(logs_contain(format!("Compilation failed: {:?}", expected_compilation_error).as_str())); } diff --git a/crates/gateway/src/gateway_test.rs b/crates/gateway/src/gateway_test.rs index 0ff0ec93c5..0015858609 100644 --- a/crates/gateway/src/gateway_test.rs +++ b/crates/gateway/src/gateway_test.rs @@ -21,7 +21,7 @@ use crate::gateway::{add_tx, AppState, SharedMempoolClient}; use crate::state_reader_test_utils::{local_test_state_reader_factory, TestStateReaderFactory}; use crate::stateful_transaction_validator::StatefulTransactionValidator; use crate::stateless_transaction_validator::StatelessTransactionValidator; -use crate::utils::external_tx_to_account_tx; +use crate::utils::rpc_tx_to_account_tx; pub fn app_state( mempool_client: SharedMempoolClient, @@ -93,16 +93,16 @@ async fn to_bytes(res: Response) -> Bytes { res.into_body().collect().await.unwrap().to_bytes() } -fn calculate_hash(external_tx: &RpcTransaction) -> TransactionHash { - let optional_class_info = match &external_tx { +fn calculate_hash(rpc_tx: &RpcTransaction) -> TransactionHash { + let optional_class_info = match &rpc_tx { RpcTransaction::Declare(_declare_tx) => { panic!("Declare transactions are not supported in this test") } _ => None, }; - let account_tx = external_tx_to_account_tx( - external_tx, + let account_tx = rpc_tx_to_account_tx( + rpc_tx, optional_class_info, &ChainInfo::create_for_testing().chain_id, ) diff --git a/crates/gateway/src/rpc_objects.rs b/crates/gateway/src/rpc_objects.rs index d6898d024f..06156f601a 100644 --- a/crates/gateway/src/rpc_objects.rs +++ b/crates/gateway/src/rpc_objects.rs @@ -90,6 +90,9 @@ impl TryInto for BlockHeader { parse_gas_price(self.l1_gas_price.price_in_fri)?, parse_gas_price(self.l1_data_gas_price.price_in_wei)?, parse_gas_price(self.l1_data_gas_price.price_in_fri)?, + // TODO(Aner): add to BlockHeader and take the value from it. + NonZeroU128::MIN, + NonZeroU128::MIN, ), use_kzg_da: matches!(self.l1_da_mode, L1DataAvailabilityMode::Blob), }) diff --git a/crates/gateway/src/stateful_transaction_validator.rs b/crates/gateway/src/stateful_transaction_validator.rs index 1b8ae35ced..8b174fdc6b 100644 --- a/crates/gateway/src/stateful_transaction_validator.rs +++ b/crates/gateway/src/stateful_transaction_validator.rs @@ -20,7 +20,7 @@ use tracing::error; use crate::config::StatefulTransactionValidatorConfig; use crate::errors::{GatewaySpecError, StatefulTransactionValidatorResult}; use crate::state_reader::{MempoolStateReader, StateReaderFactory}; -use crate::utils::{external_tx_to_account_tx, get_sender_address}; +use crate::utils::{get_sender_address, rpc_tx_to_account_tx}; #[cfg(test)] #[path = "stateful_transaction_validator_test.rs"] @@ -69,22 +69,19 @@ impl StatefulTransactionValidator { // conversion is also relevant for the Mempool. pub fn run_validate( &self, - external_tx: &RpcTransaction, + rpc_tx: &RpcTransaction, optional_class_info: Option, mut validator: V, ) -> StatefulTransactionValidatorResult { - let account_tx = external_tx_to_account_tx( - external_tx, - optional_class_info, - &self.config.chain_info.chain_id, - )?; + let account_tx = + rpc_tx_to_account_tx(rpc_tx, optional_class_info, &self.config.chain_info.chain_id)?; let tx_hash = account_tx.tx_hash(); let sender_address = get_sender_address(&account_tx); let account_nonce = validator.get_nonce(sender_address).map_err(|e| { error!("Failed to get nonce for sender address {}: {}", sender_address, e); GatewaySpecError::UnexpectedError { data: "Internal server error.".to_owned() } })?; - let skip_validate = skip_stateful_validations(external_tx, account_nonce); + let skip_validate = skip_stateful_validations(rpc_tx, account_nonce); validator .validate(account_tx, skip_validate) .map_err(|err| GatewaySpecError::ValidationFailure { data: err.to_string() })?; diff --git a/crates/gateway/src/stateful_transaction_validator_test.rs b/crates/gateway/src/stateful_transaction_validator_test.rs index 004691bc08..afefb0ae9c 100644 --- a/crates/gateway/src/stateful_transaction_validator_test.rs +++ b/crates/gateway/src/stateful_transaction_validator_test.rs @@ -78,11 +78,11 @@ fn stateful_validator(block_context: BlockContext) -> StatefulTransactionValidat )] #[case::invalid_tx(invoke_tx(CairoVersion::Cairo1), Err(STATEFUL_VALIDATOR_FEE_ERROR))] fn test_stateful_tx_validator( - #[case] external_tx: RpcTransaction, + #[case] rpc_tx: RpcTransaction, #[case] expected_result: BlockifierStatefulValidatorResult, stateful_validator: StatefulTransactionValidator, ) { - let optional_class_info = match &external_tx { + let optional_class_info = match &rpc_tx { RpcTransaction::Declare(declare_tx) => Some( ClassInfo::try_from( GatewayCompiler::new_cairo_lang_compiler(SierraToCasmCompilationConfig::default()) @@ -103,7 +103,7 @@ fn test_stateful_tx_validator( mock_validator.expect_validate().return_once(|_, _| expected_result.map(|_| ())); mock_validator.expect_get_nonce().returning(|_| Ok(Nonce(Felt::ZERO))); - let result = stateful_validator.run_validate(&external_tx, optional_class_info, mock_validator); + let result = stateful_validator.run_validate(&rpc_tx, optional_class_info, mock_validator); assert_eq!(result, expected_result_as_stateful_transaction_result); } @@ -159,12 +159,12 @@ fn test_instantiate_validator() { false )] fn test_skip_stateful_validation( - #[case] external_tx: RpcTransaction, + #[case] rpc_tx: RpcTransaction, #[case] sender_nonce: Nonce, #[case] should_skip_validate: bool, stateful_validator: StatefulTransactionValidator, ) { - let sender_address = external_tx.calculate_sender_address().unwrap(); + let sender_address = rpc_tx.calculate_sender_address().unwrap(); let mut mock_validator = MockStatefulTransactionValidatorTrait::new(); mock_validator .expect_get_nonce() @@ -174,5 +174,5 @@ fn test_skip_stateful_validation( .expect_validate() .withf(move |_, skip_validate| *skip_validate == should_skip_validate) .returning(|_, _| Ok(())); - let _ = stateful_validator.run_validate(&external_tx, None, mock_validator); + let _ = stateful_validator.run_validate(&rpc_tx, None, mock_validator); } diff --git a/crates/gateway/src/stateless_transaction_validator_test.rs b/crates/gateway/src/stateless_transaction_validator_test.rs index 294af871f8..880706615e 100644 --- a/crates/gateway/src/stateless_transaction_validator_test.rs +++ b/crates/gateway/src/stateless_transaction_validator_test.rs @@ -6,7 +6,7 @@ use mempool_test_utils::declare_tx_args; use mempool_test_utils::starknet_api_test_utils::{ create_resource_bounds_mapping, external_declare_tx, - external_tx_for_testing, + rpc_tx_for_testing, zero_resource_bounds_mapping, TransactionType, NON_EMPTY_RESOURCE_BOUNDS, @@ -118,7 +118,7 @@ fn test_positive_flow( tx_type: TransactionType, ) { let tx_validator = StatelessTransactionValidator { config }; - let tx = external_tx_for_testing(tx_type, resource_bounds, tx_calldata, signature); + let tx = rpc_tx_for_testing(tx_type, resource_bounds, tx_calldata, signature); assert_matches!(tx_validator.validate(&tx), Ok(())); } @@ -154,12 +154,8 @@ fn test_invalid_resource_bounds( tx_type: TransactionType, ) { let tx_validator = StatelessTransactionValidator { config }; - let tx = external_tx_for_testing( - tx_type, - resource_bounds, - calldata![], - TransactionSignature::default(), - ); + let tx = + rpc_tx_for_testing(tx_type, resource_bounds, calldata![], TransactionSignature::default()); assert_eq!(tx_validator.validate(&tx).unwrap_err(), expected_error); } @@ -170,7 +166,7 @@ fn test_calldata_too_long( ) { let tx_validator = StatelessTransactionValidator { config: default_validator_config_for_testing().clone() }; - let tx = external_tx_for_testing( + let tx = rpc_tx_for_testing( tx_type, zero_resource_bounds_mapping(), calldata![Felt::ONE, Felt::TWO], @@ -193,7 +189,7 @@ fn test_signature_too_long( ) { let tx_validator = StatelessTransactionValidator { config: default_validator_config_for_testing().clone() }; - let tx = external_tx_for_testing( + let tx = rpc_tx_for_testing( tx_type, zero_resource_bounds_mapping(), calldata![], diff --git a/crates/gateway/src/utils.rs b/crates/gateway/src/utils.rs index ccf6abbdcd..1b8af37bb6 100644 --- a/crates/gateway/src/utils.rs +++ b/crates/gateway/src/utils.rs @@ -24,13 +24,13 @@ use tracing::error; use crate::errors::{GatewaySpecError, StatefulTransactionValidatorResult}; -pub fn external_tx_to_account_tx( - external_tx: &RpcTransaction, +pub fn rpc_tx_to_account_tx( + rpc_tx: &RpcTransaction, // FIXME(yael 15/4/24): calculate class_info inside the function once compilation code is ready optional_class_info: Option, chain_id: &ChainId, ) -> StatefulTransactionValidatorResult { - match external_tx { + match rpc_tx { RpcTransaction::Declare(RpcDeclareTransaction::V3(tx)) => { let declare_tx = DeclareTransaction::V3(DeclareTransactionV3 { class_hash: ClassHash::default(), /* FIXME(yael 15/4/24): call the starknet-api diff --git a/crates/mempool/src/mempool_test.rs b/crates/mempool/src/mempool_test.rs index 5d612343f5..8671aa5f18 100644 --- a/crates/mempool/src/mempool_test.rs +++ b/crates/mempool/src/mempool_test.rs @@ -40,7 +40,7 @@ struct FullContent; struct PartialContent; impl MempoolContent { - fn new(pool_txs: P, queue_txs: Q) -> Self + fn with_pool_and_queue(pool_txs: P, queue_txs: Q) -> Self where P: IntoIterator, // TODO(Ayelet): Consider using `&ThinTransaction` instead of `TransactionReference`. @@ -212,7 +212,8 @@ fn test_get_txs_returns_by_priority_order(#[case] requested_txs: usize) { let tx_references_iterator = txs.iter().map(TransactionReference::new); let txs_iterator = txs.iter().cloned(); - let mut mempool: Mempool = MempoolContent::new(txs_iterator, tx_references_iterator).into(); + let mut mempool: Mempool = + MempoolContent::with_pool_and_queue(txs_iterator, tx_references_iterator).into(); // Test. let fetched_txs = mempool.get_txs(requested_txs).unwrap(); @@ -228,7 +229,8 @@ fn test_get_txs_returns_by_priority_order(#[case] requested_txs: usize) { // Assert: non-returned transactions are still in the mempool. let remaining_tx_references = remaining_txs.iter().map(TransactionReference::new); - let mempool_content = MempoolContent::new(remaining_txs.to_vec(), remaining_tx_references); + let mempool_content = + MempoolContent::with_pool_and_queue(remaining_txs.to_vec(), remaining_tx_references); mempool_content.assert_eq_mempool_content(&mempool); } @@ -244,7 +246,8 @@ fn test_get_txs_multi_nonce() { let queue_txs = [&tx_nonce_0].map(TransactionReference::new); let pool_txs = [tx_nonce_0, tx_nonce_1, tx_nonce_2]; - let mut mempool: Mempool = MempoolContent::new(pool_txs.clone(), queue_txs).into(); + let mut mempool: Mempool = + MempoolContent::with_pool_and_queue(pool_txs.clone(), queue_txs).into(); // Test. let fetched_txs = mempool.get_txs(3).unwrap(); @@ -268,7 +271,7 @@ fn test_get_txs_replenishes_queue_only_between_chunks() { let queue_txs = [&tx_address_0_nonce_0, &tx_address_1_nonce_0].map(TransactionReference::new); let pool_txs = [&tx_address_0_nonce_0, &tx_address_0_nonce_1, &tx_address_1_nonce_0].map(|tx| tx.clone()); - let mut mempool: Mempool = MempoolContent::new(pool_txs, queue_txs).into(); + let mut mempool: Mempool = MempoolContent::with_pool_and_queue(pool_txs, queue_txs).into(); // Test. let txs = mempool.get_txs(3).unwrap(); @@ -301,7 +304,7 @@ fn test_get_txs_replenishes_queue_multi_account_between_chunks() { &tx_address_1_nonce_1, ] .map(|tx| tx.clone()); - let mut mempool: Mempool = MempoolContent::new(pool_txs, queue_txs).into(); + let mut mempool: Mempool = MempoolContent::with_pool_and_queue(pool_txs, queue_txs).into(); // Test. let txs = mempool.get_txs(2).unwrap(); @@ -313,7 +316,8 @@ fn test_get_txs_replenishes_queue_multi_account_between_chunks() { let expected_queue_txs = [&tx_address_0_nonce_1, &tx_address_1_nonce_1].map(TransactionReference::new); let expected_pool_txs = [tx_address_0_nonce_1, tx_address_1_nonce_1]; - let expected_mempool_content = MempoolContent::new(expected_pool_txs, expected_queue_txs); + let expected_mempool_content = + MempoolContent::with_pool_and_queue(expected_pool_txs, expected_queue_txs); expected_mempool_content.assert_eq_mempool_content(&mempool); } @@ -327,7 +331,7 @@ fn test_get_txs_with_holes_multiple_accounts() { let queue_txs = [TransactionReference::new(&tx_address_1_nonce_0)]; let pool_txs = [tx_address_0_nonce_1.clone(), tx_address_1_nonce_0.clone()]; - let mut mempool: Mempool = MempoolContent::new(pool_txs, queue_txs).into(); + let mut mempool: Mempool = MempoolContent::with_pool_and_queue(pool_txs, queue_txs).into(); // Test. let txs = mempool.get_txs(2).unwrap(); @@ -337,7 +341,8 @@ fn test_get_txs_with_holes_multiple_accounts() { let expected_pool_txs = [tx_address_0_nonce_1]; let expected_queue_txs = []; - let expected_mempool_content = MempoolContent::new(expected_pool_txs, expected_queue_txs); + let expected_mempool_content = + MempoolContent::with_pool_and_queue(expected_pool_txs, expected_queue_txs); expected_mempool_content.assert_eq_mempool_content(&mempool); } @@ -348,7 +353,8 @@ fn test_get_txs_with_holes_single_account() { let pool_txs = [input_nonce_1.tx]; let queue_txs = []; - let mut mempool: Mempool = MempoolContent::new(pool_txs.clone(), queue_txs.clone()).into(); + let mut mempool: Mempool = + MempoolContent::with_pool_and_queue(pool_txs.clone(), queue_txs.clone()).into(); // Test. let txs = mempool.get_txs(1).unwrap(); @@ -356,7 +362,7 @@ fn test_get_txs_with_holes_single_account() { // Assert. assert_eq!(txs, &[]); - let expected_mempool_content = MempoolContent::new(pool_txs, queue_txs); + let expected_mempool_content = MempoolContent::with_pool_and_queue(pool_txs, queue_txs); expected_mempool_content.assert_eq_mempool_content(&mempool); } @@ -384,7 +390,8 @@ fn test_add_tx(mut mempool: Mempool) { let expected_queue_txs: Vec = add_tx_inputs.iter().map(|input| TransactionReference::new(&input.tx)).collect(); let expected_pool_txs = add_tx_inputs.into_iter().map(|input| input.tx); - let expected_mempool_content = MempoolContent::new(expected_pool_txs, expected_queue_txs); + let expected_mempool_content = + MempoolContent::with_pool_and_queue(expected_pool_txs, expected_queue_txs); expected_mempool_content.assert_eq_mempool_content(&mempool); } @@ -408,7 +415,8 @@ fn test_add_tx_multi_nonce_success(mut mempool: Mempool) { [&input_address_1_nonce_0.tx, &input_address_0_nonce_0.tx].map(TransactionReference::new); let expected_pool_txs = [input_address_0_nonce_0.tx, input_address_1_nonce_0.tx, input_address_0_nonce_1.tx]; - let expected_mempool_content = MempoolContent::new(expected_pool_txs, expected_queue_txs); + let expected_mempool_content = + MempoolContent::with_pool_and_queue(expected_pool_txs, expected_queue_txs); expected_mempool_content.assert_eq_mempool_content(&mempool); } @@ -441,7 +449,7 @@ fn test_add_tx_lower_than_queued_nonce() { let queue_txs = [TransactionReference::new(&valid_input.tx)]; let expected_mempool_content = MempoolContent::with_queue(queue_txs.clone()); let pool_txs = [valid_input.tx]; - let mut mempool: Mempool = MempoolContent::new(pool_txs, queue_txs).into(); + let mut mempool: Mempool = MempoolContent::with_pool_and_queue(pool_txs, queue_txs).into(); // Test and assert the original transaction remains. assert_matches!(mempool.add_tx(lower_nonce_input), Err(MempoolError::DuplicateNonce { .. })); @@ -485,7 +493,8 @@ fn test_add_tx_with_identical_tip_succeeds(mut mempool: Mempool) { let expected_queue_txs = [TransactionReference::new(&input1.tx), TransactionReference::new(&input2.tx)]; let expected_pool_txs = [input1.tx, input2.tx]; - let expected_mempool_content = MempoolContent::new(expected_pool_txs, expected_queue_txs); + let expected_mempool_content = + MempoolContent::with_pool_and_queue(expected_pool_txs, expected_queue_txs); // TODO: currently hash comparison tie-breaks the two. Once more robust tie-breaks are added // replace this assertion with a dedicated test. @@ -502,7 +511,7 @@ fn test_add_tx_delete_tx_with_lower_nonce_than_account_nonce() { let queue_txs = [TransactionReference::new(&tx_nonce_0_account_nonce_0.tx)]; let pool_txs = [tx_nonce_0_account_nonce_0.tx]; - let mut mempool: Mempool = MempoolContent::new(pool_txs, queue_txs).into(); + let mut mempool: Mempool = MempoolContent::with_pool_and_queue(pool_txs, queue_txs).into(); // Test. add_tx(&mut mempool, &tx_nonce_1_account_nonce_1); @@ -510,7 +519,8 @@ fn test_add_tx_delete_tx_with_lower_nonce_than_account_nonce() { // Assert the transaction with the lower nonce is removed. let expected_queue_txs = [TransactionReference::new(&tx_nonce_1_account_nonce_1.tx)]; let expected_pool_txs = [tx_nonce_1_account_nonce_1.tx]; - let expected_mempool_content = MempoolContent::new(expected_pool_txs, expected_queue_txs); + let expected_mempool_content = + MempoolContent::with_pool_and_queue(expected_pool_txs, expected_queue_txs); expected_mempool_content.assert_eq_mempool_content(&mempool); } @@ -568,7 +578,8 @@ fn test_add_tx_sequential_nonces(mut mempool: Mempool) { // Assert: only eligible transaction appears in the queue. let expected_queue_txs = [TransactionReference::new(&input_nonce_0.tx)]; let expected_pool_txs = [input_nonce_0.tx, input_nonce_1.tx]; - let expected_mempool_content = MempoolContent::new(expected_pool_txs, expected_queue_txs); + let expected_mempool_content = + MempoolContent::with_pool_and_queue(expected_pool_txs, expected_queue_txs); expected_mempool_content.assert_eq_mempool_content(&mempool); } @@ -585,7 +596,8 @@ fn test_add_tx_filling_hole(mut mempool: Mempool) { // Assert: the second transaction is in the pool and not in the queue. let expected_queue_txs = []; let expected_pool_txs = [input_nonce_1.tx.clone()]; - let expected_mempool_content = MempoolContent::new(expected_pool_txs, expected_queue_txs); + let expected_mempool_content = + MempoolContent::with_pool_and_queue(expected_pool_txs, expected_queue_txs); expected_mempool_content.assert_eq_mempool_content(&mempool); // Test: add the first transaction, which fills the hole. @@ -594,7 +606,8 @@ fn test_add_tx_filling_hole(mut mempool: Mempool) { // Assert: only the eligible transaction appears in the queue. let expected_queue_txs = [TransactionReference::new(&input_nonce_0.tx)]; let expected_pool_txs = [input_nonce_1.tx, input_nonce_0.tx]; - let expected_mempool_content = MempoolContent::new(expected_pool_txs, expected_queue_txs); + let expected_mempool_content = + MempoolContent::with_pool_and_queue(expected_pool_txs, expected_queue_txs); expected_mempool_content.assert_eq_mempool_content(&mempool); } @@ -607,7 +620,7 @@ fn test_add_tx_after_get_txs_fails_on_duplicate_nonce() { let pool_txs = [input_tx.tx.clone()]; let queue_txs = [TransactionReference::new(&input_tx.tx)]; - let mut mempool: Mempool = MempoolContent::new(pool_txs, queue_txs).into(); + let mut mempool: Mempool = MempoolContent::with_pool_and_queue(pool_txs, queue_txs).into(); // Test. mempool.get_txs(1).unwrap(); @@ -632,7 +645,8 @@ fn test_commit_block_includes_all_txs() { let queue_txs = [&tx_address0_nonce4, &tx_address1_nonce3, &tx_address2_nonce1] .map(TransactionReference::new); let pool_txs = [tx_address0_nonce4, tx_address0_nonce5, tx_address1_nonce3, tx_address2_nonce1]; - let mut mempool: Mempool = MempoolContent::new(pool_txs.clone(), queue_txs.clone()).into(); + let mut mempool: Mempool = + MempoolContent::with_pool_and_queue(pool_txs.clone(), queue_txs.clone()).into(); // Test. let state_changes = HashMap::from([ @@ -642,7 +656,7 @@ fn test_commit_block_includes_all_txs() { assert!(mempool.commit_block(state_changes).is_ok()); // Assert. - let expected_mempool_content = MempoolContent::new(pool_txs, queue_txs); + let expected_mempool_content = MempoolContent::with_pool_and_queue(pool_txs, queue_txs); expected_mempool_content.assert_eq_mempool_content(&mempool); } @@ -653,7 +667,7 @@ fn test_commit_block_rewinds_nonce() { let queued_txs = [TransactionReference::new(&tx_address0_nonce5)]; let pool_txs = [tx_address0_nonce5]; - let mut mempool: Mempool = MempoolContent::new(pool_txs, queued_txs).into(); + let mut mempool: Mempool = MempoolContent::with_pool_and_queue(pool_txs, queued_txs).into(); // Test. let state_changes = HashMap::from([ @@ -678,7 +692,7 @@ fn test_commit_block_from_different_leader() { let queued_txs = [TransactionReference::new(&tx_address1_nonce2)]; let pool_txs = [tx_address0_nonce3, tx_address0_nonce5, tx_address0_nonce6.clone(), tx_address1_nonce2]; - let mut mempool: Mempool = MempoolContent::new(pool_txs, queued_txs).into(); + let mut mempool: Mempool = MempoolContent::with_pool_and_queue(pool_txs, queued_txs).into(); // Test. let state_changes = HashMap::from([ @@ -753,7 +767,7 @@ fn test_flow_partial_commit_block() { &tx_address2_nonce2, ] .map(|tx| tx.clone()); - let mut mempool: Mempool = MempoolContent::new(pool_txs, queue_txs).into(); + let mut mempool: Mempool = MempoolContent::with_pool_and_queue(pool_txs, queue_txs).into(); // Test. @@ -772,7 +786,7 @@ fn test_flow_partial_commit_block() { // Assert. let expected_pool_txs = [tx_address0_nonce5, tx_address0_nonce6, tx_address1_nonce2]; - let expected_mempool_content = MempoolContent::new(expected_pool_txs, []); + let expected_mempool_content = MempoolContent::with_pool_and_queue(expected_pool_txs, []); expected_mempool_content.assert_eq_mempool_content(&mempool); } @@ -787,7 +801,7 @@ fn test_flow_commit_block_closes_hole() { let queued_txs = [TransactionReference::new(&tx_nonce3)]; let pool_txs = [tx_nonce3, tx_nonce5.clone()]; - let mut mempool: Mempool = MempoolContent::new(pool_txs, queued_txs).into(); + let mut mempool: Mempool = MempoolContent::with_pool_and_queue(pool_txs, queued_txs).into(); // Test. let state_changes = @@ -820,7 +834,7 @@ fn test_flow_send_same_nonce_tx_after_previous_not_included() { let queue_txs = [TransactionReference::new(&tx_nonce3)]; let pool_txs = [&tx_nonce3, &tx_input_nonce4.tx, &tx_nonce5].map(|tx| tx.clone()); - let mut mempool: Mempool = MempoolContent::new(pool_txs, queue_txs).into(); + let mut mempool: Mempool = MempoolContent::with_pool_and_queue(pool_txs, queue_txs).into(); // Test. let txs = mempool.get_txs(2).unwrap(); diff --git a/crates/mempool_test_utils/src/starknet_api_test_utils.rs b/crates/mempool_test_utils/src/starknet_api_test_utils.rs index 86748a0c38..1688bc4111 100644 --- a/crates/mempool_test_utils/src/starknet_api_test_utils.rs +++ b/crates/mempool_test_utils/src/starknet_api_test_utils.rs @@ -58,7 +58,7 @@ pub enum TransactionType { Invoke, } -pub fn external_tx_for_testing( +pub fn rpc_tx_for_testing( tx_type: TransactionType, resource_bounds: ResourceBoundsMapping, calldata: Calldata, @@ -530,7 +530,7 @@ pub fn external_declare_tx(declare_tx_args: DeclareTxArgs) -> RpcTransaction { ) } -pub fn external_tx_to_json(tx: &RpcTransaction) -> String { +pub fn rpc_tx_to_json(tx: &RpcTransaction) -> String { let mut tx_json = serde_json::to_value(tx) .unwrap_or_else(|tx| panic!("Failed to serialize transaction: {tx:?}")); diff --git a/crates/native_blockifier/src/errors.rs b/crates/native_blockifier/src/errors.rs index 8baaf272fe..bdf6c79443 100644 --- a/crates/native_blockifier/src/errors.rs +++ b/crates/native_blockifier/src/errors.rs @@ -106,13 +106,17 @@ pub enum InvalidNativeBlockifierInputError { #[error("Invalid builtin count: {0:?}.")] InvalidBuiltinCounts(BuiltinCount), #[error("Invalid Wei gas price: {0}.")] - InvalidGasPriceWei(u128), + InvalidL1GasPriceWei(u128), #[error("Invalid Fri gas price: {0}.")] - InvalidGasPriceFri(u128), + InvalidL1GasPriceFri(u128), #[error("Invalid Wei data gas price: {0}.")] - InvalidDataGasPriceWei(u128), + InvalidL1DataGasPriceWei(u128), #[error("Invalid Fri data gas price: {0}.")] - InvalidDataGasPriceFri(u128), + InvalidL1DataGasPriceFri(u128), + #[error("Invalid Wei l2 gas price: {0}.")] + InvalidL2GasPriceWei(u128), + #[error("Invalid Fri l2 gas price: {0}.")] + InvalidL2GasPriceFri(u128), } create_exception!(native_blockifier, UndeclaredClassHashError, PyException); diff --git a/crates/native_blockifier/src/py_state_diff.rs b/crates/native_blockifier/src/py_state_diff.rs index 634f6baac0..fb71058e88 100644 --- a/crates/native_blockifier/src/py_state_diff.rs +++ b/crates/native_blockifier/src/py_state_diff.rs @@ -9,6 +9,7 @@ use blockifier::test_utils::{ DEFAULT_STRK_L1_DATA_GAS_PRICE, DEFAULT_STRK_L1_GAS_PRICE, }; +use blockifier::versioned_constants::VersionedConstants; use indexmap::IndexMap; use pyo3::prelude::*; use pyo3::FromPyObject; @@ -140,6 +141,7 @@ pub struct PyBlockInfo { pub block_timestamp: u64, pub l1_gas_price: PyResourcePrice, pub l1_data_gas_price: PyResourcePrice, + pub l2_gas_price: PyResourcePrice, pub sequencer_address: PyFelt, pub use_kzg_da: bool, } @@ -158,6 +160,12 @@ impl Default for PyBlockInfo { price_in_wei: DEFAULT_ETH_L1_DATA_GAS_PRICE, price_in_fri: DEFAULT_STRK_L1_DATA_GAS_PRICE, }, + l2_gas_price: PyResourcePrice { + price_in_wei: VersionedConstants::latest_constants() + .l1_to_l2_gas_price_conversion(DEFAULT_ETH_L1_GAS_PRICE), + price_in_fri: VersionedConstants::latest_constants() + .l1_to_l2_gas_price_conversion(DEFAULT_STRK_L1_GAS_PRICE), + }, sequencer_address: PyFelt::default(), use_kzg_da: bool::default(), } @@ -175,32 +183,46 @@ impl TryFrom for BlockInfo { gas_prices: GasPrices::new( block_info.l1_gas_price.price_in_wei.try_into().map_err(|_| { NativeBlockifierInputError::InvalidNativeBlockifierInputError( - InvalidNativeBlockifierInputError::InvalidGasPriceWei( + InvalidNativeBlockifierInputError::InvalidL1GasPriceWei( block_info.l1_gas_price.price_in_wei, ), ) })?, block_info.l1_gas_price.price_in_fri.try_into().map_err(|_| { NativeBlockifierInputError::InvalidNativeBlockifierInputError( - InvalidNativeBlockifierInputError::InvalidGasPriceFri( + InvalidNativeBlockifierInputError::InvalidL1GasPriceFri( block_info.l1_gas_price.price_in_fri, ), ) })?, block_info.l1_data_gas_price.price_in_wei.try_into().map_err(|_| { NativeBlockifierInputError::InvalidNativeBlockifierInputError( - InvalidNativeBlockifierInputError::InvalidDataGasPriceWei( + InvalidNativeBlockifierInputError::InvalidL1DataGasPriceWei( block_info.l1_data_gas_price.price_in_wei, ), ) })?, block_info.l1_data_gas_price.price_in_fri.try_into().map_err(|_| { NativeBlockifierInputError::InvalidNativeBlockifierInputError( - InvalidNativeBlockifierInputError::InvalidDataGasPriceFri( + InvalidNativeBlockifierInputError::InvalidL1DataGasPriceFri( block_info.l1_data_gas_price.price_in_fri, ), ) })?, + block_info.l2_gas_price.price_in_wei.try_into().map_err(|_| { + NativeBlockifierInputError::InvalidNativeBlockifierInputError( + InvalidNativeBlockifierInputError::InvalidL2GasPriceWei( + block_info.l2_gas_price.price_in_wei, + ), + ) + })?, + block_info.l2_gas_price.price_in_fri.try_into().map_err(|_| { + NativeBlockifierInputError::InvalidNativeBlockifierInputError( + InvalidNativeBlockifierInputError::InvalidL2GasPriceFri( + block_info.l2_gas_price.price_in_fri, + ), + ) + })?, ), use_kzg_da: block_info.use_kzg_da, }) diff --git a/crates/papyrus_execution/src/lib.rs b/crates/papyrus_execution/src/lib.rs index 6236f3d534..1409313452 100644 --- a/crates/papyrus_execution/src/lib.rs +++ b/crates/papyrus_execution/src/lib.rs @@ -364,6 +364,9 @@ fn create_block_context( NonZeroU128::new(l1_gas_price.price_in_fri.0).unwrap_or(NonZeroU128::MIN), NonZeroU128::new(l1_data_gas_price.price_in_wei.0).unwrap_or(NonZeroU128::MIN), NonZeroU128::new(l1_data_gas_price.price_in_fri.0).unwrap_or(NonZeroU128::MIN), + // TODO(Aner - Shahak): fix to come from pending_data/block_header. + NonZeroU128::MIN, + NonZeroU128::MIN, ), }; let chain_info = ChainInfo { diff --git a/crates/sequencing/papyrus_consensus/run_consensus.py b/crates/sequencing/papyrus_consensus/run_consensus.py index d2cf6ed58e..cfe496d62c 100644 --- a/crates/sequencing/papyrus_consensus/run_consensus.py +++ b/crates/sequencing/papyrus_consensus/run_consensus.py @@ -139,16 +139,22 @@ def build_node(data_dir, logs_dir, i, papryus_args): f"--rpc.server_address 127.0.0.1:{find_free_port()} " f"--monitoring_gateway.server_address 127.0.0.1:{monitoring_gateway_server_port} " f"--consensus.test.#is_none false " - f"--consensus.timeouts.proposal_timeout {papryus_args.proposal_timeout} " - f"--consensus.timeouts.prevote_timeout {papryus_args.prevote_timeout} " - f"--consensus.timeouts.precommit_timeout {papryus_args.precommit_timeout} " - f"--consensus.test.cache_size {papryus_args.cache_size} " - f"--consensus.test.random_seed {papryus_args.random_seed} " - f"--consensus.test.drop_probability {papryus_args.drop_probability} " - f"--consensus.test.invalid_probability {papryus_args.invalid_probability} " f"--collect_metrics true " ) + conditional_params = { + "timeouts.proposal_timeout": papryus_args.proposal_timeout, + "timeouts.prevote_timeout": papryus_args.prevote_timeout, + "timeouts.precommit_timeout": papryus_args.precommit_timeout, + "test.cache_size": papryus_args.cache_size, + "test.random_seed": papryus_args.random_seed, + "test.drop_probability": papryus_args.drop_probability, + "test.invalid_probability": papryus_args.invalid_probability, + } + for key, value in conditional_params.items(): + if value is not None: + cmd += f"--consensus.{key} {value} " + if is_bootstrap: cmd += ( f"--network.secret_key {SECRET_KEY} " @@ -278,49 +284,49 @@ def main(papyrus_args, run_consensus_args): "--proposal_timeout", type=float, required=False, - default=3, + default=None, help="The timeout (seconds) for a proposal.", ) parser.add_argument( "--prevote_timeout", type=float, required=False, - default=1, + default=None, help="The timeout (seconds) for a prevote.", ) parser.add_argument( "--precommit_timeout", type=float, required=False, - default=1, + default=None, help="The timeout (seconds) for a precommit.", ) parser.add_argument( "--cache_size", type=int, required=False, - default=1000, + default=None, help="Cache size for the test simulation.", ) parser.add_argument( "--random_seed", type=int, required=False, - default=0, + default=None, help="Random seed for test simulation.", ) parser.add_argument( "--drop_probability", type=float, required=False, - default=0, + default=None, help="Probability of dropping a message for test simulation.", ) parser.add_argument( "--invalid_probability", type=float, required=False, - default=0, + default=None, help="Probability of sending an invalid message for test simulation.", ) args = parser.parse_args() diff --git a/crates/starknet_sierra_compile/Cargo.toml b/crates/starknet_sierra_compile/Cargo.toml index 96be65f1e7..2b25e5a217 100644 --- a/crates/starknet_sierra_compile/Cargo.toml +++ b/crates/starknet_sierra_compile/Cargo.toml @@ -1,9 +1,14 @@ [package] +<<<<<<< HEAD name = "starknet_sierra_compile" version.workspace = true +======= +>>>>>>> origin/main edition.workspace = true -repository.workspace = true license.workspace = true +name = "starknet_sierra_compile" +repository.workspace = true +version = "0.0.0" [lints] workspace = true diff --git a/crates/starknet_sierra_compile/src/cairo_lang_compiler.rs b/crates/starknet_sierra_compile/src/cairo_lang_compiler.rs index 7565b29afa..b78e1bbc78 100644 --- a/crates/starknet_sierra_compile/src/cairo_lang_compiler.rs +++ b/crates/starknet_sierra_compile/src/cairo_lang_compiler.rs @@ -8,10 +8,6 @@ use crate::config::SierraToCasmCompilationConfig; use crate::errors::CompilationUtilError; use crate::SierraToCasmCompiler; -#[cfg(test)] -#[path = "compile_test.rs"] -pub mod compile_test; - /// A compiler that compiles Sierra programs to Casm. Uses the code from the /// `cairo_lang_starknet_classes` crate. #[derive(Clone)] @@ -25,8 +21,12 @@ impl SierraToCasmCompiler for CairoLangSierraToCasmCompiler { contract_class: ContractClass, ) -> Result { let catch_unwind_result = panic::catch_unwind(|| self.compile_inner(contract_class)); - let casm_contract_class = - catch_unwind_result.map_err(|_| CompilationUtilError::CompilationPanic)??; + let casm_contract_class = catch_unwind_result.map_err(|error| { + CompilationUtilError::UnexpectedError(format!( + "Compilation Paniced: Error: {:?}", + error + )) + })??; Ok(casm_contract_class) } diff --git a/crates/starknet_sierra_compile/src/compile_test.rs b/crates/starknet_sierra_compile/src/compile_test.rs index badb69f8e9..547b92c497 100644 --- a/crates/starknet_sierra_compile/src/compile_test.rs +++ b/crates/starknet_sierra_compile/src/compile_test.rs @@ -2,12 +2,12 @@ use std::env; use std::path::Path; use assert_matches::assert_matches; -use cairo_lang_starknet_classes::allowed_libfuncs::AllowedLibfuncsError; use mempool_test_utils::{get_absolute_path, FAULTY_ACCOUNT_CLASS_FILE, TEST_FILES_FOLDER}; use rstest::{fixture, rstest}; -use crate::cairo_lang_compiler::{CairoLangSierraToCasmCompiler, CompilationUtilError}; +use crate::cairo_lang_compiler::CairoLangSierraToCasmCompiler; use crate::config::SierraToCasmCompilationConfig; +use crate::errors::CompilationUtilError; use crate::test_utils::contract_class_from_file; use crate::SierraToCasmCompiler; @@ -16,6 +16,7 @@ fn compiler() -> impl SierraToCasmCompiler { CairoLangSierraToCasmCompiler { config: SierraToCasmCompilationConfig::default() } } +// TODO: use the other compiler as well. #[rstest] fn test_compile_sierra_to_casm(compiler: impl SierraToCasmCompiler) { env::set_current_dir(get_absolute_path(TEST_FILES_FOLDER)).expect("Failed to set current dir."); @@ -40,8 +41,5 @@ fn test_negative_flow_compile_sierra_to_casm(compiler: impl SierraToCasmCompiler contract_class.sierra_program = contract_class.sierra_program[..100].to_vec(); let result = compiler.compile(contract_class); - assert_matches!( - result, - Err(CompilationUtilError::AllowedLibfuncsError(AllowedLibfuncsError::SierraProgramError)) - ); + assert_matches!(result, Err(CompilationUtilError::CompilationError(..))); } diff --git a/crates/starknet_sierra_compile/src/errors.rs b/crates/starknet_sierra_compile/src/errors.rs index 2d3d2575fa..c1f25719ec 100644 --- a/crates/starknet_sierra_compile/src/errors.rs +++ b/crates/starknet_sierra_compile/src/errors.rs @@ -4,10 +4,20 @@ use thiserror::Error; #[derive(Debug, Error)] pub enum CompilationUtilError { - #[error(transparent)] - AllowedLibfuncsError(#[from] AllowedLibfuncsError), - #[error(transparent)] - StarknetSierraCompilationError(#[from] StarknetSierraCompilationError), - #[error("Compilation panicked")] - CompilationPanic, + #[error("Starknet Sierra compilation error: {0}")] + CompilationError(String), + #[error("Unexpected compilation error: {0}")] + UnexpectedError(String), +} + +impl From for CompilationUtilError { + fn from(error: AllowedLibfuncsError) -> Self { + CompilationUtilError::CompilationError(error.to_string()) + } +} + +impl From for CompilationUtilError { + fn from(error: StarknetSierraCompilationError) -> Self { + CompilationUtilError::CompilationError(error.to_string()) + } } diff --git a/crates/starknet_sierra_compile/src/lib.rs b/crates/starknet_sierra_compile/src/lib.rs index 449a69ce5e..e68efcc505 100644 --- a/crates/starknet_sierra_compile/src/lib.rs +++ b/crates/starknet_sierra_compile/src/lib.rs @@ -12,6 +12,10 @@ pub mod utils; #[cfg(test)] pub mod test_utils; +#[cfg(test)] +#[path = "compile_test.rs"] +pub mod compile_test; + pub trait SierraToCasmCompiler: Send + Sync { fn compile( &self, diff --git a/crates/tests-integration/src/integration_test_utils.rs b/crates/tests-integration/src/integration_test_utils.rs index 28b4b98252..1905b68dda 100644 --- a/crates/tests-integration/src/integration_test_utils.rs +++ b/crates/tests-integration/src/integration_test_utils.rs @@ -3,7 +3,7 @@ use std::net::SocketAddr; use axum::body::Body; use blockifier::test_utils::contracts::FeatureContract; use mempool_test_utils::starknet_api_test_utils::{ - external_tx_to_json, + rpc_tx_to_json, MultiAccountTransactionGenerator, }; use reqwest::{Client, Response}; @@ -70,7 +70,7 @@ impl GatewayClient { // Prefer using assert_add_tx_success or other higher level methods of this client, to ensure // tests are boilerplate and implementation-detail free. pub async fn add_tx(&self, tx: &RpcTransaction) -> Response { - let tx_json = external_tx_to_json(tx); + let tx_json = rpc_tx_to_json(tx); self.client .post(format!("http://{}/add_tx", self.socket)) .header("content-type", "application/json")