Skip to content

Commit

Permalink
chore: cargo clippy --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
guidiaz committed Sep 24, 2024
1 parent 19072d0 commit e5d219c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
12 changes: 6 additions & 6 deletions bridges/centralized-ethereum/src/actors/dr_sender/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use witnet_data_structures::chain::{RADAggregate, RADRequest, RADRetrieve, RADTa
#[test]
fn deserialize_empty_dr() {
// An empty data request is invalid with error 0xE0: BridgeMalformedRequest
let err = deserialize_and_validate_dr_bytes(&[], 1).unwrap_err();
let err = deserialize_and_validate_dr_bytes(&[], 1, 1).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 224]);
}

#[test]
fn deserialize_dr_not_protobuf() {
// A malformed data request is invalid with error 0xE0: BridgeMalformedRequest
let err = deserialize_and_validate_dr_bytes(&[1, 2, 3, 4], 1).unwrap_err();
let err = deserialize_and_validate_dr_bytes(&[1, 2, 3, 4], 1, 1).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 224]);
}

Expand Down Expand Up @@ -55,7 +55,7 @@ fn deserialize_dr_high_value() {
let dro_bytes = dro.to_pb_bytes().unwrap();
// Setting the maximum allowed value to 1 nanowit below that will result in an error 0xE1:
// BridgePoorIncentives
let err = deserialize_and_validate_dr_bytes(&dro_bytes, total_value - 1).unwrap_err();
let err = deserialize_and_validate_dr_bytes(&dro_bytes, total_value - 1, 1).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 225]);
}

Expand All @@ -78,7 +78,7 @@ fn deserialize_dr_collateral_one_nanowit() {
assert_eq!(total_value, 20_000_000);

let dro_bytes = dro.to_pb_bytes().unwrap();
let err = deserialize_and_validate_dr_bytes(&dro_bytes, total_value).unwrap_err();
let err = deserialize_and_validate_dr_bytes(&dro_bytes, total_value, 1).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 224]);
}

Expand All @@ -95,7 +95,7 @@ fn deserialize_dr_value_overflow() {
};

let dro_bytes = dro.to_pb_bytes().unwrap();
let err = deserialize_and_validate_dr_bytes(&dro_bytes, 1).unwrap_err();
let err = deserialize_and_validate_dr_bytes(&dro_bytes, 1, 1).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 224]);
}

Expand All @@ -115,6 +115,6 @@ fn deserialize_and_validate_dr_bytes_wip_0022() {
let dro_bytes = dro.to_pb_bytes().unwrap();
let witnet_dr_max_value_nanowits = 100_000_000_000;
let err =
deserialize_and_validate_dr_bytes(&dro_bytes, witnet_dr_max_value_nanowits).unwrap_err();
deserialize_and_validate_dr_bytes(&dro_bytes, witnet_dr_max_value_nanowits, 1).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 224]);
}
35 changes: 16 additions & 19 deletions bridges/centralized-ethereum/src/actors/watch_dog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::{
config::Config,
};
use actix::prelude::*;
use core::fmt;
use std::{
sync::Arc,
time::{Duration, Instant},
sync::Arc, time::{Duration, Instant}
};
use web3::{contract::Contract, transports::Http, types::H160};
use witnet_net::client::tcp::{jsonrpc, JsonRpcClient};
Expand Down Expand Up @@ -78,18 +78,18 @@ enum WatchDogStatus {
UpAndRunning,
}

impl WatchDogStatus {
fn to_string(&self) -> String {
impl fmt::Display for WatchDogStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
WatchDogStatus::EvmDisconnect => "evm-disconnect".to_string(),
WatchDogStatus::EvmErrors => format!("evm-errors"),
WatchDogStatus::EvmSyncing => "evm-syncing".to_string(),
WatchDogStatus::WitAlmostSynced => "wit-almost-synced".to_string(),
WatchDogStatus::WitDisconnect => "wit-disconnect".to_string(),
WatchDogStatus::WitErrors => format!("wit-errors"),
WatchDogStatus::WitSyncing => "wit-syncing".to_string(),
WatchDogStatus::WitWaitingConsensus => "wit-waiting-consensus".to_string(),
WatchDogStatus::UpAndRunning => "up-and-running".to_string(),
WatchDogStatus::EvmDisconnect => write!(f, "evm-disconnect"),
WatchDogStatus::EvmErrors => write!(f, "evm-errors"),
WatchDogStatus::EvmSyncing => write!(f, "evm-syncing"),
WatchDogStatus::WitAlmostSynced => write!(f, "wit-almost-synced"),
WatchDogStatus::WitDisconnect => write!(f, "wit-disconnect"),
WatchDogStatus::WitErrors => write!(f, "wit-errors"),
WatchDogStatus::WitSyncing => write!(f, "wit-syncing"),
WatchDogStatus::WitWaitingConsensus => write!(f, "wit-waiting-consensus"),
WatchDogStatus::UpAndRunning => write!(f, "up-and-running"),
}
}
}
Expand Down Expand Up @@ -240,8 +240,8 @@ impl WatchDog {
}

metrics.push_str(&format!("\"runningSecs\": {running_secs}, "));
metrics.push_str(&format!("\"status\": \"{}\"", status.to_string()));
metrics.push_str("}");
metrics.push_str(&format!("\"status\": \"{}\"", status));
metrics.push('}');

log::info!("{metrics}");

Expand Down Expand Up @@ -355,10 +355,7 @@ async fn fetch_wit_info(
};
match res {
Ok(value) => match value.get("total") {
Some(value) => match value.as_f64() {
Some(value) => Some(value / 1000000000.0),
None => None,
},
Some(value) => value.as_f64().map(|value| value / 1000000000.0),
None => None,
},
Err(err) => {
Expand Down

0 comments on commit e5d219c

Please sign in to comment.