Add transaction decode round trip test
What changed, and why it matters
This commit only adds a new test that encodes a Bitcoin transaction and decodes it again to make sure the result matches the original. It does not change any production code, fix a bug, or introduce a security issue. The commit message mentions a 'mutant in push_bytes,' which is testing jargon for a surviving fake code change during mutation testing, not a real vulnerability.
No security action needed. Treat as routine test-coverage improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds a single unit test, transaction_encode_decode_roundtrip, in primitives/src/transaction.rs. It constructs a Transaction with segwit inputs/outputs, encodes it via encoding::encode_to_vec, feeds the bytes through Transaction::decoder().push_bytes(…), and asserts the decoded value equals the original. No library logic is modified; this is purely test-coverage expansion.
Changed components
primitives/src/transaction.rs (test module only)Inspect captured patch +21 / −0
diff --git a/primitives/src/transaction.rs b/primitives/src/transaction.rs
index 79717adb..f3f3651d 100644
--- a/primitives/src/transaction.rs
+++ b/primitives/src/transaction.rs
@@ -1502,6 +1502,27 @@ mod tests {
#[cfg(all(feature = "alloc", feature = "hex"))]
use crate::absolute::LockTime;
+ #[test]
+ #[cfg(feature = "alloc")]
+ #[cfg(feature = "hex")]
+ fn transaction_encode_decode_roundtrip() {
+ let tx = Transaction {
+ version: Version::TWO,
+ lock_time: absolute::LockTime::ZERO,
+ inputs: vec![segwit_tx_in(), segwit_tx_in()],
+ outputs: vec![tx_out(), tx_out()],
+ };
+
+ let encoded = encoding::encode_to_vec(&tx);
+
+ let mut decoder = Transaction::decoder();
+ let mut slice = encoded.as_slice();
+ decoder.push_bytes(&mut slice).unwrap();
+ let decoded = decoder.end().unwrap();
+
+ assert_eq!(tx, decoded);
+ }
+
#[test]
fn sanity_check() {
let version = Version(123);
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.