Skip to content

Conversation

Teebor-Choka
Copy link
Contributor

@Teebor-Choka Teebor-Choka commented Jun 11, 2025

  • Round the compared decimal value
  • Extend candidate build to 20min timeout
  • Improve some documentation

@Teebor-Choka Teebor-Choka added this to the 3.0.0 milestone Jun 11, 2025
@Teebor-Choka Teebor-Choka self-assigned this Jun 11, 2025
@Teebor-Choka Teebor-Choka marked this pull request as ready for review June 11, 2025 06:46
@Copilot Copilot AI review requested due to automatic review settings June 11, 2025 06:46
Copy link
Contributor

coderabbitai bot commented Jun 11, 2025

📝 Walkthrough

Walkthrough

A local variable precision is introduced in a test function without affecting control flow. The function check_unredeemed_tickets_value was updated to quantize decimal values before comparison. A typo was fixed in the HTTP 409 Conflict response description for the "open channel" API endpoint. The GitHub Actions workflow timeout for building candidate binaries was increased from 10 to 20 minutes.

Changes

File(s) Change Summary
tests/test_win_prob.py Added local precision variable (unused) in a test function.
tests/utils.py Updated check_unredeemed_tickets_value to quantize decimal values before comparison.
hoprd/rest-api/src/channels.rs Fixed typo in HTTP 409 Conflict response message for the "open channel" API endpoint.
.github/workflows/tests.yaml Increased timeout for "build-candidate-binaries" job from 10 to 20 minutes.

Sequence Diagram(s)

sequenceDiagram
    participant Test as test_hoprd_should_relay_packets_with_lower_win_prob_then_redeem_them
    participant Func as check_unredeemed_tickets_value

    Test->>Func: Call with quantized decimal values
    Func-->>Test: Await until unredeemed tickets value ≥ target (quantized)
Loading

Possibly related PRs

Suggested reviewers

  • NumberFour8

📜 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 7e190b3 and d2634b8.

📒 Files selected for processing (2)
  • tests/test_win_prob.py (1 hunks)
  • tests/utils.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/utils.py
🧰 Additional context used
🪛 Ruff (0.11.9)
tests/test_win_prob.py

116-116: Local variable precision is assigned to but never used

Remove assignment to unused variable precision

(F841)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Docs / Rust docs
  • 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.

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

This PR stabilizes the win_prob smoke test by rounding the expected unredeemed ticket value to avoid random failures due to floating‐point precision.

  • Introduces a precision variable for rounding
  • Wraps the expected value calculation in round(..., precision)

@github-actions github-actions bot added the testing Related to tests label Jun 11, 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 (2)
tests/test_win_prob.py (2)

116-116: Prefer a named, module-level constant over a magic number

precision = 10 is a hard-coded literal inside the test body. Declaring a small constant such as DECIMAL_PRECISION = 10 near the top of the module (or re-using an existing constant) makes the intent explicit and avoids scattering the same literal in future edits.


120-123: Avoid float → Decimal conversion; construct Decimal directly from a string

Decimal(win_prob) converts the binary float 0.1 to Decimal('0.100000000000000005551...'), defeating the purpose of the new rounding safeguard and still leaving room for non-deterministic comparisons.

Convert from a string (or declare win_prob itself as a Decimal) and, while at it, use quantize for explicit rounding:

-                            statistics_before.unredeemed_value + (ticket_price + ticket_price / Decimal(win_prob)),
-                            precision,
+                            (
+                                statistics_before.unredeemed_value
+                                + ticket_price
+                                + ticket_price / Decimal(str(win_prob))
+                            ).quantize(Decimal(f"1e-{precision}")),

This keeps the arithmetic purely in Decimal space and guarantees deterministic, half-even rounding to exactly precision decimal places.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9165547 and 69e906c.

📒 Files selected for processing (1)
  • tests/test_win_prob.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/test_win_prob.py (2)
tests/utils.py (1)
  • check_unredeemed_tickets_value (114-119)
tests/conftest.py (1)
  • swarm7 (95-107)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Docs / Rust docs
  • GitHub Check: Linter
  • GitHub Check: Build Candidate Binaries (hoprd)
  • GitHub Check: tests-unit
  • GitHub Check: Build Candidate Binaries (hopli)
  • GitHub Check: tests-unit-nightly
  • GitHub Check: zizmor

@Teebor-Choka Teebor-Choka linked an issue Jun 11, 2025 that may be closed by this pull request
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Teebor-Choka Teebor-Choka force-pushed the kauki/tests/fix-win-prob-tests branch from df9f5da to a180118 Compare June 11, 2025 06:56
Copy link
Contributor

@jeandemeusy jeandemeusy left a comment

Choose a reason for hiding this comment

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

Does this helps the test to pass every time ?

@Teebor-Choka Teebor-Choka requested a review from NumberFour8 June 11, 2025 07:27
@github-actions github-actions bot added the toolchain Developer and product happiness label Jun 11, 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: 1

♻️ Duplicate comments (1)
tests/test_win_prob.py (1)

116-118: precision is unused — remove or pass it to check_unredeemed_tickets_value

The local variable precision is assigned but never referenced, tripping Ruff F841 and adding noise.
Either delete the line or use the variable by passing an explicit quantize exponent to the utility:

-                precision = 10
-                await asyncio.wait_for(
-                    check_unredeemed_tickets_value(
-                        swarm7[relay],
-                        statistics_before.unredeemed_value + (ticket_price + ticket_price / Decimal(win_prob)),
-                    ),
-                    30.0,
-                )
+                await asyncio.wait_for(
+                    check_unredeemed_tickets_value(
+                        swarm7[relay],
+                        statistics_before.unredeemed_value + (ticket_price + ticket_price / Decimal(win_prob)),
+                        quantize=Decimal("1e-10"),  # or Decimal(f"1e-{precision}") if you keep the variable
+                    ),
+                    30.0,
+                )
🧰 Tools
🪛 Ruff (0.11.9)

116-116: Local variable precision is assigned to but never used

Remove assignment to unused variable precision

(F841)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 79dae1f and 7e190b3.

📒 Files selected for processing (2)
  • tests/test_win_prob.py (1 hunks)
  • tests/utils.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/utils.py (2)
sdk/python/localcluster/node.py (2)
  • Node (36-319)
  • api (84-85)
sdk/python/api/hopr.py (1)
  • get_tickets_statistics (351-357)
🪛 Ruff (0.11.9)
tests/utils.py

114-114: f-string without any placeholders

Remove extraneous f prefix

(F541)

tests/test_win_prob.py

116-116: Local variable precision is assigned to but never used

Remove assignment to unused variable precision

(F841)

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

@Teebor-Choka Teebor-Choka force-pushed the kauki/tests/fix-win-prob-tests branch from 7e190b3 to d2634b8 Compare June 11, 2025 11:19
@Teebor-Choka Teebor-Choka merged commit 7a797aa into master Jun 11, 2025
45 checks passed
@Teebor-Choka Teebor-Choka deleted the kauki/tests/fix-win-prob-tests branch June 11, 2025 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate:hoprd-api testing Related to tests toolchain Developer and product happiness
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Randomly failing winning probability smoke tests
3 participants