From d9787f95ff440ed211413ee9a69eded39db1ea45 Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Thu, 17 Oct 2024 21:53:12 -0400 Subject: [PATCH] rpc: fix tests --- rpc/types/src/base.rs | 2 +- rpc/types/src/json.rs | 8 ++++---- rpc/types/src/misc/address_type.rs | 12 +++++++++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/rpc/types/src/base.rs b/rpc/types/src/base.rs index 407b8c1..89eafc5 100644 --- a/rpc/types/src/base.rs +++ b/rpc/types/src/base.rs @@ -164,7 +164,7 @@ impl AccessResponseBase { /// use cuprate_rpc_types::{misc::*, base::*}; /// /// assert_eq!(AccessResponseBase::OK_UNTRUSTED, AccessResponseBase { - /// response_base: ResponseBase::ok_untrusted(), + /// response_base: ResponseBase::OK_UNTRUSTED, /// credits: 0, /// top_hash: "".into(), /// }); diff --git a/rpc/types/src/json.rs b/rpc/types/src/json.rs index 2b1e378..ff309f1 100644 --- a/rpc/types/src/json.rs +++ b/rpc/types/src/json.rs @@ -658,7 +658,7 @@ define_request_and_response! { connections: vec![ ConnectionInfo { address: "3evk3kezfjg44ma6tvesy7rbxwwpgpympj45xar5fo4qajrsmkoaqdqd.onion:18083".into(), - address_type: 4, + address_type: cuprate_rpc_types::misc::AddressType::Tor, avg_download: 0, avg_upload: 0, connection_id: "22ef856d0f1d44cc95e84fecfd065fe2".into(), @@ -685,7 +685,7 @@ define_request_and_response! { }, ConnectionInfo { address: "4iykytmumafy5kjahdqc7uzgcs34s2vwsadfjpk4znvsa5vmcxeup2qd.onion:18083".into(), - address_type: 4, + address_type: cuprate_rpc_types::misc::AddressType::Tor, avg_download: 0, avg_upload: 0, connection_id: "c7734e15936f485a86d2b0534f87e499".into(), @@ -1251,7 +1251,7 @@ define_request_and_response! { SyncInfoPeer { info: ConnectionInfo { address: "142.93.128.65:44986".into(), - address_type: 1, + address_type: AddressType::Ipv4, avg_download: 1, avg_upload: 1, connection_id: "a5803c4c2dac49e7b201dccdef54c862".into(), @@ -1280,7 +1280,7 @@ define_request_and_response! { SyncInfoPeer { info: ConnectionInfo { address: "4iykytmumafy5kjahdqc7uzgcs34s2vwsadfjpk4znvsa5vmcxeup2qd.onion:18083".into(), - address_type: 4, + address_type: AddressType::Tor, avg_download: 0, avg_upload: 0, connection_id: "277f7c821bc546878c8bd29977e780f5".into(), diff --git a/rpc/types/src/misc/address_type.rs b/rpc/types/src/misc/address_type.rs index ca9f837..ff2b382 100644 --- a/rpc/types/src/misc/address_type.rs +++ b/rpc/types/src/misc/address_type.rs @@ -20,7 +20,7 @@ use cuprate_epee_encoding::{ )] #[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "serde", serde(untagged))] +#[cfg_attr(feature = "serde", serde(untagged, try_from = "u8", into = "u8"))] #[repr(u8)] pub enum AddressType { #[default] @@ -80,6 +80,16 @@ impl From for u8 { } } +impl TryFrom for AddressType { + type Error = u8; + fn try_from(value: u8) -> Result { + match Self::from_u8(value) { + Some(s) => Ok(s), + None => Err(value), + } + } +} + #[cfg(feature = "epee")] impl EpeeValue for AddressType { const MARKER: Marker = u8::MARKER;