Skip to content

Commit 6a99b2e

Browse files
committed
fix(node-tests): adapt test infra to HostNotifier trait
1 parent e5acff8 commit 6a99b2e

6 files changed

Lines changed: 130 additions & 216 deletions

File tree

crates/node-tests/Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ homepage.workspace = true
99
repository.workspace = true
1010

1111
[dependencies]
12+
signet-blobber = { workspace = true, features = ["test-utils"] }
1213
signet-node.workspace = true
1314
signet-node-config = { workspace = true, features = ["test_utils"] }
15+
signet-node-types.workspace = true
1416
signet-rpc.workspace = true
1517

16-
signet-blobber.workspace = true
1718
signet-cold = { workspace = true, features = ["in-memory"] }
1819
signet-constants.workspace = true
19-
signet-evm.workspace = true
2020
signet-genesis.workspace = true
21-
signet-host-reth.workspace = true
2221
signet-hot = { workspace = true, features = ["in-memory"] }
2322
signet-storage.workspace = true
2423
signet-storage-types.workspace = true
@@ -29,9 +28,7 @@ signet-zenith.workspace = true
2928
alloy.workspace = true
3029

3130
reth.workspace = true
32-
reth-exex.workspace = true
3331
reth-exex-test-utils.workspace = true
34-
reth-node-api.workspace = true
3532

3633
eyre.workspace = true
3734
reqwest.workspace = true

crates/node-tests/src/blob_test_utils.rs

Lines changed: 0 additions & 23 deletions
This file was deleted.

crates/node-tests/src/context.rs

Lines changed: 77 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
HostBlockSpec, NotificationSpec, NotificationWithSidecars, RuBlockSpec,
3-
convert::ToRethPrimitive,
3+
convert::to_host_notification,
44
types::{CtxProvider, Log, TestCounterInstance, TestErc20Instance, TestLogInstance},
55
};
66
use alloy::{
@@ -14,37 +14,79 @@ use alloy::{
1414
},
1515
rpc::types::eth::{TransactionReceipt, TransactionRequest},
1616
};
17-
use reth::transaction_pool::{TransactionOrigin, TransactionPool, test_utils::MockTransaction};
18-
use reth_exex_test_utils::{Adapter, TestExExHandle};
19-
use reth_node_api::FullNodeComponents;
17+
use reth::{
18+
api::FullNodeComponents,
19+
transaction_pool::{TransactionOrigin, TransactionPool, test_utils::MockTransaction},
20+
};
21+
use reth_exex_test_utils::Adapter;
2022
use signet_cold::{ColdStorageReadHandle, mem::MemColdBackend};
21-
use signet_host_reth::decompose_exex_context;
2223
use signet_hot::{
2324
db::{HotDbRead, UnsafeDbWrite},
2425
mem::MemKv,
2526
};
2627
use signet_node::{NodeStatus, SignetNodeBuilder};
2728
use signet_node_config::test_utils::test_config;
29+
use signet_node_types::{HostNotification, HostNotifier};
30+
use signet_rpc::{ServeConfig, StorageRpcConfig};
2831
use signet_storage::{CancellationToken, HistoryRead, HistoryWrite, HotKv, UnifiedStorage};
2932
use signet_storage_types::{Account, BlockNumberList, DbSignetEvent, RecoveredTx, SealedHeader};
30-
use signet_test_utils::contracts::counter::COUNTER_DEPLOY_CODE;
33+
use signet_test_utils::{chain::Chain, contracts::counter::COUNTER_DEPLOY_CODE};
3134
use signet_types::constants::{HostPermitted, RollupPermitted, SignetSystemConstants};
3235
use signet_zenith::{HostOrders::OrdersInstance, RollupPassage::RollupPassageInstance};
3336
use std::sync::{
3437
Arc, Mutex,
3538
atomic::{AtomicU64, Ordering},
3639
};
37-
use tokio::{sync::watch, task::JoinHandle};
40+
use tokio::sync::{mpsc, watch};
41+
use tokio::task::JoinHandle;
3842
use tracing::instrument;
3943

44+
/// A channel-backed [`HostNotifier`] for integration tests.
45+
///
46+
/// Receives [`HostNotification`]s from the test harness and yields them
47+
/// to the signet node's main loop.
48+
pub struct TestHostNotifier {
49+
receiver: mpsc::UnboundedReceiver<HostNotification<Chain>>,
50+
}
51+
52+
impl TestHostNotifier {
53+
/// Create a new test notifier from a receiver.
54+
pub const fn new(receiver: mpsc::UnboundedReceiver<HostNotification<Chain>>) -> Self {
55+
Self { receiver }
56+
}
57+
}
58+
59+
impl core::fmt::Debug for TestHostNotifier {
60+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
61+
f.debug_struct("TestHostNotifier").finish_non_exhaustive()
62+
}
63+
}
64+
65+
impl HostNotifier for TestHostNotifier {
66+
type Chain = Chain;
67+
type Error = core::convert::Infallible;
68+
69+
async fn next_notification(
70+
&mut self,
71+
) -> Option<Result<HostNotification<Self::Chain>, Self::Error>> {
72+
self.receiver.recv().await.map(Ok)
73+
}
74+
75+
fn set_head(&mut self, _block_number: u64) {}
76+
77+
fn set_backfill_thresholds(&mut self, _max_blocks: Option<u64>) {}
78+
79+
fn send_finished_height(&self, _block_number: u64) -> Result<(), Self::Error> {
80+
Ok(())
81+
}
82+
}
83+
4084
/// Signet Node test context
4185
///
4286
/// This contains the following:
4387
///
44-
/// - Reth/ExEx context info
45-
/// - The test exex handle, which is used to send notifications to the signet
46-
/// instance.
47-
/// - The components for the Signet Node instance
88+
/// - A channel sender for host notifications
89+
/// - The reth test components (for pool access)
4890
/// - A receiver for the node status (latest block processed)
4991
/// - Unified storage backed by in-memory hot and cold storage
5092
/// - An alloy provider connected to the Signet Node RPC,
@@ -53,10 +95,10 @@ use tracing::instrument;
5395
/// - A set of addresses for testing, each of which has a pre-existing balance
5496
/// on the Signet Node chain.
5597
pub struct SignetTestContext {
56-
/// The test exex handle
57-
pub handle: TestExExHandle,
98+
/// The notification sender for the test host notifier.
99+
pub sender: mpsc::UnboundedSender<HostNotification<Chain>>,
58100

59-
/// The components for the Signet Node instance
101+
/// The reth test components (for pool access).
60102
pub components: Adapter,
61103

62104
/// The Signet Node status receiver
@@ -102,12 +144,9 @@ impl SignetTestContext {
102144
#[instrument]
103145
pub async fn new() -> (Self, JoinHandle<eyre::Result<()>>) {
104146
let cfg = test_config();
105-
let (ctx, handle) = reth_exex_test_utils::test_exex_context().await.unwrap();
147+
let (ctx, _handle) = reth_exex_test_utils::test_exex_context().await.unwrap();
106148
let components = ctx.components.clone();
107149

108-
// Decompose the ExEx context into notifier + configs
109-
let decomposed = decompose_exex_context(ctx);
110-
111150
// set up Signet Node storage
112151
let constants = cfg.constants().unwrap();
113152

@@ -152,11 +191,22 @@ impl SignetTestContext {
152191

153192
let alias_oracle: Arc<Mutex<HashSet<Address>>> = Arc::new(Mutex::new(HashSet::default()));
154193

155-
let blob_cacher = crate::test_blob_cacher(&cfg, decomposed.pool);
194+
// Create the test host notifier channel
195+
let (sender, receiver) = mpsc::unbounded_channel();
196+
let notifier = TestHostNotifier { receiver };
156197

157-
// Build serve config from the Signet test config rather than the
158-
// reth defaults (which have IPC/HTTP disabled).
159-
let serve_config = signet_rpc::ServeConfig {
198+
// Build the blob cacher from the reth test pool
199+
let blob_cacher = signet_blobber::BlobFetcher::builder()
200+
.with_config(cfg.block_extractor())
201+
.unwrap()
202+
.with_pool(components.pool().clone())
203+
.with_client(reqwest::Client::new())
204+
.build_cache()
205+
.unwrap()
206+
.spawn();
207+
208+
// Build ServeConfig from the test config's IPC endpoint
209+
let serve_config = ServeConfig {
160210
http: vec![],
161211
http_cors: None,
162212
ws: vec![],
@@ -165,13 +215,12 @@ impl SignetTestContext {
165215
};
166216

167217
let (node, mut node_status) = SignetNodeBuilder::new(cfg.clone())
168-
.with_notifier(decomposed.notifier)
218+
.with_notifier(notifier)
169219
.with_storage(Arc::clone(&storage))
170220
.with_alias_oracle(Arc::clone(&alias_oracle))
171221
.with_blob_cacher(blob_cacher)
172222
.with_serve_config(serve_config)
173-
.with_rpc_config(decomposed.rpc_config)
174-
.with_client(reqwest::Client::new())
223+
.with_rpc_config(StorageRpcConfig::default())
175224
.build()
176225
.await
177226
.unwrap();
@@ -199,7 +248,7 @@ impl SignetTestContext {
199248
.unwrap();
200249

201250
let this = Self {
202-
handle,
251+
sender,
203252
components,
204253
node_status,
205254
storage,
@@ -304,7 +353,8 @@ impl SignetTestContext {
304353
assert!(pool.get_blob(tx_hash).unwrap().is_some(), "Missing blob we just inserted");
305354
}
306355

307-
self.handle.notifications_tx.send(notification.notification.to_reth()).await.unwrap();
356+
let host_notification = to_host_notification(&notification.notification);
357+
self.sender.send(host_notification).unwrap();
308358
}
309359

310360
/// Send a notification to the Signet Node instance and wait for it to be

0 commit comments

Comments
 (0)