WIP1: implementing JSON-RPC calls over Unix Sockets
This commit is contained in:
@@ -2,6 +2,7 @@ use std::net::SocketAddr;
|
||||
use std::path::PathBuf;
|
||||
use jsonrpsee::server::{ServerBuilder, ServerHandle};
|
||||
use jsonrpsee::RpcModule;
|
||||
use reth_ipc::server::Builder as IpcServerBuilder;
|
||||
|
||||
use crate::rpc::{RpcServer, RpcServerImpl};
|
||||
|
||||
@@ -27,24 +28,25 @@ pub async fn start_rpc_server(addr: SocketAddr, base_dir: PathBuf, backend: crat
|
||||
Ok(handle)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::time::Duration;
|
||||
/// Start the JSON-RPC IPC server on the specified Unix socket endpoint
|
||||
pub async fn start_rpc_ipc_server(
|
||||
endpoint: String,
|
||||
base_dir: PathBuf,
|
||||
backend: crate::options::BackendType,
|
||||
admin_secret: String,
|
||||
) -> Result<ServerHandle, Box<dyn std::error::Error + Send + Sync>> {
|
||||
// Create the RPC server implementation
|
||||
let rpc_impl = RpcServerImpl::new(base_dir, backend, admin_secret);
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_rpc_server_startup() {
|
||||
let addr = "127.0.0.1:0".parse().unwrap(); // Use port 0 for auto-assignment
|
||||
let base_dir = PathBuf::from("/tmp/test_rpc");
|
||||
let backend = crate::options::BackendType::Redb; // Default for test
|
||||
// Create the RPC module
|
||||
let mut module = RpcModule::new(());
|
||||
module.merge(RpcServer::into_rpc(rpc_impl))?;
|
||||
|
||||
let handle = start_rpc_server(addr, base_dir, backend, "test-admin".to_string()).await.unwrap();
|
||||
// Build the IPC server and start it
|
||||
let server = IpcServerBuilder::default().build(endpoint.clone());
|
||||
let handle = server.start(module).await?;
|
||||
|
||||
// Give the server a moment to start
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
println!("RPC IPC server started on {}", endpoint);
|
||||
|
||||
// Stop the server
|
||||
handle.stop().unwrap();
|
||||
handle.stopped().await;
|
||||
}
|
||||
Ok(handle)
|
||||
}
|
||||
Reference in New Issue
Block a user