Skip to content

Commit

Permalink
Clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jfldde committed Oct 7, 2024
1 parent 0f01fdb commit 44a8ecf
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ impl BitcoinNodeCluster {
let mut cluster = Self {
inner: Vec::with_capacity(n_nodes),
};
for config in ctx.config.bitcoin.iter() {
for config in &ctx.config.bitcoin {
let node = BitcoinNode::new(config, Arc::clone(&ctx.docker)).await?;
cluster.inner.push(node)
cluster.inner.push(node);
}

Ok(cluster)
Expand Down Expand Up @@ -327,7 +327,7 @@ impl BitcoinNodeCluster {
if i != j {
let ip = match &to_node.spawn_output {
SpawnOutput::Container(container) => container.ip.clone(),
_ => "127.0.0.1".to_string(),
SpawnOutput::Child(_) => "127.0.0.1".to_string(),
};

let add_node_arg = format!("{}:{}", ip, to_node.config.p2p_port);
Expand Down
2 changes: 1 addition & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct Client {

impl Client {
pub fn new(host: &str, port: u16) -> Result<Self> {
let host = format!("http://{}:{}", host, port);
let host = format!("http://{host}:{port}");
let client = HttpClientBuilder::default()
.request_timeout(Duration::from_secs(120))
.build(host)?;
Expand Down
10 changes: 5 additions & 5 deletions src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl DockerEnv {
}

async fn create_network(docker: &Docker, test_case_id: &str) -> Result<(String, String)> {
let network_name = format!("test_network_{}", test_case_id);
let network_name = format!("test_network_{test_case_id}");
let options = CreateNetworkOptions {
name: network_name.clone(),
check_duplicate: true,
Expand All @@ -95,15 +95,15 @@ impl DockerEnv {
let exposed_ports: HashMap<String, HashMap<(), ()>> = config
.ports
.iter()
.map(|port| (format!("{}/tcp", port), HashMap::new()))
.map(|port| (format!("{port}/tcp"), HashMap::new()))
.collect();

let port_bindings: HashMap<String, Option<Vec<PortBinding>>> = config
.ports
.iter()
.map(|port| {
(
format!("{}/tcp", port),
format!("{port}/tcp"),
Some(vec![PortBinding {
host_ip: Some("0.0.0.0".to_string()),
host_port: Some(port.to_string()),
Expand Down Expand Up @@ -196,7 +196,7 @@ impl DockerEnv {
return Ok(());
}

println!("Pulling image: {}", image);
println!("Pulling image: {image}");
let options = Some(CreateImageOptions {
from_image: image,
..Default::default()
Expand All @@ -207,7 +207,7 @@ impl DockerEnv {
match result {
Ok(info) => {
if let (Some(status), Some(progress)) = (info.status, info.progress) {
print!("\r{}: {} ", status, progress);
print!("\r{status}: {progress} ");
stdout().flush().unwrap();
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ impl<C: Config> Node<C> {
let kind = C::node_kind();

config.node_config().map_or(Ok(Vec::new()), |node_config| {
let config_path = dir.join(format!("{}_config.toml", kind));
let config_path = dir.join(format!("{kind}_config.toml"));
config_to_file(node_config, &config_path)
.with_context(|| format!("Error writing {} config to file", kind))?;
.with_context(|| format!("Error writing {kind} config to file"))?;

Ok(vec![
format!("--{}-config-path", kind),
format!("--{kind}-config-path"),
config_path.display().to_string(),
])
})
Expand All @@ -102,7 +102,7 @@ impl<C: Config> Node<C> {
// Handle full node not having any node config
let node_config_args = Self::get_node_config_args(config)?;

let rollup_config_path = dir.join(format!("{}_rollup_config.toml", kind));
let rollup_config_path = dir.join(format!("{kind}_rollup_config.toml"));
config_to_file(&config.rollup_config(), &rollup_config_path)?;

Command::new(citrea)
Expand All @@ -120,7 +120,7 @@ impl<C: Config> Node<C> {
.stderr(Stdio::from(stderr_file))
.kill_on_drop(true)
.spawn()
.context(format!("Failed to spawn {} process", kind))
.context(format!("Failed to spawn {kind} process"))
.map(SpawnOutput::Child)
}

Expand Down Expand Up @@ -229,7 +229,7 @@ where
async fn start(&mut self, new_config: Option<Self::Config>) -> Result<()> {
let config = self.config_mut();
if let Some(new_config) = new_config {
*config = new_config
*config = new_config;
}
*self.spawn_output() = Self::spawn(config)?;
self.wait_for_ready(None).await
Expand Down
17 changes: 8 additions & 9 deletions src/test_case.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! This module provides the TestCaseRunner and TestCase trait for running and defining test cases.
//! This module provides the `TestCaseRunner` and `TestCase` trait for running and defining test cases.
//! It handles setup, execution, and cleanup of test environments.
use std::{
Expand Down Expand Up @@ -36,7 +36,7 @@ use crate::{
pub struct TestCaseRunner<T: TestCase>(T);

impl<T: TestCase> TestCaseRunner<T> {
/// Creates a new TestCaseRunner with the given test case.
/// Creates a new `TestCaseRunner`` with the given test case.
pub fn new(test_case: T) -> Self {
Self(test_case)
}
Expand Down Expand Up @@ -85,7 +85,7 @@ impl<T: TestCase> TestCaseRunner<T> {

if let Err(_) | Ok(Err(_)) = result {
if let Err(e) = f.dump_log() {
eprintln!("Error dumping log: {}", e);
eprintln!("Error dumping log: {e}");
}
}

Expand All @@ -100,8 +100,7 @@ impl<T: TestCase> TestCaseRunner<T> {
Err(panic_error) => {
let panic_msg = panic_error
.downcast_ref::<String>()
.map(|s| s.to_string())
.unwrap_or_else(|| "Unknown panic".to_string());
.map_or_else(|| "Unknown panic".to_string(), ToString::to_string);
bail!(panic_msg)
}
}
Expand Down Expand Up @@ -138,7 +137,7 @@ impl<T: TestCase> TestCaseRunner<T> {
env: env.bitcoin().clone(),
idx: i,
..bitcoin.clone()
})
});
}

// Target first bitcoin node as DA for now
Expand All @@ -158,7 +157,7 @@ impl<T: TestCase> TestCaseRunner<T> {
..da_config.clone()
},
storage: StorageConfig {
path: dbs_dir.join(format!("{}-db", node_kind)),
path: dbs_dir.join(format!("{node_kind}-db")),
db_max_open_files: None,
},
rpc: RpcConfig {
Expand Down Expand Up @@ -193,7 +192,7 @@ impl<T: TestCase> TestCaseRunner<T> {
..da_config.clone()
},
storage: StorageConfig {
path: dbs_dir.join(format!("{}-db", node_kind)),
path: dbs_dir.join(format!("{node_kind}-db")),
db_max_open_files: None,
},
rpc: RpcConfig {
Expand All @@ -219,7 +218,7 @@ impl<T: TestCase> TestCaseRunner<T> {
..da_config.clone()
},
storage: StorageConfig {
path: dbs_dir.join(format!("{}-db", node_kind)),
path: dbs_dir.join(format!("{node_kind}-db")),
db_max_open_files: None,
},
rpc: RpcConfig {
Expand Down
5 changes: 2 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ pub fn get_stderr_path(dir: &Path) -> PathBuf {
/// Get genesis path from resources
/// TODO: assess need for customable genesis path in e2e tests
pub fn get_default_genesis_path() -> PathBuf {
let workspace_root = get_workspace_root();
let mut path = workspace_root.to_path_buf();
let mut path = get_workspace_root();
path.push("resources");
path.push("genesis");
path.push("bitcoin-regtest");
Expand Down Expand Up @@ -101,7 +100,7 @@ pub fn tail_file(path: &Path, lines: usize) -> Result<()> {
}

for line in last_lines {
println!("{}", line);
println!("{line}");
}

Ok(())
Expand Down

0 comments on commit 44a8ecf

Please sign in to comment.