Skip to content

Commit

Permalink
test(mempool): add commit block test invalid argument
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadNassar1 committed Jul 16, 2024
1 parent 9b2069c commit c49c443
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions crates/mempool/src/mempool_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,38 @@ fn test_flow_filling_holes(mut mempool: Mempool) {
// Assert: all remaining transactions are returned.
assert_eq!(txs, &[input_address_0_nonce_0.tx]);
}

#[rstest]
#[ignore]
fn test_commit_block_invalid_account_state() {
// Mempool initializing:
// "0x0" -> 4.
// "0x1" -> 3.
// In Transaction queue there is a single transaction of address "0x0". A tx with nonce 4.
// Commit block that returns "0x0" -> 4, and "0x1" -> 3.

let tx_address0_nonce4 = add_tx_input!(tip: 1, tx_hash: 1, sender_address: "0x0", tx_nonce: 4_u8, account_nonce: 4_u8).tx;
let tx_address1_nonce3 = add_tx_input!(tip: 1, tx_hash: 2, sender_address: "0x1", tx_nonce: 3_u8, account_nonce: 3_u8).tx;

let queued_txs = vec![tx_address0_nonce4.clone()];
let pool_txs = vec![tx_address0_nonce4, tx_address1_nonce3.clone()];

let tx_references_iterator = queued_txs.iter().map(TransactionReference::new);
let txs_iterator = pool_txs.iter().cloned();

let mut mempool: Mempool = MempoolState::new(txs_iterator, tx_references_iterator).into();

let commit_state = HashMap::from([
(contract_address!("0x0"), AccountState { nonce: Nonce(felt!(4_u16)) }),
(contract_address!("0x1"), AccountState { nonce: Nonce(felt!(2_u16)) }),
]);
assert!(mempool.commit_block(commit_state).is_ok());

let invalid_commit_state =
HashMap::from([(contract_address!("0x0"), AccountState { nonce: Nonce(felt!(3_u16)) })]);
// verify that `commit_block`` handles the invalid account state.
assert!(mempool.commit_block(invalid_commit_state).is_ok());

// Check that in the transaction queue is empty.
assert_eq_mempool_state(&mempool, &[tx_address1_nonce3], &[]);
}

0 comments on commit c49c443

Please sign in to comment.