Add tests for bounty application mutations - #291
Conversation
Add validation for applicant wallet address in application.
This file contains tests for the use-bounty-application hooks, covering various scenarios including applying for slots, selecting applicants, and handling disputes.
|
@alan-provable is attempting to deploy a commit to the Threadflow Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Review limit reached
More reviews will be available in 25 minutes and 37 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a new test suite for bounty application mutation hooks and trims applicant addresses before apply calls. The tests cover optimistic updates, rollback behavior, escrow release handling, dispute posting, and query invalidation. ChangesBounty application mutation hooks
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
hooks/use-bounty-application.ts (1)
117-127: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winNormalize the applicant address before calling
apply.Line 117 validates
applicantAddress.trim(), but Line 126 still forwards the original string. A value like" GAPPLICANT "now passes validation and still hits the contract with whitespace attached.Suggested fix
}) => { - if (!applicantAddress.trim()) { + const normalizedApplicantAddress = applicantAddress.trim(); + if (!normalizedApplicantAddress) { throw new ApplicationError( "tx_failed", "Applicant wallet address is required.", ); } const client = resolveApplicationClient(); return client.apply({ - applicant: applicantAddress, + applicant: normalizedApplicantAddress, bountyId: toBountyIdBigInt(bountyId), proposal, }); },🤖 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 `@hooks/use-bounty-application.ts` around lines 117 - 127, The `use-bounty-application` flow validates `applicantAddress.trim()` but still passes the untrimmed `applicantAddress` into `client.apply`, so whitespace can leak into the contract call. Normalize the address once before the `apply` call by trimming it and use that normalized value for both validation and the `applicant` field, keeping the change localized to the hook logic around `resolveApplicationClient` and `client.apply`.
🤖 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.
Inline comments:
In `@hooks/__tests__/use-bounty-application.test.tsx`:
- Around line 489-524: The useRemoveContributor test currently verifies only
that contributorProgress shrinks, but it does not assert the slot count update.
Extend the existing "removes a contributor and decrements occupied slots" test
in use-bounty-application.test.tsx to also check
getBounty(queryClient).totalSlotsOccupied after mutateAsync, alongside the
existing contributorProgress assertion, so regressions in the decrement logic
are caught.
- Around line 206-244: Add the missing failure-path coverage in the hook tests:
`useApplyToBounty` still needs a contract-error case, and `useDeclineApplicant`
still needs a rollback-on-error case. Extend
`hooks/__tests__/use-bounty-application.test.tsx` by adding a test that forces
`applicationClient.apply` to reject and asserts the mutation surfaces the
expected `ApplicationError`/tx failure behavior, and another test around
`useDeclineApplicant` that simulates a failed decline and verifies rollback side
effects are triggered. Use the existing `renderHook`, `createWrapper`, and
`applicationClient` setup so the new tests align with the current hook behavior.
---
Outside diff comments:
In `@hooks/use-bounty-application.ts`:
- Around line 117-127: The `use-bounty-application` flow validates
`applicantAddress.trim()` but still passes the untrimmed `applicantAddress` into
`client.apply`, so whitespace can leak into the contract call. Normalize the
address once before the `apply` call by trimming it and use that normalized
value for both validation and the `applicant` field, keeping the change
localized to the hook logic around `resolveApplicationClient` and
`client.apply`.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 49e7d033-80ca-4291-9109-f419726dec01
📒 Files selected for processing (2)
hooks/__tests__/use-bounty-application.test.tsxhooks/use-bounty-application.ts
Summary
Verification
Closes #282
Summary by CodeRabbit