From cdf7be47654041ac375c80332bad0affb69c889a Mon Sep 17 00:00:00 2001 From: Vis Virial Date: Tue, 29 Jun 2021 07:59:22 +0900 Subject: [PATCH] Add extra checks for `test_segwit_transaction()`. --- src/blockdata/transaction.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index c16b0ada..0b80ba6f 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -927,7 +927,15 @@ mod tests { // weight = WITNESS_SCALE_FACTOR * stripped_size + witness_size // then, // stripped_size = (weight - size) / (WITNESS_SCALE_FACTOR - 1) - assert_eq!(realtx.get_strippedsize(), (EXPECTED_WEIGHT - tx_bytes.len()) / (WITNESS_SCALE_FACTOR - 1)); + let expected_strippedsize = (EXPECTED_WEIGHT - tx_bytes.len()) / (WITNESS_SCALE_FACTOR - 1); + assert_eq!(realtx.get_strippedsize(), expected_strippedsize); + // Construct a transaction without the witness data. + let mut tx_without_witness = realtx.clone(); + tx_without_witness.input.iter_mut().for_each(|input| input.witness.clear()); + assert_eq!(tx_without_witness.get_weight(), expected_strippedsize*WITNESS_SCALE_FACTOR); + assert_eq!(tx_without_witness.get_size(), expected_strippedsize); + assert_eq!(tx_without_witness.get_vsize(), expected_strippedsize); + assert_eq!(tx_without_witness.get_strippedsize(), expected_strippedsize); } #[test]