Skip to content

Commit 5c5d1f8

Browse files
committed
Fix clippy warnings for aggregator & client
1 parent 425e79a commit 5c5d1f8

File tree

8 files changed

+22
-41
lines changed

8 files changed

+22
-41
lines changed

mithril-network/mithril-aggregator/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ test:
1818
${CARGO} test
1919

2020
check:
21-
${CARGO} check --all-targets
22-
${CARGO} clippy --all-targets
21+
${CARGO} check --all-features
22+
${CARGO} clippy --all-features
2323

2424
help:
2525
@${CARGO} run -- -h

mithril-network/mithril-aggregator/src/apispec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl<'a> APISpec<'a> {
9191
None => Err("empty body expected".to_string()),
9292
}
9393
} else {
94-
match &serde_json::from_slice(&body) {
94+
match &serde_json::from_slice(body) {
9595
Ok(value) => self.validate_conformity(value, response_schema),
9696
Err(_) => Err("non empty body expected".to_string()),
9797
}

mithril-network/mithril-aggregator/src/entities.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ pub struct Certificate {
121121

122122
impl Certificate {
123123
/// Certificate factory
124+
#[allow(clippy::too_many_arguments)]
124125
pub fn new(
125126
hash: String,
126127
previous_hash: String,
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
pub mod apispec;
2-
mod dependency;
32
pub mod entities;
43
pub mod fake_data;
5-
pub mod http_server;
6-
mod snapshot_store;
74
pub mod snapshotter;

mithril-network/mithril-aggregator/src/main.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod snapshot_store;
99
mod snapshotter;
1010

1111
use clap::Parser;
12-
use config;
12+
1313
use log::debug;
1414
use std::env;
1515
use std::sync::Arc;
@@ -61,7 +61,7 @@ async fn main() {
6161
.init();
6262

6363
// Load config
64-
let run_mode = env::var("RUN_MODE").unwrap_or_else(|_| args.run_mode.into());
64+
let run_mode = env::var("RUN_MODE").unwrap_or(args.run_mode);
6565
debug!("Run Mode: {}", run_mode);
6666
let config: Config = config::Config::builder()
6767
.add_source(config::File::with_name(&format!("./config/{}.json", run_mode)).required(false))
@@ -84,10 +84,8 @@ async fn main() {
8484

8585
// Start snapshot uploader
8686
let handle = tokio::spawn(async move {
87-
let snapshotter = Snapshotter::new(
88-
args.snapshot_interval.clone() * 1000,
89-
args.db_directory.clone(),
90-
);
87+
let snapshotter =
88+
Snapshotter::new(args.snapshot_interval * 1000, args.db_directory.clone());
9189
snapshotter.run().await
9290
});
9391

mithril-network/mithril-aggregator/src/snapshotter.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use cloud_storage::object_access_control::NewObjectAccessControl;
66
use cloud_storage::Client;
77
use flate2::write::GzEncoder;
88
use flate2::Compression;
9-
use hex;
9+
1010
use log::error;
1111
use log::info;
12-
use serde_json;
12+
1313
use sha2::{Digest, Sha256};
1414
use std::env;
1515
use std::ffi::OsStr;
@@ -37,10 +37,11 @@ pub struct Snapshotter {
3737
#[derive(Debug)]
3838
struct SnapshotError {
3939
/// Detailed error
40+
#[allow(dead_code)] // Indirectly used in Snapshotter::run when logging the error
4041
reason: String,
4142
}
4243

43-
impl std::convert::From<io::Error> for SnapshotError {
44+
impl From<io::Error> for SnapshotError {
4445
fn from(err: io::Error) -> Self {
4546
SnapshotError {
4647
reason: err.to_string(),
@@ -114,11 +115,7 @@ impl Snapshotter {
114115
let tar_gz = match File::create(&path) {
115116
Err(e) => {
116117
return Err(SnapshotError {
117-
reason: format!(
118-
"cannot create archive {}: {}",
119-
&path.to_str().unwrap(),
120-
e.to_string()
121-
),
118+
reason: format!("cannot create archive {}: {}", &path.to_str().unwrap(), e),
122119
})
123120
}
124121
Ok(f) => f,
@@ -222,15 +219,11 @@ impl Progress {
222219

223220
impl std::fmt::Display for Progress {
224221
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
225-
write!(
226-
f,
227-
"{}",
228-
format!("{}/{} ({}%)", self.index, self.total, self.percent())
229-
)
222+
write!(f, "{}/{} ({}%)", self.index, self.total, self.percent())
230223
}
231224
}
232225

233-
fn compute_hash(entries: &Vec<&DirEntry>) -> [u8; 32] {
226+
fn compute_hash(entries: &[&DirEntry]) -> [u8; 32] {
234227
let mut hasher = Sha256::new();
235228
let mut progress = Progress {
236229
index: 0,
@@ -277,9 +270,9 @@ mod tests {
277270
total: 7000,
278271
};
279272

280-
assert_eq!(false, progress.report(1));
281-
assert_eq!(false, progress.report(4));
282-
assert_eq!(true, progress.report(350));
283-
assert_eq!(false, progress.report(351));
273+
assert!(!progress.report(1));
274+
assert!(!progress.report(4));
275+
assert!(progress.report(350));
276+
assert!(!progress.report(351));
284277
}
285278
}

mithril-network/mithril-client/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ test:
2323
${CARGO} test
2424

2525
check:
26-
${CARGO} check
27-
${CARGO} clippy
26+
${CARGO} check --all-features
27+
${CARGO} clippy --all-features
2828

2929
clean:
3030
${CARGO} clean
@@ -33,4 +33,4 @@ help:
3333
@${CARGO} run -- -h
3434

3535
doc:
36-
${CARGO} doc --no-deps --open
36+
${CARGO} doc --no-deps --open

mithril-network/mithril-client/src/client.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,10 @@ pub(crate) fn convert_to_field_items(
148148
#[cfg(test)]
149149
mod tests {
150150
use super::*;
151-
use std::sync::Arc;
152151

153152
use crate::aggregator::MockAggregatorHandler;
154153
use mithril_aggregator::fake_data;
155154

156-
fn setup_test() -> Arc<Config> {
157-
Arc::new(Config {
158-
network: "testnet".to_string(),
159-
aggregator_endpoint: "".to_string(),
160-
})
161-
}
162-
163155
#[tokio::test]
164156
async fn test_list_snapshots_ok() {
165157
let network = "testnet".to_string();

0 commit comments

Comments
 (0)