test(early-cashout): add dust stake edge-case tests for #407 - #467
Open
diahtech1 wants to merge 2 commits into
Open
test(early-cashout): add dust stake edge-case tests for #407#467diahtech1 wants to merge 2 commits into
diahtech1 wants to merge 2 commits into
Conversation
… TTL touches (Closes TevaLabs#397) Fix error semantics for reclaim_expired_pending_winnings that were confused in recent diffs. The function now returns three distinct errors: - ExpiryNotConfigured (78) when pending winnings expiry is disabled (0) - PendingWinningsNotFound (77) when no entry exists for the user - PendingWinningsNotExpired (79) when the entry has not yet reached the configured age threshold Also fixes a critical error discriminant collision where PendingWinningsNotExpired shared value 66 with OracleTimestampOutsideWindow. PendingWinningsNotExpired is now 79. Changes: - contracts/src/errors.rs: move PendingWinningsNotExpired from 66 to 79 - contracts/src/admin.rs: add _extend_persistent_ttl on expiry key, pending winnings key, and updated-at key before reading them; update doc comment to document the three distinct errors - contracts/src/tests/pending_winnings_expiry.rs: fix wrong error expectations (NoActiveRound -> ExpiryNotConfigured/PendingWinningsNotFound), add test_reclaim_fails_when_expiry_disabled_after_enable and test_reclaim_fails_for_premature_reclaim - bindings/src/index.ts: fix wrong discriminants for EpochBudgetExceeded, OracleNotLive, InvalidPayoutPolicy; add RotationDelayNotElapsed, OracleTimestampOutsideWindow, and all missing error codes 70-79 - docs/WALLET_ERROR_GUIDE.md: add 14 missing error codes (55, 62-79), fix malformed table lines 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
Add comprehensive test suite covering adversarial dust stake interactions with early cash-out and fee paths to pin down conservation invariants. 13 scenario tests + 1 proptest covering: - 1-stroop dust stakes with fee on/off (full refund when forfeit floors to 0) - Forfeit boundary transition (stake=10, penalty=1000 bps → forfeit=1) - Dust cash-out followed by pool settlement (two-sided and one-sided) - Multiple dust participants cashing out in the same round - Dust on losing side vs winning side - All participants as dust (pool drains to zero) - FeeOnPot and FeeOnWinnings models with dust - Max penalty (1000 bps) × min stake (1 stroop) still yields full refund - Property-based test: conservation holds for any dust_stake in [1..99], penalty_bps in [1000..10000], and random opposing stake Core identity verified per round: sum(cashouts) + sum(settlement_payouts) + protocol_fee_delta == original_pot
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.
Summary
Adds a comprehensive test suite for adversarial dust stake interactions with early cash-out and fee paths. Pins down the exact conservation invariant for every combination of dust-vs-non-dust stakes and fee-on / fee-off settlement.
Closes #407
Motivation
Adversarial dust stakes (1-stroop positions) and their interaction with the fee-on / fee-off paths can break token conservation. When
stake * penalty_bps / BPS_DENOMINATORfloors to zero, the user receives a full refund with no forfeit — the pool shrinks by the full stake while zero goes to treasury. Until now, there were no tests verifying that this path maintains the conservation identity:What's included
13 scenario tests + 1 property-based test
dust_cashout_fee_off_full_refunddust_cashout_fee_on_full_refunddust_cashout_fee_on_forfeit_rounds_to_zerodust_cashout_settle_remaining_fee_offdust_cashout_settle_remaining_fee_onmultiple_dust_cashouts_fee_offmultiple_dust_cashouts_settle_fee_ondust_cashout_pool_totals_consistencyall_dust_cashouts_fee_on_full_rounddust_on_loser_side_cashout_fee_ondust_forfeit_boundary_transitiondust_cashout_fee_on_winnings_modeldust_cashout_max_penalty_still_full_refundProperty-based test (proptest, 25 cases)
Verifies conservation for random
dust_stakein [1..99],penalty_bpsin [1000..10000], and arbitrary opposing stake. Asserts:cashout + forfeit == stakepool_up == 0after cash-outcashout + settlement_payout + treasury_delta == original_potKey edge cases covered
stake * penalty_bps / 10_000floors to zero for any stake < 10_000 / penalty_bps. This means 1-stroop dust always gets a full refund regardless of penalty rate.Files changed
contracts/src/tests/early_cashout_dust.rs— new (854 lines)contracts/src/tests/mod.rs— addedmod early_cashout_dust;Testing
All tests exercise the contract through the public Soroban client interface (no internal state manipulation beyond the setup helpers for fee/penalty configuration). Each test verifies conservation with explicit
assert_eq!on the full accounting identity.Checklist