Skip to content

Commit

Permalink
Fixed 'mithril-end-to-end' clippy warnings from Rust 1.67.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jpraynaud committed Jan 26, 2023
1 parent f8a89a8 commit 72667f4
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 59 deletions.
34 changes: 17 additions & 17 deletions mithril-test-lab/mithril-end-to-end/src/devnet/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl PoolNode {
let party_id = content
.split('=')
.nth(1)
.ok_or(format!("could not get party_id from string '{}'", content))?;
.ok_or(format!("could not get party_id from string '{content}'"))?;

Ok(party_id.trim().to_string())
}
Expand Down Expand Up @@ -75,7 +75,7 @@ impl Devnet {

if artifacts_target_dir.exists() {
fs::remove_dir_all(&artifacts_target_dir)
.map_err(|e| format!("Previous artifacts dir removal failed: {}", e))?;
.map_err(|e| format!("Previous artifacts dir removal failed: {e}"))?;
}

let mut bootstrap_command = Command::new(&bootstrap_script_path);
Expand All @@ -96,10 +96,10 @@ impl Devnet {

bootstrap_command
.spawn()
.map_err(|e| format!("{} failed to start: {}", bootstrap_script, e))?
.map_err(|e| format!("{bootstrap_script} failed to start: {e}"))?
.wait()
.await
.map_err(|e| format!("{} failed to run: {}", bootstrap_script, e))?;
.map_err(|e| format!("{bootstrap_script} failed to run: {e}"))?;

Ok(Devnet {
artifacts_dir: artifacts_target_dir,
Expand All @@ -126,27 +126,27 @@ impl Devnet {
let bft_nodes = (1..=self.number_of_bft_nodes)
.into_iter()
.map(|n| BftNode {
db_path: self.artifacts_dir.join(format!("node-bft{}/db", n)),
db_path: self.artifacts_dir.join(format!("node-bft{n}/db")),
socket_path: self
.artifacts_dir
.join(format!("node-bft{}/ipc/node.sock", n)),
.join(format!("node-bft{n}/ipc/node.sock")),
})
.collect::<Vec<_>>();

let pool_nodes = (1..=self.number_of_pool_nodes)
.into_iter()
.map(|n| PoolNode {
db_path: self.artifacts_dir.join(format!("node-pool{}/db", n)),
db_path: self.artifacts_dir.join(format!("node-pool{n}/db")),
socket_path: self
.artifacts_dir
.join(format!("node-pool{}/ipc/node.sock", n)),
pool_env_path: self.artifacts_dir.join(format!("node-pool{}/pool.env", n)),
.join(format!("node-pool{n}/ipc/node.sock")),
pool_env_path: self.artifacts_dir.join(format!("node-pool{n}/pool.env")),
kes_secret_key_path: self
.artifacts_dir
.join(format!("node-pool{}/shelley/kes.skey", n)),
.join(format!("node-pool{n}/shelley/kes.skey")),
operational_certificate_path: self
.artifacts_dir
.join(format!("node-pool{}/shelley/node.cert", n)),
.join(format!("node-pool{n}/shelley/node.cert")),
})
.collect::<Vec<_>>();

Expand All @@ -168,10 +168,10 @@ impl Devnet {

run_command
.spawn()
.map_err(|e| format!("Failed to start the devnet: {}", e))?
.map_err(|e| format!("Failed to start the devnet: {e}"))?
.wait()
.await
.map_err(|e| format!("Error while starting the devnet: {}", e))?;
.map_err(|e| format!("Error while starting the devnet: {e}"))?;
Ok(())
}

Expand All @@ -187,10 +187,10 @@ impl Devnet {

stop_command
.spawn()
.map_err(|e| format!("Failed to stop the devnet: {}", e))?
.map_err(|e| format!("Failed to stop the devnet: {e}"))?
.wait()
.await
.map_err(|e| format!("Error while stopping the devnet: {}", e))?;
.map_err(|e| format!("Error while stopping the devnet: {e}"))?;
Ok(())
}

Expand All @@ -206,10 +206,10 @@ impl Devnet {

run_command
.spawn()
.map_err(|e| format!("Failed to delegate stakes to the pools: {}", e))?
.map_err(|e| format!("Failed to delegate stakes to the pools: {e}"))?
.wait()
.await
.map_err(|e| format!("Error while delegating stakes to the pools: {}", e))?;
.map_err(|e| format!("Error while delegating stakes to the pools: {e}"))?;
Ok(())
}
}
Expand Down
45 changes: 20 additions & 25 deletions mithril-test-lab/mithril-end-to-end/src/end_to_end_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async fn wait_for_enough_immutable(db_directory: &Path) -> Result<(), String> {
}

async fn wait_for_epoch_settings(aggregator_endpoint: &str) -> Result<EpochSettings, String> {
let url = format!("{}/epoch-settings", aggregator_endpoint);
let url = format!("{aggregator_endpoint}/epoch-settings");
info!("Waiting for the aggregator to expose epoch settings");

match attempt!(20, Duration::from_millis(1000), {
Expand All @@ -138,7 +138,7 @@ async fn wait_for_epoch_settings(aggregator_endpoint: &str) -> Result<EpochSetti
let epoch_settings = response
.json::<EpochSettings>()
.await
.map_err(|e| format!("Invalid EpochSettings body : {}", e))?;
.map_err(|e| format!("Invalid EpochSettings body : {e}"))?;
info!("Aggregator ready"; "epoch_settings" => #?epoch_settings);
Ok(Some(epoch_settings))
}
Expand All @@ -157,8 +157,7 @@ async fn wait_for_epoch_settings(aggregator_endpoint: &str) -> Result<EpochSetti
AttemptResult::Ok(epoch_settings) => Ok(epoch_settings),
AttemptResult::Err(error) => Err(error),
AttemptResult::Timeout() => Err(format!(
"Timeout exhausted for aggregator to be up, no response from `{}`",
url
"Timeout exhausted for aggregator to be up, no response from `{url}`"
)),
}
}
Expand All @@ -183,7 +182,7 @@ async fn wait_for_target_epoch(
}
}
Ok(None) => Ok(None),
Err(err) => Err(format!("Could not query current epoch: {}", err)),
Err(err) => Err(format!("Could not query current epoch: {err}")),
}
}) {
AttemptResult::Ok(_) => {
Expand Down Expand Up @@ -242,7 +241,7 @@ async fn update_protocol_parameters(aggregator: &mut Aggregator) -> Result<(), S
}

async fn assert_node_producing_snapshot(aggregator_endpoint: &str) -> Result<String, String> {
let url = format!("{}/snapshots", aggregator_endpoint);
let url = format!("{aggregator_endpoint}/snapshots");
info!("Waiting for the aggregator to produce a snapshot");

// todo: reduce the number of attempts if we can reduce the delay between two immutables
Expand All @@ -252,11 +251,11 @@ async fn assert_node_producing_snapshot(aggregator_endpoint: &str) -> Result<Str
StatusCode::OK => match response.json::<Vec<Snapshot>>().await.as_deref() {
Ok([snapshot, ..]) => Ok(Some(snapshot.digest.clone())),
Ok(&[]) => Ok(None),
Err(err) => Err(format!("Invalid snapshot body : {}", err,)),
Err(err) => Err(format!("Invalid snapshot body : {err}",)),
},
s => Err(format!("Unexpected status code from Aggregator: {}", s)),
s => Err(format!("Unexpected status code from Aggregator: {s}")),
},
Err(err) => Err(format!("Request to `{}` failed: {}", url, err)),
Err(err) => Err(format!("Request to `{url}` failed: {err}")),
}
}) {
AttemptResult::Ok(digest) => {
Expand All @@ -265,8 +264,7 @@ async fn assert_node_producing_snapshot(aggregator_endpoint: &str) -> Result<Str
}
AttemptResult::Err(error) => Err(error),
AttemptResult::Timeout() => Err(format!(
"Timeout exhausted assert_node_producing_snapshot, no response from `{}`",
url
"Timeout exhausted assert_node_producing_snapshot, no response from `{url}`"
)),
}
}
Expand All @@ -276,7 +274,7 @@ async fn assert_signer_is_signing_snapshot(
digest: &str,
expected_epoch_min: Epoch,
) -> Result<String, String> {
let url = format!("{}/snapshot/{}", aggregator_endpoint, digest);
let url = format!("{aggregator_endpoint}/snapshot/{digest}");
info!(
"Asserting the aggregator is signing the snapshot message `{}` with an expected min epoch of `{}`",
digest,
Expand All @@ -290,16 +288,15 @@ async fn assert_signer_is_signing_snapshot(
Ok(snapshot) => match snapshot.beacon.epoch {
epoch if epoch >= expected_epoch_min => Ok(Some(snapshot)),
epoch => Err(format!(
"Minimum expected snapshot epoch not reached : {} < {}",
epoch, expected_epoch_min
"Minimum expected snapshot epoch not reached : {epoch} < {expected_epoch_min}"
)),
},
Err(err) => Err(format!("Invalid snapshot body : {}", err,)),
Err(err) => Err(format!("Invalid snapshot body : {err}",)),
},
StatusCode::NOT_FOUND => Ok(None),
s => Err(format!("Unexpected status code from Aggregator: {}", s)),
s => Err(format!("Unexpected status code from Aggregator: {s}")),
},
Err(err) => Err(format!("Request to `{}` failed: {}", url, err)),
Err(err) => Err(format!("Request to `{url}` failed: {err}")),
}
}) {
AttemptResult::Ok(snapshot) => {
Expand All @@ -309,8 +306,7 @@ async fn assert_signer_is_signing_snapshot(
}
AttemptResult::Err(error) => Err(error),
AttemptResult::Timeout() => Err(format!(
"Timeout exhausted assert_signer_is_signing_snapshot, no response from `{}`",
url
"Timeout exhausted assert_signer_is_signing_snapshot, no response from `{url}`"
)),
}
}
Expand All @@ -320,19 +316,19 @@ async fn assert_is_creating_certificate_with_enough_signers(
certificate_hash: &str,
total_signers_expected: usize,
) -> Result<(), String> {
let url = format!("{}/certificate/{}", aggregator_endpoint, certificate_hash);
let url = format!("{aggregator_endpoint}/certificate/{certificate_hash}");

match attempt!(10, Duration::from_millis(1000), {
match reqwest::get(url.clone()).await {
Ok(response) => match response.status() {
StatusCode::OK => match response.json::<Certificate>().await {
Ok(certificate) => Ok(Some(certificate)),
Err(err) => Err(format!("Invalid snapshot body : {}", err,)),
Err(err) => Err(format!("Invalid snapshot body : {err}",)),
},
StatusCode::NOT_FOUND => Ok(None),
s => Err(format!("Unexpected status code from Aggregator: {}", s)),
s => Err(format!("Unexpected status code from Aggregator: {s}")),
},
Err(err) => Err(format!("Request to `{}` failed: {}", url, err)),
Err(err) => Err(format!("Request to `{url}` failed: {err}")),
}
}) {
AttemptResult::Ok(certificate) => {
Expand All @@ -354,8 +350,7 @@ async fn assert_is_creating_certificate_with_enough_signers(
}
AttemptResult::Err(error) => Err(error),
AttemptResult::Timeout() => Err(format!(
"Timeout exhausted assert_is_creating_certificate, no response from `{}`",
url
"Timeout exhausted assert_is_creating_certificate, no response from `{url}`"
)),
}
}
Expand Down
9 changes: 4 additions & 5 deletions mithril-test-lab/mithril-end-to-end/src/mithril/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ impl Aggregator {
Ok(())
} else {
Err(match status.code() {
Some(c) => format!(
"`mithril-aggregator genesis bootstrap` exited with code: {}",
c
),
Some(c) => {
format!("`mithril-aggregator genesis bootstrap` exited with code: {c}")
}
None => {
"`mithril-aggregator genesis bootstrap` was terminated with a signal"
.to_string()
Expand All @@ -98,7 +97,7 @@ impl Aggregator {
process
.kill()
.await
.map_err(|e| format!("Could not kill aggregator: {:?}", e))?;
.map_err(|e| format!("Could not kill aggregator: {e:?}"))?;
}
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions mithril-test-lab/mithril-end-to-end/src/mithril/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ impl Client {
Ok(())
} else {
self.command
.tail_logs(Some(format!("mithril-client {:?}", args).as_str()), 20)
.tail_logs(Some(format!("mithril-client {args:?}").as_str()), 20)
.await?;

Err(match status.code() {
Some(c) => format!("mithril-client exited with code: {}", c),
Some(c) => format!("mithril-client exited with code: {c}"),
None => "mithril-client was terminated with a signal".to_string(),
})
}
Expand Down
4 changes: 2 additions & 2 deletions mithril-test-lab/mithril-end-to-end/src/mithril/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Signer {
) -> Result<Self, String> {
let party_id = pool_node.party_id()?;
let magic_id = DEVNET_MAGIC_ID.to_string();
let data_stores_path = format!("./stores/signer-{}", party_id);
let data_stores_path = format!("./stores/signer-{party_id}");
let mut env = HashMap::from([
("NETWORK", "devnet"),
("RUN_INTERVAL", "300"),
Expand Down Expand Up @@ -53,7 +53,7 @@ impl Signer {
let args = vec!["-vvv"];

let mut command = MithrilCommand::new("mithril-signer", work_dir, bin_dir, env, &args)?;
command.set_log_name(format!("mithril-signer-{}", party_id).as_str());
command.set_log_name(format!("mithril-signer-{party_id}").as_str());

Ok(Self {
party_id,
Expand Down
8 changes: 4 additions & 4 deletions mithril-test-lab/mithril-end-to-end/src/utils/file_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub async fn tail(file_path: &Path, number_of_line: u64) -> Result<String, Strin
.map_err(|e| format!("Failed to tail file `{}`: {}", file_path.display(), e))?;

String::from_utf8(tail_result.stdout)
.map_err(|e| format!("Failed to parse tail output to utf8: {}", e))
.map_err(|e| format!("Failed to parse tail output to utf8: {e}"))
}

#[cfg(test)]
Expand All @@ -35,17 +35,17 @@ mod tests {
.join(subfolder_name);
if temp_dir.exists() {
fs::remove_dir_all(&temp_dir)
.unwrap_or_else(|_| panic!("Could not remove dir {:?}", temp_dir));
.unwrap_or_else(|_| panic!("Could not remove dir {temp_dir:?}"));
}
fs::create_dir_all(&temp_dir)
.unwrap_or_else(|_| panic!("Could not create dir {:?}", temp_dir));
.unwrap_or_else(|_| panic!("Could not create dir {temp_dir:?}"));

temp_dir
}

fn write_file(path: &Path, file_content: &str) {
let mut source_file = File::create(path).unwrap();
write!(source_file, "{}", file_content).unwrap();
write!(source_file, "{file_content}").unwrap();
}

#[tokio::test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl MithrilCommand {
default_args: &[&str],
) -> Result<MithrilCommand, String> {
let process_path = bin_dir.canonicalize().unwrap().join(name);
let log_path = work_dir.join(format!("{}.log", name));
let log_path = work_dir.join(format!("{name}.log"));

// ugly but it's far easier for callers to manipulate string literals
let mut env_vars: HashMap<String, String> = env_vars
Expand Down Expand Up @@ -53,7 +53,7 @@ impl MithrilCommand {
}

pub fn set_log_name(&mut self, name: &str) {
self.log_path = self.work_dir.join(format!("{}.log", name));
self.log_path = self.work_dir.join(format!("{name}.log"));
}

pub fn set_env_var(&mut self, name: &str, value: &str) {
Expand Down
3 changes: 1 addition & 2 deletions mithril-test-lab/mithril-end-to-end/src/utils/spec_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ mod tests {
let elapsed = now.elapsed().as_millis();
assert!(
(10..=12).contains(&elapsed),
"Failure, after one loop the elapsed time was not ~10ms, elapsed: {}",
elapsed
"Failure, after one loop the elapsed time was not ~10ms, elapsed: {elapsed}"
);
}
}

0 comments on commit 72667f4

Please sign in to comment.