Skip to content

Add comprehensive dispute-resolution tests: window, minimum stake, tally, tie rule, double-dispute #592

@greatest0fallt1me

Description

@greatest0fallt1me

Description

The dispute subsystem in contracts/predictify-hybrid/src/disputes.rs is substantial but several core rules lack dedicated coverage, especially the stake-weighted tally and the exact-tie rule. DisputeUtils::calculate_stake_weighted_outcome resolves by comparing total_support_stake vs total_against_stake and, per its own comment, resolves an exact tie to false (oracle result stands). This issue adds a focused test module exercising the full dispute lifecycle and its edge rules.

Requirements and context

  • Functions under test: DisputeManager::process_dispute (disputes.rs:822), vote_on_dispute (disputes.rs:1406), calculate_dispute_outcome (disputes.rs:1509), resolve_dispute (disputes.rs:984), and DisputeUtils::calculate_stake_weighted_outcome.
  • Rules to verify: minimum stake (MIN_DISPUTE_STAKE), the dispute voting window (voting_start/voting_end on DisputeVoting), stake-weighted tally, the exact-tie rule (ties resolve to false), and double-dispute prevention (Error::AlreadyDisputed via has_user_disputed).
  • Verify events are emitted (emit_dispute_created, emit_dispute_resolved, dispute vote events) for the lifecycle.
  • Non-functional: use Soroban testutils and ledger time manipulation to test window boundaries; keep tests deterministic.
  • Re-enable or add the module cleanly in lib.rs (the dispute_stake_tests under tests/ is currently not wired in).

Acceptance criteria

  • Tests assert rejection below MIN_DISPUTE_STAKE and acceptance at/above it.
  • Tests cover voting inside vs after the dispute window (expired votes rejected).
  • A stake-weighted tally test confirms the higher-stake side wins, and an exact-tie test confirms resolution to false (oracle stands).
  • A double-dispute test asserts Error::AlreadyDisputed.
  • At least one test asserts the expected dispute events are published.
  • cargo fmt, cargo clippy, and cargo test pass with the module enabled.

Suggested execution

1. Fork the repo and create a branchgit checkout -b feature/dispute-resolution-tests.
2. Implement changes — none required in production code; if a testability gap is found, make a minimal, justified change in contracts/predictify-hybrid/src/disputes.rs.
3. Write/extend tests — extend contracts/predictify-hybrid/src/tests/dispute_stake_tests.rs (wire it into lib.rs) and/or resolution_delay_dispute_window_tests.rs.
4. Test and commit

cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
cargo test -p predictify-hybrid

Example commit message

test: add comprehensive dispute lifecycle and tie-rule coverage

Guidelines

Target ≥90% line/branch coverage of the dispute resolution paths. Cross-link the documented tie rule with docs/designs/outcome_selection.md and update API_DOCUMENTATION.md (Voting & Disputes) if behavior is clarified. Timeframe: 96 hours.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions