diff --git a/bridges/centralized-ethereum/src/actors/dr_sender/tests.rs b/bridges/centralized-ethereum/src/actors/dr_sender/tests.rs index 58ae02e43..cc43e1957 100644 --- a/bridges/centralized-ethereum/src/actors/dr_sender/tests.rs +++ b/bridges/centralized-ethereum/src/actors/dr_sender/tests.rs @@ -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]); } @@ -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]); } @@ -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]); } @@ -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]); } @@ -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]); } diff --git a/bridges/centralized-ethereum/src/actors/watch_dog.rs b/bridges/centralized-ethereum/src/actors/watch_dog.rs index 9f38ab409..db209c1b5 100644 --- a/bridges/centralized-ethereum/src/actors/watch_dog.rs +++ b/bridges/centralized-ethereum/src/actors/watch_dog.rs @@ -3,6 +3,7 @@ use crate::{ config::Config, }; use actix::prelude::*; +use core::fmt; use std::{ sync::Arc, time::{Duration, Instant}, @@ -78,18 +79,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"), } } } @@ -240,8 +241,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}"); @@ -355,10 +356,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) => {