From 44a8ecf98a066356a1b34d24ab883afa440c9d3a Mon Sep 17 00:00:00 2001 From: jfldde <168934971+jfldde@users.noreply.github.com> Date: Mon, 7 Oct 2024 09:20:50 +0100 Subject: [PATCH] Clippy fixes --- src/bitcoin.rs | 6 +++--- src/client.rs | 2 +- src/docker.rs | 10 +++++----- src/node.rs | 12 ++++++------ src/test_case.rs | 17 ++++++++--------- src/utils.rs | 5 ++--- 6 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/bitcoin.rs b/src/bitcoin.rs index c149368..19c83bd 100644 --- a/src/bitcoin.rs +++ b/src/bitcoin.rs @@ -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) @@ -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); diff --git a/src/client.rs b/src/client.rs index 341a1de..fe87110 100644 --- a/src/client.rs +++ b/src/client.rs @@ -19,7 +19,7 @@ pub struct Client { impl Client { pub fn new(host: &str, port: u16) -> Result { - let host = format!("http://{}:{}", host, port); + let host = format!("http://{host}:{port}"); let client = HttpClientBuilder::default() .request_timeout(Duration::from_secs(120)) .build(host)?; diff --git a/src/docker.rs b/src/docker.rs index e248a52..f30eaec 100644 --- a/src/docker.rs +++ b/src/docker.rs @@ -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, @@ -95,7 +95,7 @@ impl DockerEnv { let exposed_ports: HashMap> = config .ports .iter() - .map(|port| (format!("{}/tcp", port), HashMap::new())) + .map(|port| (format!("{port}/tcp"), HashMap::new())) .collect(); let port_bindings: HashMap>> = config @@ -103,7 +103,7 @@ impl DockerEnv { .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()), @@ -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() @@ -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(); } } diff --git a/src/node.rs b/src/node.rs index 949d13d..ccc5cea 100644 --- a/src/node.rs +++ b/src/node.rs @@ -77,12 +77,12 @@ impl Node { 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(), ]) }) @@ -102,7 +102,7 @@ impl Node { // 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) @@ -120,7 +120,7 @@ impl Node { .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) } @@ -229,7 +229,7 @@ where async fn start(&mut self, new_config: Option) -> 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 diff --git a/src/test_case.rs b/src/test_case.rs index 736f6b3..2bd0932 100644 --- a/src/test_case.rs +++ b/src/test_case.rs @@ -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::{ @@ -36,7 +36,7 @@ use crate::{ pub struct TestCaseRunner(T); impl TestCaseRunner { - /// 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) } @@ -85,7 +85,7 @@ impl TestCaseRunner { if let Err(_) | Ok(Err(_)) = result { if let Err(e) = f.dump_log() { - eprintln!("Error dumping log: {}", e); + eprintln!("Error dumping log: {e}"); } } @@ -100,8 +100,7 @@ impl TestCaseRunner { Err(panic_error) => { let panic_msg = panic_error .downcast_ref::() - .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) } } @@ -138,7 +137,7 @@ impl TestCaseRunner { env: env.bitcoin().clone(), idx: i, ..bitcoin.clone() - }) + }); } // Target first bitcoin node as DA for now @@ -158,7 +157,7 @@ impl TestCaseRunner { ..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 { @@ -193,7 +192,7 @@ impl TestCaseRunner { ..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 { @@ -219,7 +218,7 @@ impl TestCaseRunner { ..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 { diff --git a/src/utils.rs b/src/utils.rs index f5060a5..e05b683 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -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"); @@ -101,7 +100,7 @@ pub fn tail_file(path: &Path, lines: usize) -> Result<()> { } for line in last_lines { - println!("{}", line); + println!("{line}"); } Ok(())