What changed, and why it matters
This commit adds a new automated test to verify that a helper function correctly returns nothing when given a non-coinbase Bitcoin transaction. It does not change any production code, fix a bug, or alter behavior. It is purely a test addition.
No security action required. This is a benign test-only commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit introduces a unit test witness_commitment_from_non_coinbase_returns_none in primitives/src/block.rs. The test constructs a non-coinbase Transaction (a transaction whose single input spends a previous output, i.e., previous_output is not the coinbase null outpoint) and asserts that witness_commitment_from_coinbase(&tx) returns None. No implementation code is modified.
Changed components
primitives/src/block.rs (test module only)Inspect captured patch +24 / −0
diff --git a/primitives/src/block.rs b/primitives/src/block.rs
index 9eda5364..cc051bb5 100644
--- a/primitives/src/block.rs
+++ b/primitives/src/block.rs
@@ -1383,6 +1383,30 @@ mod tests {
assert_eq!(extracted, Some(witness_commitment));
}
+ #[test]
+ #[cfg(feature = "alloc")]
+ fn witness_commitment_from_non_coinbase_returns_none() {
+ let tx = Transaction {
+ version: crate::transaction::Version::ONE,
+ lock_time: crate::absolute::LockTime::ZERO,
+ inputs: vec![crate::TxIn {
+ previous_output: crate::OutPoint {
+ txid: crate::Txid::from_byte_array([1; 32]),
+ vout: 0,
+ },
+ script_sig: crate::ScriptSigBuf::new(),
+ sequence: units::Sequence::ENABLE_LOCKTIME_AND_RBF,
+ witness: crate::Witness::new(),
+ }],
+ outputs: vec![crate::TxOut {
+ amount: units::Amount::MIN,
+ script_pubkey: crate::ScriptPubKeyBuf::new(),
+ }],
+ };
+
+ assert!(witness_commitment_from_coinbase(&tx).is_none());
+ }
+
#[test]
#[cfg(feature = "alloc")]
fn block_check_witness_commitment_empty_script_pubkey() {
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.