tests: verify all max attainable target constants against explicit hex
What changed, and why it matters
This commit only adds new unit tests that check the hexadecimal string representation of existing maximum mining target constants for Bitcoin's mainnet, testnet, regtest, and signet networks. It does not change any production code, library behavior, or security-sensitive logic. It is purely a regression test addition.
No action required. This is a benign test-only change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds a single test function, target_max_attainable_hex, in bitcoin/src/pow.rs. The test uses format!(“{:x}”, …) to compare the LowerHex output of Target::MAX_ATTAINABLE_* constants against hardcoded expected hex strings. No constants are modified, no APIs are added or changed, and no consensus or cryptographic code is touched.
Changed components
bitcoin/src/pow.rs (test module only)Inspect captured patch +21 / −0
diff --git a/bitcoin/src/pow.rs b/bitcoin/src/pow.rs
index 22b9d950..7b0e6ffb 100644
--- a/bitcoin/src/pow.rs
+++ b/bitcoin/src/pow.rs
@@ -2014,6 +2014,27 @@ mod tests {
);
}
+ #[test]
+ fn target_max_attainable_hex() {
+ // Also check explicit hex representations for regression testing.
+ assert_eq!(
+ format!("{:x}", Target::MAX_ATTAINABLE_MAINNET),
+ "00000000ffff0000000000000000000000000000000000000000000000000000"
+ );
+ assert_eq!(
+ format!("{:x}", Target::MAX_ATTAINABLE_TESTNET),
+ "00000000ffff0000000000000000000000000000000000000000000000000000"
+ );
+ assert_eq!(
+ format!("{:x}", Target::MAX_ATTAINABLE_REGTEST),
+ "7fffff0000000000000000000000000000000000000000000000000000000000"
+ );
+ assert_eq!(
+ format!("{:x}", Target::MAX_ATTAINABLE_SIGNET),
+ "00000377ae000000000000000000000000000000000000000000000000000000"
+ );
+ }
+
#[test]
fn target_difficulty_float() {
let params = Params::new(crate::Network::Bitcoin);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.