Skip to content

Commit

Permalink
update effected tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smatthewenglish committed Jun 30, 2024
1 parent 0a0f206 commit 88099f6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 38 deletions.
2 changes: 1 addition & 1 deletion crates/node/builder/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ where
let mut server_config = config.rpc.rpc_server_config();

let cloned_modules = modules.clone();
let launch_rpc = server_config.build_ws_http(&cloned_modules).await?;
let launch_rpc = server_config.start_ws_http(&cloned_modules).await?;

if let Some(path) = launch_rpc.ipc_endpoint() {
info!(target: "reth::cli", %path, "RPC IPC server started");
Expand Down
46 changes: 19 additions & 27 deletions crates/rpc/rpc-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,8 @@
//! evm_config,
//! )
//! .build(transports);
//! let handle = RpcServerConfig::default()
//! .with_http(ServerBuilder::default())
//! .start(transport_modules)
//! .await
//! .unwrap();
//! let mut handle = RpcServerConfig::default().with_http(ServerBuilder::default());
//! handle.start_ws_http(&transport_modules).await.unwrap();
//! }
//! ```
//!
Expand Down Expand Up @@ -139,10 +136,10 @@
//!
//! // start the servers
//! let auth_config = AuthServerConfig::builder(JwtSecret::random()).build();
//! let config = RpcServerConfig::default();
//! let mut config = RpcServerConfig::default();
//!
//! let (_rpc_handle, _auth_handle) =
//! try_join!(modules.start_server(config), auth_module.start_server(auth_config),)
//! try_join!(config.start_ws_http(&modules), auth_module.start_server(auth_config),)
//! .unwrap();
//! }
//! ```
Expand Down Expand Up @@ -254,12 +251,10 @@ where
{
let module_config = module_config.into();
let mut server_config = server_config.into();

let value = RpcModuleBuilder::new(provider, pool, network, executor, events, evm_config)
let modules = RpcModuleBuilder::new(provider, pool, network, executor, events, evm_config)
.build(module_config);

let output: RpcServerHandle = server_config.build_ws_http(&value).await?;
Ok(output)
let handle: RpcServerHandle = server_config.start_ws_http(&modules).await?;
Ok(handle)
}

/// A builder type to configure the RPC module: See [`RpcModule`]
Expand Down Expand Up @@ -1249,8 +1244,6 @@ impl RpcServerConfig {
}

/// Returns true if any server is configured.
///
/// If no server is configured, no server will be launched on [`RpcServerConfig::start`].
pub const fn has_server(&self) -> bool {
self.http_server_config.is_some() ||
self.ws_server_config.is_some() ||
Expand Down Expand Up @@ -1285,7 +1278,7 @@ impl RpcServerConfig {
/// Builds the ws and http server(s).
///
/// If both are on the same port, they are combined into one server.
pub async fn build_ws_http(
pub async fn start_ws_http(
&mut self,
modules: &TransportRpcModules,
) -> Result<RpcServerHandle, RpcError> {
Expand Down Expand Up @@ -1314,7 +1307,7 @@ impl RpcServerConfig {
http_cors_domains: Some(http_cors.clone()),
ws_cors_domains: Some(ws_cors.clone()),
}
.into())
.into());
}
Some(ws_cors)
}
Expand Down Expand Up @@ -1362,9 +1355,9 @@ impl RpcServerConfig {
http: http_handle,
ws: ws_handle,
ipc_endpoint: None,
ipc: None,
ipc: None,
jwt_secret: self.jwt_secret,
})
});
}

let mut http_local_addr = None;
Expand Down Expand Up @@ -1417,18 +1410,17 @@ impl RpcServerConfig {
http_local_addr = Some(local_addr);
http_server = Some(server);
}

http_handle =
Some(http_server.expect("REASON").start(modules.http.clone().expect("REASON")));
ws_handle = Some(ws_server.expect("REASON").start(modules.ws.clone().expect("REASON")));

http_handle = http_server
.map(|http_server| http_server.start(modules.http.clone().expect("http server error")));
ws_handle = ws_server
.map(|ws_server| ws_server.start(modules.ws.clone().expect("ws server error")));
Ok(RpcServerHandle {
http_local_addr,
ws_local_addr,
http: http_handle,
ws: ws_handle,
ipc_endpoint: None,
ipc: None,
ipc: None,
jwt_secret: self.jwt_secret,
})
}
Expand Down Expand Up @@ -1596,7 +1588,7 @@ impl TransportRpcModules {
/// Returns [Ok(false)] if no http transport is configured.
pub fn merge_http(&mut self, other: impl Into<Methods>) -> Result<bool, RegisterMethodError> {
if let Some(ref mut http) = self.http {
return http.merge(other.into()).map(|_| true)
return http.merge(other.into()).map(|_| true);
}
Ok(false)
}
Expand All @@ -1608,7 +1600,7 @@ impl TransportRpcModules {
/// Returns [Ok(false)] if no ws transport is configured.
pub fn merge_ws(&mut self, other: impl Into<Methods>) -> Result<bool, RegisterMethodError> {
if let Some(ref mut ws) = self.ws {
return ws.merge(other.into()).map(|_| true)
return ws.merge(other.into()).map(|_| true);
}
Ok(false)
}
Expand All @@ -1620,7 +1612,7 @@ impl TransportRpcModules {
/// Returns [Ok(false)] if no ipc transport is configured.
pub fn merge_ipc(&mut self, other: impl Into<Methods>) -> Result<bool, RegisterMethodError> {
if let Some(ref mut ipc) = self.ipc {
return ipc.merge(other.into()).map(|_| true)
return ipc.merge(other.into()).map(|_| true);
}
Ok(false)
}
Expand Down
10 changes: 5 additions & 5 deletions crates/rpc/rpc-builder/tests/it/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async fn test_http_addr_in_use() {
let builder = test_rpc_builder();
let server = builder.build(TransportRpcModuleConfig::set_http(vec![RethRpcModule::Admin]));
let mut config = RpcServerConfig::http(Default::default()).with_http_address(addr);
let result = config.build_ws_http(&server).await;
let result = config.start_ws_http(&server).await;
let err = result.unwrap_err();
assert!(is_addr_in_use_kind(&err, ServerKind::Http(addr)), "{err}");
}
Expand All @@ -38,7 +38,7 @@ async fn test_ws_addr_in_use() {
let builder = test_rpc_builder();
let server = builder.build(TransportRpcModuleConfig::set_ws(vec![RethRpcModule::Admin]));
let mut config = RpcServerConfig::ws(Default::default()).with_ws_address(addr);
let result = config.build_ws_http(&server).await;
let result = config.start_ws_http(&server).await;
let err = result.unwrap_err();
assert!(is_addr_in_use_kind(&err, ServerKind::WS(addr)), "{err}");
}
Expand All @@ -63,7 +63,7 @@ async fn test_launch_same_port_different_modules() {
.with_ws_address(addr)
.with_http(Default::default())
.with_http_address(addr);
let res = config.build_ws_http(&server).await;
let res = config.start_ws_http(&server).await;
let err = res.unwrap_err();
assert!(matches!(
err,
Expand All @@ -85,7 +85,7 @@ async fn test_launch_same_port_same_cors() {
.with_cors(Some("*".to_string()))
.with_http_cors(Some("*".to_string()))
.with_http_address(addr);
let res = config.build_ws_http(&server).await;
let res = config.start_ws_http(&server).await;
assert!(res.is_ok());
}

Expand All @@ -103,7 +103,7 @@ async fn test_launch_same_port_different_cors() {
.with_cors(Some("*".to_string()))
.with_http_cors(Some("example".to_string()))
.with_http_address(addr);
let res = config.build_ws_http(&server).await;
let res = config.start_ws_http(&server).await;
let err = res.unwrap_err();
assert!(matches!(
err,
Expand Down
8 changes: 4 additions & 4 deletions crates/rpc/rpc-builder/tests/it/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ pub async fn launch_http(modules: impl Into<RpcModuleSelection>) -> RpcServerHan
let builder = test_rpc_builder();
let server = builder.build(TransportRpcModuleConfig::set_http(modules));
let mut config = RpcServerConfig::http(Default::default()).with_http_address(test_address());
config.build_ws_http(&server).await.unwrap()
config.start_ws_http(&server).await.unwrap()
}

/// Launches a new server with ws only with the given modules
pub async fn launch_ws(modules: impl Into<RpcModuleSelection>) -> RpcServerHandle {
let builder = test_rpc_builder();
let server = builder.build(TransportRpcModuleConfig::set_ws(modules));
let mut config = RpcServerConfig::ws(Default::default()).with_http_address(test_address());
config.build_ws_http(&server).await.unwrap()
config.start_ws_http(&server).await.unwrap()
}

/// Launches a new server with http and ws and with the given modules
Expand All @@ -74,7 +74,7 @@ pub async fn launch_http_ws(modules: impl Into<RpcModuleSelection>) -> RpcServer
.with_ws_address(test_address())
.with_http(Default::default())
.with_http_address(test_address());
config.build_ws_http(&server).await.unwrap()
config.start_ws_http(&server).await.unwrap()
}

/// Launches a new server with http and ws and with the given modules on the same port.
Expand All @@ -88,7 +88,7 @@ pub async fn launch_http_ws_same_port(modules: impl Into<RpcModuleSelection>) ->
.with_ws_address(addr)
.with_http(Default::default())
.with_http_address(addr);
config.build_ws_http(&server).await.unwrap()
config.start_ws_http(&server).await.unwrap()
}

/// Returns an [`RpcModuleBuilder`] with testing components.
Expand Down
2 changes: 1 addition & 1 deletion examples/rpc-db/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async fn main() -> eyre::Result<()> {
// Start the server & keep it alive
let mut server_args =
RpcServerConfig::http(Default::default()).with_http_address("0.0.0.0:8545".parse()?);
let _handle = server_args.build_ws_http(&server).await?;
let _handle = server_args.start_ws_http(&server).await?;
futures::future::pending::<()>().await;

Ok(())
Expand Down

0 comments on commit 88099f6

Please sign in to comment.