refactor: replace wildcard match arms with explicit enum variants#10440
Open
zmanian wants to merge 5 commits intoZcashFoundation:mainfrom
Open
refactor: replace wildcard match arms with explicit enum variants#10440zmanian wants to merge 5 commits intoZcashFoundation:mainfrom
zmanian wants to merge 5 commits intoZcashFoundation:mainfrom
Conversation
Add comprehensive unit tests for policy functions added in ZcashFoundation#10314: - count_script_push_ops: PUSHDATA1/2/4, mixed types, truncated scripts - extract_p2sh_redeemed_script: existing + edge cases - script_sig_args_expected: P2PK, multisig via script classification - are_inputs_standard: P2PKH accept/reject, wrong stack depth, non-standard spent outputs, P2SH with standard/non-standard redeemed scripts, sigops boundary, multi-input rejection - p2sh_sigop_count: P2SH/non-P2SH/multi-input summation Also adds defensive improvements: - saturating_add for sigop count arithmetic - debug_assert_eq for input/spent_output alignment - Expanded doc comments with correctness notes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove unnecessary Hash derive from NonStandardTransactionError - Move p2pkh_lock_script, p2sh_lock_script, p2pk_lock_script to module level in policy.rs as #[cfg(test)] pub(super) functions, eliminating duplication between policy::tests and tests::vectors Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace `_ =>` wildcard patterns with explicit enum variant listings across the workspace to improve safety. When new enum variants are added, the compiler will now produce errors instead of silently falling through to a default case. - 42 files modified across zebra-chain, zebra-consensus, zebra-network, zebra-rpc, zebra-state, and zebrad - Feature-gated variants (ReadResponse::TransactionId behind `indexer`, Transaction::V6 behind `nu7`/`tx_v6`) handled with #[cfg] arms - halo2::plonk::Error retains wildcard with #[allow] due to upstream #[non_exhaustive] - Pre-existing println! lint fix in zebra-state test (-> tracing::warn!) Closes ZcashFoundation#10211
Contributor
Author
|
@conradoplg This is ready for review — CI workflows need maintainer approval to run (fork PR). Could you approve the Actions runs when you get a chance? Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Closes #10211
Wildcard match arms (
_ =>) silently swallow new enum variants, which can hide bugs when new variants are added. Replacing them with explicit variant listings ensures the compiler flags any match that needs updating.Solution
_ =>patterns across 42 files with explicit enum variant listingsReadResponse::TransactionIdbehindindexer,Transaction::V6behindnu7/tx_v6,NetworkUpgrade::ZFuturebehindzfuture) handled with#[cfg]armshalo2::plonk::Errorretains wildcard with#[allow(clippy::wildcard_enum_match_arm)]due to upstream#[non_exhaustive]indexerfeature propagation fromzebrad->zebra-rpc->zebra-stateprintln!clippy lint inzebra-state/src/service/read/tests/vectors.rs(changed totracing::warn!)Verification
cargo fmt --all -- --checkpassescargo clippy --workspace --all-targets -- -D warningspasses (default features)cargo clippy --workspace --all-targets --features indexer -- -D warningspassesAI Disclosure
Used Claude Code for initial enumeration of wildcard patterns and mechanical replacement. All changes were reviewed and verified by the contributor.