Skip to content

Commit

Permalink
dev: Decouple test environment from .env file (kkrt-labs#886)
Browse files Browse the repository at this point in the history
* Generate test RPCConfig via hardcoded socket address

* add cfg
  • Loading branch information
tcoratger authored Mar 22, 2024
1 parent b90dc19 commit 929e18c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/eth_rpc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,21 @@ impl RPCConfig {
}
Ok(config)
}

#[cfg(feature = "testing")]
pub fn new_test_config() -> Self {
// Hardcode the socket address for testing environment
Self::new("127.0.0.1:3030".to_string())
}

#[cfg(feature = "testing")]
pub fn new_test_config_from_port(port: u16) -> Self {
let mut config = Self::new_test_config();
// Remove port from socket address and replace it with provided port
let parts: Vec<&str> = config.socket_addr.split(':').collect();
if let Some(addr) = parts.first() {
config.socket_addr = format!("{}:{}", addr, port);
}
config
}
}
5 changes: 4 additions & 1 deletion src/test_utils/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ async fn get_next_port() -> u16 {
pub async fn start_kakarot_rpc_server(katana: &Katana) -> Result<(SocketAddr, ServerHandle), eyre::Report> {
Ok(run_server(
KakarotRpcModuleBuilder::new(katana.eth_provider()).rpc_module()?,
RPCConfig::from_port(get_next_port().await)?,
#[cfg(feature = "testing")]
RPCConfig::new_test_config_from_port(get_next_port().await),
#[cfg(not(feature = "testing"))]
RPCConfig::from_port(get_next_port().await),
)
.await?)
}

0 comments on commit 929e18c

Please sign in to comment.