Skip to content

Task: Dispute tally property tests & resolved outcome summary cache#564

Merged
greatest0fallt1me merged 2 commits into
Predictify-org:masterfrom
Dopezapha:task/dispute-tally-property-tests-and-resolution-cache
May 27, 2026
Merged

Task: Dispute tally property tests & resolved outcome summary cache#564
greatest0fallt1me merged 2 commits into
Predictify-org:masterfrom
Dopezapha:task/dispute-tally-property-tests-and-resolution-cache

Conversation

@Dopezapha
Copy link
Copy Markdown
Contributor

Closes #553
Closes #547

Summary

Property tests for DisputeManager::calculate_dispute_outcome`

Files changed: property_based_tests.rs, tests/dispute_stake_tests.rs

Added a proptest suite and deterministic unit tests covering all required invariants for
DisputeUtils::calculate_stake_weighted_outcome and DisputeManager::calculate_dispute_outcome:

Test Invariant
deterministic_tally Same inputs always produce the same outcome
tie_resolves_to_reject Equal support/against stake resolves to false (reject)
monotonic_in_support_stake Adding more support stake never flips a winning outcome to losing
empty_stakes_no_panic Zero-stake voting completes without panic
dispute_tally_single_voter_support Single supporter with no opposition always wins
dispute_tally_all_equal_stakes_is_tie Tie case confirmed to reject

All tests use real DisputeVoting / DisputeVote types from disputes.rs.
Edge cases covered: empty set, single voter, all-equal stakes, monotonic increase.

ResolvedOutcomeSummary cache in resolution.rs

Files changed: resolution.rs, lib.rs, bets.rs, disputes.rs

Precomputes and persists a ResolvedOutcomeSummary struct
(winning_total, total_pool, num_winning_outcomes) once at resolution time via
ResolutionOutcomeCache::refresh(), eliminating repeated full-bet-set iteration on every
payout/claim call.

Payout paths updated to O(1) cache reads:

  • lib.rs::distribute_payoutsResolutionOutcomeCache::require() (line 3300)
  • lib.rs::claim_winningsResolutionOutcomeCache::require() (line 1881)

Cache invalidation:

  • ResolutionOutcomeCache::invalidate() called before admin outcome override
  • disputes.rs calls refresh() after dispute-driven outcome change
  • require() includes a staleness guard: re-computes automatically if total_pool or
    num_winning_outcomes drifts from cached values

…y property tests and cache resolved outcome summary for O(1) payout reads
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 26, 2026

@Dopezapha 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

@Dopezapha Dopezapha changed the title Dispute tally property tests & resolved outcome summary cache Task: Dispute tally property tests & resolved outcome summary cache May 26, 2026
@greatest0fallt1me greatest0fallt1me merged commit a4b0018 into Predictify-org:master May 27, 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

2 participants