Improve test coverage for TxMerkleNode
What changed, and why it matters
This commit only adds two new unit tests for the TxMerkleNode type. It does not change any production code, fix a bug, or alter behavior. There is no security relevance.
No action needed; this is a routine test-coverage improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds test-only code in primitives/src/hash_types/transaction_merkle_node.rs under #[cfg(test)]. It verifies the decoder’s read_limit returns 32 and that an incomplete-byte decoding error produces a non-empty display string and has a source error. No implementation code is modified.
Changed components
primitives/src/hash_types/transaction_merkle_node.rs (tests only)Inspect captured patch +30 / −0
diff --git a/primitives/src/hash_types/transaction_merkle_node.rs b/primitives/src/hash_types/transaction_merkle_node.rs
index 8f962b18..abbfe138 100644
--- a/primitives/src/hash_types/transaction_merkle_node.rs
+++ b/primitives/src/hash_types/transaction_merkle_node.rs
@@ -118,3 +118,33 @@ impl fmt::Display for TxMerkleNodeDecoderError {
impl std::error::Error for TxMerkleNodeDecoderError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
}
+
+#[cfg(test)]
+mod tests {
+ use encoding::Decoder as _;
+
+ use super::*;
+
+ #[test]
+ fn decoder_full_read_limit() {
+ assert_eq!(TxMerkleNodeDecoder::default().read_limit(), 32);
+ assert_eq!(<TxMerkleNode as encoding::Decodable>::decoder().read_limit(), 32);
+ }
+
+ #[test]
+ #[cfg(feature = "std")]
+ fn decoder_error_display() {
+ use std::error::Error as _;
+ use std::string::ToString as _;
+
+ const NODE_LEN: usize = 32;
+
+ let mut decoder = TxMerkleNodeDecoder::new();
+ let mut bytes = &[0u8; NODE_LEN - 1][..];
+ assert!(decoder.push_bytes(&mut bytes).unwrap());
+
+ let err = decoder.end().unwrap_err();
+ assert!(!err.to_string().is_empty());
+ assert!(err.source().is_some());
+ }
+}
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.