Skip to content

Conversation

Teebor-Choka
Copy link
Contributor

Fix the win_prob smoke test to properly divide by the probability to get the correct incentive.

@Teebor-Choka Teebor-Choka self-assigned this Jun 10, 2025
Copy link
Contributor

coderabbitai bot commented Jun 10, 2025

📝 Walkthrough

Walkthrough

The tests for ticket redemption and relay behavior were updated to increase tolerance for winning ticket count deviations and to adjust the expected unredeemed ticket value calculations, incorporating terms involving the inverse of the win probability. No changes to logic or control flow were made.

Changes

File(s) Change Summary
tests/test_win_prob.py Increased winning ticket count tolerance from 0.1 to 0.3 in three tests; adjusted expected unredeemed ticket value calculations to include (ticket_price + ticket_price / Decimal(win_prob)) and reduced max allowed unredeemed value after redeeming tickets from ticket_price / Decimal(win_prob) to ticket_price.

Sequence Diagram(s)

sequenceDiagram
    participant Test
    participant RelayNode

    Test->>RelayNode: Send packets with tickets (win_prob < 1)
    RelayNode-->>Test: Update unredeemed ticket value with adjusted expectation
    Test->>Test: Await unredeemed value = unredeemed_value_before + (ticket_price + ticket_price / win_prob)
Loading

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 53253b4 and 4230375.

📒 Files selected for processing (1)
  • tests/test_win_prob.py (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_win_prob.py
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Docs / Rust docs
  • GitHub Check: Build Candidate Binaries (hoprd)
  • GitHub Check: Build Candidate Binaries (hopli)
  • GitHub Check: tests-unit
  • GitHub Check: tests-unit-nightly
  • GitHub Check: Linter
  • GitHub Check: zizmor
  • GitHub Check: Cargo Audit
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Teebor-Choka Teebor-Choka marked this pull request as ready for review June 10, 2025 13:11
@Copilot Copilot AI review requested due to automatic review settings June 10, 2025 13:11
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Fix the smoke test for win_prob by adjusting the expected unredeemed ticket value to account for the probability factor.

  • Update the expected value calculation in the test to divide total ticket value by the win probability.

@github-actions github-actions bot added the testing Related to tests label Jun 10, 2025
Copy link
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: 0

🧹 Nitpick comments (1)
tests/test_win_prob.py (1)

118-118: Correct expected value calculation for probabilistic tickets.

The change properly accounts for the winning probability in the expected value calculation. When win_prob = 0.1, dividing by the probability correctly scales the expected unredeemed ticket value, which aligns with the mathematical expectation for probabilistic systems and is consistent with similar calculations throughout the file.

However, the line exceeds the 120-character limit. Consider breaking it for better readability:

-                        swarm7[relay], statistics_before.unredeemed_value + (ticket_count * ticket_price / Decimal(win_prob))
+                        swarm7[relay], 
+                        statistics_before.unredeemed_value + (ticket_count * ticket_price / Decimal(win_prob))
🧰 Tools
🪛 Ruff (0.11.9)

118-118: Line too long (125 > 120)

(E501)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1299504 and 56bee27.

📒 Files selected for processing (1)
  • tests/test_win_prob.py (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: NumberFour8
PR: hoprnet/hoprnet#6511
File: tests/test_integration.py:1182-1198
Timestamp: 2024-10-01T04:47:11.992Z
Learning: In the test `test_hoprd_should_not_accept_tickets_with_lower_than_min_win_prob`, the relay's `rejected_tickets_value` and `unredeemed_value` are already being verified to ensure tickets are rejected and the unredeemed value does not increase.
tests/test_win_prob.py (1)
Learnt from: NumberFour8
PR: hoprnet/hoprnet#6511
File: tests/test_integration.py:1182-1198
Timestamp: 2024-10-01T04:47:11.992Z
Learning: In the test `test_hoprd_should_not_accept_tickets_with_lower_than_min_win_prob`, the relay's `rejected_tickets_value` and `unredeemed_value` are already being verified to ensure tickets are rejected and the unredeemed value does not increase.
🪛 Ruff (0.11.9)
tests/test_win_prob.py

118-118: Line too long (125 > 120)

(E501)

⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: hopli / docker
  • GitHub Check: Docs / Rust docs
  • GitHub Check: tests-unit
  • GitHub Check: Build Candidate Binaries (hoprd)
  • GitHub Check: tests-unit-nightly
  • GitHub Check: Linter
  • GitHub Check: zizmor
  • GitHub Check: Cargo Audit

@Teebor-Choka Teebor-Choka force-pushed the kauki/tests/fix-the-randomly-failing-win-prob-tests branch from 53253b4 to 4230375 Compare June 10, 2025 15:10
@NumberFour8 NumberFour8 merged commit 9165547 into master Jun 10, 2025
33 checks passed
@NumberFour8 NumberFour8 deleted the kauki/tests/fix-the-randomly-failing-win-prob-tests branch June 10, 2025 16:29
@Teebor-Choka Teebor-Choka linked an issue Jun 10, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Related to tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Randomly failing winning probability smoke tests
2 participants