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: make transaction-generating scripts more robust #2690

Merged
merged 20 commits into from
Oct 11, 2024
Merged

Conversation

mvadari
Copy link
Collaborator

@mvadari mvadari commented May 3, 2024

High Level Overview of Change

Title says it all.

Context of Change

There were some issues when working on price oracle.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Did you update HISTORY.md?

  • No, this change does not impact library users

Test Plan

Tested locally.

@mvadari mvadari marked this pull request as ready for review May 8, 2024 17:03
@justinr1234
Copy link
Collaborator

@CodeRabbit full review

@justinr1234
Copy link
Collaborator

@coderabbitai full review

Copy link

coderabbitai bot commented Sep 19, 2024

Actions performed

Full review triggered.

Copy link

coderabbitai bot commented Sep 19, 2024

Walkthrough

The changes involve updates to the generateModels.js script, focusing on file path modifications and enhancements to transaction model generation. The source for reading SField and TxFormats has shifted directories, and regex patterns have been adjusted accordingly. The transaction type name has been changed from Transaction to SubmittableTransaction, with additional transaction types included. The script now conditionally writes validation tests and has improved the handling of imports and validation functions.

Changes

File Path Change Summary
packages/xrpl/tools/generateModels.js Updated file paths for SField and TxFormats, modified transaction type handling, enhanced import and validation function management, and added conditional writing for validation tests. Renamed export type Transaction to export type SubmittableTransaction.

Suggested reviewers

  • khancode
  • justinr1234

Poem

🐰 In the code where rabbits play,
Paths have shifted, bright as day.
Transactions now hop with glee,
New types and tests, oh what a spree!
With each change, we leap and bound,
In our code, joy can be found! 🐇


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.

@mvadari
Copy link
Collaborator Author

mvadari commented Sep 19, 2024

@coderabbitai full review

Copy link

coderabbitai bot commented Sep 19, 2024

Actions performed

Full review triggered.

Copy link

@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

Outside diff range and nitpick comments (1)
packages/xrpl/tools/generateModels.js (1)

263-263: Suggestion: Create GitHub issues to track the planned improvements.

The TODO comment indicates valuable planned improvements to add docstrings and integration tests. To ensure these tasks are properly tracked and prioritized, consider creating GitHub issues for each item:

  1. Add docstrings to the transaction models to improve code documentation and maintainability.
  2. Implement integration tests for the transaction models to enhance the robustness and reliability of the system.

This will help maintain visibility on these important enhancements and allow for better collaboration and progress tracking.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f3960c3 and fe08836.

Files selected for processing (2)
  • packages/xrpl/tools/createValidateTests.js (3 hunks)
  • packages/xrpl/tools/generateModels.js (2 hunks)
Additional comments not posted (4)
packages/xrpl/tools/createValidateTests.js (2)

14-14: Verify the impact of replacing the error throw with a placeholder return.

The change replaces the error throw with a return statement that provides a placeholder string. This alters the function's behavior when no valid transactions are found for the given txName. Instead of terminating with an error, the function now returns a default value.

Please ensure that the calling code is equipped to handle this change in behavior appropriately. Additionally, consider providing a more informative placeholder or comment to guide the user on adding a sample transaction.


77-77: Verify the impact of replacing error throws with placeholder comments.

The changes replace error throws with return statements that provide placeholder comments for unsupported parameter types. This modifies the function's behavior by allowing it to return non-error values instead of terminating execution when encountering unsupported types.

Please ensure that the calling code is prepared to handle these placeholder values appropriately. Consider providing more specific placeholders or comments to indicate the unsupported parameter types encountered. This will aid in identifying and addressing any gaps in parameter type handling.

Also applies to: 89-89

packages/xrpl/tools/generateModels.js (2)

251-255: LGTM!

The conditional check before writing the validation tests file is a good addition. It prevents the creation of empty test files, improving the quality and maintainability of the test suite.


52-55: Verify consistent usage of the updated transaction type terminology.

The change in the regex pattern from Transaction to SubmittableTransaction is appropriate. Please ensure that this updated terminology is consistently used throughout the codebase and documentation to maintain clarity.

Run the following script to verify the usage of the updated terminology:

Verification successful

Clarification on SubmittableTransaction usage and its impact

The change from 'Transaction' to 'SubmittableTransaction' has been implemented, but it's not a complete replacement. Instead, it's a refinement that provides more specificity when needed. Here's a summary of the findings:

  • 'SubmittableTransaction' is now defined as a union of all transaction types that can be submitted by clients.
  • 'Transaction' still exists and is defined as a union of 'SubmittableTransaction' and 'PseudoTransaction'.
  • 'PseudoTransaction' includes transactions that can only be created by validators.
  • Most of the codebase, including the 'validate' function, still uses the broader 'Transaction' type.

The impact of this change is minimal:

  • Existing code using 'Transaction' should continue to work as before.
  • Developers now have the option to use 'SubmittableTransaction' when they specifically want to work with client-submittable transactions.
  • This change improves type safety and clarity in scenarios where only submittable transactions should be used.

To maintain consistency, you may want to review usage of 'Transaction' throughout the codebase and consider using 'SubmittableTransaction' where appropriate, especially in client-facing APIs or functions specifically dealing with submittable transactions.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent usage of `SubmittableTransaction` terminology.

# Test: Search for the old `Transaction` terminology. Expect: No occurrences.
rg --type typescript $'export type Transaction'

# Test: Search for the new `SubmittableTransaction` terminology. Expect: Only occurrences of the new terminology.
rg --type typescript $'export type SubmittableTransaction'

Length of output: 178


Script:

#!/bin/bash
# Description: Verify consistent usage of `SubmittableTransaction` terminology without relying on file type recognition.

# Search for the old `Transaction` terminology in relevant directories
echo "Searching for 'export type Transaction':"
rg 'export type Transaction' packages/xrpl

# Search for the new `SubmittableTransaction` terminology in relevant directories
echo "Searching for 'export type SubmittableTransaction':"
rg 'export type SubmittableTransaction' packages/xrpl

# Search for any remaining usage of 'Transaction' type to ensure complete migration
echo "Searching for any remaining 'Transaction' type usage:"
rg 'Transaction(?!.*SubmittableTransaction)' packages/xrpl

Length of output: 1196


Script:

#!/bin/bash
# Description: Search for remaining 'Transaction' usages without complex regex

echo "Searching for remaining 'Transaction' usages:"
rg 'Transaction' packages/xrpl --type ts --type js

Length of output: 143709


Script:

#!/bin/bash
# Description: Examine the content of the transaction.ts file

echo "Content of packages/xrpl/src/models/transactions/transaction.ts:"
cat packages/xrpl/src/models/transactions/transaction.ts

Length of output: 10920

Copy link

@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: 2

🧹 Outside diff range and nitpick comments (2)
packages/xrpl/tools/generateModels.js (2)

251-255: Use braces for the 'if' statement to improve readability.

It's recommended to use curly braces {} with if statements, even when there is only a single statement inside. This enhances code readability and reduces the risk of errors during future modifications.

Apply this diff to include braces:

 if (validateTests !== '') {
   fs.writeFileSync(
     path.join(path.dirname(__filename), `../test/models/${tx}.test.ts`),
     validateTests,
   )
-  )
+}

263-263: Address the TODO: Add docstrings and integration tests.

There's a TODO comment indicating the need to add docstrings to the models and integration tests. Completing this task will improve code documentation and ensure that the models are thoroughly tested in real-world scenarios.

Would you like assistance in generating the docstrings and setting up the integration tests? I can help create a template or open a new GitHub issue to track this task.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fe08836 and 25ccc09.

📒 Files selected for processing (1)
  • packages/xrpl/tools/generateModels.js (4 hunks)

packages/xrpl/tools/generateModels.js Show resolved Hide resolved
packages/xrpl/tools/generateModels.js Show resolved Hide resolved
@mvadari mvadari merged commit 8beb129 into main Oct 11, 2024
13 checks passed
@mvadari mvadari deleted the better-scripts branch October 11, 2024 21:40
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