refactor: add is_already_voted predicate for AlreadyVoted rejections#101
Closed
dev-miro26 wants to merge 1 commit intoentrius:testfrom
Closed
refactor: add is_already_voted predicate for AlreadyVoted rejections#101dev-miro26 wants to merge 1 commit intoentrius:testfrom
dev-miro26 wants to merge 1 commit intoentrius:testfrom
Conversation
Author
|
Hi, @LandynDev |
Collaborator
|
Closing — |
3 tasks
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.
Closes: #100
Summary
is_already_voted(e)alongsideis_contract_rejectioninallways/contract_client.py— a single source of truth for detecting theAlreadyVotedcontract-error variant, anchored toCONTRACT_ERROR_VARIANTS[3].'AlreadyVoted' in str(e)substring checks inallways/validator/forward.pywith calls to the new predicate.Why
forward.py:254andforward.py:395were branching onif 'AlreadyVoted' in str(e):. The codebase already exports a structuredCONTRACT_ERROR_VARIANTSmap and a canonicalis_contract_rejection(e)predicate fromallways/contract_client.py, but theAlreadyVotedcheck bypassed both with a raw substring match. If theContractErrormessage format ever changes (e.g. variant rename, localisation, format tweak indecode_contract_error), the two call sites would silently stop matching with no lint or test signal.Co-locating the predicate with
is_contract_rejectionalso leaves room for a small documented predicate set (is_duplicate_source_tx,is_miner_reserved, …) if future code wants variant-specific branching.Changes
allways/contract_client.py: addis_already_voted(e) -> boolnext tois_contract_rejection; docstring points atCONTRACT_ERROR_VARIANTS[3]as the canonical variant source.allways/validator/forward.py:is_already_votedalongside the existingis_contract_rejection.forward.py:254(extend-reservation vote failure branch) — swap substring check for predicate.forward.py:395(extend-timeout vote failure branch) — swap substring check for predicate.+8 / −2lines; no signature changes.Type of Change
Test plan
ruff check allways/ neurons/ tests/— cleanruff format --check allways/ neurons/ tests/— cleanpytest tests/— 291 passed; 9 pre-existing failures intests/test_axon_handlers.pyonupstream/testare unrelated ("too many values to unpack (expected 3)"in theSwapConfirmhandler) and unchanged by this diffrg "'AlreadyVoted' in str"— now returns exactly one hit (the predicate itself), zero remaining inline substring checks