Skip to content

Commit

Permalink
Merge #2528: hash_types: add unit tests for display of all hash types…
Browse files Browse the repository at this point in the history
… in the library

b816c0b hash_types: add unit tests for display of all hash types in the library (Andrew Poelstra)

Pull request description:

  This can be checked against the 0.29.x branch, and against the commit prior to #1659 (40c2467^) and you will see that it is consistent EXCEPT:

  * In rust-bitcoin 0.29.x we did not have multiple sighash types, only `Sighash`; we now have `LegacySighash`, `SegwitV0Sighash`, and `TapSighash`.
  * In #1565 we deliberately changed the display direction of the sighashes, to match BIP 143.

  Fixes #2495.

ACKs for top commit:
  tcharding:
    That's a win. ACK b816c0b

Tree-SHA512: 5b44f40165699910ea9ba945657cd1f960cf00a0b4dfa44c513feb3b74cda33ed80d3551042c15b85d6e57c30a54242db202eefd9ec8c8b6e1498b5578e52800
  • Loading branch information
apoelstra committed Mar 20, 2024
2 parents f495bd9 + b816c0b commit 4d90e0b
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions bitcoin/src/hash_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,83 @@ pub use crate::{
BlockHash, FilterHash, FilterHeader, TxMerkleNode, Txid, WitnessCommitment, WitnessMerkleNode,
Wtxid,
};

#[cfg(test)]
mod tests {
use crate::hashes::Hash;
use super::*;

use crate::{LegacySighash, SegwitV0Sighash, TapSighash, PubkeyHash, WPubkeyHash, WScriptHash, ScriptHash, XKeyIdentifier};

#[test]
fn hash_display() {
assert_eq!(
Txid::hash(&[]).to_string(),
"56944c5d3f98413ef45cf54545538103cc9f298e0575820ad3591376e2e0f65d",
);

assert_eq!(
Wtxid::hash(&[]).to_string(),
"56944c5d3f98413ef45cf54545538103cc9f298e0575820ad3591376e2e0f65d",
);
assert_eq!(
BlockHash::hash(&[]).to_string(),
"56944c5d3f98413ef45cf54545538103cc9f298e0575820ad3591376e2e0f65d",
);
assert_eq!(
LegacySighash::hash(&[]).to_string(),
"5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456",
);
assert_eq!(
SegwitV0Sighash::hash(&[]).to_string(),
"5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456",
);
assert_eq!(
TapSighash::hash(&[]).to_string(),
"dabc11914abcd8072900042a2681e52f8dba99ce82e224f97b5fdb7cd4b9c803",
);

assert_eq!(
PubkeyHash::hash(&[]).to_string(),
"b472a266d0bd89c13706a4132ccfb16f7c3b9fcb",
);
assert_eq!(
ScriptHash::hash(&[]).to_string(),
"b472a266d0bd89c13706a4132ccfb16f7c3b9fcb",
);
assert_eq!(
WPubkeyHash::hash(&[]).to_string(),
"b472a266d0bd89c13706a4132ccfb16f7c3b9fcb",
);
assert_eq!(
WScriptHash::hash(&[]).to_string(),
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
);

assert_eq!(
TxMerkleNode::hash(&[]).to_string(),
"56944c5d3f98413ef45cf54545538103cc9f298e0575820ad3591376e2e0f65d",
);
assert_eq!(
WitnessMerkleNode::hash(&[]).to_string(),
"56944c5d3f98413ef45cf54545538103cc9f298e0575820ad3591376e2e0f65d",
);
assert_eq!(
WitnessCommitment::hash(&[]).to_string(),
"56944c5d3f98413ef45cf54545538103cc9f298e0575820ad3591376e2e0f65d",
);
assert_eq!(
XKeyIdentifier::hash(&[]).to_string(),
"b472a266d0bd89c13706a4132ccfb16f7c3b9fcb",
);

assert_eq!(
FilterHash::hash(&[]).to_string(),
"56944c5d3f98413ef45cf54545538103cc9f298e0575820ad3591376e2e0f65d",
);
assert_eq!(
FilterHeader::hash(&[]).to_string(),
"56944c5d3f98413ef45cf54545538103cc9f298e0575820ad3591376e2e0f65d",
);
}
}

0 comments on commit 4d90e0b

Please sign in to comment.