Skip to content

Test/contracts dispute payouts#672

Merged
mikewheeleer merged 3 commits into
Talenttrust:mainfrom
T-kesh:test/contracts-dispute-payouts
Jun 29, 2026
Merged

Test/contracts dispute payouts#672
mikewheeleer merged 3 commits into
Talenttrust:mainfrom
T-kesh:test/contracts-dispute-payouts

Conversation

@T-kesh

@T-kesh T-kesh commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

This PR adds comprehensive unit tests for the resolution_payouts function in contracts/escrow/src/dispute.rs, which implements the pure money-splitting logic for dispute resolution.

Changes
contracts/escrow/src/test/dispute.rs
Unit tests for payout arithmetic covering all DisputeResolution variants:
FullRefund: verifies all available balance goes to client (available, 0)
FullPayout: verifies all available balance goes to freelancer (0, available)
PartialRefund: table-driven tests for 70/30 floor division at odd amounts (7, 10, 99, 100, 101, 102, 103)
Split: tests negative amount rejection, non-conserving sum rejection, overflow protection
AccountingInvariantViolated: test for corrupted accounting state detection
Conservation invariant tests: verify client_payout + freelancer_payout == available across all resolution types
Integration tests: end-to-end tests for raise_dispute and resolve_dispute with FullRefund, FullPayout, PartialRefund, and Split resolutions
contracts/escrow/src/dispute.rs
Removed duplicate DisputeResolution enum (now centralized in types.rs)
Kept resolution_payouts and final_status_after_resolution functions with proper DisputeSplit struct handling
contracts/escrow/src/types.rs
Removed duplicate Error enum and DataKey definition
Added code() method to DisputeResolution for event emission compatibility
contracts/escrow/src/lib.rs
Removed duplicate safe_add_amounts function
Exported resolution_payouts and final_status_after_resolution for testability
docs/escrow/README.md
Added "Dispute Resolution Payout Matrix" section documenting the payout logic and security invariants

closes #465

T-kesh and others added 3 commits June 28, 2026 19:21
…nsfer

- Add cancel_governance_admin_proposal_impl in governance.rs
  * Requires admin auth and initialized contract
  * Rejects with InvalidState when no pending proposal exists
  * Removes DataKey::PendingAdmin and emits (admin, cancelled) event
  * Includes doc comments

- Add public entrypoint cancel_governance_admin_proposal in lib.rs
  * Delegates to cancel_governance_admin_proposal_impl

- Add comprehensive security tests in test/security.rs
  * cancel_clears_pending_admin: verifies PendingAdmin is removed
  * cancel_blocks_later_accept: ensures cancelled proposal cannot be accepted
  * cancel_without_proposal_rejected: validates InvalidState error
  * cancel_before_initialize_rejected: validates NotInitialized error
  * cancel_then_repropose_and_accept_succeeds: confirms clean slate after cancel
  * cancel_rejects_non_admin_auth: verifies admin-gated with #[should_panic]
  * cancel_emits_cancelled_event: validates audit event emission

- Fix get_pending_governance_admin_impl signature to take &Env for consistency

- Refactor set_protocol_fee_bps to remove duplicate admin parameter and use
  require_initialized helper

Addresses Talenttrust#450

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Add comprehensive unit tests for resolution_payouts covering:
  - FullRefund: returns (available, 0)
  - FullPayout: returns (0, available)
  - PartialRefund: 70/30 floor division with table-driven odd amount tests
  - Split: accepts valid splits, rejects negative amounts and non-conserving sums
- Add tests for AccountingInvariantViolated edge case
- Add integration tests for raise_dispute and resolve_dispute
- Add documentation in docs/escrow/README.md describing payout matrix
- Cleanup: remove duplicate DisputeResolution enum from dispute.rs
- Cleanup: consolidate types in types.rs with code() method
- Remove duplicate safe_add_amounts function from lib.rs
@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@T-kesh 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! 🚀

Learn more about application limits

@mikewheeleer

Copy link
Copy Markdown
Contributor

great stuff — shipping it 🚀

@mikewheeleer mikewheeleer merged commit 9077df4 into Talenttrust:main Jun 29, 2026
1 check failed
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 tests for the dispute resolution_payouts split math in dispute.rs

2 participants