consensus_encoding: switch tests to should_panic macro
What changed, and why it matters
This commit only changes how two existing tests are written. It replaces manual panic-catching code with Rust's standard #[should_panic] test attribute. The tests still verify the same behavior: that decoding functions panic when decoded values do not match expected values. There is no change to production code, no security fix, and no vulnerability introduced.
No action required. This is a non-functional test refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies consensus_encoding/tests/decode.rs to use the #[should_panic(expected = “decoded value doesn’t match expected value”)] macro instead of std::panic::catch_unwind and AssertUnwindSafe wrappers. This is a test-code refactoring that reduces boilerplate and improves readability. The assertions being tested (panic on mismatched decoded values) remain identical.
Changed components
consensus_encoding/tests/decode.rsInspect captured patch +4 / −8
diff --git a/consensus_encoding/tests/decode.rs b/consensus_encoding/tests/decode.rs
index 70b0bb07..d8fe094e 100644
--- a/consensus_encoding/tests/decode.rs
+++ b/consensus_encoding/tests/decode.rs
@@ -658,22 +658,18 @@ fn decode_vec_decoder_end_incomplete_item() {
#[test]
#[cfg(feature = "alloc")]
+#[should_panic(expected = "decoded value doesn't match expected value")]
fn check_decode_panic_on_mismatched_value() {
let encoded = [0xEF, 0xBE, 0xAD, 0xDEu8];
let expected = Inner(0x1234_5678);
- let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
- check_decode(&encoded, &expected);
- }));
- assert!(result.is_err());
+ check_decode(&encoded, &expected);
}
#[test]
+#[should_panic(expected = "decoded value doesn't match expected value")]
fn check_decoder_panic_on_mismatched_value() {
let decoder = ArrayDecoder::<1>::new();
let bytes = &[0x42u8][..];
let expected = [0x99u8];
- let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
- check_decoder(decoder, bytes, &expected);
- }));
- assert!(result.is_err());
+ check_decoder(decoder, bytes, &expected);
}
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.