What changed, and why it matters
This commit only adds new test code to check that certain 'decoder' types can be created with a default value and a `new()` function. It does not change any production code, fix a bug, or alter behavior. There is no security issue here.
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 patch extends primitives/tests/api.rs and units/tests/api.rs with compile-time/regression tests asserting that public decoder types implement Default and expose a new() constructor. No runtime logic, interfaces, or cryptographic operations are modified. It is purely a testing/API-surface coverage change.
Changed components
primitives/tests/api.rsunits/tests/api.rsInspect captured patch +68 / −1
diff --git a/primitives/tests/api.rs b/primitives/tests/api.rs
index 6b91844d..6b6605db 100644
--- a/primitives/tests/api.rs
+++ b/primitives/tests/api.rs
@@ -15,7 +15,9 @@
use arbitrary::Arbitrary;
use bitcoin_primitives::block::{Checked, Unchecked};
-use bitcoin_primitives::script::{self, ScriptHash, WScriptHash};
+use bitcoin_primitives::script::{
+ self, ScriptHash, ScriptPubKeyBufDecoder, ScriptSigBufDecoder, WScriptHash,
+};
use bitcoin_primitives::{
absolute, block, merkle_tree, pow, relative, transaction, witness, OutPoint, RedeemScript,
RedeemScriptBuf, ScriptPubKey, ScriptPubKeyBuf, ScriptSig, ScriptSigBuf, Sequence, TapScript,
@@ -195,6 +197,24 @@ struct Default {
e: Witness,
}
+/// A struct that includes all public decoder types.
+#[derive(Default)] // All decoders implement `Default`.
+struct Decoders {
+ a: block::BlockDecoder,
+ b: block::BlockHashDecoder,
+ c: block::HeaderDecoder,
+ d: block::VersionDecoder,
+ e: merkle_tree::TxMerkleNodeDecoder,
+ f: ScriptPubKeyBufDecoder,
+ g: ScriptSigBufDecoder,
+ h: transaction::TransactionDecoder,
+ i: transaction::TxInDecoder,
+ j: transaction::TxOutDecoder,
+ k: transaction::OutPointDecoder,
+ l: transaction::VersionDecoder,
+ m: witness::WitnessDecoder,
+}
+
/// A struct that includes all public error types.
// These derives are the policy of `rust-bitcoin` not Rust API guidelines.
#[derive(Debug, Clone, PartialEq, Eq)] // All public types implement Debug (C-DEBUG).
@@ -370,6 +390,26 @@ fn regression_default() {
assert_eq!(got, want);
}
+#[test]
+fn decoders_implement_default() { let _ = Decoders::default(); }
+
+#[test]
+fn decoders_implement_new() {
+ let _ = block::BlockDecoder::new();
+ let _ = block::BlockHashDecoder::new();
+ let _ = block::HeaderDecoder::new();
+ let _ = block::VersionDecoder::new();
+ let _ = merkle_tree::TxMerkleNodeDecoder::new();
+ let _ = ScriptPubKeyBufDecoder::new();
+ let _ = ScriptSigBufDecoder::new();
+ let _ = transaction::TransactionDecoder::new();
+ let _ = transaction::TxInDecoder::new();
+ let _ = transaction::TxOutDecoder::new();
+ let _ = transaction::OutPointDecoder::new();
+ let _ = transaction::VersionDecoder::new();
+ let _ = witness::WitnessDecoder::new();
+}
+
#[test]
// The only trait in this crate is `block::Validation` and it is not dyn compatible.
fn dyn_compatible() {}
diff --git a/units/tests/api.rs b/units/tests/api.rs
index 886a7cc0..429146b0 100644
--- a/units/tests/api.rs
+++ b/units/tests/api.rs
@@ -164,6 +164,18 @@ struct Errors {
x: result::NumOpError,
}
+/// A struct that includes all public decoder types.
+#[derive(Default)] // All decoders implement `Default`.
+#[cfg(feature = "encoding")]
+struct Decoders {
+ a: amount::AmountDecoder,
+ b: block::BlockHeightDecoder,
+ c: locktime::absolute::LockTimeDecoder,
+ d: pow::CompactTargetDecoder,
+ e: sequence::SequenceDecoder,
+ f: time::BlockTimeDecoder,
+}
+
/// A struct that includes all public decoder error types.
// These derives are the policy of `rust-bitcoin` not Rust API guidelines.
#[derive(Debug, Clone, PartialEq, Eq)] // All public types implement Debug (C-DEBUG).
@@ -440,6 +452,21 @@ fn dyn_compatible() {
}
}
+#[test]
+#[cfg(feature = "encoding")]
+fn decoders_implement_default() { let _ = Decoders::default(); }
+
+#[test]
+#[cfg(feature = "encoding")]
+fn decoders_implement_new() {
+ let _ = amount::AmountDecoder::new();
+ let _ = block::BlockHeightDecoder::new();
+ let _ = locktime::absolute::LockTimeDecoder::new();
+ let _ = pow::CompactTargetDecoder::new();
+ let _ = sequence::SequenceDecoder::new();
+ let _ = time::BlockTimeDecoder::new();
+}
+
#[cfg(feature = "arbitrary")]
impl<'a> Arbitrary<'a> for Types {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
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.