Skip to content

Commit

Permalink
test(mempool): add mempool state struct and new function
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeletstarkware committed Jul 8, 2024
1 parent c7fa63e commit 5882630
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions crates/mempool/src/mempool_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,35 @@ use starknet_mempool_types::mempool_types::{Account, ThinTransaction};
use starknet_types_core::felt::Felt;

use crate::mempool::{Mempool, MempoolInput, TransactionReference};
use crate::transaction_pool::TransactionPool;
use crate::transaction_queue::TransactionQueue;

struct MempoolState {
tx_pool: TransactionPool,
tx_queue: TransactionQueue,
}

impl MempoolState {
fn new(pool_txs: Vec<ThinTransaction>, queue_txs: Vec<ThinTransaction>) -> Self {
let mut tx_pool = TransactionPool::default();
for tx in pool_txs {
tx_pool.insert(tx).unwrap();
}

let mut tx_queue = TransactionQueue::default();
for tx in queue_txs {
tx_queue.insert(TransactionReference::new(&tx));
}

MempoolState { tx_pool, tx_queue }
}
}

impl From<MempoolState> for Mempool {
fn from(state: MempoolState) -> Mempool {
Mempool { tx_pool: state.tx_pool, tx_queue: state.tx_queue }
}
}

#[track_caller]
fn add_tx(mempool: &mut Mempool, input: &MempoolInput) {
Expand Down Expand Up @@ -74,14 +103,15 @@ fn test_get_txs(#[case] requested_txs: usize) {
let input_tip_100_address_1 = add_tx_input!(tip: 100, tx_hash: 2, sender_address: "0x1");
let input_tip_10_address_2 = add_tx_input!(tip: 10, tx_hash: 3, sender_address: "0x2");

let txs = [
input_tip_50_address_0.clone(),
input_tip_100_address_1.clone(),
input_tip_10_address_2.clone(),
let txs = vec![
input_tip_50_address_0.clone().tx,
input_tip_100_address_1.clone().tx,
input_tip_10_address_2.clone().tx,
];
let n_txs = txs.len();

let mut mempool = Mempool::new(txs).unwrap();
let mempool_state = MempoolState::new(txs.clone(), txs);
let mut mempool: Mempool = mempool_state.into();

let sorted_txs =
[input_tip_100_address_1.tx, input_tip_50_address_0.tx, input_tip_10_address_2.tx];
Expand Down

0 comments on commit 5882630

Please sign in to comment.