@@ -35,10 +35,22 @@ impl MempoolState {
35
35
MempoolState { tx_pool, tx_queue }
36
36
}
37
37
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
+
38
46
fn assert_eq_mempool_state ( & self , mempool : & Mempool ) {
39
- assert_eq ! ( self . tx_pool , mempool. tx_pool ) ;
47
+ self . assert_eq_tx_pool ( mempool) ;
40
48
assert_eq ! ( self . tx_queue, mempool. tx_queue) ;
41
49
}
50
+
51
+ fn assert_eq_tx_pool ( & self , mempool : & Mempool ) {
52
+ assert_eq ! ( self . tx_pool, mempool. tx_pool) ;
53
+ }
42
54
}
43
55
44
56
impl From < MempoolState > for Mempool {
@@ -223,17 +235,20 @@ fn test_new_with_duplicate_tx() {
223
235
224
236
#[ rstest]
225
237
fn test_add_tx_with_duplicate_tx ( mut mempool : Mempool ) {
238
+ // Setup
226
239
let input = add_tx_input ! ( tip: 50 , tx_hash: Felt :: ONE ) ;
227
- let same_input = input. clone ( ) ;
240
+ let duplicate_input = input. clone ( ) ;
228
241
242
+ // Test: assert that the duplicate tx is not added to the mempool.
229
243
add_tx ( & mut mempool, & input) ;
230
-
231
244
assert_matches ! (
232
- mempool. add_tx( same_input . clone ( ) ) ,
245
+ mempool. add_tx( duplicate_input ) ,
233
246
Err ( MempoolError :: DuplicateTransaction { .. } )
234
247
) ;
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) ;
237
252
}
238
253
239
254
#[ rstest]
0 commit comments