diff --git a/crates/mempool/src/mempool_test.rs b/crates/mempool/src/mempool_test.rs index 3f46cf0715..5b0b9a4d47 100644 --- a/crates/mempool/src/mempool_test.rs +++ b/crates/mempool/src/mempool_test.rs @@ -5,6 +5,7 @@ use assert_matches::assert_matches; use mempool_test_utils::starknet_api_test_utils::{ create_executable_tx, test_resource_bounds_mapping, + VALID_L2_GAS_MAX_PRICE_PER_UNIT, }; use pretty_assertions::assert_eq; use rstest::{fixture, rstest}; @@ -49,8 +50,8 @@ impl MempoolContent { self.tx_queue.as_ref().unwrap().assert_eq_priority_queue(&mempool.tx_queue); } - fn _assert_eq_transaction_pending_queue_content(&self, mempool: &Mempool) { - self.tx_queue.as_ref().unwrap()._assert_eq_pending_queue(&mempool.tx_queue); + fn assert_eq_transaction_pending_queue_content(&self, mempool: &Mempool) { + self.tx_queue.as_ref().unwrap().assert_eq_pending_queue(&mempool.tx_queue); } fn _assert_eq_transaction_queues_content(&self, mempool: &Mempool) { @@ -104,7 +105,7 @@ impl MempoolContentBuilder { self } - fn _with_pending_queue(mut self, queue_txs: Q) -> Self + fn with_pending_queue(mut self, queue_txs: Q) -> Self where Q: IntoIterator, { @@ -215,6 +216,9 @@ macro_rules! add_tx_input { (tip: $tip:expr, tx_hash: $tx_hash:expr) => { add_tx_input!(tip: $tip, tx_hash: $tx_hash, sender_address: "0x0", tx_nonce: 0_u8, account_nonce: 0_u8) }; + () => { + add_tx_input!(tip: 1, tx_hash: 0_u8, sender_address: "0x0", tx_nonce: 0_u8, account_nonce: 0_u8) + }; } // Fixtures. @@ -962,6 +966,36 @@ fn test_account_nonces_removal_in_commit_block(mut mempool: Mempool) { expected_mempool_content.assert_eq_account_nonces(&mempool); } +// Update gas price threshold tests. + +#[rstest] +fn test_update_gas_price_threshold() { + // Setup. + let txs = [&add_tx_input!().tx, &add_tx_input!().tx].map(TransactionReference::new); + let (priority_txs, pending_txs) = ([txs[0]], [txs[1]]); + let mut mempool: Mempool = MempoolContentBuilder::new() + .with_priority_queue(priority_txs) + .with_pending_queue(pending_txs) + .build() + .into(); + + // Test. + // All txs should be in the pending queue. + mempool._update_gas_price_threshold(VALID_L2_GAS_MAX_PRICE_PER_UNIT + 2); + + // Assert. + let expected_mempool_content = MempoolContentBuilder::new().with_pending_queue(txs).build(); + expected_mempool_content.assert_eq_transaction_pending_queue_content(&mempool); + + // Test. + // All txs should be in the pending queue. + mempool._update_gas_price_threshold(VALID_L2_GAS_MAX_PRICE_PER_UNIT - 2); + + // Assert. + let expected_mempool_content = MempoolContentBuilder::new().with_priority_queue(txs).build(); + expected_mempool_content.assert_eq_transaction_priority_queue_content(&mempool); +} + // Flow tests. #[rstest] diff --git a/crates/mempool/src/transaction_queue_test_utils.rs b/crates/mempool/src/transaction_queue_test_utils.rs index f664eb2861..5f82984e0b 100644 --- a/crates/mempool/src/transaction_queue_test_utils.rs +++ b/crates/mempool/src/transaction_queue_test_utils.rs @@ -21,7 +21,7 @@ pub struct TransactionQueueContent { impl TransactionQueueContent { pub fn _assert_eq_priority_and_pending_queues(&self, tx_queue: &TransactionQueue) { self.assert_eq_priority_queue(tx_queue); - self._assert_eq_pending_queue(tx_queue); + self.assert_eq_pending_queue(tx_queue); } pub fn assert_eq_priority_queue(&self, tx_queue: &TransactionQueue) { @@ -29,7 +29,7 @@ impl TransactionQueueContent { assert_eq!(self.address_to_tx.as_ref().unwrap(), &tx_queue.address_to_tx); } - pub fn _assert_eq_pending_queue(&self, tx_queue: &TransactionQueue) { + pub fn assert_eq_pending_queue(&self, tx_queue: &TransactionQueue) { assert_eq!(self.pending_queue.as_ref().unwrap(), &tx_queue.pending_queue); assert_eq!(self.address_to_tx.as_ref().unwrap(), &tx_queue.address_to_tx); }