Skip to content

fix(torii-core): client negative i128 conversion - #2840

Merged
glihm merged 2 commits into
dojoengine:mainfrom
Larkooo:fix-neg-i128
Dec 23, 2024
Merged

fix(torii-core): client negative i128 conversion#2840
glihm merged 2 commits into
dojoengine:mainfrom
Larkooo:fix-neg-i128

Conversation

@Larkooo

@Larkooo Larkooo commented Dec 23, 2024

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of hexadecimal string conversion to the I128 primitive type, enhancing data population from SQLite rows.

@coderabbitai

coderabbitai Bot commented Dec 23, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

Ohayo, sensei! The pull request introduces a modification in the map_row_to_ty function within the crates/torii/core/src/model.rs file. It specifically targets the handling of the Primitive::I128 type conversion, changing the process from direct hexadecimal parsing to a two-step conversion: first to u128, followed by casting to i128. This adjustment maintains the existing error handling while refining the conversion method.

Changes

File Change Summary
crates/torii/core/src/model.rs Modified map_row_to_ty function's handling of Primitive::I128 type conversion

Suggested reviewers

  • glihm

Possibly related PRs

The change is straightforward but demonstrates careful attention to type conversion nuances in Rust. Sensei would be proud of such meticulous code refinement! 🦀✨


📜 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 654b3f6 and 751e891.

📒 Files selected for processing (1)
  • crates/torii/core/src/model.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/torii/core/src/model.rs

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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)
crates/torii/core/src/model.rs (1)

273-276: Consider adding test coverage for negative i128 values, sensei!

While the implementation is correct, it would be beneficial to add test cases that explicitly verify the conversion of negative i128 values from their hexadecimal representation.

Would you like me to help create test cases that cover:

  1. Maximum negative value (-2^127)
  2. Maximum positive value (2^127 - 1)
  3. Common negative values
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3c32891 and 654b3f6.

📒 Files selected for processing (1)
  • crates/torii/core/src/model.rs (1 hunks)
🔇 Additional comments (1)
crates/torii/core/src/model.rs (1)

273-276: Ohayo sensei! The i128 conversion implementation looks solid.

The two-step conversion approach (hex → u128 → i128) aligns well with how other large integers are handled in the codebase. This implementation ensures proper handling of the full range of i128 values, including negative numbers.

Let's verify the handling of edge cases:

✅ Verification successful

Ohayo sensei! The i128 conversion implementation is verified as correct and consistent.

The codebase analysis reveals:

  • The conversion from hex string to i128 via u128 is consistent with how other large integers are handled
  • Tests in crates/dojo/types/src/primitive_conversion.rs verify i128 conversion with edge cases including negative values (e.g. -170141183460469231731687303715884105728)
  • The implementation is used consistently across the codebase for handling i128 values in Primitive types
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for test cases that exercise i128 conversion edge cases
# Expected: Tests covering negative values and boundary conditions

# Search for i128-related test cases
rg -A 5 "i128|I128" "tests/"

# Search for hex string constants that might be used in tests
rg -A 2 "0x[0-9a-fA-F]+" "tests/"

Length of output: 156


Script:

#!/bin/bash
# Let's search in the entire codebase for test files and i128 related tests
fd -e rs | xargs rg -l "test" | xargs rg -A 5 "i128|I128"

# Search for hex string test cases in all Rust files
fd -e rs | xargs rg -A 2 "0x[0-9a-fA-F]+"

# Look for primitive type conversion tests
fd -e rs | xargs rg -A 5 "Primitive::(I128|U128)"

Length of output: 82241

@codecov

codecov Bot commented Dec 23, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 56.28%. Comparing base (3c32891) to head (751e891).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
crates/torii/core/src/model.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2840   +/-   ##
=======================================
  Coverage   56.27%   56.28%           
=======================================
  Files         439      439           
  Lines       56276    56274    -2     
=======================================
+ Hits        31671    31673    +2     
+ Misses      24605    24601    -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@glihm
glihm merged commit 02557ae into dojoengine:main Dec 23, 2024
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.

2 participants