-
Notifications
You must be signed in to change notification settings - Fork 188
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: split calldata and provider call #2852
Conversation
WalkthroughOhayo, sensei! The pull request introduces enhancements to the TypeScript function generator in the Dojo bindgen system. The changes focus on improving the function calldata generation process by adding a new Changes
Possibly Related PRs
Suggested Reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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
🧹 Nitpick comments (5)
crates/dojo/bindgen/src/plugins/typescript/generator/function.rs (5)
59-63
: Ohayo sensei, doc note improvement.Your doc comments clearly describe the function’s purpose and inputs. Consider adding a note about any usage constraints or caveats to help other developers use it correctly.
70-87
: Ohayo sensei, improve error details.You log the error with
console.error
, which is good, but consider providing more context (e.g., parameters) to facilitate debugging in complex scenarios.
Line range hint
165-216
: Ohayo sensei, consider refactoring for clarity.The logic in
setup_function_wrapper_end
is quite verbose. Extracting smaller helper methods can improve readability and maintainability.
294-301
: Ohayo sensei, expand test coverage.This test snippet looks fine, but consider adding negative or edge-case tests (e.g., invalid input) to ensure the function behaves correctly under all conditions.
302-303
: Ohayo sensei, verify error behavior in tests.The generated code snippet includes robust error handling with
try/catch
. Verify in tests that the error messages or codes are as expected for clearer coverage on failure scenarios.Also applies to: 307-307, 312-312
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/dojo/bindgen/src/plugins/typescript/generator/function.rs
(8 hunks)
🔇 Additional comments (6)
crates/dojo/bindgen/src/plugins/typescript/generator/function.rs (6)
38-57
: Ohayo sensei, watch for potential injection risk.
This new function builds a JavaScript snippet via string interpolation. If any of these parameters (contract_name
, token.name
) come from untrusted sources, it could pose injection vulnerabilities. Ensure these values are sanitized or constrained.
101-103
: Ohayo sensei, well-structured concatenation.
Combining function_calldata
and function_call
works nicely and keeps down duplicate code.
138-138
: Ohayo sensei, concise input merging.
Merging the snAccount
parameter with function inputs in a single line is a clean approach.
411-411
: Ohayo sensei, consistent coverage is great.
Your tests for the second function maintain consistent style and coverage. Good job.
Also applies to: 414-414, 416-416
424-424
: Ohayo sensei, multi-contract scenario looks good.
Verifying multiple contracts in a single test suite ensures the code can handle varied uses. Nicely done.
Also applies to: 427-427, 429-429, 433-433
448-448
: Ohayo sensei, duplication check is handy.
Ensuring identifiers aren’t duplicated helps avoid confusion and conflicts. This is a thoughtful test.
"\tconst {function_name} = async ({}) => {{ | ||
\t\ttry {{ | ||
\t\t\treturn await provider.call(\"{namespace}\", {{ | ||
\t\t\t\tcontractName: \"{contract_name}\", | ||
\t\t\t\tentrypoint: \"{}\", | ||
\t\t\t\tcalldata: [{}], | ||
\t\t\t}}); | ||
\t\t\treturn await provider.call(\"{namespace}\", build_{function_name}_calldata({}); | ||
\t\t}} catch (error) {{ | ||
\t\t\tconsole.error(error); | ||
\t\t\tthrow error; | ||
\t\t}} | ||
\t}};\n", | ||
token.name.to_case(Case::Camel), | ||
self.format_function_inputs(token), | ||
token.name, | ||
self.format_function_calldata(token) | ||
self.format_function_calldata(token), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohayo sensei, fix the missing parenthesis.
There’s a syntax error with the provider.call(...)
invocation. Add the closing parenthesis.
- return await provider.call("{namespace}", build_{function_name}_calldata({});
+ return await provider.call("{namespace}", build_{function_name}_calldata({}));
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
"\tconst {function_name} = async ({}) => {{ | |
\t\ttry {{ | |
\t\t\treturn await provider.call(\"{namespace}\", {{ | |
\t\t\t\tcontractName: \"{contract_name}\", | |
\t\t\t\tentrypoint: \"{}\", | |
\t\t\t\tcalldata: [{}], | |
\t\t\t}}); | |
\t\t\treturn await provider.call(\"{namespace}\", build_{function_name}_calldata({}); | |
\t\t}} catch (error) {{ | |
\t\t\tconsole.error(error); | |
\t\t\tthrow error; | |
\t\t}} | |
\t}};\n", | |
token.name.to_case(Case::Camel), | |
self.format_function_inputs(token), | |
token.name, | |
self.format_function_calldata(token) | |
self.format_function_calldata(token), | |
"\tconst {function_name} = async ({}) => {{ | |
\t\ttry {{ | |
\t\t\treturn await provider.call(\"{namespace}\", build_{function_name}_calldata({})); | |
\t\t}} catch (error) {{ | |
\t\t\tconsole.error(error); | |
\t\t\tthrow error; | |
\t\t}} | |
\t}};\n", | |
self.format_function_inputs(token), | |
self.format_function_calldata(token), |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2852 +/- ##
==========================================
+ Coverage 56.16% 56.19% +0.02%
==========================================
Files 440 440
Lines 56635 56656 +21
==========================================
+ Hits 31810 31837 +27
+ Misses 24825 24819 -6 ☔ View full report in Codecov by Sentry. |
Solves #2833
Summary by CodeRabbit
New Features
Refactor