Skip to content

test: add proptest invariants for VotingManager stake conservation (#607)#638

Open
Jonahadukwu5 wants to merge 1 commit into
Predictify-org:masterfrom
Jonahadukwu5:test/voting-invariant-proptests
Open

test: add proptest invariants for VotingManager stake conservation (#607)#638
Jonahadukwu5 wants to merge 1 commit into
Predictify-org:masterfrom
Jonahadukwu5:test/voting-invariant-proptests

Conversation

@Jonahadukwu5

@Jonahadukwu5 Jonahadukwu5 commented Jun 26, 2026

Copy link
Copy Markdown

Closes #607


Summary

Implements issue #607. Adds a proptest harness that asserts the global stake conservation invariant after every sequence of valid votes:

sum(outcome_distribution.values()) == market.total_staked == VotingStats.total_staked

Changes

  • New: contracts/predictify-hybrid/src/voting_invariants.rs — 5 proptest suites (1000 cases each, deterministic seed)
  • Modified: src/lib.rs — register #[cfg(test)] mod voting_invariants
  • Fixed: require_auth_coverage_tests.rs — 4 pre-existing build errors (missing max_deviation_bps arg)

Test suites

Test Coverage
prop_sequential_votes_conserve_stake Invariant checked after every step in sequences of 1–20 votes
prop_multi_outcome_distribution_conserves_stake All 4 outcome labels covered
prop_duplicate_user_stake_not_silently_doubled Documents upsert/accumulate split; confirms AlreadyVoted guard is load-bearing
prop_zero_stake_does_not_corrupt_total Zero-stake edge case
prop_large_voter_set_conserves_stake 50–200 voters, sum verified

Test output

test voting_invariants::prop_duplicate_user_stake_not_silently_doubled ... ok
test voting_invariants::prop_multi_outcome_distribution_conserves_stake ... ok
test voting_invariants::prop_sequential_votes_conserve_stake ... ok
test voting_invariants::prop_zero_stake_does_not_corrupt_total ... ok
test voting_invariants::prop_large_voter_set_conserves_stake ... ok

test result: ok. 608 passed; 0 failed; 0 ignored

Acceptance criteria

  • ✅ 1000+ cases per invariant
  • ✅ Failure shrinks to minimal counterexample (verified: duplicate test shrinks to stake1=1_000_000, stake2=1_000_000)
  • ✅ Deterministic seed via source_file in ProptestConfig
  • ✅ No unwrap() added to production code

- Add voting_invariants.rs with 5 proptest suites (1000 cases each)
- Assert sum(outcome_distribution) == total_staked after every vote
- Covers: sequential votes, multi-outcome, duplicate-user guard,
  zero-stake, large voter sets (50-200 voters)
- Deterministic seed via source_file in ProptestConfig
- Fix pre-existing require_auth_coverage_tests.rs build errors
  (missing max_deviation_bps arg in 4 calls)

Closes Predictify-org#607
@drips-wave

drips-wave Bot commented Jun 26, 2026

Copy link
Copy Markdown

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

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 invariant property tests for VotingManager total-stake conservation

1 participant