Skip to content

Commit

Permalink
test(starknet_mempool): mempool content builder with state (#3152)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware authored Jan 13, 2025
1 parent 3181ef1 commit d2d5498
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions crates/starknet_mempool/src/mempool_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use starknet_mempool_types::errors::MempoolError;
use starknet_mempool_types::mempool_types::AddTransactionArgs;

use crate::communication::MempoolCommunicationWrapper;
use crate::mempool::{Mempool, MempoolConfig, TransactionReference};
use crate::mempool::{Mempool, MempoolConfig, MempoolState, TransactionReference};
use crate::test_utils::{add_tx, add_tx_expect_error, commit_block, get_txs_and_assert_expected};
use crate::transaction_pool::TransactionPool;
use crate::transaction_queue::transaction_queue_test_utils::{
Expand All @@ -37,6 +37,7 @@ struct MempoolContent {
config: MempoolConfig,
tx_pool: Option<TransactionPool>,
tx_queue_content: Option<TransactionQueueContent>,
state: Option<MempoolState>,
}

impl MempoolContent {
Expand All @@ -54,15 +55,14 @@ impl MempoolContent {

impl From<MempoolContent> for Mempool {
fn from(mempool_content: MempoolContent) -> Mempool {
let MempoolContent { tx_pool, tx_queue_content, config } = mempool_content;
let MempoolContent { config, tx_pool, tx_queue_content, state } = mempool_content;
Mempool {
config,
tx_pool: tx_pool.unwrap_or_default(),
tx_queue: tx_queue_content
.map(|content| content.complete_to_tx_queue())
.unwrap_or_default(),
// TODO: Add implementation when needed.
state: Default::default(),
state: state.unwrap_or_default(),
}
}
}
Expand All @@ -72,6 +72,7 @@ struct MempoolContentBuilder {
config: MempoolConfig,
tx_pool: Option<TransactionPool>,
tx_queue_content_builder: TransactionQueueContentBuilder,
state: Option<MempoolState>,
}

impl MempoolContentBuilder {
Expand All @@ -80,6 +81,7 @@ impl MempoolContentBuilder {
config: MempoolConfig { enable_fee_escalation: false, ..Default::default() },
tx_pool: None,
tx_queue_content_builder: Default::default(),
state: None,
}
}

Expand All @@ -91,6 +93,11 @@ impl MempoolContentBuilder {
self
}

fn _with_state(mut self, state: MempoolState) -> Self {
self.state = Some(state);
self
}

fn with_priority_queue<Q>(mut self, queue_txs: Q) -> Self
where
Q: IntoIterator<Item = TransactionReference>,
Expand Down Expand Up @@ -123,6 +130,7 @@ impl MempoolContentBuilder {
config: self.config,
tx_pool: self.tx_pool,
tx_queue_content: self.tx_queue_content_builder.build(),
state: self.state,
}
}

Expand Down

0 comments on commit d2d5498

Please sign in to comment.