From 4a4460b1a36d775dda51a9e2f7f4a33ca58d3dba Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Mon, 26 Apr 2021 11:51:19 +0200 Subject: [PATCH] Add test for script serialize/deserialize --- src/blockdata/script.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/blockdata/script.rs b/src/blockdata/script.rs index 17a2e7c6..605ddbfa 100644 --- a/src/blockdata/script.rs +++ b/src/blockdata/script.rs @@ -1293,5 +1293,22 @@ mod test { assert!(script_p2pkh.is_p2pkh()); assert_eq!(script_p2pkh.dust_value(), 546); } + + #[test] + #[cfg(feature = "serde")] + fn test_script_serde_human_and_not() { + let script = Script::from(vec![0u8, 1u8, 2u8]); + + // Serialize + let json = ::serde_json::to_string(&script).unwrap(); + assert_eq!(json, "\"000102\""); + let bincode = ::bincode::serialize(&script).unwrap(); + assert_eq!(bincode, [3, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2]); // bincode adds u64 for length, serde_cbor use varint + + // Deserialize + assert_eq!(script, ::serde_json::from_str(&json).unwrap()); + assert_eq!(script, ::bincode::deserialize(&bincode).unwrap()); + } + }