From 945db009b2638151ac80e3750a11ade455c2a034 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Wed, 19 Aug 2020 13:46:07 -0700 Subject: [PATCH] Add test for transaction and block version serialization --- src/blockdata/block.rs | 15 +++++++++++++++ src/blockdata/transaction.rs | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/blockdata/block.rs b/src/blockdata/block.rs index 989201db..93d7c591 100644 --- a/src/blockdata/block.rs +++ b/src/blockdata/block.rs @@ -311,6 +311,21 @@ mod tests { assert_eq!(serialize(&real_decode), segwit_block); } + #[test] + fn block_version_test() { + let block = Vec::from_hex("ffffff7f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); + let decode: Result = deserialize(&block); + assert!(decode.is_ok()); + let real_decode = decode.unwrap(); + assert_eq!(real_decode.header.version, 2147483647); + + let block2 = Vec::from_hex("000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); + let decode2: Result = deserialize(&block2); + assert!(decode2.is_ok()); + let real_decode2 = decode2.unwrap(); + assert_eq!(real_decode2.header.version, -2147483648); + } + #[test] fn compact_roundrtip_test() { let some_header = Vec::from_hex("010000004ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914cd74d6e49ffff001d323b3a7b").unwrap(); diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index bc9cd2fb..8cc37d84 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -761,6 +761,21 @@ mod tests { assert_eq!(realtx.get_size(), tx_bytes.len()); } + #[test] + fn test_transaction_version() { + let tx_bytes = Vec::from_hex("ffffff7f0100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000").unwrap(); + let tx: Result = deserialize(&tx_bytes); + assert!(tx.is_ok()); + let realtx = tx.unwrap(); + assert_eq!(realtx.version, 2147483647); + + let tx2_bytes = Vec::from_hex("000000800100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000").unwrap(); + let tx2: Result = deserialize(&tx2_bytes); + assert!(tx2.is_ok()); + let realtx2 = tx2.unwrap(); + assert_eq!(realtx2.version, -2147483648); + } + #[test] fn tx_no_input_deserialization() { let tx_bytes = Vec::from_hex(