|
| 1 | +use { |
| 2 | + crate::{platform::Flashblocks, tests::assert_has_sequencer_tx}, |
| 3 | + itertools::Itertools, |
| 4 | + rblib::{ |
| 5 | + alloy::primitives::U256, |
| 6 | + test_utils::{BlockResponseExt, TransactionRequestExt}, |
| 7 | + }, |
| 8 | + std::time::Duration, |
| 9 | +}; |
| 10 | + |
1 | 11 | /// This test ensures that the transactions are ordered by fee priority in the |
2 | 12 | /// block. This version of the test is only applicable to the standard builder |
3 | 13 | /// because in flashblocks the transaction order is commited by the block after |
4 | 14 | /// each flashblock is produced, so the order is only going to hold within one |
5 | 15 | /// flashblock, but not the entire block. |
6 | 16 | #[tokio::test] |
7 | 17 | async fn txs_ordered_by_priority_fee() -> eyre::Result<()> { |
8 | | - todo!() |
| 18 | + let node = Flashblocks::test_node().await?; |
| 19 | + |
| 20 | + let tx_tips = vec![100, 300, 200, 500, 400]; |
| 21 | + let mut sent_txs = Vec::new(); |
| 22 | + for (i, tip) in tx_tips.iter().enumerate() { |
| 23 | + let tx = node |
| 24 | + .send_tx( |
| 25 | + node |
| 26 | + .build_tx() |
| 27 | + .transfer() |
| 28 | + .with_funded_signer(i.try_into().unwrap()) |
| 29 | + .value(U256::from(1_234_000)) |
| 30 | + .max_priority_fee_per_gas(*tip), |
| 31 | + ) |
| 32 | + .await?; |
| 33 | + sent_txs.push(*tx.tx_hash()); |
| 34 | + } |
| 35 | + |
| 36 | + // We need to wait to build the block |
| 37 | + tokio::time::sleep(Duration::from_millis(100)).await; |
| 38 | + |
| 39 | + let sorted_sent_txs: Vec<_> = tx_tips |
| 40 | + .into_iter() |
| 41 | + .zip(sent_txs) |
| 42 | + .inspect(|(tip, hash)| println!("tip: {tip}, hash: {hash}")) |
| 43 | + .sorted_by_key(|tuple| tuple.0) |
| 44 | + .rev() |
| 45 | + .map(|(_tip, hash)| hash) |
| 46 | + .collect(); |
| 47 | + |
| 48 | + let block = node.next_block().await?; |
| 49 | + assert_eq!(block.number(), 1); |
| 50 | + assert_has_sequencer_tx!(&block); |
| 51 | + assert_eq!(block.tx_count(), 6); // sequencer deposit tx + the 5 we sent |
| 52 | + |
| 53 | + let hashes: Vec<_> = block |
| 54 | + .transactions |
| 55 | + .into_transactions() |
| 56 | + .map(|tx| tx.inner.inner.tx_hash()) |
| 57 | + .collect(); |
| 58 | + |
| 59 | + assert_eq!(sorted_sent_txs, hashes[1..]); |
| 60 | + |
| 61 | + Ok(()) |
9 | 62 | } |
0 commit comments