From 15e3caf62daad0073d7e7458ad9361595bcef431 Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Fri, 16 Jul 2021 10:20:45 +0200 Subject: [PATCH] [test] Test also sighash legacy API with legacy tests --- src/blockdata/transaction.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index 4ecac18a..348ca2e8 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -771,6 +771,7 @@ mod tests { use hash_types::*; use SigHashType; + use util::sighash::SigHashCache; #[test] fn test_outpoint() { @@ -1004,7 +1005,15 @@ mod tests { raw_expected.reverse(); let expected_result = SigHash::from_slice(&raw_expected[..]).unwrap(); - let actual_result = tx.signature_hash(input_index, &script, hash_type as u32); + let actual_result = if raw_expected[0] % 2 == 0 { + // tx.signature_hash and cache.legacy_signature_hash are the same, this if helps to test + // both the codepaths without repeating the test code + tx.signature_hash(input_index, &script, hash_type as u32) + } else { + let cache = SigHashCache::new(&tx); + cache.legacy_signature_hash(input_index, &script, hash_type as u32).unwrap() + }; + assert_eq!(actual_result, expected_result); }