Skip to content

Commit 3bfec92

Browse files
test(mempool): refactor test_add_tx_with_duplicate_tx to use mempool state
1 parent 9852d18 commit 3bfec92

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

crates/mempool/src/mempool_test.rs

+21-6
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,22 @@ impl MempoolState {
3535
MempoolState { tx_pool, tx_queue }
3636
}
3737

38+
fn new_with_pool_txs_default_queue<PoolTxs>(pool_txs: PoolTxs) -> Self
39+
where
40+
PoolTxs: IntoIterator<Item = ThinTransaction>,
41+
{
42+
let tx_pool: TransactionPool = pool_txs.into_iter().collect();
43+
MempoolState { tx_pool, tx_queue: Default::default() }
44+
}
45+
3846
fn assert_eq_mempool_state(&self, mempool: &Mempool) {
39-
assert_eq!(self.tx_pool, mempool.tx_pool);
47+
self.assert_eq_tx_pool(mempool);
4048
assert_eq!(self.tx_queue, mempool.tx_queue);
4149
}
50+
51+
fn assert_eq_tx_pool(&self, mempool: &Mempool) {
52+
assert_eq!(self.tx_pool, mempool.tx_pool);
53+
}
4254
}
4355

4456
impl From<MempoolState> for Mempool {
@@ -223,17 +235,20 @@ fn test_new_with_duplicate_tx() {
223235

224236
#[rstest]
225237
fn test_add_tx_with_duplicate_tx(mut mempool: Mempool) {
238+
// Setup
226239
let input = add_tx_input!(tip: 50, tx_hash: Felt::ONE);
227-
let same_input = input.clone();
240+
let duplicate_input = input.clone();
228241

242+
// Test: assert that the duplicate tx is not added to the mempool.
229243
add_tx(&mut mempool, &input);
230-
231244
assert_matches!(
232-
mempool.add_tx(same_input.clone()),
245+
mempool.add_tx(duplicate_input),
233246
Err(MempoolError::DuplicateTransaction { .. })
234247
);
235-
// Assert that the original tx remains in the pool after the failed attempt.
236-
assert_eq_mempool_queue(&mempool, &[same_input.tx])
248+
249+
// Assert that the original tx remains in Mempool after the failed attempt.
250+
let expected_mempool_state = MempoolState::new_with_pool_txs_default_queue([input.tx]);
251+
expected_mempool_state.assert_eq_tx_pool(&mempool);
237252
}
238253

239254
#[rstest]

0 commit comments

Comments
 (0)