Skip to content

Commit c2ebda7

Browse files
prestwichclaude
andauthored
fix(node-tests): adapt test infra to HostNotifier trait (#108)
* fix(node-tests): adapt test infra to HostNotifier trait * fix: group tokio imports into single use statement Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8f9f4f8 commit c2ebda7

6 files changed

Lines changed: 136 additions & 216 deletions

File tree

crates/node-tests/Cargo.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ 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
20+
signet-extract.workspace = true
2021
signet-genesis.workspace = true
21-
signet-host-reth.workspace = true
2222
signet-hot = { workspace = true, features = ["in-memory"] }
2323
signet-storage.workspace = true
2424
signet-storage-types.workspace = true
@@ -29,9 +29,7 @@ signet-zenith.workspace = true
2929
alloy.workspace = true
3030

3131
reth.workspace = true
32-
reth-exex.workspace = true
3332
reth-exex-test-utils.workspace = true
34-
reth-node-api.workspace = true
3533

3634
eyre.workspace = true
3735
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: 79 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,81 @@ 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::{
41+
sync::{mpsc, watch},
42+
task::JoinHandle,
43+
};
3844
use tracing::instrument;
3945

46+
/// A channel-backed [`HostNotifier`] for integration tests.
47+
///
48+
/// Receives [`HostNotification`]s from the test harness and yields them
49+
/// to the signet node's main loop.
50+
pub struct TestHostNotifier {
51+
receiver: mpsc::UnboundedReceiver<HostNotification<Chain>>,
52+
}
53+
54+
impl TestHostNotifier {
55+
/// Create a new test notifier from a receiver.
56+
pub const fn new(receiver: mpsc::UnboundedReceiver<HostNotification<Chain>>) -> Self {
57+
Self { receiver }
58+
}
59+
}
60+
61+
impl core::fmt::Debug for TestHostNotifier {
62+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
63+
f.debug_struct("TestHostNotifier").finish_non_exhaustive()
64+
}
65+
}
66+
67+
impl HostNotifier for TestHostNotifier {
68+
type Chain = Chain;
69+
type Error = core::convert::Infallible;
70+
71+
async fn next_notification(
72+
&mut self,
73+
) -> Option<Result<HostNotification<Self::Chain>, Self::Error>> {
74+
self.receiver.recv().await.map(Ok)
75+
}
76+
77+
fn set_head(&mut self, _block_number: u64) {}
78+
79+
fn set_backfill_thresholds(&mut self, _max_blocks: Option<u64>) {}
80+
81+
fn send_finished_height(&self, _block_number: u64) -> Result<(), Self::Error> {
82+
Ok(())
83+
}
84+
}
85+
4086
/// Signet Node test context
4187
///
4288
/// This contains the following:
4389
///
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
90+
/// - A channel sender for host notifications
91+
/// - The reth test components (for pool access)
4892
/// - A receiver for the node status (latest block processed)
4993
/// - Unified storage backed by in-memory hot and cold storage
5094
/// - An alloy provider connected to the Signet Node RPC,
@@ -53,10 +97,10 @@ use tracing::instrument;
5397
/// - A set of addresses for testing, each of which has a pre-existing balance
5498
/// on the Signet Node chain.
5599
pub struct SignetTestContext {
56-
/// The test exex handle
57-
pub handle: TestExExHandle,
100+
/// The notification sender for the test host notifier.
101+
pub sender: mpsc::UnboundedSender<HostNotification<Chain>>,
58102

59-
/// The components for the Signet Node instance
103+
/// The reth test components (for pool access).
60104
pub components: Adapter,
61105

62106
/// The Signet Node status receiver
@@ -102,12 +146,9 @@ impl SignetTestContext {
102146
#[instrument]
103147
pub async fn new() -> (Self, JoinHandle<eyre::Result<()>>) {
104148
let cfg = test_config();
105-
let (ctx, handle) = reth_exex_test_utils::test_exex_context().await.unwrap();
149+
let (ctx, _handle) = reth_exex_test_utils::test_exex_context().await.unwrap();
106150
let components = ctx.components.clone();
107151

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

@@ -152,11 +193,22 @@ impl SignetTestContext {
152193

153194
let alias_oracle: Arc<Mutex<HashSet<Address>>> = Arc::new(Mutex::new(HashSet::default()));
154195

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

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 {
200+
// Build the blob cacher from the reth test pool
201+
let blob_cacher = signet_blobber::BlobFetcher::builder()
202+
.with_config(cfg.block_extractor())
203+
.unwrap()
204+
.with_pool(components.pool().clone())
205+
.with_client(reqwest::Client::new())
206+
.build_cache()
207+
.unwrap()
208+
.spawn();
209+
210+
// Build ServeConfig from the test config's IPC endpoint
211+
let serve_config = ServeConfig {
160212
http: vec![],
161213
http_cors: None,
162214
ws: vec![],
@@ -165,13 +217,12 @@ impl SignetTestContext {
165217
};
166218

167219
let (node, mut node_status) = SignetNodeBuilder::new(cfg.clone())
168-
.with_notifier(decomposed.notifier)
220+
.with_notifier(notifier)
169221
.with_storage(Arc::clone(&storage))
170222
.with_alias_oracle(Arc::clone(&alias_oracle))
171223
.with_blob_cacher(blob_cacher)
172224
.with_serve_config(serve_config)
173-
.with_rpc_config(decomposed.rpc_config)
174-
.with_client(reqwest::Client::new())
225+
.with_rpc_config(StorageRpcConfig::default())
175226
.build()
176227
.await
177228
.unwrap();
@@ -199,7 +250,7 @@ impl SignetTestContext {
199250
.unwrap();
200251

201252
let this = Self {
202-
handle,
253+
sender,
203254
components,
204255
node_status,
205256
storage,
@@ -304,7 +355,8 @@ impl SignetTestContext {
304355
assert!(pool.get_blob(tx_hash).unwrap().is_some(), "Missing blob we just inserted");
305356
}
306357

307-
self.handle.notifications_tx.send(notification.notification.to_reth()).await.unwrap();
358+
let host_notification = to_host_notification(&notification.notification);
359+
self.sender.send(host_notification).unwrap();
308360
}
309361

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

0 commit comments

Comments
 (0)