Skip to content

Commit bd64901

Browse files
committed
Fix clippy recommendations
1 parent 77c0de1 commit bd64901

File tree

2 files changed

+46
-17
lines changed

2 files changed

+46
-17
lines changed

mithril-aggregator/src/event_store/database/repository.rs

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,38 @@ mod tests {
191191
let _event = persister.persist(message).unwrap();
192192
}
193193

194+
#[derive(PartialEq)]
195+
struct StakeSignerVersion {
196+
epoch: i64,
197+
version: String,
198+
total_epoch_stakes: i64,
199+
stakes_version: i64,
200+
stakes_ratio: String,
201+
pool_count: i64,
202+
}
203+
impl StakeSignerVersion {
204+
fn new(
205+
epoch: i64,
206+
version: &str,
207+
total_epoch_stakes: i64,
208+
stakes_version: i64,
209+
stakes_ratio: &str,
210+
pool_count: i64,
211+
) -> Self {
212+
Self {
213+
epoch,
214+
version: version.to_string(),
215+
total_epoch_stakes,
216+
stakes_version,
217+
stakes_ratio: stakes_ratio.to_string(),
218+
pool_count,
219+
}
220+
}
221+
}
222+
194223
fn get_all_registrations(
195224
connection: Arc<ConnectionThreadSafe>,
196-
) -> StdResult<Vec<(i64, String, i64, i64, String, i64)>> {
225+
) -> StdResult<Vec<StakeSignerVersion>> {
197226
let query = "select
198227
epoch,
199228
version,
@@ -205,12 +234,12 @@ mod tests {
205234
let mut statement = connection.prepare(query)?;
206235
let mut result = Vec::new();
207236
while let Ok(sqlite::State::Row) = statement.next() {
208-
result.push((
237+
result.push(StakeSignerVersion::new(
209238
statement.read::<i64, _>("epoch")?,
210-
statement.read::<String, _>("version")?,
239+
&statement.read::<String, _>("version")?,
211240
statement.read::<i64, _>("total_epoch_stakes")?,
212241
statement.read::<i64, _>("stakes_version")?,
213-
statement.read::<String, _>("stakes_ratio")?,
242+
&statement.read::<String, _>("stakes_ratio")?,
214243
statement.read::<i64, _>("pool_count")?,
215244
));
216245
}
@@ -229,9 +258,9 @@ mod tests {
229258

230259
let result = get_all_registrations(connection).unwrap();
231260

232-
assert!(result.contains(&(3, "0.2.234".to_string(), 15, 15, "100 %".to_string(), 1)));
233-
assert!(result.contains(&(4, "15.24.32".to_string(), 15, 15, "100 %".to_string(), 1)));
234-
assert!(result.contains(&(5, "0.4.789".to_string(), 15, 15, "100 %".to_string(), 1)));
261+
assert!(result.contains(&StakeSignerVersion::new(3, "0.2.234", 15, 15, "100 %", 1)));
262+
assert!(result.contains(&StakeSignerVersion::new(4, "15.24.32", 15, 15, "100 %", 1)));
263+
assert!(result.contains(&StakeSignerVersion::new(5, "0.4.789", 15, 15, "100 %", 1)));
235264
}
236265

237266
#[test]
@@ -245,8 +274,8 @@ mod tests {
245274
insert_registration_event(&persister, "9", "B", 31, "1.0.2");
246275
let result = get_all_registrations(connection).unwrap();
247276

248-
assert!(result.contains(&(8, "1.0.2".to_string(), 35, 35, "100 %".to_string(), 2)));
249-
assert!(result.contains(&(9, "1.0.2".to_string(), 87, 87, "100 %".to_string(), 2)));
277+
assert!(result.contains(&StakeSignerVersion::new(8, "1.0.2", 35, 35, "100 %", 2)));
278+
assert!(result.contains(&StakeSignerVersion::new(9, "1.0.2", 87, 87, "100 %", 2)));
250279
}
251280

252281
#[test]
@@ -259,8 +288,8 @@ mod tests {
259288
insert_registration_event(&persister, "8", "C", 80, "1.0.4");
260289
let result = get_all_registrations(connection).unwrap();
261290

262-
assert!(result.contains(&(8, "1.0.2".to_string(), 200, 120, "60 %".to_string(), 2)));
263-
assert!(result.contains(&(8, "1.0.4".to_string(), 200, 80, "40 %".to_string(), 1)));
291+
assert!(result.contains(&StakeSignerVersion::new(8, "1.0.2", 200, 120, "60 %", 2)));
292+
assert!(result.contains(&StakeSignerVersion::new(8, "1.0.4", 200, 80, "40 %", 1)));
264293
}
265294

266295
#[test]
@@ -274,10 +303,10 @@ mod tests {
274303
insert_registration_event(&persister, "9", "B", 12, "1.0.4");
275304
let result = get_all_registrations(connection).unwrap();
276305

277-
assert!(result.contains(&(8, "1.0.2".to_string(), 10, 6, "60 %".to_string(), 1)));
278-
assert!(result.contains(&(8, "1.0.4".to_string(), 10, 4, "40 %".to_string(), 1)));
279-
assert!(result.contains(&(9, "1.0.2".to_string(), 40, 28, "70 %".to_string(), 1)));
280-
assert!(result.contains(&(9, "1.0.4".to_string(), 40, 12, "30 %".to_string(), 1)));
306+
assert!(result.contains(&StakeSignerVersion::new(8, "1.0.2", 10, 6, "60 %", 1)));
307+
assert!(result.contains(&StakeSignerVersion::new(8, "1.0.4", 10, 4, "40 %", 1)));
308+
assert!(result.contains(&StakeSignerVersion::new(9, "1.0.2", 40, 28, "70 %", 1)));
309+
assert!(result.contains(&StakeSignerVersion::new(9, "1.0.4", 40, 12, "30 %", 1)));
281310
}
282311

283312
#[test]
@@ -292,7 +321,7 @@ mod tests {
292321

293322
let result = get_all_registrations(connection).unwrap();
294323

295-
assert!(result.contains(&(8, "1.0.3".to_string(), 7, 7, "100 %".to_string(), 1)));
324+
assert!(result.contains(&StakeSignerVersion::new(8, "1.0.3", 7, 7, "100 %", 1)));
296325
assert!(result.len() == 1);
297326
}
298327
}

mithril-aggregator/src/http_server/routes/signer_routes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub(crate) mod handlers {
127127
transmitter.send_event_message::<SignerWithStake>(
128128
"HTTP::signer_register",
129129
"register_signer",
130-
&signer_with_stake,
130+
signer_with_stake,
131131
headers,
132132
)
133133
}

0 commit comments

Comments
 (0)