Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(libp2p): fix typed data from model #2357

Merged
merged 6 commits into from
Aug 29, 2024
Merged

Conversation

Larkooo
Copy link
Collaborator

@Larkooo Larkooo commented Aug 28, 2024

Summary by CodeRabbit

  • New Features
    • Enhanced the TypedData functionality by including the model's name in both the values and types maps, improving data representation and processing capabilities.
    • Updated the validate_message function to accept a more structured TypedData input, streamlining message parsing and error handling.
  • Bug Fixes
    • Improved error handling in the validate_message function for clearer context in error reporting.
  • Tests
    • Simplified the TypedData initialization in tests by consolidating entries and focusing on relevant fields.

Copy link

coderabbitai bot commented Aug 28, 2024

Ohayo, sensei! Here’s the updated structured summary of the changes:

Walkthrough

The changes introduce new entries in the TypedData implementation, adding a key-value pair to the values map with the key "model" and its value derived from model.name, converted to PrimitiveType::String. Additionally, corresponding entries are added to the types map to represent the model as a SimpleField of type "shortstring". The validate_message function is also modified to accept a TypedData structure instead of an IndexMap.

Changes

Files Change Summary
crates/torii/libp2p/src/typed_data.rs Added a key-value pair ("model", model.name as PrimitiveType::String) to the values map and a corresponding entry for "model" in the types map as a SimpleField of type "shortstring".
crates/torii/libp2p/src/server/mod.rs Changed the validate_message function to accept a TypedData structure instead of an IndexMap<String, PrimitiveType>, and updated the internal logic for message validation.
crates/torii/libp2p/src/tests.rs Simplified the TypedData initialization by removing "OffchainMessage" and focusing on "types_test-Message", consolidating entries and streamlining field associations.

Sequence Diagram(s)

sequenceDiagram
    participant A as Client
    participant B as TypedData
    participant C as Model

    A->>B: Request TypedData
    B->>C: Retrieve model.name
    C-->>B: Return model.name
    B->>B: Add ("model", model.name as PrimitiveType::String) to values
    B->>B: Add ("model", SimpleField of type "shortstring") to types
    B-->>A: Return TypedData with updated values and types
Loading
sequenceDiagram
    participant D as Database
    participant E as Relay
    participant F as Message

    E->>D: Validate Message with TypedData
    D->>E: Check primary_type in TypedData
    E->>F: Parse message using PrimitiveType::Object
    F-->>E: Return parsed message
    E-->>D: Return validation result
Loading

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 779aba4 and f1f98e2.

Files selected for processing (1)
  • crates/torii/libp2p/src/tests.rs (2 hunks)
Additional comments not posted (4)
crates/torii/libp2p/src/tests.rs (4)

607-610: Ohayo sensei! Simplify the TypedData initialization.

The initialization of TypedData has been simplified by focusing on the "types_test-Message" entry and removing the "OffchainMessage" entry. This change enhances clarity and reduces complexity.


646-647: Ohayo sensei! Directly associate identity with the account's address.

The identity field is now directly associated with the account's address, simplifying the structure.


651-652: Ohayo sensei! Directly associate message with a string value.

The message field is now directly associated with the string value "mimi", streamlining the initialization process.


641-643: Ohayo sensei! Ensure consistency in TypedData initialization.

The TypedData initialization now directly maps to the "types_test-Message" entry. Ensure that this change is consistent with the rest of the codebase and that all references to the old structure are updated.

Run the following script to verify the consistency of TypedData initialization:

Verification successful

Ohayo sensei! The TypedData initialization is consistent. The search confirms that all instances of TypedData initialization align with the new structure. Other usages are related to deserialization and don't affect the initialization. No updates are needed elsewhere in the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all references to `TypedData` initialization are updated.

# Test: Search for `TypedData` initialization. Expect: Only occurrences of the new structure.
rg --type rust -A 5 $'TypedData::new'

Length of output: 471


Script:

#!/bin/bash
# Description: Verify all references to `TypedData` are consistent.

# Test: Search for all occurrences of `TypedData` to ensure consistency.
rg --type rust 'TypedData'

Length of output: 2312


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 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.

@Larkooo Larkooo changed the title fix(typeddata): fix from model fix(libp2p): fix typed data from model Aug 28, 2024
Copy link
Collaborator

@glihm glihm left a comment

Choose a reason for hiding this comment

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

Good cleanup. 👍

Copy link

codecov bot commented Aug 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.48%. Comparing base (d31f81e) to head (f1f98e2).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2357      +/-   ##
==========================================
- Coverage   67.51%   67.48%   -0.04%     
==========================================
  Files         359      359              
  Lines       46955    46933      -22     
==========================================
- Hits        31704    31671      -33     
- Misses      15251    15262      +11     

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

@Larkooo Larkooo merged commit fc1f894 into dojoengine:main Aug 29, 2024
14 of 15 checks passed
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