Skip to content

Commit 912e172

Browse files
authored
Add a test to ensure a FCU call without block delay can be built by the builder (#231)
* Add test to ensure the builder can still produce blocks with short fcu spans * Rename test * Fix
1 parent 4d4ee74 commit 912e172

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

tests/common/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use std::net::TcpListener;
2828
use std::path::PathBuf;
2929
use std::str::FromStr;
3030
use std::sync::{Arc, LazyLock};
31-
use std::time::SystemTime;
31+
use std::time::{Duration, SystemTime};
3232
use std::{fs::File, io::BufReader, time::UNIX_EPOCH};
3333
use testcontainers::core::ContainerPort;
3434
use testcontainers::core::client::docker_client_instance;
@@ -385,6 +385,7 @@ pub struct SimpleBlockGenerator {
385385
timestamp: u64,
386386
genesis: Genesis,
387387
current_block_number: u64,
388+
block_time: Duration,
388389
}
389390

390391
impl SimpleBlockGenerator {
@@ -400,9 +401,14 @@ impl SimpleBlockGenerator {
400401
timestamp: genesis.timestamp,
401402
genesis,
402403
current_block_number: 0,
404+
block_time: Duration::from_secs(1),
403405
}
404406
}
405407

408+
pub fn set_block_time(&mut self, block_time: Duration) {
409+
self.block_time = block_time;
410+
}
411+
406412
/// Initialize the block generator by fetching the latest block
407413
pub async fn init(&mut self) -> eyre::Result<()> {
408414
let latest_block = self.engine_api.latest().await?.expect("block not found");

tests/fcu_no_block_time_delay.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
mod common;
2+
3+
use common::RollupBoostTestHarnessBuilder;
4+
use common::proxy::ProxyHandler;
5+
use futures::FutureExt;
6+
use serde_json::Value;
7+
use std::pin::Pin;
8+
use std::sync::Arc;
9+
use std::time::Duration;
10+
11+
// TODO: Use the same implementation as in builder_full_delay.rs
12+
struct DelayHandler {
13+
delay: Duration,
14+
}
15+
16+
impl DelayHandler {
17+
pub fn new(delay: Duration) -> Self {
18+
Self { delay }
19+
}
20+
}
21+
22+
impl ProxyHandler for DelayHandler {
23+
fn handle(
24+
&self,
25+
_method: String,
26+
_params: Value,
27+
_result: Value,
28+
) -> Pin<Box<dyn Future<Output = Option<Value>> + Send>> {
29+
let delay = self.delay;
30+
async move {
31+
tokio::time::sleep(delay).await;
32+
None
33+
}
34+
.boxed()
35+
}
36+
}
37+
38+
#[tokio::test]
39+
async fn fcu_no_block_time_delay() -> eyre::Result<()> {
40+
// This test ensures that even with delay in between RB and the external builder (50ms) the
41+
// builder can still build the block if there is an avalanche of FCUs without block time delay
42+
let delay = DelayHandler::new(Duration::from_millis(50));
43+
44+
let harness = RollupBoostTestHarnessBuilder::new("fcu_no_block_time_delay")
45+
.proxy_handler(Arc::new(delay))
46+
.build()
47+
.await?;
48+
let mut block_generator = harness.block_generator().await?;
49+
block_generator.set_block_time(Duration::from_millis(0));
50+
51+
for _ in 0..30 {
52+
let (_block, block_creator) = block_generator.generate_block(false).await?;
53+
assert!(
54+
block_creator.is_builder(),
55+
"Block creator should be the builder"
56+
);
57+
}
58+
59+
Ok(())
60+
}

0 commit comments

Comments
 (0)