From 5fbb5b075f10b9ab8df6ec826ed043eb3e19baa6 Mon Sep 17 00:00:00 2001 From: Clara van Staden Date: Thu, 17 Nov 2022 15:16:41 +0200 Subject: [PATCH] Fixes failure tests resulting in stack overflow error. (#5) Co-authored-by: claravanstaden --- ssz-rs/src/de.rs | 16 +++++++++------- ssz-rs/tests/basic_vector.rs | 2 -- ssz-rs/tests/bitlist.rs | 2 -- ssz-rs/tests/bitvector.rs | 2 -- ssz-rs/tests/boolean.rs | 3 +-- ssz-rs/tests/containers.rs | 2 -- ssz-rs/tests/uints.rs | 3 +-- 7 files changed, 11 insertions(+), 19 deletions(-) diff --git a/ssz-rs/src/de.rs b/ssz-rs/src/de.rs index 0d7a489b..0c8d1a39 100644 --- a/ssz-rs/src/de.rs +++ b/ssz-rs/src/de.rs @@ -2,6 +2,7 @@ use crate::ser::BYTES_PER_LENGTH_OFFSET; use crate::SimpleSerialize; use crate::std::{Vec, vec, Debug, Display, Formatter}; +#[derive(Debug)] pub enum DeserializeError { InputTooShort, ExtraInput, @@ -11,15 +12,16 @@ pub enum DeserializeError { IllegalType { bound: usize }, } -impl Debug for DeserializeError { - fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { - write!(f, "{:?}", self) - } -} - impl Display for DeserializeError { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { - write!(f, "{:?}", self) + match *self { + DeserializeError::InputTooShort => write!(f, "InputTooShort"), + DeserializeError::ExtraInput => write!(f, "ExtraInput"), + DeserializeError::InvalidInput => write!(f, "InvalidInput"), + DeserializeError::IOError => write!(f, "IOError"), + DeserializeError::TypeBoundsViolated { bound, len } => write!(f, "TypeBoundsViolated bound: {} len {}", bound, len), + DeserializeError::IllegalType { bound } => write!(f, "IllegalType bound: {}", bound), + } } } diff --git a/ssz-rs/tests/basic_vector.rs b/ssz-rs/tests/basic_vector.rs index 05d060f5..c1e80bfd 100644 --- a/ssz-rs/tests/basic_vector.rs +++ b/ssz-rs/tests/basic_vector.rs @@ -22175,7 +22175,6 @@ fn test_basic_vector_vec_uint32_3_zero() { assert_eq!(root, expected_root); } -/* #[test] #[should_panic] fn test_basic_vector_vec_uint16_2_max_one_byte_less() { @@ -30018,4 +30017,3 @@ fn test_basic_vector_vec_uint16_3_nil() { deserialize::>(&encoding); } -*/ diff --git a/ssz-rs/tests/bitlist.rs b/ssz-rs/tests/bitlist.rs index 923419ef..6192a74f 100644 --- a/ssz-rs/tests/bitlist.rs +++ b/ssz-rs/tests/bitlist.rs @@ -5507,7 +5507,6 @@ fn test_bitlist_bitlist_1_zero_4() { assert_eq!(root, expected_root); } -/* #[test] #[should_panic] fn test_bitlist_bitlist_1_but_2() { @@ -5647,4 +5646,3 @@ fn test_bitlist_bitlist_no_delimiter_zeroes() { deserialize::>(&encoding); } -*/ diff --git a/ssz-rs/tests/bitvector.rs b/ssz-rs/tests/bitvector.rs index 4cc18af7..0c43d787 100644 --- a/ssz-rs/tests/bitvector.rs +++ b/ssz-rs/tests/bitvector.rs @@ -799,7 +799,6 @@ fn test_bitvector_bitvec_8_max() { assert_eq!(root, expected_root); } -/* #[test] #[should_panic] fn test_bitvector_bitvec_9_max_8() { @@ -1109,4 +1108,3 @@ fn test_bitvector_bitvec_16_random_8() { deserialize::>(&encoding); } -*/ diff --git a/ssz-rs/tests/boolean.rs b/ssz-rs/tests/boolean.rs index 993e3f19..bdb8f117 100644 --- a/ssz-rs/tests/boolean.rs +++ b/ssz-rs/tests/boolean.rs @@ -41,7 +41,6 @@ fn test_boolean_false() { assert_eq!(root, expected_root); } -/* #[test] #[should_panic] fn test_boolean_byte_0x80() { @@ -80,4 +79,4 @@ fn test_boolean_byte_rev_nibble() { ); deserialize::(&encoding); -}*/ +} diff --git a/ssz-rs/tests/containers.rs b/ssz-rs/tests/containers.rs index c12b66fc..98f5a219 100644 --- a/ssz-rs/tests/containers.rs +++ b/ssz-rs/tests/containers.rs @@ -22202,7 +22202,6 @@ fn test_containers_bits_struct_one_chaos_2() { assert_eq!(root, expected_root); } -/* #[test] #[should_panic] fn test_containers_bits_struct_offset_6_zeroed() { @@ -22386,4 +22385,3 @@ fn test_containers_complex_test_struct_extra_byte() { deserialize::(&encoding); } -*/ diff --git a/ssz-rs/tests/uints.rs b/ssz-rs/tests/uints.rs index a4f43e46..c109fae9 100644 --- a/ssz-rs/tests/uints.rs +++ b/ssz-rs/tests/uints.rs @@ -1781,7 +1781,6 @@ fn test_uints_uint_64_last_byte_empty() { assert_eq!(root, expected_root); } -/* #[test] #[should_panic] fn test_uints_uint_128_one_too_high() { @@ -1960,4 +1959,4 @@ fn test_uints_uint_8_one_byte_shorter() { ); deserialize::(&encoding); -}*/ +}