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

feat(bindgen): add AccountInterface to function #2770

Merged
merged 2 commits into from
Dec 6, 2024

Conversation

starknetdev
Copy link
Contributor

@starknetdev starknetdev commented Dec 5, 2024

Description

This PR adds AccountInterface as another type to the typescript function bindgen.

Related issue

In dojo.js the DojoProvider.execute accepts the account input with type Account | AccountInterface:

    public async execute(
        account: Account | AccountInterface,
        call: AllowArray<DojoCall | Call>,
        nameSpace: string,
        details: UniversalDetails = {}
    ): Promise<InvokeFunctionResponse> {

This is specifically relevant with starknet-react that defines accounts as the AccountInterface type, however the bindgen is only generating account inputs as type Account. Therefore, currently the starknet-react accounts need to be mapped to the Account type before being passed to the bindings.

Tests

  • Yes
  • No, because they aren't needed
  • No, because I need help

Added to documentation?

  • README.md
  • Dojo Book
  • No documentation needed

Checklist

  • I've formatted my code (scripts/prettier.sh, scripts/rust_fmt.sh, scripts/cairo_fmt.sh)
  • I've linted my code (scripts/clippy.sh, scripts/docs.sh)
  • I've commented my code
  • I've requested a review after addressing the comments

Summary by CodeRabbit

  • New Features

    • Enhanced function signature flexibility by allowing both Account and AccountInterface types as inputs.
    • Updated function generation to accommodate the broader range of account types.
  • Bug Fixes

    • Improved error handling in tests for better clarity on failures.
    • Adjusted test cases to validate new input types and expected outputs correctly.

Copy link

coderabbitai bot commented Dec 5, 2024

Walkthrough

Ohayo, sensei! The recent changes in the function.rs file focus on enhancing the TsFunctionGenerator struct's handling of function parameters and imports. The check_imports method now includes AccountInterface in the import statement, while the format_function_inputs method has adjusted the input type for snAccount to accept both Account and AccountInterface. These updates are reflected in the relevant methods and test cases, ensuring the new functionality is validated and integrated into the existing structure.

Changes

File Path Change Summary
crates/dojo/bindgen/src/plugins/typescript/generator/function.rs - Updated check_imports to include AccountInterface in imports.
- Changed input type for snAccount from Account to `Account
crates/dojo/bindgen/src/lib.rs - Replaced unwrap() with expect("Failed to gather dojo data") in gather_data_ok test for better error clarity.
- Added dbg!(&config.manifest_path()); for logging the manifest path.

Possibly related PRs

Suggested reviewers

  • Larkooo

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e06dbab and fb96357.

📒 Files selected for processing (2)
  • crates/dojo/bindgen/src/lib.rs (1 hunks)
  • crates/dojo/bindgen/src/plugins/typescript/generator/function.rs (5 hunks)
🔇 Additional comments (4)
crates/dojo/bindgen/src/lib.rs (1)

260-263: Ohayo sensei! Nice improvements to error handling and debugging!

The changes enhance the test's robustness by:

  • Adding debug logging for the manifest path
  • Using expect() with a descriptive message instead of unwrap()
crates/dojo/bindgen/src/plugins/typescript/generator/function.rs (3)

16-22: Ohayo sensei! Clean implementation of the AccountInterface import!

The import statement now correctly includes both Account and AccountInterface types from the starknet package.


87-87: Perfect implementation of the dual account type support!

The change to support both Account and AccountInterface aligns perfectly with the PR objective to improve compatibility with starknet-react.


267-268: Well-maintained test coverage, sensei!

The test expectations have been properly updated to reflect the new type signature, ensuring the changes are thoroughly verified.

Also applies to: 300-300, 315-315


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • 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 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.

@glihm glihm changed the title Add AccountInterface to function bindgen feat(bindgen): add AccountInterface to function Dec 5, 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.

Thank you @starknetdev for the addition, @MartianGreed any additional comment on this?

@MartianGreed
Copy link
Contributor

Perfect !

Copy link

codecov bot commented Dec 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.67%. Comparing base (0cb5923) to head (fb96357).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2770      +/-   ##
==========================================
+ Coverage   55.50%   55.67%   +0.17%     
==========================================
  Files         434      434              
  Lines       54295    54542     +247     
==========================================
+ Hits        30137    30368     +231     
- Misses      24158    24174      +16     

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

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.

3 participants