What changed, and why it matters
This commit simply moves existing unit tests from one crate to another within the same project. No production code behavior is changed, so it has no security impact on users of the library.
No security action required. Treat as routine test maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit relocates test cases for OutPoint, Version, CompactTarget, and Sequence from the main bitcoin crate into the upstream primitives and units crates where those types now live. The diff shows only additions and removals of #[test] functions and minor import adjustments (e.g., removing parse_int usage in bitcoin/src/blockdata/transaction.rs). No runtime logic, APIs, or cryptographic code is modified.
Changed components
bitcoin/src/blockdata/block.rsbitcoin/src/blockdata/transaction.rsbitcoin/src/pow.rsprimitives/src/block.rsprimitives/src/transaction.rsunits/src/pow.rsunits/src/sequence.rsInspect captured patch +186 / −183
diff --git a/bitcoin/src/blockdata/block.rs b/bitcoin/src/blockdata/block.rs
index 63f726e1..edf2cd2a 100644
--- a/bitcoin/src/blockdata/block.rs
+++ b/bitcoin/src/blockdata/block.rs
@@ -646,24 +646,6 @@ mod tests {
assert_eq!(got, want)
}
- #[test]
- fn soft_fork_signalling() {
- for i in 0..31 {
- let version_int = (0x20000000u32 ^ (1 << i)) as i32;
- let version = Version::from_consensus(version_int);
- if i < 29 {
- assert!(version.is_signalling_soft_fork(i));
- } else {
- assert!(!version.is_signalling_soft_fork(i));
- }
- }
-
- let segwit_signal = Version::from_consensus(0x20000000 ^ (1 << 1));
- assert!(!segwit_signal.is_signalling_soft_fork(0));
- assert!(segwit_signal.is_signalling_soft_fork(1));
- assert!(!segwit_signal.is_signalling_soft_fork(2));
- }
-
#[test]
fn block_validation_success_with_coinbase() {
use crate::constants;
diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs
index e5d2ddab..4a30fa18 100644
--- a/bitcoin/src/blockdata/transaction.rs
+++ b/bitcoin/src/blockdata/transaction.rs
@@ -1307,8 +1307,8 @@ mod tests {
use super::*;
use crate::consensus::encode::{deserialize, serialize};
use crate::constants::WITNESS_SCALE_FACTOR;
+ use crate::hex;
use crate::script::ScriptSigBuf;
- use crate::{hex, parse_int};
const SOME_TX: &str = "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000";
@@ -1323,74 +1323,6 @@ mod tests {
assert_eq!(raw_tx, &buf[..size]);
}
- #[test]
- fn outpoint() {
- assert_eq!("i don't care".parse::<OutPoint>(), Err(ParseOutPointError::Format));
- assert_eq!(
- "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:1:1"
- .parse::<OutPoint>(),
- Err(ParseOutPointError::Format)
- );
- assert_eq!(
- "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:".parse::<OutPoint>(),
- Err(ParseOutPointError::Format)
- );
- assert_eq!(
- "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:11111111111"
- .parse::<OutPoint>(),
- Err(ParseOutPointError::TooLong)
- );
- assert_eq!(
- "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:01"
- .parse::<OutPoint>(),
- Err(ParseOutPointError::VoutNotCanonical)
- );
- assert_eq!(
- "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:+42"
- .parse::<OutPoint>(),
- Err(ParseOutPointError::VoutNotCanonical)
- );
- assert_eq!(
- "i don't care:1".parse::<OutPoint>(),
- Err(ParseOutPointError::Txid("i don't care".parse::<Txid>().unwrap_err()))
- );
- assert_eq!(
- "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c945X:1"
- .parse::<OutPoint>(),
- Err(ParseOutPointError::Txid(
- "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c945X"
- .parse::<Txid>()
- .unwrap_err()
- ))
- );
- assert_eq!(
- "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:lol"
- .parse::<OutPoint>(),
- Err(ParseOutPointError::Vout(parse_int::int_from_str::<u32>("lol").unwrap_err()))
- );
-
- assert_eq!(
- "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:42"
- .parse::<OutPoint>(),
- Ok(OutPoint {
- txid: "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456"
- .parse()
- .unwrap(),
- vout: 42,
- })
- );
- assert_eq!(
- "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:0"
- .parse::<OutPoint>(),
- Ok(OutPoint {
- txid: "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456"
- .parse()
- .unwrap(),
- vout: 0,
- })
- );
- }
-
#[test]
fn txin() {
let txin: Result<TxIn, _> = deserialize(&hex!("a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff"));
@@ -1704,58 +1636,6 @@ mod tests {
}
}
- #[test]
- fn sequence_number() {
- let seq_final = Sequence::from_consensus(0xFFFFFFFF);
- let seq_non_rbf = Sequence::from_consensus(0xFFFFFFFE);
- let block_time_lock = Sequence::from_consensus(0xFFFF);
- let unit_time_lock = Sequence::from_consensus(0x40FFFF);
- let lock_time_disabled = Sequence::from_consensus(0x80000000);
-
- assert!(seq_final.is_final());
- assert!(!seq_final.is_rbf());
- assert!(!seq_final.is_relative_lock_time());
- assert!(!seq_non_rbf.is_rbf());
- assert!(block_time_lock.is_relative_lock_time());
- assert!(block_time_lock.is_height_locked());
- assert!(block_time_lock.is_rbf());
- assert!(unit_time_lock.is_relative_lock_time());
- assert!(unit_time_lock.is_time_locked());
- assert!(unit_time_lock.is_rbf());
- assert!(!lock_time_disabled.is_relative_lock_time());
- }
-
- #[test]
- fn sequence_from_hex_lower() {
- let sequence = Sequence::from_hex("0xffffffff").unwrap();
- assert_eq!(sequence, Sequence::MAX);
- }
-
- #[test]
- fn sequence_from_hex_upper() {
- let sequence = Sequence::from_hex("0XFFFFFFFF").unwrap();
- assert_eq!(sequence, Sequence::MAX);
- }
-
- #[test]
- fn sequence_from_unprefixed_hex_lower() {
- let sequence = Sequence::from_unprefixed_hex("ffffffff").unwrap();
- assert_eq!(sequence, Sequence::MAX);
- }
-
- #[test]
- fn sequence_from_unprefixed_hex_upper() {
- let sequence = Sequence::from_unprefixed_hex("FFFFFFFF").unwrap();
- assert_eq!(sequence, Sequence::MAX);
- }
-
- #[test]
- fn sequence_from_str_hex_invalid_hex_should_err() {
- let hex = "0xzb93";
- let result = Sequence::from_hex(hex);
- assert!(result.is_err());
- }
-
#[test]
fn effective_value_happy_path() {
let value = "1 cBTC".parse::<Amount>().unwrap();
@@ -2094,37 +1974,6 @@ mod tests {
);
}
- #[test]
-
- fn outpoint_format() {
- let outpoint = OutPoint::COINBASE_PREVOUT;
-
- let debug = "OutPoint { txid: Txid(bitcoin_hashes::sha256d::Hash(0000000000000000000000000000000000000000000000000000000000000000)), vout: 4294967295 }";
- assert_eq!(debug, format!("{:?}", &outpoint));
-
- let display = "0000000000000000000000000000000000000000000000000000000000000000:4294967295";
- assert_eq!(display, format!("{}", &outpoint));
-
- let pretty_debug = "OutPoint {
- txid: Txid(
- bitcoin_hashes::sha256d::Hash(
- 0x0000000000000000000000000000000000000000000000000000000000000000,
- ),
- ),
- vout: 4294967295,
-}";
- assert_eq!(pretty_debug, format!("{:#?}", &outpoint));
-
- let debug_txid = "Txid(bitcoin_hashes::sha256d::Hash(0000000000000000000000000000000000000000000000000000000000000000))";
- assert_eq!(debug_txid, format!("{:?}", &outpoint.txid));
-
- let display_txid = "0000000000000000000000000000000000000000000000000000000000000000";
- assert_eq!(display_txid, format!("{}", &outpoint.txid));
-
- let pretty_txid = "0x0000000000000000000000000000000000000000000000000000000000000000";
- assert_eq!(pretty_txid, format!("{:#}", &outpoint.txid));
- }
-
#[test]
fn coinbase_assume_methods() {
use crate::constants;
diff --git a/bitcoin/src/pow.rs b/bitcoin/src/pow.rs
index a9f1be39..1a2bee5a 100644
--- a/bitcoin/src/pow.rs
+++ b/bitcoin/src/pow.rs
@@ -661,19 +661,6 @@ mod tests {
);
}
- #[test]
- fn roundtrip_compact_target() {
- let consensus = 0x1d00_ffff;
- let compact = CompactTarget::from_consensus(consensus);
- let t = Target::from_compact(CompactTarget::from_consensus(consensus));
- assert_eq!(t, Target::from(compact)); // From/Into sanity check.
-
- let back = t.to_compact_lossy();
- assert_eq!(back, compact); // From/Into sanity check.
-
- assert_eq!(back.to_consensus(), consensus);
- }
-
#[test]
fn roundtrip_target_work() {
let target = u32_to_target(0xdeadbeef_u32);
diff --git a/primitives/src/block.rs b/primitives/src/block.rs
index 771716cc..a1db1b03 100644
--- a/primitives/src/block.rs
+++ b/primitives/src/block.rs
@@ -1058,6 +1058,24 @@ mod tests {
assert!(!Version::is_signalling_soft_fork(version, 0));
}
+ #[test]
+ fn soft_fork_signalling() {
+ for i in 0..31 {
+ let version_int = (0x20000000u32 ^ (1 << i)) as i32;
+ let version = Version::from_consensus(version_int);
+ if i < 29 {
+ assert!(version.is_signalling_soft_fork(i));
+ } else {
+ assert!(!version.is_signalling_soft_fork(i));
+ }
+ }
+
+ let segwit_signal = Version::from_consensus(0x20000000 ^ (1 << 1));
+ assert!(!segwit_signal.is_signalling_soft_fork(0));
+ assert!(segwit_signal.is_signalling_soft_fork(1));
+ assert!(!segwit_signal.is_signalling_soft_fork(2));
+ }
+
#[test]
fn version_to_consensus() {
let version = Version::from_consensus(1_234_567_890);
diff --git a/primitives/src/transaction.rs b/primitives/src/transaction.rs
index 54ffd823..4394271e 100644
--- a/primitives/src/transaction.rs
+++ b/primitives/src/transaction.rs
@@ -1809,6 +1809,76 @@ mod tests {
assert_eq!(outpoint, Err(ParseOutPointError::TooLong));
}
+ #[test]
+ #[cfg(feature = "hex")]
+ #[cfg(feature = "alloc")]
+ fn outpoint() {
+ assert_eq!("i don't care".parse::<OutPoint>(), Err(ParseOutPointError::Format));
+ assert_eq!(
+ "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:1:1"
+ .parse::<OutPoint>(),
+ Err(ParseOutPointError::Format)
+ );
+ assert_eq!(
+ "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:".parse::<OutPoint>(),
+ Err(ParseOutPointError::Format)
+ );
+ assert_eq!(
+ "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:11111111111"
+ .parse::<OutPoint>(),
+ Err(ParseOutPointError::TooLong)
+ );
+ assert_eq!(
+ "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:01"
+ .parse::<OutPoint>(),
+ Err(ParseOutPointError::VoutNotCanonical)
+ );
+ assert_eq!(
+ "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:+42"
+ .parse::<OutPoint>(),
+ Err(ParseOutPointError::VoutNotCanonical)
+ );
+ assert_eq!(
+ "i don't care:1".parse::<OutPoint>(),
+ Err(ParseOutPointError::Txid("i don't care".parse::<Txid>().unwrap_err()))
+ );
+ assert_eq!(
+ "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c945X:1"
+ .parse::<OutPoint>(),
+ Err(ParseOutPointError::Txid(
+ "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c945X"
+ .parse::<Txid>()
+ .unwrap_err()
+ ))
+ );
+ assert_eq!(
+ "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:lol"
+ .parse::<OutPoint>(),
+ Err(ParseOutPointError::Vout(parse_int::int_from_str::<u32>("lol").unwrap_err()))
+ );
+
+ assert_eq!(
+ "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:42"
+ .parse::<OutPoint>(),
+ Ok(OutPoint {
+ txid: "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456"
+ .parse()
+ .unwrap(),
+ vout: 42,
+ })
+ );
+ assert_eq!(
+ "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456:0"
+ .parse::<OutPoint>(),
+ Ok(OutPoint {
+ txid: "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456"
+ .parse()
+ .unwrap(),
+ vout: 0,
+ })
+ );
+ }
+
#[test]
#[cfg(feature = "hex")]
fn canonical_vout() {
@@ -1827,6 +1897,38 @@ mod tests {
assert_eq!(format!("{}", outpoint), outpoint_str);
}
+ #[test]
+ #[cfg(feature = "alloc")]
+ #[cfg(feature = "hex")]
+ fn outpoint_format() {
+ let outpoint = OutPoint::COINBASE_PREVOUT;
+
+ let debug = "OutPoint { txid: Txid(bitcoin_hashes::sha256d::Hash(0000000000000000000000000000000000000000000000000000000000000000)), vout: 4294967295 }";
+ assert_eq!(debug, format!("{:?}", &outpoint));
+
+ let display = "0000000000000000000000000000000000000000000000000000000000000000:4294967295";
+ assert_eq!(display, format!("{}", &outpoint));
+
+ let pretty_debug = "OutPoint {
+ txid: Txid(
+ bitcoin_hashes::sha256d::Hash(
+ 0x0000000000000000000000000000000000000000000000000000000000000000,
+ ),
+ ),
+ vout: 4294967295,
+}";
+ assert_eq!(pretty_debug, format!("{:#?}", &outpoint));
+
+ let debug_txid = "Txid(bitcoin_hashes::sha256d::Hash(0000000000000000000000000000000000000000000000000000000000000000))";
+ assert_eq!(debug_txid, format!("{:?}", &outpoint.txid));
+
+ let display_txid = "0000000000000000000000000000000000000000000000000000000000000000";
+ assert_eq!(display_txid, format!("{}", &outpoint.txid));
+
+ let pretty_txid = "0x0000000000000000000000000000000000000000000000000000000000000000";
+ assert_eq!(pretty_txid, format!("{:#}", &outpoint.txid));
+ }
+
#[test]
fn version_display() {
let version = Version(123);
diff --git a/units/src/pow.rs b/units/src/pow.rs
index 994bd007..ea378282 100644
--- a/units/src/pow.rs
+++ b/units/src/pow.rs
@@ -1444,6 +1444,19 @@ mod tests {
}
}
+ #[test]
+ fn roundtrip_compact_target() {
+ let consensus = 0x1d00_ffff;
+ let compact = CompactTarget::from_consensus(consensus);
+ let t = Target::from_compact(CompactTarget::from_consensus(consensus));
+ assert_eq!(t, Target::from(compact)); // From/Into sanity check.
+
+ let back = t.to_compact_lossy();
+ assert_eq!(back, compact); // From/Into sanity check.
+
+ assert_eq!(back.to_consensus(), consensus);
+ }
+
#[test]
fn max_target_from_compact() {
// The highest possible target is defined as 0x1d00ffff
diff --git a/units/src/sequence.rs b/units/src/sequence.rs
index 5abaa062..6ba7c543 100644
--- a/units/src/sequence.rs
+++ b/units/src/sequence.rs
@@ -419,6 +419,58 @@ mod tests {
assert!(Sequence::from_seconds_ceil(MAXIMUM_ENCODABLE_SECONDS + 1).is_err());
}
+ #[test]
+ fn sequence_number() {
+ let seq_final = Sequence::from_consensus(0xFFFFFFFF);
+ let seq_non_rbf = Sequence::from_consensus(0xFFFFFFFE);
+ let block_time_lock = Sequence::from_consensus(0xFFFF);
+ let unit_time_lock = Sequence::from_consensus(0x40FFFF);
+ let lock_time_disabled = Sequence::from_consensus(0x80000000);
+
+ assert!(seq_final.is_final());
+ assert!(!seq_final.is_rbf());
+ assert!(!seq_final.is_relative_lock_time());
+ assert!(!seq_non_rbf.is_rbf());
+ assert!(block_time_lock.is_relative_lock_time());
+ assert!(block_time_lock.is_height_locked());
+ assert!(block_time_lock.is_rbf());
+ assert!(unit_time_lock.is_relative_lock_time());
+ assert!(unit_time_lock.is_time_locked());
+ assert!(unit_time_lock.is_rbf());
+ assert!(!lock_time_disabled.is_relative_lock_time());
+ }
+
+ #[test]
+ fn sequence_from_hex_lower() {
+ let sequence = Sequence::from_hex("0xffffffff").unwrap();
+ assert_eq!(sequence, Sequence::MAX);
+ }
+
+ #[test]
+ fn sequence_from_hex_upper() {
+ let sequence = Sequence::from_hex("0XFFFFFFFF").unwrap();
+ assert_eq!(sequence, Sequence::MAX);
+ }
+
+ #[test]
+ fn sequence_from_unprefixed_hex_lower() {
+ let sequence = Sequence::from_unprefixed_hex("ffffffff").unwrap();
+ assert_eq!(sequence, Sequence::MAX);
+ }
+
+ #[test]
+ fn sequence_from_unprefixed_hex_upper() {
+ let sequence = Sequence::from_unprefixed_hex("FFFFFFFF").unwrap();
+ assert_eq!(sequence, Sequence::MAX);
+ }
+
+ #[test]
+ fn sequence_from_str_hex_invalid_hex_should_err() {
+ let hex = "0xzb93";
+ let result = Sequence::from_hex(hex);
+ assert!(result.is_err());
+ }
+
#[test]
fn sequence_properties() {
let seq_max = Sequence(0xFFFF_FFFF);
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.