Feat/issue 161 min bet floor#216
Open
Richardkingz2019 wants to merge 3 commits into
Open
Conversation
…tion suite Resolves TevaLabs#171 by adding a dedicated integration test that exercises the commit -> reveal -> resolve -> claim pipeline for Precision-mode rounds across multiple users and ledger advances. Tests added in contracts/src/tests/commit_reveal_e2e.rs: * test_commit_reveal_e2e_full_lifecycle: happy path walking 3 users (Alice, Bob, Carol) through commit, reveal, resolve, and claim with full assertions on round metadata, payout vector, pending winnings, per-user stats deltas, archived round summary, and conservation invariant (sum of balances + pending == total supply). * test_commit_reveal_e2e_invalid_salt_or_price_returns_hash_mismatch: verifies HashMismatch on both wrong-salt and wrong-price reveal attempts and confirms the commitment is preserved. * test_commit_reveal_e2e_reveal_before_bet_window_closes_is_rejected: invalid-reveal-window at ledger 0 (inside bet window). * test_commit_reveal_e2e_late_reveal_after_round_ends_is_rejected: invalid-reveal-window after end_ledger is reached. * test_commit_reveal_e2e_double_reveal_returns_already_revealed: AlreadyRevealed on a second reveal call. * test_commit_reveal_e2e_reveal_without_commit_returns_not_found: CommitmentNotFound when revealing without an earlier commit. * test_commit_reveal_e2e_commit_then_direct_prediction_is_rejected: AlreadyBet is enforced in both directions (commit-then-direct and direct-then-commit), keeping indexed per-user keys exclusive. * test_commit_reveal_e2e_two_way_tie_splits_pot_evenly: pins the exact 50/50 split for two equal-bet winners in a tied commit-reveal precision round. Acceptance criteria from TevaLabs#171: * One test covers the full happy path from commit to claim. * Six failure scenarios (>=3 required) covering bad preimage, window boundaries, idempotency, missing-commit, and mixed-route exclusivity. * Tie-resolution correctness is pinned with exact integer split. * Tests run in the default suite. Workspace Cargo.toml: prune unused (, ) — these were duplicates already declared in contracts/Cargo.toml, where they belong.
Adds a per-contract minimum bet/prediction floor that the admin can
configure via set_min_bet. Affects place_bet, place_precision_prediction,
and commit_prediction — all three paths call _enforce_min_bet after
the amount<=0 check so the floor is enforced uniformly.
Public API:
- set_min_bet(min_bet: Option<i128>) -> Result<(), ContractError>
Validates the value (None or Some(v) with v in [1, 1e18]),
stores it under DataKey::MinBet, applies TTL extension on write,
and emits ('min_bet', 'updated') with Option<i128> payload.
- get_min_bet() -> Option<i128>
Returns the configured floor (None when unset).
Both helpers (_validate_min_bet and _enforce_min_bet) use the
(MIN_MIN_BET_AMOUNT..=MAX_MIN_BET_AMOUNT).contains(&v) idiom for
the clippy::manual-range-contains lint. _enforce_min_bet refreshes
the storage TTL only when the floor is configured (gas opt: avoids
paying a TTL bump on every bet when no floor is set on fresh deploys).
Important: the runtime floor (bet below min) and the setter
validation rejection both reuse ContractError::InvalidBetAmount
rather than introducing dedicated BetBelowMinimum / InvalidMinBet
variants. The Soroban #[contracterror] enum is hard-capped at 50
variants by the XDR spec (VecM<T, 50>); the existing enum was
already at that ceiling. Reusing InvalidBetAmount keeps the
variant count stable — introducing a new variant trips the
LengthExceedsMax macro panic at compile time. The DOC NOTE
near ContractError::InvalidBetAmount and on set_min_bet /
_enforce_min_bet explains this so a future contributor does not
attempt to 'fix back' to dedicated variants.
Mid-round admin tuning is intentional: set_min_bet does not gate
on assert_no_active_round so floors can be reactively adjusted.
v1-deploys remain forward-compatible: get_min_bet() returns None
on contracts initialised under SchemaVersion 1 until an admin
call sets it; no migration script needed.
Closes TevaLabs#161
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
Linked issues
Validation
cargo test --workspacecargo clippy --workspace --all-targets -- -D warningscargo fmt --all -- --checkcd bindings && npm ci && npm run buildGovernance checklist
CONTRIBUTING.mdfor workflow expectationsCODEOWNERSimpact for touched pathsSUPPORT.mddisclosure guidance for any security-sensitive changecloses #161