Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(mempool): get txs multi nonce multi account validate replenishin… #502

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions crates/mempool/src/mempool_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,36 @@ fn test_get_txs_multi_nonce() {
expected_mempool_state.assert_eq_mempool_state(&mempool);
}

#[rstest]
fn test_get_txs_replenishes_queue_only_between_chunks() {
// Setup.
let tx_address_0_nonce_0 =
add_tx_input!(tip: 20, tx_hash: 1, sender_address: "0x0", tx_nonce: 0_u8, account_nonce: 0_u8).tx;
let tx_address_0_nonce_1 =
add_tx_input!(tip: 20, tx_hash: 2, sender_address: "0x0", tx_nonce: 1_u8, account_nonce: 0_u8).tx;
let tx_address_1_nonce_0 =
add_tx_input!(tip: 10, tx_hash: 3, sender_address: "0x1", tx_nonce: 0_u8, account_nonce: 0_u8).tx;

let queue_txs = [
TransactionReference::new(&tx_address_0_nonce_0),
TransactionReference::new(&tx_address_1_nonce_0),
];
let pool_txs =
[tx_address_0_nonce_0.clone(), tx_address_0_nonce_1.clone(), tx_address_1_nonce_0.clone()];
let mut mempool: Mempool = MempoolState::new(pool_txs, queue_txs).into();

// Test.
let txs = mempool.get_txs(3).unwrap();

// Assert: all transactions returned.
// Replenishment done in chunks: account 1 transaction is returned before the one of account 0,
// although its priority is higher.
assert_eq!(txs, &[tx_address_0_nonce_0, tx_address_1_nonce_0, tx_address_0_nonce_1]);
// TODO(Ayelet): Add an MempoolState empty constructor.
let expected_mempool_state = MempoolState::new([], []);
expected_mempool_state.assert_eq_mempool_state(&mempool);
}

#[rstest]
fn test_add_tx(mut mempool: Mempool) {
// Setup.
Expand Down
Loading