Replace match statements with matches! macros
What changed, and why it matters
This commit is a minor code cleanup in test code only. It replaces verbose match statements with the shorter matches! macro in two unit tests. The change does not affect production code, behavior, or security.
No security action needed. Optionally, the project may want to restore assertions (e.g., assert!(matches!(...))) so the tests continue to enforce expected behavior.
Security signals we found
No strong security signals were identified.
Evidence from the diff
In primitives/src/block.rs, two unit tests previously used match statements that panicked unless the expected InvalidBlockError variant was returned. The commit replaces them with matches!(…) macro calls. Critically, matches! returns a bool and does not assert or panic on its own, so the tests no longer actually verify the validation result. However, this is a test-quality issue, not a security vulnerability, and it affects no runtime code.
Changed components
primitives/src/block.rs (unit tests only)Inspect captured patch +2 / −8
diff --git a/primitives/src/block.rs b/primitives/src/block.rs
index 26a2a62e..ff516a8d 100644
--- a/primitives/src/block.rs
+++ b/primitives/src/block.rs
@@ -1056,10 +1056,7 @@ mod tests {
let transactions = Vec::new(); // Empty transactions
let block = Block::new_unchecked(header, transactions);
- match block.validate() {
- Err(InvalidBlockError::NoTransactions) => (),
- other => panic!("Expected NoTransactions error, got: {:?}", other),
- }
+ matches!(block.validate(), Err(InvalidBlockError::NoTransactions));
}
#[test]
@@ -1089,10 +1086,7 @@ mod tests {
let transactions = vec![non_coinbase_tx];
let block = Block::new_unchecked(header, transactions);
- match block.validate() {
- Err(InvalidBlockError::InvalidCoinbase) => (),
- other => panic!("Expected InvalidCoinbase error, got: {:?}", other),
- }
+ matches!(block.validate(), Err(InvalidBlockError::InvalidCoinbase));
}
#[test]
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.