Skip to content

Commit

Permalink
Add test for sighash_single_bug incompatility fix
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchengxu committed Feb 25, 2025
1 parent 5d38073 commit 7ab2f5b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions bitcoin/src/crypto/sighash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1545,8 +1545,6 @@ mod tests {

#[test]
fn sighash_single_bug() {
const SIGHASH_SINGLE: u32 = 3;

// We need a tx with more inputs than outputs.
let tx = Transaction {
version: transaction::Version::ONE,
Expand All @@ -1557,10 +1555,16 @@ mod tests {
let script = ScriptBuf::new();
let cache = SighashCache::new(&tx);

let got = cache.legacy_signature_hash(1, &script, SIGHASH_SINGLE).expect("sighash");
let sighash_single = 3;
let got = cache.legacy_signature_hash(1, &script, sighash_single).expect("sighash");
let want = LegacySighash::from_byte_array(UINT256_ONE);
assert_eq!(got, want);

assert_eq!(got, want)
// https://github.com/rust-bitcoin/rust-bitcoin/issues/4112
let sighash_single = 131;
let got = cache.legacy_signature_hash(1, &script, sighash_single).expect("sighash");
let want = LegacySighash::from_byte_array(UINT256_ONE);
assert_eq!(got, want);
}

#[test]
Expand Down

0 comments on commit 7ab2f5b

Please sign in to comment.