Skip to content

Add tests for bounty application mutations - #291

Closed
alan-provable wants to merge 5 commits into
boundlessfi:mainfrom
alan-provable:main
Closed

Add tests for bounty application mutations#291
alan-provable wants to merge 5 commits into
boundlessfi:mainfrom
alan-provable:main

Conversation

@alan-provable

@alan-provable alan-provable commented Jun 26, 2026

Copy link
Copy Markdown

Summary

  • add focused tests for use-bounty-application mutation hooks requested in Add unit tests for the bounty application mutation hooks #282
  • cover contract success paths, optimistic cache updates, rollback behavior, dispute POSTs, and escrow release cache updates
  • reject missing applicant wallet addresses before contract calls

Verification

  • npm test -- hooks/tests/use-bounty-application.test.tsx --runInBand
  • npx eslint hooks/use-bounty-application.ts hooks/tests/use-bounty-application.test.tsx

Closes #282

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation when applying to a bounty by trimming the entered wallet address and requiring a non-blank value, returning a clearer error when missing.
    • Strengthened handling of bounty-related actions so failed requests roll back changes more reliably, keeping bounty status and escrow details accurate.
    • Verified dispute and bounty workflow updates continue to refresh the latest bounty details and lists after successful actions.
  • Tests
    • Added a comprehensive test suite covering the bounty application mutation hook behaviors, including success, rollback, and dispute payload correctness.

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.
@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown

@alan-provable is attempting to deploy a commit to the Threadflow Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@alan-provable, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cd712dfe-35ae-4aa2-81f5-c024d38cec6e

📥 Commits

Reviewing files that changed from the base of the PR and between 54f2d25 and 8a88918.

📒 Files selected for processing (1)
  • hooks/__tests__/use-bounty-application.test.tsx
📝 Walkthrough

Walkthrough

Adds 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.

Changes

Bounty application mutation hooks

Layer / File(s) Summary
Test scaffold and mocks
hooks/__tests__/use-bounty-application.test.tsx
Sets up the React Query test harness, global mocks, shared helpers, and contract wiring used by the mutation tests.
Apply and status mutations
hooks/use-bounty-application.ts, hooks/__tests__/use-bounty-application.test.tsx
useApplyToBounty trims and validates applicant addresses, and the tests cover apply, select, approve, and request-revisions mutations with success and rollback cases.
Slot and escrow mutations
hooks/__tests__/use-bounty-application.test.tsx
The tests cover slot assignment updates and escrow release cache updates, including rollback after contract or service failures.
Contributor removal and dispute flow
hooks/__tests__/use-bounty-application.test.tsx
The tests cover contributor removal, applicant decline, and dispute posting with bounty query invalidation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • Benjtalkshow
  • 0xdevcollins

Poem

A bunny hopped through hooks all day,
and found the bugs had hopped away.
With escrow hops and cache rollback,
the bounty trail stayed right on track.
🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding bounty application mutation tests.
Linked Issues check ✅ Passed The PR appears to cover the requested hook tests and required behaviors from #282, including optimistic updates, rollbacks, dispute POSTing, and missing-address validation.
Out of Scope Changes check ✅ Passed The only code change beyond tests is the applicant address normalization/validation, which is directly required by the linked issue.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Normalize 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9e5dc91 and ed97451.

📒 Files selected for processing (2)
  • hooks/__tests__/use-bounty-application.test.tsx
  • hooks/use-bounty-application.ts

Comment thread hooks/__tests__/use-bounty-application.test.tsx
Comment thread hooks/__tests__/use-bounty-application.test.tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for the bounty application mutation hooks

2 participants