What changed, and why it matters
This commit only adds new unit tests for an existing encoding helper. It does not change any production code, fix bugs, or introduce new behavior. There is no security relevance.
Recommended action
No action needed; this is a test-only change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds a test module in consensus_encoding/src/encode/encoders.rs with two tests for BytesEncoder::without_length_prefix: one for a non-empty byte slice and one for an empty slice. The production implementation is untouched.
Changed components
consensus_encoding/src/encode/encoders.rsInspect captured patch +38 / −0
diff --git a/consensus_encoding/src/encode/encoders.rs b/consensus_encoding/src/encode/encoders.rs
index 781af904..fcec3305 100644
--- a/consensus_encoding/src/encode/encoders.rs
+++ b/consensus_encoding/src/encode/encoders.rs
@@ -155,3 +155,41 @@ impl<
fn current_chunk(&self) -> Option<&[u8]> { self.inner.current_chunk() }
fn advance(&mut self) -> bool { self.inner.advance() }
}
+
+#[cfg(test)]
+#[cfg(feature = "alloc")]
+mod tests {
+ use alloc::vec::Vec;
+
+ use super::*;
+
+ // Run the encoder i.e., use it to encode into a vector.
+ fn run_encoder<'e>(mut encoder: impl Encoder<'e>) -> Vec<u8> {
+ let mut vec = Vec::new();
+ while let Some(chunk) = encoder.current_chunk() {
+ vec.extend_from_slice(chunk);
+ encoder.advance();
+ }
+ vec
+ }
+
+ #[test]
+ fn encode_byte_slice_without_prefix() {
+ let obj = [1u8, 2, 3];
+
+ let encoder = BytesEncoder::without_length_prefix(&obj);
+ let got = run_encoder(encoder);
+
+ assert_eq!(got, obj);
+ }
+
+ #[test]
+ fn encode_empty_byte_slice_without_prefix() {
+ let obj = [];
+
+ let encoder = BytesEncoder::without_length_prefix(&obj);
+ let got = run_encoder(encoder);
+
+ assert_eq!(got, obj);
+ }
+}
Risk score
Our methodology →Why this scored 15/100
Human-validated context
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
No validated notes yet.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.