Skip to content

Commit

Permalink
test(mempool): test update gas threshold api
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadNassar1 committed Sep 19, 2024
1 parent 5eb3cb5 commit a3e84d6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
38 changes: 35 additions & 3 deletions crates/mempool/src/mempool_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -104,7 +105,7 @@ impl MempoolContentBuilder {
self
}

fn _with_pending_queue<Q>(mut self, queue_txs: Q) -> Self
fn with_pending_queue<Q>(mut self, queue_txs: Q) -> Self
where
Q: IntoIterator<Item = TransactionReference>,
{
Expand Down Expand Up @@ -964,6 +965,37 @@ 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]
Expand Down
4 changes: 2 additions & 2 deletions crates/mempool/src/transaction_queue_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ 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) {
assert_eq!(self.priority_queue.as_ref().unwrap(), &tx_queue.priority_queue);
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);
}
Expand Down

0 comments on commit a3e84d6

Please sign in to comment.