From c610e14ea059dc8e99359edf5fa4a1f53274a73b Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Tue, 20 Feb 2024 14:32:32 +0000 Subject: [PATCH] Add `borsh` serialization roundtrip tests --- src/borsh.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/borsh.rs b/src/borsh.rs index 9338f435..24899acb 100644 --- a/src/borsh.rs +++ b/src/borsh.rs @@ -94,3 +94,32 @@ fn check_zst() -> Result<()> { } Ok(()) } + +#[cfg(test)] +mod borsh_tests { + use super::*; + + #[test] + fn map_borsh_roundtrip() { + let original_map: IndexMap = { + let mut map = IndexMap::new(); + map.insert(1, 2); + map.insert(3, 4); + map.insert(5, 6); + map + }; + let serialized_map = borsh::to_vec(&original_map).unwrap(); + let deserialized_map: IndexMap = + BorshDeserialize::try_from_slice(&serialized_map).unwrap(); + assert_eq!(original_map, deserialized_map); + } + + #[test] + fn set_borsh_roundtrip() { + let original_map: IndexSet = [1, 2, 3, 4, 5, 6].into_iter().collect(); + let serialized_map = borsh::to_vec(&original_map).unwrap(); + let deserialized_map: IndexSet = + BorshDeserialize::try_from_slice(&serialized_map).unwrap(); + assert_eq!(original_map, deserialized_map); + } +}