Skip to content

Commit a560fb5

Browse files
add tests
1 parent f78243b commit a560fb5

File tree

3 files changed

+237
-5
lines changed

3 files changed

+237
-5
lines changed

crates/flashblocks/node/tests/p2p.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,4 +963,3 @@ async fn test_peer_monitoring() -> eyre::Result<()> {
963963

964964
Ok(())
965965
}
966-

crates/world/node/tests/e2e-testsuite/setup.rs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,40 @@ where
140140
T: WorldChainTestContextBounds,
141141
WorldChainNode<T>: WorldChainNodeTestBounds<T>,
142142
{
143-
setup_with_tx_peers::<T>(
143+
setup_inner::<T>(
144144
num_nodes,
145145
attributes_generator,
146146
false,
147147
false,
148148
flashblocks_enabled,
149+
None,
150+
)
151+
.await
152+
}
153+
154+
pub async fn setup_with_block_uncompressed_size_limit<T>(
155+
num_nodes: u8,
156+
attributes_generator: impl Fn(u64) -> <<WorldChainNode<T> as NodeTypes>::Payload as PayloadTypes>::PayloadBuilderAttributes + Send + Sync + Copy + 'static,
157+
flashblocks_enabled: bool,
158+
block_uncompressed_size_limit: Option<u64>,
159+
) -> eyre::Result<(
160+
Range<u8>,
161+
Vec<WorldChainTestingNodeContext<T>>,
162+
TaskManager,
163+
Environment<OpEngineTypes>,
164+
TxSpammer,
165+
)>
166+
where
167+
T: WorldChainTestContextBounds,
168+
WorldChainNode<T>: WorldChainNodeTestBounds<T>,
169+
{
170+
setup_inner::<T>(
171+
num_nodes,
172+
attributes_generator,
173+
false,
174+
false,
175+
flashblocks_enabled,
176+
block_uncompressed_size_limit,
149177
)
150178
.await
151179
}
@@ -164,6 +192,35 @@ pub async fn setup_with_tx_peers<T>(
164192
Environment<OpEngineTypes>,
165193
TxSpammer,
166194
)>
195+
where
196+
T: WorldChainTestContextBounds,
197+
WorldChainNode<T>: WorldChainNodeTestBounds<T>,
198+
{
199+
setup_inner::<T>(
200+
num_nodes,
201+
attributes_generator,
202+
enable_tx_peers,
203+
disable_gossip,
204+
flashblocks_enabled,
205+
None,
206+
)
207+
.await
208+
}
209+
210+
async fn setup_inner<T>(
211+
num_nodes: u8,
212+
attributes_generator: impl Fn(u64) -> <<WorldChainNode<T> as NodeTypes>::Payload as PayloadTypes>::PayloadBuilderAttributes + Send + Sync + Copy + 'static,
213+
enable_tx_peers: bool,
214+
disable_gossip: bool,
215+
flashblocks_enabled: bool,
216+
block_uncompressed_size_limit: Option<u64>,
217+
) -> eyre::Result<(
218+
Range<u8>,
219+
Vec<WorldChainTestingNodeContext<T>>,
220+
TaskManager,
221+
Environment<OpEngineTypes>,
222+
TxSpammer,
223+
)>
167224
where
168225
T: WorldChainTestContextBounds,
169226
WorldChainNode<T>: WorldChainNodeTestBounds<T>,
@@ -232,6 +289,8 @@ where
232289
} else {
233290
test_config_with_peers_and_gossip(None, disable_gossip, flashblocks_enabled)
234291
};
292+
let mut config = config;
293+
config.args.block_uncompressed_size_limit = block_uncompressed_size_limit;
235294

236295
let node = WorldChainNode::<T>::new(config.args.clone().into_config(&mut node_config)?);
237296

crates/world/node/tests/e2e-testsuite/testsuite.rs

Lines changed: 177 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
setup::{TX_SET_L1_BLOCK, build_payload_attributes},
77
};
88
use alloy_network::{Ethereum, EthereumWallet, TransactionBuilder, eip2718::Encodable2718};
9-
use alloy_primitives::b64;
9+
use alloy_primitives::{Bytes, b64};
1010
use alloy_rpc_types::TransactionRequest;
1111
use alloy_rpc_types_engine::PayloadStatusEnum;
1212
use eyre::eyre::eyre;
@@ -18,7 +18,7 @@ use reth::{
1818
use reth_e2e_test_utils::testsuite::actions::Action;
1919
use reth_optimism_node::utils::optimism_payload_attributes;
2020
use reth_transaction_pool::TransactionPool;
21-
use revm_primitives::{Address, U256};
21+
use revm_primitives::{Address, B256, U256};
2222
use std::{
2323
sync::{
2424
Arc,
@@ -34,9 +34,35 @@ use world_chain_test::{
3434
};
3535

3636
use crate::setup::{
37-
CHAIN_SPEC, create_test_transaction, encode_eip1559_params, setup, setup_with_tx_peers,
37+
CHAIN_SPEC, create_test_transaction, encode_eip1559_params, setup,
38+
setup_with_block_uncompressed_size_limit, setup_with_tx_peers,
3839
};
3940

41+
async fn create_priority_transaction(
42+
signer_index: u32,
43+
nonce: u64,
44+
calldata_len: usize,
45+
gas_limit: u64,
46+
max_priority_fee_per_gas: u128,
47+
) -> eyre::Result<(Bytes, B256)> {
48+
let mut tx_request = tx(
49+
CHAIN_SPEC.chain.id(),
50+
Some(Bytes::from(vec![0u8; calldata_len])),
51+
nonce,
52+
Address::default(),
53+
gas_limit,
54+
);
55+
tx_request.value = Some(U256::ZERO);
56+
tx_request.max_priority_fee_per_gas = Some(max_priority_fee_per_gas);
57+
tx_request.max_fee_per_gas = Some(100_000_000_000u128 + max_priority_fee_per_gas);
58+
59+
let wallet = EthereumWallet::from(signer(signer_index));
60+
let signed =
61+
<TransactionRequest as TransactionBuilder<Ethereum>>::build(tx_request, &wallet).await?;
62+
63+
Ok((signed.encoded_2718().into(), *signed.tx_hash()))
64+
}
65+
4066
#[tokio::test]
4167
async fn test_can_build_pbh_payload() -> eyre::Result<()> {
4268
reth_tracing::init_test_tracing();
@@ -113,6 +139,154 @@ async fn test_transaction_pool_ordering() -> eyre::Result<()> {
113139
Ok(())
114140
}
115141

142+
#[tokio::test]
143+
async fn test_enforces_block_uncompressed_size_limit() -> eyre::Result<()> {
144+
reth_tracing::init_test_tracing();
145+
146+
let (tx1, tx1_hash) = create_priority_transaction(0, 0, 50_000, 600_000, 100).await?;
147+
let (tx_small, tx_small_hash) = create_priority_transaction(1, 0, 30_000, 400_000, 95).await?;
148+
let (tx2, tx2_hash) = create_priority_transaction(2, 0, 50_000, 600_000, 90).await?;
149+
let (tx3, tx3_hash) = create_priority_transaction(3, 0, 50_000, 600_000, 80).await?;
150+
151+
let block_uncompressed_size_limit =
152+
TX_SET_L1_BLOCK.len() as u64 + tx1.len() as u64 + tx_small.len() as u64;
153+
154+
let (_, mut nodes, _tasks, _, _) =
155+
setup_with_block_uncompressed_size_limit::<FlashblocksContext>(
156+
1,
157+
optimism_payload_attributes,
158+
false,
159+
Some(block_uncompressed_size_limit),
160+
)
161+
.await?;
162+
let node = &mut nodes[0].node;
163+
164+
assert_eq!(node.rpc.inject_tx(tx1.clone()).await?, tx1_hash);
165+
assert_eq!(node.rpc.inject_tx(tx_small.clone()).await?, tx_small_hash);
166+
assert_eq!(node.rpc.inject_tx(tx2.clone()).await?, tx2_hash);
167+
assert_eq!(node.rpc.inject_tx(tx3.clone()).await?, tx3_hash);
168+
169+
let block1 = node.advance_block().await?;
170+
assert!(
171+
block1
172+
.block()
173+
.body()
174+
.transactions
175+
.iter()
176+
.any(|tx| *tx.tx_hash() == tx1_hash),
177+
"tx1 should be included in block 1"
178+
);
179+
assert!(
180+
block1
181+
.block()
182+
.body()
183+
.transactions
184+
.iter()
185+
.any(|tx| *tx.tx_hash() == tx_small_hash),
186+
"tx_small should fit in block 1"
187+
);
188+
assert!(
189+
!block1
190+
.block()
191+
.body()
192+
.transactions
193+
.iter()
194+
.any(|tx| *tx.tx_hash() == tx2_hash),
195+
"tx2 should go to a later block"
196+
);
197+
assert!(
198+
!block1
199+
.block()
200+
.body()
201+
.transactions
202+
.iter()
203+
.any(|tx| *tx.tx_hash() == tx3_hash),
204+
"tx3 should go to a later block"
205+
);
206+
207+
let block2 = node.advance_block().await?;
208+
assert!(
209+
block2
210+
.block()
211+
.body()
212+
.transactions
213+
.iter()
214+
.any(|tx| *tx.tx_hash() == tx2_hash),
215+
"tx2 should be included in block 2"
216+
);
217+
assert!(
218+
!block2
219+
.block()
220+
.body()
221+
.transactions
222+
.iter()
223+
.any(|tx| *tx.tx_hash() == tx3_hash),
224+
"tx3 should still go after block 2"
225+
);
226+
227+
let block3 = node.advance_block().await?;
228+
assert!(
229+
block3
230+
.block()
231+
.body()
232+
.transactions
233+
.iter()
234+
.any(|tx| *tx.tx_hash() == tx3_hash),
235+
"tx3 should be included in block 3"
236+
);
237+
238+
Ok(())
239+
}
240+
241+
#[tokio::test]
242+
async fn test_without_block_uncompressed_size_limit_includes_all_transactions() -> eyre::Result<()>
243+
{
244+
reth_tracing::init_test_tracing();
245+
246+
let (_, mut nodes, _tasks, _, _) =
247+
setup::<FlashblocksContext>(1, optimism_payload_attributes, false).await?;
248+
let node = &mut nodes[0].node;
249+
250+
let (tx1, tx1_hash) = create_priority_transaction(0, 0, 50_000, 600_000, 100).await?;
251+
let (tx2, tx2_hash) = create_priority_transaction(1, 0, 50_000, 600_000, 90).await?;
252+
let (tx3, tx3_hash) = create_priority_transaction(2, 0, 50_000, 600_000, 80).await?;
253+
254+
assert_eq!(node.rpc.inject_tx(tx1).await?, tx1_hash);
255+
assert_eq!(node.rpc.inject_tx(tx2).await?, tx2_hash);
256+
assert_eq!(node.rpc.inject_tx(tx3).await?, tx3_hash);
257+
258+
let block = node.advance_block().await?;
259+
assert!(
260+
block
261+
.block()
262+
.body()
263+
.transactions
264+
.iter()
265+
.any(|tx| *tx.tx_hash() == tx1_hash),
266+
"tx1 should be included"
267+
);
268+
assert!(
269+
block
270+
.block()
271+
.body()
272+
.transactions
273+
.iter()
274+
.any(|tx| *tx.tx_hash() == tx2_hash),
275+
"tx2 should be included"
276+
);
277+
assert!(
278+
block
279+
.block()
280+
.body()
281+
.transactions
282+
.iter()
283+
.any(|tx| *tx.tx_hash() == tx3_hash),
284+
"tx3 should be included"
285+
);
286+
287+
Ok(())
288+
}
289+
116290
#[tokio::test]
117291
async fn test_invalidate_dup_tx_and_nullifier() -> eyre::Result<()> {
118292
reth_tracing::init_test_tracing();

0 commit comments

Comments
 (0)