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: add support for the simulate RPC (XLS-69d) #2867

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Conversation

mvadari
Copy link
Collaborator

@mvadari mvadari commented Jan 2, 2025

High Level Overview of Change

This PR adds support to xrpl-py for the new simulate RPC.

Context of Change

Spec: https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0069d-simulate
rippled PR: XRPLF/rippled#5069

Type of Change

  • New feature (non-breaking change which adds functionality)

Did you update CHANGELOG.md?

  • Yes

Test Plan

TODO

Copy link

coderabbitai bot commented Jan 2, 2025

Walkthrough

This pull request updates the XRPL library by replacing the deprecated transaction flag function with a new utility (convertTxFlagsToNumber) and introducing a simulate RPC. The changes include adding a new method in the Client class, defining associated request and response types for simulation, and updating related interface types. There are also minor updates to import paths and error messages, along with a new integration test suite for the simulation functionality.

Changes

File(s) Change Summary
packages/xrpl/HISTORY.md, packages/xrpl/src/client/index.ts Added the new utility convertTxFlagsToNumber (replacing setTransactionFlagsToNumber), and a new simulate method in the Client class for simulating transactions.
packages/xrpl/src/models/methods/index.ts, packages/xrpl/src/models/methods/simulate.ts, packages/xrpl/test/integration/requests/simulate.test.ts Introduced simulation-related request and response types (e.g., SimulateRequest, SimulateBinary/JsonRequest, SimulateResponse) and added integration tests for JSON, binary, and sugar simulation methods.
packages/xrpl/src/models/methods/ledger.ts Simplified Ledger interface declarations by consolidating nested Omit calls into a single operation.
packages/xrpl/src/sugar/submit.ts Updated the import source for decode/encode utilities and corrected the error message punctuation.

Possibly related PRs

Suggested reviewers

  • khancode
  • achowdhry-ripple

Poem

I’m a rabbit in a coding burrow,
Hopping through new functions, nice and mellow.
Flags convert and transactions simulate,
In a land of code where changes create.
Happy hops in every line, oh what a fate! 🐰💻
Cheers to updates that truly innovate!

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 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.

@mvadari mvadari marked this pull request as ready for review February 5, 2025 18:47
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

🧹 Nitpick comments (8)
packages/xrpl/src/models/methods/simulate.ts (1)

67-88: Consider adding JSDoc comments for the generic type parameter.

The SimulateJsonResponse interface looks good, but it would be helpful to document the generic type parameter T.

Add JSDoc comments to explain the purpose of the generic type parameter:

+/**
+ * Response for a JSON simulate request.
+ *
+ * @template T - The type of transaction, defaults to BaseTransaction.
+ */
 export interface SimulateJsonResponse<T extends BaseTransaction = Transaction>
   extends BaseResponse {
   // ...
 }
packages/xrpl/test/integration/requests/simulate.test.ts (4)

12-14: Consider using a constant for the timeout value.

Extract the timeout value into a named constant at the module level for better maintainability.

+const SIMULATE_TEST_TIMEOUT = 20000
-const TIMEOUT = 20000

23-43: Add test cases for error scenarios.

The JSON request test looks good but only covers the success case. Consider adding test cases for error scenarios such as:

  • Invalid transaction format
  • Missing required fields
  • Network errors

45-65: Add test cases for binary response validation.

The binary request test looks good but could be enhanced by validating the binary response format more thoroughly:

  • Verify the binary encoding format
  • Check for specific binary fields

67-84: Add test cases for the sugar method with different transaction types.

The sugar method test looks good but only tests AccountSet. Consider adding test cases for other transaction types to ensure the sugar method works correctly with all transaction types.

packages/xrpl/src/client/index.ts (1)

772-805: Consider adding error handling and validation.

The simulate method implementation looks good but could be enhanced with:

  • Input validation for the transaction parameter
  • Error handling for network issues
  • Validation of the binary flag value

Example implementation:

 public async simulate<Binary extends boolean = false>(
   transaction: SubmittableTransaction | string,
   opts?: {
     binary?: Binary
   },
 ): Promise<
   Binary extends true ? SimulateBinaryResponse : SimulateJsonResponse
 > {
+  if (!transaction) {
+    throw new ValidationError('Transaction is required')
+  }
+
+  if (opts?.binary !== undefined && typeof opts.binary !== 'boolean') {
+    throw new ValidationError('Binary flag must be a boolean')
+  }
+
   // send request
   const binary = opts?.binary ?? false
   const request: SimulateRequest =
     typeof transaction === 'string'
       ? { command: 'simulate', tx_blob: transaction, binary }
       : { command: 'simulate', tx_json: transaction, binary }
-  return this.request(request)
+  try {
+    return await this.request(request)
+  } catch (error) {
+    throw new RippledError(`Failed to simulate transaction: ${error.message}`)
+  }
 }
packages/xrpl/HISTORY.md (2)

13-15: New Feature Addition: Support for the simulate RPC
The release history now documents the support for the new simulate RPC. For consistency with the other bullet points under "### Added", consider revising the bullet text from:

    * Support for the simulate RPC

to:

    * Adds support for the simulate RPC

This small change aligns the wording with the earlier bullet that uses “Adds utility function …”.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

13-13: Multiple headings with the same content
null

(MD024, no-duplicate-heading)


13-13: Duplicate Heading Observation
Static analysis detected that the "### Added" heading appears more than once in this section. If the intent is to separately list different additions (e.g. one for the utility function and one for RPC support), this may be acceptable. Otherwise, consider consolidating the headings to improve clarity.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

13-13: Multiple headings with the same content
null

(MD024, no-duplicate-heading)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 991a1d2 and a421062.

📒 Files selected for processing (7)
  • packages/xrpl/HISTORY.md (1 hunks)
  • packages/xrpl/src/client/index.ts (2 hunks)
  • packages/xrpl/src/models/methods/index.ts (5 hunks)
  • packages/xrpl/src/models/methods/ledger.ts (1 hunks)
  • packages/xrpl/src/models/methods/simulate.ts (1 hunks)
  • packages/xrpl/src/sugar/submit.ts (2 hunks)
  • packages/xrpl/test/integration/requests/simulate.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/xrpl/src/sugar/submit.ts
  • packages/xrpl/src/models/methods/ledger.ts
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
packages/xrpl/HISTORY.md

13-13: Multiple headings with the same content
null

(MD024, no-duplicate-heading)

🔇 Additional comments (8)
packages/xrpl/src/models/methods/simulate.ts (3)

15-28: LGTM! The request type definition looks good.

The SimulateRequest type correctly enforces mutual exclusivity between tx_blob and tx_json using a discriminated union type.


30-36: LGTM! The binary and JSON request types look good.

The specialized request types correctly extend the base SimulateRequest type and handle the binary flag appropriately.


45-65: LGTM! The binary response type looks good.

The SimulateBinaryResponse interface correctly defines the structure for binary responses, including all necessary fields.

packages/xrpl/src/models/methods/index.ts (4)

151-158: LGTM! The imports look good.

The simulate-related types are correctly imported.


214-214: LGTM! The Request union type is correctly updated.

The SimulateRequest type is correctly added to the Request union.


273-274: LGTM! The Response union type is correctly updated.

The SimulateResponse type is correctly added to the Response union.


411-417: LGTM! The RequestResponseMap is correctly updated.

The simulate-related types are correctly mapped in the RequestResponseMap.

packages/xrpl/src/client/index.ts (1)

43-44: LGTM! The imports look good.

The simulate-related types are correctly imported.

Also applies to: 47-49

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