fix(orders): block change-drop when escrow is already funded#620
fix(orders): block change-drop when escrow is already funded#620nyxsky404 wants to merge 2 commits into
Conversation
The Escrow contract reverts on a second deposit for the same bookingId, so allowing change-drop after funding produces a divergence between the Supabase total_amount and the on-chain escrow with no way to reconcile. Return 409 with a recovery hint to cancel and rebook instead.
|
🎉 Thank you for your contribution! Your pull request has been received and will be reviewed shortly. If you enjoy the project, please consider giving the repository a ⭐. You can also follow my GitHub profile to stay updated on future open-source projects. Thanks for being part of the community! 🚀 |
📝 WalkthroughWalkthroughA guard clause is added to the ChangesBlock change-drop when escrow is funded
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
Blocks drop-location changes once an order’s escrow has already been funded, preventing the database total_amount from diverging from the immutable on-chain escrow amount (and therefore avoiding incorrect driver payouts on escrow release).
Changes:
- Add an early
409 Conflictreturn in thePUT /orders/:id/change-drophandler whenorder.escrow_status === 'funded'. - Surface an explicit recovery hint to cancel and rebook since the on-chain amount can’t be adjusted post-funding.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
backend/api/test/integration/orders.test.js (1)
1832-1834: ⚡ Quick winStrengthen response-contract assertions for
error/recovery.Right now this passes as long as keys exist. Since this endpoint’s UX depends on explicit recovery guidance, assert message content (or stable substrings) to prevent silent regressions.
Proposed test hardening
expect(res.status).toBe(409); - expect(res.body).toHaveProperty('error'); - expect(res.body).toHaveProperty('recovery'); + expect(res.body.error).toBe('Drop location cannot be changed after escrow has been funded.'); + expect(res.body.recovery).toContain('Cancel this order'); + expect(res.body.recovery).toContain('rebook');🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/api/test/integration/orders.test.js` around lines 1832 - 1834, The test assertions in the integration test for orders endpoint are only checking for the existence of error and recovery properties without validating their content. Strengthen the assertions for res.body.error and res.body.recovery to validate that they contain actual meaningful message content, such as checking that they are non-empty strings or contain expected substrings relevant to the conflict resolution guidance. This prevents silent regressions where these properties might exist but be empty or contain incorrect values.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@backend/api/test/integration/orders.test.js`:
- Around line 1832-1834: The test assertions in the integration test for orders
endpoint are only checking for the existence of error and recovery properties
without validating their content. Strengthen the assertions for res.body.error
and res.body.recovery to validate that they contain actual meaningful message
content, such as checking that they are non-empty strings or contain expected
substrings relevant to the conflict resolution guidance. This prevents silent
regressions where these properties might exist but be empty or contain incorrect
values.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: c0456fe7-b5d8-4823-8a74-dc1bd1bcb526
📒 Files selected for processing (1)
backend/api/test/integration/orders.test.js
|
CI failures are pre-existing — backend test failures (expected 500, got 422) are caused by the wallet-address guard added in an earlier PR, not this change. Flutter failures are unrelated infra issues present on |
Closes #607
The change-drop handler was recalculating and persisting a new
total_amountwithout checking whether escrow was already funded. OnceescrowReleasefires on delivery it releases the original on-chain amount, not the updated total, so the driver payout diverges from the Supabase record.The
Escrow.solcontract itself reverts on a seconddeposit()for the samebookingId("Escrow exists"), so there's no path to adjust the on-chain amount after funding anyway. The handler now returns 409 early ifescrow_status === 'funded', surfacing the constraint explicitly with a recovery hint to cancel and rebook.Summary by CodeRabbit
/api/orders/:id/change-dropis blocked when escrow is already funded.