Skip to content

feat: add input validation for bet creation#34

Open
MuhamadRifansyah wants to merge 3 commits into
genlayerlabs:mainfrom
MuhamadRifansyah:MuhamadRifansyah-patch-1
Open

feat: add input validation for bet creation#34
MuhamadRifansyah wants to merge 3 commits into
genlayerlabs:mainfrom
MuhamadRifansyah:MuhamadRifansyah-patch-1

Conversation

@MuhamadRifansyah
Copy link
Copy Markdown

@MuhamadRifansyah MuhamadRifansyah commented Mar 23, 2026

Added input validation to ensure valid bet creation, preventing identical teams, empty inputs, and invalid predictions.

Summary by CodeRabbit

  • Bug Fixes
    • Stronger input validation when creating bets: trims team names, rejects empty or identical teams, and disallows invalid winner selections; clearer "Bet not found" error when resolving non-existent bets.
  • Documentation
    • Improved docstrings/descriptions for bet resolution and scoring to make behavior and errors clearer for users and integrators.

Added input validation to ensure valid bet creation, preventing identical teams, empty inputs, and invalid predictions.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 23, 2026

📝 Walkthrough

Walkthrough

Added stricter input validation and sanitization in create_bet, adjusted existence checks and docstrings in resolve_bet, and relaxed prompt formatting constraints in _check_match; a minor formatting change in get_player_points removed a trailing newline. All changes are confined to contracts/football_bets.py.

Changes

Cohort / File(s) Summary
Football bets contract
contracts/football_bets.py
create_bet: strips whitespace from team1/team2, rejects empty team names, rejects identical teams (case-insensitive), and enforces predicted_winner ∈ {"1","2","0"}. resolve_bet: added existence checks for sender's bet and bet_id (raises "Bet not found") and expanded docstrings. _check_match: removed explicit comment-style/“output must be only JSON” instructions while keeping response_format="json" and JSON parsing. get_player_points: minor removal of trailing newline. No exported API changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibble code lines, tidy and neat,
Trimming whitespace from each team's seat.
No twins allowed, no blanks in sight,
Fair scores hop in, everything's right. 🥕⚽️

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: add input validation for bet creation' directly aligns with the main changes: additional validation in create_bet including team name whitespace stripping, empty team rejection, duplicate team rejection, and predicted_winner validation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 190f71a5e5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread contracts/football_bets.py Outdated
Comment on lines +61 to +62
if team1 == team2:
raise Exception("Teams cannot be the same")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 Badge Fix indentation of the new validation block

The new if team1 == team2: guard has no indented body because raise Exception("Teams cannot be the same") is aligned with the if, which makes this module fail to parse with an IndentationError and prevents the contract from loading at all. In this state, none of the contract methods can run, so this is a release-blocking regression.

Useful? React with 👍 / 👎.

Comment thread contracts/football_bets.py Outdated
if not team1 or not team2:
raise Exception("Team names cannot be empty")

if predicted_winner not in [team1, team2, "draw"]:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Align prediction validation with winner code format

This check only allows team1, team2, or draw, but the contract and existing callers use numeric winner codes ("1", "2", "0"): for example tests invoke create_bet(..., "1"), and resolve_bet compares bet.real_winner (stored as numeric string from _check_match) against bet.predicted_winner. As written, valid client inputs are rejected and scoring logic becomes inconsistent unless all related code is migrated together.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@contracts/football_bets.py`:
- Around line 61-68: Fix the incorrect indentation in the validation block that
causes a SyntaxError: ensure the "raise Exception('Teams cannot be the same')"
is indented under its if team1 == team2: and that the following validation
statements checking team1/team2 emptiness and predicted_winner membership are
indented to the same method scope (i.e., inside the function/method where team1,
team2, and predicted_winner are defined). Locate the block that references
team1, team2, and predicted_winner and adjust indentation so all three if
statements and their raises are at the method level (not class level) and
properly nested.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 54a511d1-3b25-4539-8689-21afeeaf1d9a

📥 Commits

Reviewing files that changed from the base of the PR and between 2164ec6 and 190f71a.

📒 Files selected for processing (1)
  • contracts/football_bets.py

Comment thread contracts/football_bets.py Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@contracts/football_bets.py`:
- Around line 74-81: Normalize and validate team names by trimming whitespace
and normalizing case before checks: compute normalized_team1 =
team1.strip().lower() and normalized_team2 = team2.strip().lower(), then check
emptiness with if not normalized_team1 or not normalized_team2 and equality with
if normalized_team1 == normalized_team2; keep the existing predicted_winner
validation as-is. Apply the same normalization and checks to the other
occurrence referenced (the block around the symbols handling team1/team2 at
lines ~94-105) so both validation sites use stripped, lowercased comparisons.
- Around line 118-123: The code indexes
self.bets[gl.message.sender_address][bet_id] directly which can raise an
unhandled lookup error if the sender or the bet_id is missing; update the
resolve path in the method to first check that gl.message.sender_address exists
in self.bets and that bet_id exists in self.bets[gl.message.sender_address]
(e.g., using "in" checks or dict.get) and raise a clear Exception like "Bet not
found" or "No bets for sender" before checking .has_resolved, then proceed to
raise "Bet already resolved" only after the existence checks pass.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a3f00005-ccf8-4a58-ae3d-198b2dd074df

📥 Commits

Reviewing files that changed from the base of the PR and between 190f71a and 903d251.

📒 Files selected for processing (1)
  • contracts/football_bets.py

Comment thread contracts/football_bets.py Outdated
Comment thread contracts/football_bets.py
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
contracts/football_bets.py (1)

41-48: Minor: JSON example uses Python type hints instead of concrete values.

The prompt shows "score": str and "winner": int which aren't valid JSON. While LLMs typically interpret this correctly as type documentation, using concrete example values would be clearer:

{
    "score": "2-1",
    "winner": 1
}

This is a low-risk observation since response_format="json" is specified and the code handles the parsed result correctly.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@contracts/football_bets.py` around lines 41 - 48, The JSON example in the
prompt passed to gl.nondet.exec_prompt uses Python type hints ("score": str,
"winner": int) which aren't valid JSON; update the example in the prompt string
(the one constructed for variable task before calling gl.nondet.exec_prompt with
response_format="json") to use concrete sample values such as "score": "2-1" and
"winner": 1 so the LLM sees a valid JSON example while leaving
response_format="json" and the surrounding call to gl.nondet.exec_prompt
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@contracts/football_bets.py`:
- Around line 41-48: The JSON example in the prompt passed to
gl.nondet.exec_prompt uses Python type hints ("score": str, "winner": int) which
aren't valid JSON; update the example in the prompt string (the one constructed
for variable task before calling gl.nondet.exec_prompt with
response_format="json") to use concrete sample values such as "score": "2-1" and
"winner": 1 so the LLM sees a valid JSON example while leaving
response_format="json" and the surrounding call to gl.nondet.exec_prompt
unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f1880545-a21c-471c-8d1a-68cec89f231f

📥 Commits

Reviewing files that changed from the base of the PR and between 903d251 and 79b1da1.

📒 Files selected for processing (1)
  • contracts/football_bets.py

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.

1 participant