Skip to content

feat: Add dispute resolution mechanism for milestones#8

Merged
0xdevcollins merged 1 commit intomainfrom
feat/dispute-resolution
Apr 4, 2026
Merged

feat: Add dispute resolution mechanism for milestones#8
0xdevcollins merged 1 commit intomainfrom
feat/dispute-resolution

Conversation

@0xdevcollins
Copy link
Copy Markdown
Contributor

@0xdevcollins 0xdevcollins commented Apr 4, 2026

Summary

  • Adds resolve_dispute(campaign_id, milestone_index, resolution) admin-only function with two resolution paths: ApproveCreator (releases milestone funds) and ApproveBacker (rejects milestone, cancels campaign, enables refunds)
  • Adds get_dispute_status(campaign_id, milestone_index) query for checking current milestone dispute state
  • Emits DisputeResolved event with campaign_id, milestone_id, and resolution for indexer integration
  • Fixes stale integration test call sites missing submit bool and reason arguments from prior commits

Closes #2

Test plan

  • test_resolve_dispute_approve_creator — full flow: dispute → resolve for creator → funds released → campaign continues
  • test_resolve_dispute_approve_backer — full flow: dispute → resolve for backer → milestone rejected → campaign cancelled → refunds processed
  • test_resolve_dispute_not_disputed_fails — resolving a non-disputed milestone returns MilestoneNotDisputed error
  • All 57 integration tests pass
  • All unit tests pass

Summary by CodeRabbit

Release Notes

  • New Features
    • Admins can now resolve disputed milestones with two resolution options: approve the creator (releases the milestone and allows the campaign to continue) or approve the backer (cancels the campaign and enables refunds).
    • Added the ability to check the dispute status of any milestone in a campaign.
    • New event emitted whenever a dispute is resolved.

Disputed milestones were a dead-end with no way to resolve them.
This adds admin-only `resolve_dispute` to settle disputes in favor
of either the creator (release funds) or backer (reject + cancel
campaign for refunds), along with a `get_dispute_status` query and
`DisputeResolved` event for indexer integration.

Also fixes stale integration test call sites missing the `submit`
bool and `reason` arguments added in prior commits.

Closes #2

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 4, 2026

📝 Walkthrough

Walkthrough

A dispute resolution mechanism for crowdfunding milestones has been implemented, adding admin-only functions to query and resolve disputed milestones with different outcomes: creator approval releases funds and completes campaigns when all milestones are released, while backer approval rejects milestones, cancels campaigns, and enables refunds. Corresponding event, error, and storage types have been added, along with comprehensive tests and snapshot updates.

Changes

Cohort / File(s) Summary
Dispute Resolution Core Logic
contracts/crowdfund_registry/src/contract.rs
Added get_dispute_status() query and resolve_dispute() admin action with dual-path logic: ApproveCreator releases milestone and conditionally completes campaign; ApproveBacker rejects milestone and cancels campaign. Includes escrow and reputation registry interactions, event emission, and TTL extension.
Type System Extensions
contracts/crowdfund_registry/src/storage/mod.rs, contracts/crowdfund_registry/src/error.rs, contracts/crowdfund_registry/src/events/mod.rs
Added DisputeResolution enum with two variants, new MilestoneNotDisputed error code (827), and DisputeResolved event struct with campaign/milestone topics and resolution payload.
Dispute Resolution Tests
contracts/crowdfund_registry/src/tests/mod.rs
Added three test cases: ApproveCreator path (milestone released, campaign executes), ApproveBacker path (milestone rejected, campaign cancelled, refunds enabled), and error case (non-disputed milestone rejection).
Test Snapshots - Dispute Resolution
contracts/crowdfund_registry/test_snapshots/tests/test_resolve_dispute_*.1.json
Three new snapshot files capturing full ledger state and invocation traces for both resolution outcomes and error cases, including escrow, governance, campaign, and asset balance states.
Integration Tests - Campaign Signature Update
tests/integration/src/test_*.rs (5 files)
Updated create_campaign() call sites across E2E, cross-module, edge-case, and new-feature test suites to pass additional boolean parameter; also updated governance rejection test to include rejection reason string.
Integration Test Snapshots - Signature Alignment
tests/integration/test_snapshots/test_*/\*.1.json (25+ files)
Updated serialized create_campaign() argument lists to include trailing boolean parameter (false); one governance snapshot also adds rejection reason argument to reject_campaign() call.

Sequence Diagram(s)

sequenceDiagram
    participant Admin as Admin User
    participant Contract as Crowdfund Contract
    participant Escrow as Escrow Contract
    participant Reputation as Reputation Registry

    rect rgb(100, 150, 200, 0.5)
    Note over Admin,Reputation: ApproveCreator Resolution Path
    Admin->>Contract: resolve_dispute(campaign_id, milestone, ApproveCreator)
    Contract->>Contract: Load milestone (assert Disputed)
    Contract->>Contract: Set milestone status to Released
    Contract->>Escrow: release_slot(milestone)
    Escrow-->>Contract: Funds released
    Contract->>Contract: Check all milestones Released?
    alt All milestones released
        Contract->>Contract: Mark campaign Completed
        Contract->>Reputation: record_campaign_backed(campaign_id)
        Reputation-->>Contract: Reputation recorded
    end
    Contract->>Contract: Emit DisputeResolved(ApproveCreator)
    Contract-->>Admin: Success
    end

    rect rgb(200, 100, 100, 0.5)
    Note over Admin,Contract: ApproveBacker Resolution Path
    Admin->>Contract: resolve_dispute(campaign_id, milestone, ApproveBacker)
    Contract->>Contract: Load milestone (assert Disputed)
    Contract->>Contract: Set milestone status to Rejected
    Contract->>Contract: Mark campaign Cancelled
    Contract->>Contract: Reset refund_progress to 0
    Contract->>Contract: Emit DisputeResolved(ApproveBacker)
    Contract-->>Admin: Success (refunds now available)
    end
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly Related Issues

  • Implement dispute resolution mechanism for milestones #2: Implement dispute resolution mechanism for milestones — This PR directly implements the requested dispute resolution functionality, including resolve_dispute() admin action, get_dispute_status() query, DisputeResolution type variants, DisputeResolved event emission, and comprehensive test coverage for both resolution paths (ApproveCreator and ApproveBacker), fulfilling all stated acceptance criteria.

Poem

🐰 A dispute once trapped in limbo deep,
Now finds resolution—no more to keep!
Creator wins or backer's way,
The rabbit hops disputes away! 🎯

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: Add dispute resolution mechanism for milestones' accurately describes the primary change: implementing dispute resolution functionality for milestones, which is the core focus of this PR.
Linked Issues check ✅ Passed All coding requirements from issue #2 are met: resolve_dispute() with ApproveCreator/ApproveBacker paths, get_dispute_status() query, DisputeResolved event, MilestoneNotDisputed error, and comprehensive tests covering both resolution outcomes.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing dispute resolution. Test snapshot updates reflect necessary adjustments to test call signatures due to prior API changes, not new scope creep.
Docstring Coverage ✅ Passed Docstring coverage is 96.67% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/dispute-resolution

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 and usage tips.

@0xdevcollins 0xdevcollins merged commit 0bf7e84 into main Apr 4, 2026
1 check was pending
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.

Implement dispute resolution mechanism for milestones

1 participant