From 4ae3ba6be059fad65af2450b9797bb5931c1710b Mon Sep 17 00:00:00 2001 From: Mohammad Nassar Date: Mon, 8 Jul 2024 13:11:22 +0300 Subject: [PATCH] test(mempool): add tests for commit block method --- crates/mempool/src/mempool_test.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/crates/mempool/src/mempool_test.rs b/crates/mempool/src/mempool_test.rs index 8f015548..9a02734c 100644 --- a/crates/mempool/src/mempool_test.rs +++ b/crates/mempool/src/mempool_test.rs @@ -424,7 +424,35 @@ fn test_flow_filling_holes(mut mempool: Mempool) { #[rstest] #[ignore] +fn test_commit_block_includes_all_transactions() { + // Setup. + let tx_address0_nonce4 = add_tx_input!(tip: 4, tx_hash: 1, sender_address: "0x0", tx_nonce: 4_u8, account_nonce: 4_u8).tx; + let tx_address0_nonce5 = add_tx_input!(tip: 3, tx_hash: 2, sender_address: "0x0", tx_nonce: 5_u8, account_nonce: 4_u8).tx; + let tx_address1_nonce3 = add_tx_input!(tip: 2, tx_hash: 3, sender_address: "0x1", tx_nonce: 3_u8, account_nonce: 3_u8).tx; + let tx_address2_nonce1 = add_tx_input!(tip: 1, tx_hash: 4, sender_address: "0x2", tx_nonce: 1_u8, account_nonce: 1_u8).tx; + + let queue_txs = [ + TransactionReference::new(&tx_address0_nonce4), + TransactionReference::new(&tx_address1_nonce3), + TransactionReference::new(&tx_address2_nonce1), + ]; + let pool_txs = [tx_address0_nonce4, tx_address0_nonce5, tx_address1_nonce3, tx_address2_nonce1]; + let mut mempool: Mempool = MempoolState::new(pool_txs.clone(), queue_txs).into(); + + // Test. + let state_changes = HashMap::from([ + (contract_address!("0x0"), AccountState { nonce: Nonce(felt!(3_u16)) }), + (contract_address!("0x1"), AccountState { nonce: Nonce(felt!(2_u16)) }), + ]); + assert!(mempool.commit_block(state_changes).is_ok()); + // Assert. + let expected_state = MempoolState::new(pool_txs, queue_txs); + expected_state.assert_eq_mempool_state(&mempool); +} + +#[rstest] +#[ignore] fn test_commit_block_rewinds_nonce() { // Setup. let tx_address0_nonce5 = add_tx_input!(tip: 1, tx_hash: 2, sender_address: "0x0", tx_nonce: 5_u8, account_nonce: 4_u8).tx;