units: Remove old encoding test cases
What changed, and why it matters
This commit simply deletes redundant unit tests for encoding and decoding of Sequence, BlockHeight, and BlockTime. It does not change any production code, so it cannot introduce a security vulnerability or fix one. The remaining error-handling tests still exercise the encoding feature.
No security action required. Treat as routine test maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch removes duplicated happy-path encoding/decoding tests from units/src/block.rs, units/src/sequence.rs, and units/src/time.rs. The commit message states these are no longer needed for coverage because a new encoding test module covers them. No library code is modified; only test code is deleted, and one unused import (Decodable) is removed from each file. The remaining decoding_error tests still import and use the encoding feature.
Changed components
units/src/block.rs (tests only)units/src/sequence.rs (tests only)units/src/time.rs (tests only)Inspect captured patch +3 / −87
diff --git a/units/src/block.rs b/units/src/block.rs
index bb0ad874..77e9fec8 100644
--- a/units/src/block.rs
+++ b/units/src/block.rs
@@ -598,7 +598,7 @@ impl<'a> core::iter::Sum<&'a Self> for BlockMtpInterval {
#[cfg(test)]
mod tests {
#[cfg(feature = "encoding")]
- use encoding::{Decodable as _, Decoder as _, UnexpectedEofError};
+ use encoding::{Decoder as _, UnexpectedEofError};
use super::*;
use crate::relative::{NumberOf512Seconds, TimeOverflowError};
@@ -779,34 +779,6 @@ mod tests {
);
}
- #[test]
- #[cfg(all(feature = "encoding", feature = "alloc"))]
- fn block_height_encoding_round_trip() {
- let blockheight = BlockHeight(0x7FFF_FFFF);
- let expected_bytes = alloc::vec![0xff, 0xff, 0xff, 0x7f];
-
- let encoded = encoding::encode_to_vec(&blockheight);
- assert_eq!(encoded, expected_bytes);
-
- let decoded = encoding::decode_from_slice::<BlockHeight>(encoded.as_slice()).unwrap();
- assert_eq!(decoded, blockheight);
- }
-
- #[test]
- #[cfg(feature = "encoding")]
- fn block_height_decoding() {
- let bytes = [0xff, 0xff, 0xff, 0xff];
- let expected = BlockHeight(0xFFFF_FFFF);
-
- let mut decoder = BlockHeight::decoder();
- assert_eq!(decoder.read_limit(), 4);
- assert!(!decoder.push_bytes(&mut bytes.as_slice()).unwrap());
- assert_eq!(decoder.read_limit(), 0);
-
- let decoded = decoder.end().unwrap();
- assert_eq!(decoded, expected);
- }
-
#[test]
#[cfg(feature = "encoding")]
fn block_height_decoding_error() {
diff --git a/units/src/sequence.rs b/units/src/sequence.rs
index 345531e0..2cd29415 100644
--- a/units/src/sequence.rs
+++ b/units/src/sequence.rs
@@ -395,7 +395,7 @@ mod tests {
#[cfg(all(feature = "encoding", feature = "alloc"))]
use encoding::UnexpectedEofError;
#[cfg(feature = "encoding")]
- use encoding::{Decodable as _, Decoder as _};
+ use encoding::Decoder as _;
use super::*;
@@ -501,34 +501,6 @@ mod tests {
}
}
- #[test]
- #[cfg(all(feature = "encoding", feature = "alloc"))]
- fn sequence_encoding_round_trip() {
- let sequence = Sequence(0x7FFF_FFFF);
- let expected_bytes = alloc::vec![0xff, 0xff, 0xff, 0x7f];
-
- let encoded = encoding::encode_to_vec(&sequence);
- assert_eq!(encoded, expected_bytes);
-
- let decoded = encoding::decode_from_slice::<Sequence>(encoded.as_slice()).unwrap();
- assert_eq!(decoded, sequence);
- }
-
- #[test]
- #[cfg(feature = "encoding")]
- fn sequence_decoding() {
- let bytes = [0xff, 0xff, 0xff, 0xff];
- let expected = Sequence::default();
-
- let mut decoder = Sequence::decoder();
- assert_eq!(decoder.read_limit(), 4);
- assert!(!decoder.push_bytes(&mut bytes.as_slice()).unwrap());
- assert_eq!(decoder.read_limit(), 0);
-
- let decoded = decoder.end().unwrap();
- assert_eq!(decoded, expected);
- }
-
#[test]
#[cfg(all(feature = "encoding", feature = "alloc"))]
fn sequence_decoding_error() {
diff --git a/units/src/time.rs b/units/src/time.rs
index d6ec602b..b2f9e976 100644
--- a/units/src/time.rs
+++ b/units/src/time.rs
@@ -171,7 +171,7 @@ mod tests {
#[cfg(all(feature = "encoding", feature = "alloc"))]
use encoding::UnexpectedEofError;
#[cfg(feature = "encoding")]
- use encoding::{Decodable as _, Decoder as _};
+ use encoding::Decoder as _;
use super::*;
@@ -193,34 +193,6 @@ mod tests {
assert_eq!(t, roundtrip);
}
- #[test]
- #[cfg(all(feature = "encoding", feature = "alloc"))]
- fn block_time_encoding_round_trip() {
- let t = BlockTime::from(1_742_979_600); // 26 Mar 2025 9:00 UTC
- let expected_bytes = alloc::vec![0x10, 0xc2, 0xe3, 0x67];
-
- let encoded = encoding::encode_to_vec(&t);
- assert_eq!(encoded, expected_bytes);
-
- let decoded = encoding::decode_from_slice::<BlockTime>(encoded.as_slice()).unwrap();
- assert_eq!(decoded, t);
- }
-
- #[test]
- #[cfg(feature = "encoding")]
- fn block_time_decoding() {
- let bytes = [0xb0, 0x52, 0x39, 0x69];
- let expected = BlockTime::from(1_765_364_400); // 10 Dec 2025 11:00 UTC
-
- let mut decoder = BlockTime::decoder();
- assert_eq!(decoder.read_limit(), 4);
- assert!(!decoder.push_bytes(&mut bytes.as_slice()).unwrap());
- assert_eq!(decoder.read_limit(), 0);
-
- let decoded = decoder.end().unwrap();
- assert_eq!(decoded, expected);
- }
-
#[test]
#[cfg(all(feature = "encoding", feature = "alloc"))]
fn block_time_decoding_error() {
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.