Skip to content

Commit a871ada

Browse files
authored
fix all integration tests (#41)
1 parent e7b43b6 commit a871ada

File tree

4 files changed

+33
-29
lines changed

4 files changed

+33
-29
lines changed

src/main.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,22 @@ fn build_pipeline(
9696

9797
let ws = Arc::new(WebSocketSink::new(cli_args.flashblocks_args.ws_address)?);
9898

99-
let flashblock_building_pipeline_steps = (
100-
AppendOrders::from_pool(pool).with_ok_on_limit(),
101-
OrderByPriorityFee::default(),
102-
RemoveRevertedTransactions::default(),
103-
BreakAfterDeadline,
104-
)
105-
.into_pipeline();
99+
let flashblock_building_pipeline_steps = if cli_args.revert_protection {
100+
(
101+
AppendOrders::from_pool(pool).with_ok_on_limit(),
102+
OrderByPriorityFee::default(),
103+
RemoveRevertedTransactions::default(),
104+
BreakAfterDeadline,
105+
)
106+
.into_pipeline()
107+
} else {
108+
(
109+
AppendOrders::from_pool(pool).with_ok_on_limit(),
110+
OrderByPriorityFee::default(),
111+
BreakAfterDeadline,
112+
)
113+
.into_pipeline()
114+
};
106115

107116
let flashblock_building_pipeline_steps = if let Some(ref signer) =
108117
cli_args.builder_signer
@@ -121,8 +130,8 @@ fn build_pipeline(
121130
let flashblock_number = Arc::new(FlashblockNumber::new());
122131

123132
let pipeline = Pipeline::<Flashblocks>::named("flashblocks")
124-
.with_prologue(OptimismPrologue)
125-
.with_prologue(FlashtestationsPrologue::try_new(
133+
.with_step(OptimismPrologue)
134+
.with_step(FlashtestationsPrologue::try_new(
126135
cli_args.flashtestations.clone(),
127136
cli_args.builder_signer.clone(),
128137
)?)

src/platform.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use {
1414
/// the `Flashblocks` platform.
1515
///
1616
/// See [`rblib::Platform`] for more details on platform definitions.
17-
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
17+
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
1818
pub struct Flashblocks;
1919

2020
impl Platform for Flashblocks {

src/tests/ordering.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use {
22
crate::{platform::Flashblocks, tests::assert_has_sequencer_tx},
3-
itertools::Itertools,
43
rblib::{
5-
alloy::primitives::U256,
4+
alloy::{consensus::Transaction, primitives::U256},
65
test_utils::{BlockResponseExt, TransactionRequestExt},
76
},
87
std::time::Duration,
@@ -17,10 +16,9 @@ use {
1716
async fn txs_ordered_by_priority_fee() -> eyre::Result<()> {
1817
let (node, _) = Flashblocks::test_node().await?;
1918

20-
let tx_tips = vec![100, 300, 200, 500, 400];
21-
let mut sent_txs = Vec::new();
19+
let tx_tips = [100, 300, 200, 500, 400];
2220
for (i, tip) in tx_tips.iter().enumerate() {
23-
let tx = node
21+
let _tx = node
2422
.send_tx(
2523
node
2624
.build_tx()
@@ -30,33 +28,30 @@ async fn txs_ordered_by_priority_fee() -> eyre::Result<()> {
3028
.max_priority_fee_per_gas(*tip),
3129
)
3230
.await?;
33-
sent_txs.push(*tx.tx_hash());
3431
}
3532

3633
// We need to wait to build the block
3734
tokio::time::sleep(Duration::from_millis(100)).await;
3835

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-
4836
let block = node.next_block().await?;
4937
assert_eq!(block.number(), 1);
5038
assert_has_sequencer_tx!(&block);
5139
assert_eq!(block.tx_count(), 6); // sequencer deposit tx + the 5 we sent
5240

53-
let hashes: Vec<_> = block
41+
let base_fee = block.header.base_fee_per_gas.unwrap();
42+
43+
let tx_tips: Vec<_> = block
5444
.transactions
5545
.into_transactions()
56-
.map(|tx| tx.inner.inner.tx_hash())
46+
.skip(1) // skip the deposit transaction
47+
.map(|tx| tx.effective_tip_per_gas(base_fee))
48+
.rev() // we want to check descending order
5749
.collect();
5850

59-
assert_eq!(sorted_sent_txs, hashes[1..]);
51+
assert!(
52+
tx_tips.is_sorted(),
53+
"Transactions not ordered by fee priority"
54+
);
6055

6156
Ok(())
6257
}

src/tests/standard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async fn blocks_have_builder_tx() -> eyre::Result<()> {
7171
debug!("produced block: {block:#?}");
7272

7373
assert_eq!(block.number(), 1);
74-
assert_eq!(block.tx_count(), 2); // sequencer deposit tx + builder tx
74+
assert_eq!(block.tx_count(), 9); // sequencer deposit tx + 8 builder txs for each flashblock
7575

7676
let builder_tx = block.tx(1).unwrap();
7777
assert_eq!(builder_tx.nonce(), 0);

0 commit comments

Comments
 (0)