test(exex): introduce utils for testing (#8636)

This commit is contained in:
Alexey Shekhirin
2024-06-06 14:28:28 +01:00
committed by GitHub
parent b11c83cee6
commit 40d8ac099f
12 changed files with 392 additions and 3 deletions

View File

@ -14,3 +14,8 @@ reth-tracing.workspace = true
eyre.workspace = true
futures.workspace = true
[dev-dependencies]
reth-exex-test-utils.workspace = true
tokio.workspace = true

View File

@ -36,6 +36,7 @@ async fn exex<Node: FullNodeComponents>(mut ctx: ExExContext<Node>) -> eyre::Res
ctx.events.send(ExExEvent::FinishedHeight(committed_chain.tip().number))?;
}
}
Ok(())
}
@ -50,3 +51,44 @@ fn main() -> eyre::Result<()> {
handle.wait_for_node_exit().await
})
}
#[cfg(test)]
mod tests {
use std::pin::pin;
use reth::providers::{BundleStateWithReceipts, Chain};
use reth_exex_test_utils::{test_exex_context, PollOnce};
#[tokio::test]
async fn exex() -> eyre::Result<()> {
// Initialize a test Execution Extension context with all dependencies
let (ctx, mut handle) = test_exex_context().await?;
// Save the current head of the chain to check the finished height against it later
let head = ctx.head;
// Send a notification to the Execution Extension that the chain has been committed
handle
.send_notification_chain_committed(Chain::from_block(
handle.genesis.clone(),
BundleStateWithReceipts::default(),
None,
))
.await?;
// Initialize the Execution Extension
let mut exex = pin!(super::exex_init(ctx).await?);
// Check that the Execution Extension did not emit any events until we polled it
handle.assert_events_empty();
// Poll the Execution Extension once to process incoming notifications
exex.poll_once().await;
// Check that the Execution Extension emitted a `FinishedHeight` event with the correct
// height
handle.assert_event_finished_height(head.number)?;
Ok(())
}
}