From a2d9b6f9ce7ac54432e9635c60b38ef6d5e6ffe8 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 12 Oct 2017 23:35:52 +0200 Subject: [PATCH] remove RPC parameter leniency now that mist formats correctly (#6651) --- rpc/src/v1/types/block_number.rs | 14 +++++++++----- rpc/src/v1/types/bytes.rs | 20 +++----------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/rpc/src/v1/types/block_number.rs b/rpc/src/v1/types/block_number.rs index 334bf360d..9570f4420 100644 --- a/rpc/src/v1/types/block_number.rs +++ b/rpc/src/v1/types/block_number.rs @@ -82,9 +82,7 @@ impl<'a> Visitor<'a> for BlockNumberVisitor { _ if value.starts_with("0x") => u64::from_str_radix(&value[2..], 16).map(BlockNumber::Num).map_err(|e| { Error::custom(format!("Invalid block number: {}", e)) }), - _ => value.parse::().map(BlockNumber::Num).map_err(|e| { - Error::custom(format!("Invalid block number: {}", e)) - }), + _ => Err(Error::custom(format!("Invalid block number: missing 0x prefix"))), } } @@ -112,9 +110,15 @@ mod tests { #[test] fn block_number_deserialization() { - let s = r#"["0xa", "10", "latest", "earliest", "pending"]"#; + let s = r#"["0xa", "latest", "earliest", "pending"]"#; let deserialized: Vec = serde_json::from_str(s).unwrap(); - assert_eq!(deserialized, vec![BlockNumber::Num(10), BlockNumber::Num(10), BlockNumber::Latest, BlockNumber::Earliest, BlockNumber::Pending]) + assert_eq!(deserialized, vec![BlockNumber::Num(10), BlockNumber::Latest, BlockNumber::Earliest, BlockNumber::Pending]) + } + + #[test] + fn should_not_deserialize_decimal() { + let s = r#""10""#; + assert!(serde_json::from_str::(s).is_err()); } #[test] diff --git a/rpc/src/v1/types/bytes.rs b/rpc/src/v1/types/bytes.rs index 4bd10af44..fdbcb729b 100644 --- a/rpc/src/v1/types/bytes.rs +++ b/rpc/src/v1/types/bytes.rs @@ -74,13 +74,7 @@ impl<'a> Visitor<'a> for BytesVisitor { } fn visit_str(self, value: &str) -> Result where E: Error { - if value.is_empty() { - warn!( - target: "deprecated", - "Deserializing empty string as empty bytes. This is a non-standard behaviour that will be removed in future versions. Please update your code to send `0x` instead!" - ); - Ok(Bytes::new(Vec::new())) - } else if value.len() >= 2 && &value[0..2] == "0x" && value.len() & 1 == 0 { + if value.len() >= 2 && &value[0..2] == "0x" && value.len() & 1 == 0 { Ok(Bytes::new(FromHex::from_hex(&value[2..]).map_err(|e| Error::custom(format!("Invalid hex: {}", e)))?)) } else { Err(Error::custom("Invalid bytes format. Expected a 0x-prefixed hex string with even length")) @@ -108,8 +102,7 @@ mod tests { #[test] fn test_bytes_deserialize() { - // TODO [ToDr] Uncomment when Mist starts sending correct data - // let bytes1: Result = serde_json::from_str(r#""""#); + let bytes1: Result = serde_json::from_str(r#""""#); let bytes2: Result = serde_json::from_str(r#""0x123""#); let bytes3: Result = serde_json::from_str(r#""0xgg""#); @@ -117,19 +110,12 @@ mod tests { let bytes5: Bytes = serde_json::from_str(r#""0x12""#).unwrap(); let bytes6: Bytes = serde_json::from_str(r#""0x0123""#).unwrap(); - // assert!(bytes1.is_err()); + assert!(bytes1.is_err()); assert!(bytes2.is_err()); assert!(bytes3.is_err()); assert_eq!(bytes4, Bytes(vec![])); assert_eq!(bytes5, Bytes(vec![0x12])); assert_eq!(bytes6, Bytes(vec![0x1, 0x23])); } - - // TODO [ToDr] Remove when Mist starts sending correct data - #[test] - fn test_bytes_lenient_against_the_spec_deserialize_for_empty_string_for_mist_compatibility() { - let deserialized: Bytes = serde_json::from_str(r#""""#).unwrap(); - assert_eq!(deserialized, Bytes(Vec::new())); - } }