[test] Test also sighash legacy API with legacy tests

This commit is contained in:
Riccardo Casatta 2021-07-16 10:20:45 +02:00
parent 24acfe3672
commit 15e3caf62d
No known key found for this signature in database
GPG Key ID: FD986A969E450397
1 changed files with 10 additions and 1 deletions

View File

@ -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);
}