Skip to content

Feat/issue 161 min bet floor#216

Open
Richardkingz2019 wants to merge 3 commits into
TevaLabs:mainfrom
Richardkingz2019:feat/issue-161-min-bet-floor
Open

Feat/issue 161 min bet floor#216
Richardkingz2019 wants to merge 3 commits into
TevaLabs:mainfrom
Richardkingz2019:feat/issue-161-min-bet-floor

Conversation

@Richardkingz2019

Copy link
Copy Markdown
Contributor

Summary

  • What changed and why?

Linked issues

  • Closes #

Validation

  • cargo test --workspace
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo fmt --all -- --check
  • cd bindings && npm ci && npm run build

Governance checklist

  • I reviewed CONTRIBUTING.md for workflow expectations
  • I checked CODEOWNERS impact for touched paths
  • I followed SUPPORT.md disclosure guidance for any security-sensitive change

closes #161

…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
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.

Protocol config: add admin-configurable minimum bet amount

1 participant