From 8e094b9d6031321bb84330b5d31e509e96c0346c Mon Sep 17 00:00:00 2001 From: 2-NOW Date: Sun, 15 Oct 2023 16:24:19 +0900 Subject: [PATCH] Add test for CommitHash encoding and decoding --- core/src/types.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/src/types.rs b/core/src/types.rs index a65eb836..3dc7548e 100644 --- a/core/src/types.rs +++ b/core/src/types.rs @@ -268,8 +268,15 @@ pub struct FinalizationInfo { #[cfg(test)] mod tests { + use super::CommitHash; + use serde_json::{from_str, to_string}; + #[test] fn en_decode_commit_hash() { - // TODO: test a successful encode/decode of CommitHash + let commit_hash = CommitHash { hash: [1; 20] }; + let serialized = to_string(&commit_hash).unwrap(); + assert_eq!(serialized, "\"0101010101010101010101010101010101010101\""); + let deserialized: CommitHash = from_str(&serialized).unwrap(); + assert_eq!(deserialized, commit_hash); } }