From 4b83267d2e83f6a8810bf406b5da2c03a27a0b39 Mon Sep 17 00:00:00 2001 From: SW van Heerden Date: Thu, 7 Sep 2023 10:07:16 +0200 Subject: [PATCH] test: improve tests code (#5747) Description --- Improves some test code Co-Authored-By: Stringhandler --- .../core/src/proof_of_work/monero_rx/fixed_array.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/base_layer/core/src/proof_of_work/monero_rx/fixed_array.rs b/base_layer/core/src/proof_of_work/monero_rx/fixed_array.rs index 923d2f8238..1d9482872f 100644 --- a/base_layer/core/src/proof_of_work/monero_rx/fixed_array.rs +++ b/base_layer/core/src/proof_of_work/monero_rx/fixed_array.rs @@ -141,6 +141,8 @@ mod test { #[test] fn from_bytes() { + let empty = FixedByteArray::from_bytes(&[]).unwrap(); + assert_eq!(empty.len(), 0); let arr = FixedByteArray::from_bytes(&[1u8][..]).unwrap(); assert_eq!(arr.len(), 1); assert!(arr.iter().all(|b| *b == 1)); @@ -184,4 +186,14 @@ mod test { assert_eq!(fixed_byte_array, FixedByteArray::deserialize(buf).unwrap()); assert_eq!(buf, &[1, 2, 3]); } + + #[test] + fn test_borsh_deserialize_wrong_length() { + let mut buf = Vec::new(); + buf.extend_from_slice(&[3, 1, 1]); + let buf = &mut buf.as_slice(); + let result = FixedByteArray::deserialize(buf); + assert!(result.is_err()); + assert_eq!(buf, &[1u8; 0]); + } }