Skip to content

Commit

Permalink
test: improve tests code (#5747)
Browse files Browse the repository at this point in the history
Description
---
Improves some test code
Co-Authored-By: Stringhandler
  • Loading branch information
SWvheerden authored Sep 7, 2023
1 parent 3f82852 commit 4b83267
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions base_layer/core/src/proof_of_work/monero_rx/fixed_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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]);
}
}

0 comments on commit 4b83267

Please sign in to comment.