Skip to content

Commit a3e84d6

Browse files
test(mempool): test update gas threshold api
1 parent 5eb3cb5 commit a3e84d6

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

crates/mempool/src/mempool_test.rs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use assert_matches::assert_matches;
55
use mempool_test_utils::starknet_api_test_utils::{
66
create_executable_tx,
77
test_resource_bounds_mapping,
8+
VALID_L2_GAS_MAX_PRICE_PER_UNIT,
89
};
910
use pretty_assertions::assert_eq;
1011
use rstest::{fixture, rstest};
@@ -49,8 +50,8 @@ impl MempoolContent {
4950
self.tx_queue.as_ref().unwrap().assert_eq_priority_queue(&mempool.tx_queue);
5051
}
5152

52-
fn _assert_eq_transaction_pending_queue_content(&self, mempool: &Mempool) {
53-
self.tx_queue.as_ref().unwrap()._assert_eq_pending_queue(&mempool.tx_queue);
53+
fn assert_eq_transaction_pending_queue_content(&self, mempool: &Mempool) {
54+
self.tx_queue.as_ref().unwrap().assert_eq_pending_queue(&mempool.tx_queue);
5455
}
5556

5657
fn _assert_eq_transaction_queues_content(&self, mempool: &Mempool) {
@@ -104,7 +105,7 @@ impl MempoolContentBuilder {
104105
self
105106
}
106107

107-
fn _with_pending_queue<Q>(mut self, queue_txs: Q) -> Self
108+
fn with_pending_queue<Q>(mut self, queue_txs: Q) -> Self
108109
where
109110
Q: IntoIterator<Item = TransactionReference>,
110111
{
@@ -964,6 +965,37 @@ fn test_account_nonces_removal_in_commit_block(mut mempool: Mempool) {
964965
expected_mempool_content.assert_eq_account_nonces(&mempool);
965966
}
966967

968+
// Update gas price threshold tests.
969+
970+
#[rstest]
971+
fn test_update_gas_price_threshold() {
972+
// Setup.
973+
let txs =
974+
[&add_tx_input!().tx, &add_tx_input!().tx].map(TransactionReference::new);
975+
let (priority_txs, pending_txs) = ([txs[0]], [txs[1]]);
976+
let mut mempool: Mempool = MempoolContentBuilder::new()
977+
.with_priority_queue(priority_txs)
978+
.with_pending_queue(pending_txs)
979+
.build()
980+
.into();
981+
982+
// Test.
983+
// All txs should be in the pending queue.
984+
mempool._update_gas_price_threshold(VALID_L2_GAS_MAX_PRICE_PER_UNIT + 2);
985+
986+
// Assert.
987+
let expected_mempool_content = MempoolContentBuilder::new().with_pending_queue(txs).build();
988+
expected_mempool_content.assert_eq_transaction_pending_queue_content(&mempool);
989+
990+
// Test.
991+
// All txs should be in the pending queue.
992+
mempool._update_gas_price_threshold(VALID_L2_GAS_MAX_PRICE_PER_UNIT - 2);
993+
994+
// Assert.
995+
let expected_mempool_content = MempoolContentBuilder::new().with_priority_queue(txs).build();
996+
expected_mempool_content.assert_eq_transaction_priority_queue_content(&mempool);
997+
}
998+
967999
// Flow tests.
9681000

9691001
#[rstest]

crates/mempool/src/transaction_queue_test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ pub struct TransactionQueueContent {
2020
impl TransactionQueueContent {
2121
pub fn _assert_eq_priority_and_pending_queues(&self, tx_queue: &TransactionQueue) {
2222
self.assert_eq_priority_queue(tx_queue);
23-
self._assert_eq_pending_queue(tx_queue);
23+
self.assert_eq_pending_queue(tx_queue);
2424
}
2525

2626
pub fn assert_eq_priority_queue(&self, tx_queue: &TransactionQueue) {
2727
assert_eq!(self.priority_queue.as_ref().unwrap(), &tx_queue.priority_queue);
2828
assert_eq!(self.address_to_tx.as_ref().unwrap(), &tx_queue.address_to_tx);
2929
}
3030

31-
pub fn _assert_eq_pending_queue(&self, tx_queue: &TransactionQueue) {
31+
pub fn assert_eq_pending_queue(&self, tx_queue: &TransactionQueue) {
3232
assert_eq!(self.pending_queue.as_ref().unwrap(), &tx_queue.pending_queue);
3333
assert_eq!(self.address_to_tx.as_ref().unwrap(), &tx_queue.address_to_tx);
3434
}

0 commit comments

Comments
 (0)