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 5, 2024
1 parent c65f0b9 commit 615ad00
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion crates/mempool/src/mempool_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ use std::collections::HashMap;
use assert_matches::assert_matches;
use mempool_test_utils::starknet_api_test_utils::{
create_executable_tx,
create_resource_bounds_mapping,
test_resource_bounds_mapping,
VALID_L2_GAS_MAX_PRICE_PER_UNIT,
};
use pretty_assertions::assert_eq;
use rstest::{fixture, rstest};
use starknet_api::core::{ContractAddress, Nonce, PatriciaKey};
use starknet_api::executable_transaction::Transaction;
use starknet_api::hash::StarkHash;
use starknet_api::transaction::{Tip, TransactionHash, ValidResourceBounds};
use starknet_api::transaction::{ResourceBounds, Tip, TransactionHash, ValidResourceBounds};
use starknet_api::{contract_address, felt, patricia_key};
use starknet_mempool_types::errors::MempoolError;
use starknet_mempool_types::mempool_types::{Account, AccountState};
Expand Down Expand Up @@ -770,6 +772,52 @@ fn test_commit_block_from_different_leader() {
expected_mempool_content.assert_eq_transaction_queue_content(&mempool);
}

// Update gas price threshold tests.

#[rstest]
fn test_update_gas_price_threshold(mut mempool: Mempool) {
// Setup.
let high_l2_resource_bound = create_resource_bounds_mapping(
ResourceBounds::default(),
ResourceBounds { max_amount: 0, max_price_per_unit: VALID_L2_GAS_MAX_PRICE_PER_UNIT + 1 },
ResourceBounds::default(),
);

let low_l2_resource_bound = create_resource_bounds_mapping(
ResourceBounds::default(),
ResourceBounds { max_amount: 0, max_price_per_unit: VALID_L2_GAS_MAX_PRICE_PER_UNIT - 1 },
ResourceBounds::default(),
);

let high_gas_price_input_tx = add_tx_input!();
let low_gas_price_input_tx = add_tx_input!();
let mut mempool: Mempool = MempoolContent::with_transaction_queues(
TransactionReference::new(&high_gas_price_input_tx.tx),
TransactionReference::new(&low_gas_price_input_tx.tx),
)
.into();

// Test.
// All txs should be in the pending queue.
mempool._update_gas_price_threshold(VALID_L2_GAS_MAX_PRICE_PER_UNIT + 2);

// Assert.
mempool.assert_eq_pending_queue_content(&[
&high_gas_price_input_tx.tx,
&low_gas_price_input_tx.tx,
]);

// Test.
// All txs should be in the pending queue.
mempool._update_gas_price_threshold(VALID_L2_GAS_MAX_PRICE_PER_UNIT - 2);

// Assert.
mempool.assert_eq_pending_queue_content(&[
&high_gas_price_input_tx.tx,
&low_gas_price_input_tx.tx,
]);
}

// Flow tests.

#[rstest]
Expand Down

0 comments on commit 615ad00

Please sign in to comment.