feat: return 422 for invalid withdrawal destination_key (closes #391) - #639
Open
collinsezedike wants to merge 1 commit into
Open
Conversation
|
@collinsezedike Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
Author
|
CI failures here ( |
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.
What I built
withdrawals.jsalready validateddestination_keywithKeypair.fromPublicKeyvia the sharedwithdrawalValidationmiddleware, but the sharedvalidateRequesthandler only mapped validation failures to422for paths containing/contributions— everything else, including/withdrawals, fell through to400. That meant an invalid Stellar key was rejected, just with the wrong status code, failing the issue's acceptance criteria.Fixed
validateRequestinbackend/src/middleware/validation.jsto also return422for/withdrawalspaths, and added a regression test asserting an invaliddestination_keyonPOST /api/withdrawals/requestreturns422with a clear error message.Decisions worth noting
No new validation logic was added — the
Keypair.fromPublicKeycheck already existed and matches the pattern used incontributions.js. This PR only corrects the status code mapping so the existing validation actually satisfies the issue's acceptance criteria.How to test manually
POST /api/withdrawals/requestwith a validcampaign_id/amountanddestination_key: "not-a-valid-key"→ expect422witherror.messagecontaining "destination_key must be a valid Stellar public key"destination_key→ expect the normal201pending-request flow, unaffectedChecklist
npm test— could not run in this environment (nonode_modulesinstalled); please runcd backend && npm testin reviewmain, branch is rebased and cleanCloses #391