Test/contracts dispute payouts#672
Merged
mikewheeleer merged 3 commits intoJun 29, 2026
Merged
Conversation
…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
|
@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! 🚀 |
Contributor
|
great stuff — shipping it 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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