From b8fa5786916aafb72c6d10b4d21e2ce10c86dad1 Mon Sep 17 00:00:00 2001 From: Mohammad Nassar Date: Tue, 20 Aug 2024 21:56:30 +0300 Subject: [PATCH] test(mempool): enable l2 gas resource for mempool-test --- crates/gateway/src/gateway_test.rs | 10 ++++++++-- .../src/stateful_transaction_validator_test.rs | 2 +- crates/mempool/src/mempool_test.rs | 12 ++++++++++-- .../src/starknet_api_test_utils.rs | 8 ++++++-- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/crates/gateway/src/gateway_test.rs b/crates/gateway/src/gateway_test.rs index 4204f0b3bff..acf697c3e45 100644 --- a/crates/gateway/src/gateway_test.rs +++ b/crates/gateway/src/gateway_test.rs @@ -10,7 +10,7 @@ use mempool_test_utils::starknet_api_test_utils::{create_executable_tx, invoke_t use mockall::predicate::eq; use starknet_api::core::ContractAddress; use starknet_api::rpc_transaction::RpcTransaction; -use starknet_api::transaction::TransactionHash; +use starknet_api::transaction::{ResourceBoundsMapping, TransactionHash}; use starknet_mempool_types::communication::MockMempoolClient; use starknet_mempool_types::mempool_types::{Account, AccountState, MempoolInput}; use starknet_sierra_compile::config::SierraToCasmCompilationConfig; @@ -67,7 +67,13 @@ async fn test_add_tx() { .with(eq(MempoolInput { // TODO(Arni): Use external_to_executable_tx instead of `create_executable_tx`. Consider // creating a `convertor for testing` that does not do the compilation. - tx: create_executable_tx(sender_address, tx_hash, *tx.tip(), *tx.nonce()), + tx: create_executable_tx( + sender_address, + tx_hash, + *tx.tip(), + *tx.nonce(), + ResourceBoundsMapping::default(), + ), account: Account { sender_address, state: AccountState { nonce: *tx.nonce() } }, })) .return_once(|_| Ok(())); diff --git a/crates/gateway/src/stateful_transaction_validator_test.rs b/crates/gateway/src/stateful_transaction_validator_test.rs index 4f9354e4c70..c9367544be1 100644 --- a/crates/gateway/src/stateful_transaction_validator_test.rs +++ b/crates/gateway/src/stateful_transaction_validator_test.rs @@ -69,7 +69,7 @@ fn stateful_validator(block_context: BlockContext) -> StatefulTransactionValidat invoke_tx(CairoVersion::Cairo1), Ok(ValidateInfo{ tx_hash: TransactionHash(felt!( - "0x152b8dd0c30e95fa3a4ee7a9398fcfc46fb00c048b4fdcfa9958c64d65899b8" + "0x3b93426272b6e281bc9bde29b91a9fb100c2f9689388c62360b2be2f4e7b493" )), sender_address: contract_address!("0xc0020000"), account_nonce: Nonce::default() diff --git a/crates/mempool/src/mempool_test.rs b/crates/mempool/src/mempool_test.rs index 94f238fb156..9add6f595ac 100644 --- a/crates/mempool/src/mempool_test.rs +++ b/crates/mempool/src/mempool_test.rs @@ -2,7 +2,10 @@ use std::cmp::Reverse; use std::collections::HashMap; use assert_matches::assert_matches; -use mempool_test_utils::starknet_api_test_utils::create_executable_tx; +use mempool_test_utils::starknet_api_test_utils::{ + create_executable_tx, + executable_resource_bounds_mapping, +}; use pretty_assertions::assert_eq; use rstest::{fixture, rstest}; use starknet_api::core::{ContractAddress, Nonce, PatriciaKey}; @@ -151,7 +154,7 @@ fn add_tx_expect_error(mempool: &mut Mempool, input: &MempoolInput, expected_err /// 5. add_tx_input!(tip: 1, tx_hash: 2) macro_rules! add_tx_input { (tip: $tip:expr, tx_hash: $tx_hash:expr, sender_address: $sender_address:expr, - tx_nonce: $tx_nonce:expr, account_nonce: $account_nonce:expr) => {{ + tx_nonce: $tx_nonce:expr, account_nonce: $account_nonce:expr, resource_bounds: $resource_bounds:expr) => {{ let sender_address = contract_address!($sender_address); let account_nonce = Nonce(felt!($account_nonce)); let account = Account { sender_address, state: AccountState {nonce: account_nonce}}; @@ -161,9 +164,14 @@ macro_rules! add_tx_input { TransactionHash(StarkHash::from($tx_hash)), Tip($tip), Nonce(felt!($tx_nonce)), + $resource_bounds, ); MempoolInput { tx, account } }}; + (tip: $tip:expr, tx_hash: $tx_hash:expr, sender_address: $sender_address:expr, + tx_nonce: $tx_nonce:expr, account_nonce: $account_nonce:expr) => {{ + add_tx_input!(tip: $tip, tx_hash: $tx_hash, sender_address: $sender_address, tx_nonce: $tx_nonce, account_nonce: $account_nonce, resource_bounds: executable_resource_bounds_mapping().into()) + }}; (tx_hash: $tx_hash:expr, sender_address: $sender_address:expr, tx_nonce: $tx_nonce:expr, account_nonce: $account_nonce:expr) => { add_tx_input!(tip: 0, tx_hash: $tx_hash, sender_address: $sender_address, tx_nonce: $tx_nonce, account_nonce: $account_nonce) }; 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 9352c97b232..41326305a4e 100644 --- a/crates/mempool_test_utils/src/starknet_api_test_utils.rs +++ b/crates/mempool_test_utils/src/starknet_api_test_utils.rs @@ -110,7 +110,10 @@ pub fn executable_resource_bounds_mapping() -> ResourceBoundsMapping { max_amount: VALID_L1_GAS_MAX_AMOUNT, max_price_per_unit: VALID_L1_GAS_MAX_PRICE_PER_UNIT, }, - ResourceBounds::default(), + ResourceBounds { + max_amount: VALID_L1_GAS_MAX_AMOUNT, + max_price_per_unit: VALID_L1_GAS_MAX_PRICE_PER_UNIT, + }, ) } @@ -547,6 +550,7 @@ pub fn create_executable_tx( tx_hash: TransactionHash, tip: Tip, nonce: Nonce, + resource_bounds: ExecutableResourceBoundsMapping, ) -> Transaction { Transaction::Invoke(InvokeTransaction { tx: starknet_api::transaction::InvokeTransaction::V3( @@ -554,7 +558,7 @@ pub fn create_executable_tx( sender_address, tip, nonce, - resource_bounds: ExecutableResourceBoundsMapping::default(), + resource_bounds, signature: TransactionSignature::default(), calldata: Calldata::default(), nonce_data_availability_mode: DataAvailabilityMode::L1,