Test/issue 98 cross contract invariants - #188
Conversation
Verifies that constant combinations across all contracts produce safe behavior. Tests cover: 1. AccumulatedFees == sum(MarketFees) + LegacyFees at all times 2. cancel_market reclaims exactly the market's fee balance 3. withdraw_fees cap prevents single-call draining 4. PULSE total supply tracks all reward mints exactly 5. Market TTL outlives duration + dispute window 6. Fee conservation: total = withdrawn + reclaimed + remaining 7. Leaderboard points conserved across win/loss/bonus 8. Withdrawal cap exceeds fee rate (can actually withdraw) 9. Dispute window fits within TTL for zero-side claims 10. Multi-market fee isolation (cancel doesn't leak across markets) Each test exercises an invariant that emerges from constant interactions, not from any single constant alone.
Muyideen-js
left a comment
There was a problem hiding this comment.
@praizeD10 The PR adds tests but does not solve the issue. The issue requires a cross-contract invariant test suite that exercises every constant combination (fee BPS × market duration × TTL × reward rate × referral depth) and documents the invariant matrix. The added tests only check individual invariants (e.g., accumulator equals ledger sum, cancel reclaims exact fees) but do not test the dangerous interactions listed in the issue. Specifically, missing tests: 1) TTL vs max_duration_secs (30 days vs 60 days) — a market running full duration will have expired BetEntry before claim window closes. 2) Leaderboard points vs PULSE minting cap with MAX_TOP_PLAYERS — increasing MAX_TOP_PLAYERS without adjusting REWARD_RATE can exceed token supply cap. 3) Referral depth vs fee caps — deep referral chains can wipe accumulator on cancel. 4) Order-of-operations between cancel_market reclaim and withdraw_fees cap. Also, the issue requests documentation of the invariant matrix and a governance process for constant changes, which are not provided. Please add these missing tests and documentation, and ensure CI is run. The current tests are insufficient to approve.
closes #175
What
Adds 10 cross-contract invariant tests that verify constant combinations
across prediction_market, leaderboard, and pulse_token produce safe behavior.
Why
Individual unit tests pass, but constant interactions (fees × TTL × reward
rate × withdrawal caps) were untested. These invariants only emerge when
contracts interact.
Tests
Verification
Manual API audit confirmed all method names match contract ABIs.