diff --git a/crates/starknet_mempool/src/mempool_test.rs b/crates/starknet_mempool/src/mempool_test.rs index 508b8ae1c8..2bede58317 100644 --- a/crates/starknet_mempool/src/mempool_test.rs +++ b/crates/starknet_mempool/src/mempool_test.rs @@ -1,5 +1,6 @@ use pretty_assertions::assert_eq; use rstest::{fixture, rstest}; +use starknet_api::block::GasPrice; use starknet_api::executable_transaction::AccountTransaction; use starknet_api::{contract_address, nonce}; use starknet_mempool_types::errors::MempoolError; @@ -94,9 +95,9 @@ impl MempoolContentBuilder { self } - fn _with_gas_price_threshold(mut self, gas_price_threshold: u128) -> Self { + fn with_gas_price_threshold(mut self, gas_price_threshold: u128) -> Self { self.tx_queue_content_builder = - self.tx_queue_content_builder._with_gas_price_threshold(gas_price_threshold); + self.tx_queue_content_builder.with_gas_price_threshold(gas_price_threshold); self } @@ -613,3 +614,57 @@ fn test_fee_escalation_invalid_replacement_overflow_gracefully_handled() { let invalid_replacement_input = add_tx_input!(tip: u64::MAX, max_l2_gas_price: u128::MAX); add_txs_and_verify_no_replacement(mempool, existing_tx, [invalid_replacement_input]); } + +// `update_gas_price_threshold` tests. + +#[rstest] +fn test_update_gas_price_threshold_increases_threshold() { + // Setup. + let [tx_low_gas, tx_high_gas] = [ + &tx!(tx_hash: 0, address: "0x0", max_l2_gas_price: 100), + &tx!(tx_hash: 1, address: "0x1", max_l2_gas_price: 101), + ] + .map(TransactionReference::new); + + let mut mempool: Mempool = MempoolContentBuilder::new() + .with_priority_queue([tx_low_gas, tx_high_gas]) + .with_gas_price_threshold(100) + .build() + .into(); + + // Test. + mempool._update_gas_price_threshold(GasPrice(101)); + + // Assert. + let expected_mempool_content = MempoolContentBuilder::new() + .with_pending_queue([tx_low_gas]) + .with_priority_queue([tx_high_gas]) + .build(); + expected_mempool_content.assert_eq(&mempool); +} + +#[rstest] +fn test_update_gas_price_threshold_decreases_threshold() { + // Setup. + let [tx_low_gas, tx_high_gas] = [ + &tx!(tx_hash: 0, address: "0x0", max_l2_gas_price: 89), + &tx!(tx_hash: 1, address: "0x1", max_l2_gas_price: 90), + ] + .map(TransactionReference::new); + + let mut mempool: Mempool = MempoolContentBuilder::new() + .with_pending_queue([tx_low_gas, tx_high_gas]) + .with_gas_price_threshold(100) + .build() + .into(); + + // Test. + mempool._update_gas_price_threshold(GasPrice(90)); + + // Assert. + let expected_mempool_content = MempoolContentBuilder::new() + .with_pending_queue([tx_low_gas]) + .with_priority_queue([tx_high_gas]) + .build(); + expected_mempool_content.assert_eq(&mempool); +} diff --git a/crates/starknet_mempool/src/test_utils.rs b/crates/starknet_mempool/src/test_utils.rs index d495b79c7e..15685fe603 100644 --- a/crates/starknet_mempool/src/test_utils.rs +++ b/crates/starknet_mempool/src/test_utils.rs @@ -65,6 +65,15 @@ macro_rules! tx { (tx_hash: $tx_hash:expr, address: $address:expr, tip: $tip:expr) => { tx!(tx_hash: $tx_hash, address: $address, tx_nonce: 0, tip: $tip) }; + (tx_hash: $tx_hash:expr, address: $address:expr, max_l2_gas_price: $max_l2_gas_price:expr) => { + tx!( + tx_hash: $tx_hash, + address: $address, + tx_nonce: 0, + tip: 0, + max_l2_gas_price: $max_l2_gas_price + ) + }; (tx_hash: $tx_hash:expr, tip: $tip:expr, max_l2_gas_price: $max_l2_gas_price:expr) => { tx!( tx_hash: $tx_hash, diff --git a/crates/starknet_mempool/src/transaction_queue_test_utils.rs b/crates/starknet_mempool/src/transaction_queue_test_utils.rs index 5cef7f2396..6e1636ee72 100644 --- a/crates/starknet_mempool/src/transaction_queue_test_utils.rs +++ b/crates/starknet_mempool/src/transaction_queue_test_utils.rs @@ -87,7 +87,7 @@ impl TransactionQueueContentBuilder { self } - pub fn _with_gas_price_threshold(mut self, gas_price_threshold: u128) -> Self { + pub fn with_gas_price_threshold(mut self, gas_price_threshold: u128) -> Self { self.gas_price_threshold = Some(gas_price_threshold.into()); self }