Skip to content

Conversation

ckeshava
Copy link
Collaborator

@ckeshava ckeshava commented Mar 4, 2025

High Level Overview of Change

CPP implementation for SAV: XRPLF/rippled#5224
CPP implementation of the STNumber type: https://github.com/XRPLF/rippled/pull/5121/files

XLS Specification for this feature: XRPLF/XRPL-Standards#192
Please view the updates to the specification in this PR: https://github.com/XRPLF/XRPL-Standards/pull/275/files

Context of Change

This PR adds the following transactions: Vault<Create, Set, Deposit, Withdraw, Clawback, Delete>
This PR also adds the models and the unit tests for the VaultInfo RPC. This is the reference commit: (a1073b3).

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Tests (You added tests for code that already exists, or your new feature included in this PR)
  • Documentation Updates
  • Release

Did you update CHANGELOG.md?

  • Yes

Test Plan

I don't see the value of writing unit tests for the transaction models. All the tem codes are caught in the preflight method of the relevant Transactor class. Additional latency to an already failing transaction should not affect user-experience.

Transaction-model unit tests add unnecessary code bloat and duplication. Certain transactions (like the ones related to XChain amendment) do not have unit tests associated with them. Furthermore, requests also do not have unit tests associated with their models.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 4, 2025

Walkthrough

This update introduces comprehensive support for Single Asset Vaults (XLS-65d) in the XRPL Python codebase. It adds new transaction models, request types, enums, and serialization logic for vault operations, along with corresponding integration and unit tests. Configuration, changelog, and binary codec definitions are updated to reflect the new feature.

Changes

File(s) Change Summary
.ci-config/rippled.cfg Added SingleAssetVault amendment under new 2.5.0 Amendments header in [features] section.
CHANGELOG.md Documented Single Asset Vault (XLS-65d) support in the "Unreleased" section.
xrpl/core/binarycodec/types/number.py, xrpl/core/binarycodec/types/init.py Added Number serialization/deserialization logic and exported Number type.
xrpl/core/binarycodec/definitions/definitions.json Added tedADDRESS_COLLISION error; reordered vault-related transaction types.
xrpl/models/transactions/vault_create.py, vault_clawback.py, vault_delete.py, vault_deposit.py, vault_set.py, vault_withdraw.py Added transaction models for vault creation, clawback, deletion, deposit, setting, and withdrawal.
xrpl/models/transactions/types/transaction_type.py Added six new vault-related transaction types to the TransactionType enum.
xrpl/models/transactions/init.py Exported new vault transaction classes.
xrpl/models/requests/vault_info.py, init.py, request.py Added VaultInfo request model, exported it, and added VAULT_INFO to the request method enum.
xrpl/models/requests/account_objects.py Added VAULT to AccountObjectType enum.
xrpl/models/requests/ledger_entry.py Added SINGLE_ASSET_VAULT to LedgerEntryType, new Vault dataclass, and updated LedgerEntry validation.
xrpl/models/amounts/clawback_amount.py, init.py Introduced and exported ClawbackAmount type alias for clawback operations.
xrpl/models/transactions/clawback.py Updated amount field to use ClawbackAmount type alias.
xrpl/asyncio/transaction/main.py Included VAULT_CREATE in transaction types using owner reserve fee calculation.
tests/unit/core/binarycodec/types/test_number.py Added unit tests for Number type serialization/deserialization and edge cases.
tests/unit/core/binarycodec/fixtures/data/codec-fixtures.json Added fixture for VaultCreate transaction encoding/decoding.
tests/unit/models/transactions/test_vault_create.py, test_vault_delete.py, test_vault_set.py, test_vault_withdraw.py Added unit tests for vault transaction models, including validation and error cases.
tests/unit/models/requests/test_vault_info.py Added unit tests for VaultInfo request model validation.
tests/integration/transactions/test_single_asset_vault.py Added integration test covering the full lifecycle of a single-asset vault.
tests/integration/reqs/test_vault_info.py Added integration test for querying vault info via RPC.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant XRPL_Python
    participant XRPL_Node

    Client->>XRPL_Python: Submit VaultCreate transaction
    XRPL_Python->>XRPL_Node: Broadcast VaultCreate
    XRPL_Node-->>XRPL_Python: Confirm transaction
    XRPL_Python-->>Client: Return transaction result

    Client->>XRPL_Python: Query VaultInfo (by vault_id or owner+seq)
    XRPL_Python->>XRPL_Node: Send vault_info request
    XRPL_Node-->>XRPL_Python: Return vault details
    XRPL_Python-->>Client: Return vault info

    Client->>XRPL_Python: Submit VaultDeposit / VaultWithdraw / VaultSet / VaultClawback / VaultDelete
    XRPL_Python->>XRPL_Node: Broadcast transaction
    XRPL_Node-->>XRPL_Python: Confirm transaction
    XRPL_Python-->>Client: Return transaction result
Loading

Suggested reviewers

  • pdp2121
  • achowdhry-ripple
  • Patel-Raj
  • khancode

Poem

In burrows deep, a vault appears,
With tokens, flags, and ledger cheers.
We test, we code, we hop with glee,
For Single Asset Vaults, now XRPL can see!
From clawbacks swift to deposits bright,
This rabbit’s code just feels so right.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@ckeshava ckeshava marked this pull request as ready for review March 6, 2025 20:58
Copy link
Contributor

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

🧹 Nitpick comments (18)
xrpl/models/amounts/mpt_amount.py (1)

42-50: Consider making MPTIssue consistent with other data models.

Currently, this class does not inherit from BaseModel or use a dataclass. If you anticipate adding dynamic validation or JSON serialization logic, aligning it with the approach used for MPTAmount may simplify future enhancements.

xrpl/core/binarycodec/definitions/definitions.json (2)

2073-2082: New field “AssetTotal”.

This addition follows the same pattern. Keep an eye on whether integrators might interpret it as a typical “UINT” or a decimal. Documentation should clarify that it’s a “Number” with potential decimal representation.


2702-2711: New field “WithdrawalPolicy”.

Added as a UInt8 with nth=20. This is typically used for small enumerations. Confirm you’ve reserved or documented permissible values (e.g., 0,1,2).

xrpl/models/transactions/vault_set.py (3)

1-3: Fix docstring formatting

The module docstring should fit on one line with quotes per linting rules.

-"""
-Represents a VaultSet transaction on the XRP Ledger.
-"""
+"""Represents a VaultSet transaction on the XRP Ledger."""
🧰 Tools
🪛 GitHub Actions: Unit test

[warning] 1-1: D200 One-line docstring should fit on one line with quotes


16-19: Fix class docstring formatting

The class docstring should fit on one line with quotes per linting rules.

-    """
-    The VaultSet updates an existing Vault ledger object.
-    """
+    """The VaultSet updates an existing Vault ledger object."""
🧰 Tools
🪛 GitHub Actions: Unit test

[warning] 17-17: D200 One-line docstring should fit on one line with quotes


30-33: Fix trailing whitespace

There's a trailing whitespace at the end of line 31.

-    """The maximum asset amount that can be held in a vault. The value cannot be lower 
+    """The maximum asset amount that can be held in a vault. The value cannot be lower
     than the current AssetTotal unless the value is 0.
     """
🧰 Tools
🪛 GitHub Actions: Unit test

[warning] 31-31: W291 trailing whitespace

xrpl/models/transactions/vault_clawback.py (2)

1-3: Fix docstring formatting

The module docstring should fit on one line with quotes per linting rules.

-"""
-Represents a VaultClawback transaction on the XRP Ledger.
-"""
+"""Represents a VaultClawback transaction on the XRP Ledger."""
🧰 Tools
🪛 GitHub Actions: Unit test

[warning] 1-1: D200 One-line docstring should fit on one line with quotes


35-38: Fix trailing whitespace

There's a trailing whitespace at the end of line 36.

-    """The asset amount to clawback. When Amount is 0 clawback all funds, up to the 
+    """The asset amount to clawback. When Amount is 0 clawback all funds, up to the
     total shares the Holder owns.
     """
🧰 Tools
🪛 GitHub Actions: Unit test

[warning] 36-36: W291 trailing whitespace

xrpl/models/transactions/vault_create.py (6)

1-3: Fix docstring formatting

The module docstring should fit on one line with quotes per linting rules.

-"""
-Represents a VaultCreate transaction on the XRP Ledger.
-"""
+"""Represents a VaultCreate transaction on the XRP Ledger."""
🧰 Tools
🪛 GitHub Actions: Unit test

[warning] 1-1: D200 One-line docstring should fit on one line with quotes


18-22: Add docstring to VaultCreateFlag enum

The enum class is missing a docstring, which is required for public classes.

 class VaultCreateFlag(int, Enum):
+    """Flags that can be set on a VaultCreate transaction."""
 
     TF_VAULT_PRIVATE = 0x0001
     TF_VAULT_SHARE_NON_TRANSFERABLE = 0x0002
🧰 Tools
🪛 GitHub Actions: Unit test

[warning] 18-18: D101 Missing docstring in public class


24-28: Add docstring to VaultCreateFlagInterface class

The interface class is missing a docstring, which is required for public classes.

 class VaultCreateFlagInterface(FlagInterface):
+    """Interface for VaultCreate transaction flags."""
 
     TF_VAULT_PRIVATE: bool
     TF_VAULT_SHARE_NON_TRANSFERABLE: bool
🧰 Tools
🪛 GitHub Actions: Unit test

[warning] 24-24: D101 Missing docstring in public class


32-35: Fix class docstring formatting

The class docstring should fit on one line with quotes per linting rules.

-    """
-    The VaultCreate transaction creates a new Vault object.
-    """
+    """The VaultCreate transaction creates a new Vault object."""
🧰 Tools
🪛 GitHub Actions: Unit test

[warning] 33-33: D200 One-line docstring should fit on one line with quotes


53-60: Fix blank line with whitespace

Line 54 contains whitespace on an otherwise blank line.

     """Indicates the withdrawal strategy used by the Vault.
-    
+
     The below withdrawal policy is supported:

     Strategy Name	           Value	      Description
🧰 Tools
🪛 GitHub Actions: Unit test

[warning] 54-54: W293 blank line contains whitespace


37-61: Document flag meanings and consider adding more withdrawal policies

While the implementation is solid, it would be helpful to:

  1. Document what each flag means (TF_VAULT_PRIVATE and TF_VAULT_SHARE_NON_TRANSFERABLE)
  2. Consider using an enum for withdrawal_policy instead of an int with comments, to make the API more type-safe
🧰 Tools
🪛 GitHub Actions: Unit test

[warning] 54-54: W293 blank line contains whitespace

tests/unit/core/binarycodec/types/test_number.py (1)

35-42: Consider adding validation for negative exponents in extreme limits test

The current test only checks extreme mantissa values with positive exponents. For comprehensive testing, consider adding test cases with negative exponents as well, which would test the handling of extremely small numbers.

tests/integration/transactions/test_sav.py (3)

78-78: Variable name should follow Python convention

Use lowercase for variable names according to PEP 8. VAULT_ID should be renamed to vault_id.

-        VAULT_ID = account_objects_response.result["account_objects"][0]["index"]
+        vault_id = account_objects_response.result["account_objects"][0]["index"]

114-123: Improve comment clarity for VaultClawback transaction

The comment describing the behavior is somewhat confusing. It would be clearer to explicitly state that the transaction will clawback the entire remaining balance (1 unit) regardless of the specified amount (9).

-            # Note: Although the amount is specified as 9, 1 unit of the IOU will be
-            # clawed back, because that is the remaining balance in the vault
+            # Note: This will clawback only 1 unit of the IOU (the remaining balance),
+            # even though the amount is specified as 9. The clawback amount is limited
+            # to the available balance in the vault.

27-135: Add verification of vault state after each operation

The test validates that transactions are successful, but doesn't verify the actual state of the vault after each operation (e.g., checking balances). Adding assertions for vault state would strengthen the test.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 13fdbd8 and 6c4f801.

📒 Files selected for processing (19)
  • .ci-config/rippled.cfg (1 hunks)
  • CHANGELOG.md (1 hunks)
  • tests/integration/transactions/test_sav.py (1 hunks)
  • tests/unit/core/binarycodec/types/test_number.py (1 hunks)
  • xrpl/asyncio/transaction/main.py (1 hunks)
  • xrpl/core/binarycodec/definitions/definitions.json (6 hunks)
  • xrpl/core/binarycodec/types/__init__.py (2 hunks)
  • xrpl/core/binarycodec/types/number.py (1 hunks)
  • xrpl/models/amounts/mpt_amount.py (1 hunks)
  • xrpl/models/requests/account_objects.py (1 hunks)
  • xrpl/models/requests/ledger_entry.py (3 hunks)
  • xrpl/models/transactions/__init__.py (2 hunks)
  • xrpl/models/transactions/types/transaction_type.py (1 hunks)
  • xrpl/models/transactions/vault_clawback.py (1 hunks)
  • xrpl/models/transactions/vault_create.py (1 hunks)
  • xrpl/models/transactions/vault_delete.py (1 hunks)
  • xrpl/models/transactions/vault_deposit.py (1 hunks)
  • xrpl/models/transactions/vault_set.py (1 hunks)
  • xrpl/models/transactions/vault_withdraw.py (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Unit test
xrpl/models/transactions/vault_delete.py

[warning] 1-1: D200 One-line docstring should fit on one line with quotes


[warning] 16-16: D200 One-line docstring should fit on one line with quotes

xrpl/models/transactions/vault_deposit.py

[warning] 1-1: D200 One-line docstring should fit on one line with quotes


[warning] 17-17: D200 One-line docstring should fit on one line with quotes

xrpl/models/transactions/vault_withdraw.py

[warning] 1-1: D200 One-line docstring should fit on one line with quotes


[warning] 18-18: D200 One-line docstring should fit on one line with quotes

xrpl/models/transactions/vault_set.py

[warning] 1-1: D200 One-line docstring should fit on one line with quotes


[warning] 17-17: D200 One-line docstring should fit on one line with quotes


[warning] 31-31: W291 trailing whitespace

xrpl/models/transactions/vault_create.py

[warning] 1-1: D200 One-line docstring should fit on one line with quotes


[warning] 18-18: D101 Missing docstring in public class


[warning] 24-24: D101 Missing docstring in public class


[warning] 33-33: D200 One-line docstring should fit on one line with quotes


[warning] 54-54: W293 blank line contains whitespace

tests/unit/core/binarycodec/types/test_number.py

[error] 8-8: Error in test_serialization_and_deserialization: TypeError occurred during test execution.

xrpl/models/transactions/vault_clawback.py

[warning] 1-1: D200 One-line docstring should fit on one line with quotes


[warning] 36-36: W291 trailing whitespace

xrpl/core/binarycodec/types/number.py

[error] 87-87: TypeError: to_bytes() missing required argument 'byteorder' (pos 2)

🔇 Additional comments (23)
.ci-config/rippled.cfg (1)

199-199: Ensure supported configuration for new feature.

Adding SingleAssetVault under [features] is straightforward. However, as noted in line 91, standalone mode may not honor these flags. If you plan on using this feature in standalone mode, please validate that the enabling logic is recognized by your rippled version.

Would you like a shell script to cross-check whether the feature is supported on your targeted rippled build?

xrpl/core/binarycodec/definitions/definitions.json (8)

2043-2052: ”Number” field creation.

The “Number” field is added as an alias to the newly introduced type with nth=1. Ensure consistency regarding bit size constraints when using “Number” in practice, as it differs from standard “UInt32” or “UInt64.”


2053-2062: New field “AssetAvailable”.

Marking this as a “Number” with nth=2 is fine. Please confirm in your usage or docs that the “Number” type properly handles large integer or floating-point values as intended for this field.


2063-2072: New field “AssetMaximum”.

Same consideration as “AssetAvailable.” If “AssetMaximum” can be quite large, the “Number” type must handle big mantissa/exponent pairs without overflow or precision loss.


2083-2092: New field “LossUnrealized”.

As a “Number,” ensure that negative values are supported if “loss” can indeed be negative. If not, consider validating to ensure non-negative input.


2959-2959: New Ledger Entry Type “Vault”.

Assigned ID 131. Check that no collisions exist with previously assigned ledger entry type codes.


3197-3202: New Transaction Types for Vault operations.

The new codes (64, 65, 66, 67, 68, 69) appear unique. Ensure that any transaction processing logic (like TransactionType enum usage) recognizes these new values and is tested accordingly.


3226-3226: Number type assigned ID=9.

Declaring “Number” in the TYPES set is consistent with the newly introduced serialization logic. Confirm everything referencing type 9 is fully implemented and tested.


1263-1272:

❓ Verification inconclusive

Addition of VaultID field.

Declaring a new Hash256 field with nth=35 in the [FIELDS] array is valid. Verify that no collisions occur with existing fields using the same index, especially if similar sets of indices are reused for different data types.


🏁 Script executed:

#!/bin/bash
# Verify no index collisions for VaultID by scanning "nth": 35 usage across the file
rg '"nth": 35' -A 5 definitions.json

Length of output: 95


I'll perform an additional check to see if the file exists at the expected path. Below is a shell script to search for the file relative to the repository root:

#!/bin/bash
# Locate the definitions.json file and verify its path.
find . -type f -name definitions.json | grep "xrpl/core/binarycodec/definitions/definitions.json"

If the above script finds the file, please re-run the previous scan using the correct full path:

#!/bin/bash
# Verify no index collisions for VaultID by scanning "nth": 35 usage in the file:
rg '"nth": 35' -A 5 xrpl/core/binarycodec/definitions/definitions.json

VaultID Field Addition – Manual Verification Required

  • The addition of the VaultID field (with nth: 35 and type Hash256) appears valid provided there are no conflicts.
  • The initial automated scan couldn’t locate definitions.json using the relative path. Please verify the file exists at xrpl/core/binarycodec/definitions/definitions.json and confirm that no other field uses the nth index 35.

Please double-check the file location and ensure the intended consistency across the field indices.

xrpl/models/requests/account_objects.py (1)

39-39: Addition of VAULT type looks good

This new enumeration value for AccountObjectType allows retrieving vault objects associated with an account, which aligns with the Single Asset Vault (XLS-65d) feature being introduced.

xrpl/core/binarycodec/types/__init__.py (1)

13-13: Appropriate exposure of the Number type

The addition of the Number type to the module exports is correctly implemented, following the existing pattern for exposing binary codec types. This new type will be essential for handling numerical values in the Single Asset Vault implementation.

Also applies to: 36-36

xrpl/models/transactions/vault_delete.py (2)

20-21: Implementation of the vault_id field looks good

The required vault_id field is properly defined with appropriate documentation.


23-26: Transaction type definition looks good

The transaction_type is correctly set to TransactionType.VAULT_DELETE with appropriate initialization parameters.

CHANGELOG.md (1)

15-15: Appropriate changelog entry

The addition of "Support for Single Asset Vault (XLS-65d)" to the changelog correctly documents this new feature following the project's changelog format.

xrpl/asyncio/transaction/main.py (1)

483-487: LGTM! Good addition of VAULT_CREATE transaction type fee calculation.

The addition of TransactionType.VAULT_CREATE to the list of transaction types that require owner reserve fee is consistent with the existing pattern for similar transaction types (ACCOUNT_DELETE and AMM_CREATE).

xrpl/models/transactions/types/transaction_type.py (1)

55-60: LGTM! Properly added new transaction types.

The six new vault-related transaction types have been added correctly to the TransactionType enumeration, following the established pattern.

xrpl/models/requests/ledger_entry.py (3)

44-44: New LedgerEntryType for Single Asset Vault looks good

The addition of a new enumeration value for the Single Asset Vault is appropriate and follows the established naming convention in the class.


319-320: Good documentation for vault_id field

The comment and field definition for the vault_id are clear and follow the established pattern. The comment explaining that Single Asset Vault ledger objects can only be retrieved by index is helpful for API users.


355-355: Error handling update complete

The addition of self.vault_id to the query parameters list in _get_errors ensures proper validation for the newly added field.

xrpl/models/transactions/vault_set.py (1)

21-39: VaultSet implementation looks good

The transaction definition follows the established pattern for XRPL transaction types with appropriate attributes, typing, and documentation. Good job implementing the VaultSet transaction.

🧰 Tools
🪛 GitHub Actions: Unit test

[warning] 31-31: W291 trailing whitespace

xrpl/models/transactions/vault_clawback.py (1)

17-43: VaultClawback implementation is well documented

The implementation of the VaultClawback transaction includes comprehensive documentation that clearly explains the transaction's purpose, behavior with insufficient funds, and how it handles future fees or penalties. The required and optional fields are properly defined following the established pattern.

🧰 Tools
🪛 GitHub Actions: Unit test

[warning] 36-36: W291 trailing whitespace

xrpl/models/transactions/__init__.py (2)

99-104: LGTM! Vault transaction imports added correctly

The new vault-related transaction models are properly imported and will be available for library users.


202-207: LGTM! Vault transaction classes added to all list

The vault-related transaction classes are correctly added to the __all__ list, making them accessible when importing from xrpl.models.transactions.

ckeshava and others added 3 commits March 6, 2025 14:20
Copy link
Contributor

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

🧹 Nitpick comments (1)
tests/unit/core/binarycodec/types/test_number.py (1)

6-42: Consider adding more test coverage

The current tests provide good coverage but could be enhanced by adding:

  1. Tests for zero in scientific notation (e.g., "0e0")
  2. Tests for negative exponents in the extreme limits test
  3. Tests for error handling with invalid inputs
🧰 Tools
🪛 GitHub Actions: Unit test

[error] 38-38: AttributeError: 'Number' object has no attribute 'hex'

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 18bfd1c and f967f23.

📒 Files selected for processing (1)
  • tests/unit/core/binarycodec/types/test_number.py (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Unit test
tests/unit/core/binarycodec/types/test_number.py

[error] 38-38: AttributeError: 'Number' object has no attribute 'hex'

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Snippet test (3.11)
  • GitHub Check: Snippet test (3.13)
  • GitHub Check: Snippet test (3.12)
  • GitHub Check: Snippet test (3.10)
  • GitHub Check: Snippet test (3.9)
  • GitHub Check: Snippet test (3.8)
🔇 Additional comments (2)
tests/unit/core/binarycodec/types/test_number.py (2)

1-6: Good job with the test organization.

The imports and test class declaration look correct. The test class follows proper unittest conventions.


7-34: Good comprehensive test coverage for serialization.

Your test cases cover a good range of scenarios including positive/negative integers, decimals, and scientific notation values. Each assertion is clear and properly formatted.

@ckeshava
Copy link
Collaborator Author

ckeshava commented Mar 7, 2025

Note: The integration tests will not pass until the C++ code is merged into the rippled:develop branch. After this, a new docker container needs to be generated for the said branch.

@ckeshava ckeshava requested a review from pdp2121 June 30, 2025 19:08
@ckeshava ckeshava requested a review from khancode July 2, 2025 21:46
@ckeshava
Copy link
Collaborator Author

ckeshava commented Jul 2, 2025

@khancode I have addressed your comments.

@ckeshava ckeshava requested a review from khancode July 3, 2025 18:00
Copy link
Contributor

@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

♻️ Duplicate comments (1)
xrpl/models/transactions/vault_create.py (1)

17-19: Fix swapped constant values for domain_id and mptoken_metadata lengths.

The constant values are swapped. Based on the spec and past review comments:

  • domain_id is a Hash256 field requiring exactly 64 hex characters (32 bytes)
  • mptoken_metadata can be up to 1024 bytes (2048 hex characters)

Also, remove the leading underscore from _VAULT_MAX_MPTOKEN_METADATA_LENGTH since it's used in other modules.

 VAULT_MAX_DATA_LENGTH = 256 * 2
-VAULT_MAX_DOMAIN_ID_LENGTH = 1024 * 2
-_VAULT_MAX_MPTOKEN_METADATA_LENGTH = 32 * 2
+VAULT_MAX_DOMAIN_ID_LENGTH = 32 * 2
+VAULT_MAX_MPTOKEN_METADATA_LENGTH = 1024 * 2
🧹 Nitpick comments (3)
tests/integration/transactions/test_single_asset_vault.py (2)

34-39: Consider adding assertions after wallet funding.

While the current implementation allows natural test failures per the learning about xrpl-py test patterns, adding simple assertions after funding would make test failures more explicit and easier to debug.

 vault_owner = Wallet.create()
 await fund_wallet_async(vault_owner)
+self.assertIsNotNone(vault_owner.address)

 issuer_wallet = Wallet.create()
 await fund_wallet_async(issuer_wallet)
+self.assertIsNotNone(issuer_wallet.address)

168-168: Add newline at end of file.

Python files should end with a newline character.

         self.assertEqual(response.result["engine_result"], "tesSUCCESS")
+
xrpl/models/transactions/vault_create.py (1)

108-110: Simplify the domain_id error message.

The error message is confusing by mentioning both "32 characters" and "64 hex characters". Since this is a hex-encoded Hash256 field, just mention the hex character requirement.

             errors["domain_id"] = (
-                "Invalid domain ID: Length must be 32 characters (64 hex characters)."
+                "Invalid domain ID: Length must be exactly 64 hex characters."
             )
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6a1be36 and 9144d2c.

📒 Files selected for processing (9)
  • tests/integration/transactions/test_single_asset_vault.py (1 hunks)
  • xrpl/core/binarycodec/types/number.py (1 hunks)
  • xrpl/models/amounts/__init__.py (2 hunks)
  • xrpl/models/amounts/clawback_amount.py (1 hunks)
  • xrpl/models/requests/vault_info.py (1 hunks)
  • xrpl/models/transactions/clawback.py (2 hunks)
  • xrpl/models/transactions/vault_clawback.py (1 hunks)
  • xrpl/models/transactions/vault_create.py (1 hunks)
  • xrpl/models/transactions/vault_set.py (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • xrpl/models/amounts/init.py
  • xrpl/models/amounts/clawback_amount.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • xrpl/models/transactions/vault_set.py
  • xrpl/models/requests/vault_info.py
  • xrpl/models/transactions/vault_clawback.py
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: mvadari
PR: XRPLF/xrpl-py#759
File: tests/unit/models/transactions/test_account_delete.py:52-60
Timestamp: 2024-12-12T00:48:38.042Z
Learning: The credential ID format validation for xrpl-py is being tracked in issue #766 and should not be duplicated in other PRs.
Learnt from: mvadari
PR: XRPLF/xrpl-py#765
File: xrpl/models/transactions/xchain_add_claim_attestation.py:82-88
Timestamp: 2024-11-01T20:24:17.202Z
Learning: Changing the type of `was_locking_chain_send` in `xrpl/models/transactions/xchain_add_claim_attestation.py` to `bool` is out of scope for the current PR.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/credential_delete.py:57-68
Timestamp: 2024-10-30T20:34:35.451Z
Learning: Consistent implementation patterns are preferred in the `xrpl-py` codebase, especially in transaction models under `xrpl/models/transactions/`. When suggesting refactoring that affects multiple transactions, consider the impact on overall consistency and propose comprehensive changes when appropriate.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/deposit_preauth.py:54-64
Timestamp: 2024-10-30T20:45:02.301Z
Learning: In the `DepositPreauth` class in `xrpl/models/transactions/deposit_preauth.py`, when validating that exactly one of the parameters `authorize`, `unauthorize`, `authorize_credentials`, or `unauthorize_credentials` is set, ensure that any refactoring maintains logical equivalence with the original condition to prevent altering the intended functionality.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#814
File: xrpl/models/requests/vault_info.py:16-31
Timestamp: 2025-06-04T22:17:47.822Z
Learning: In the xrpl-py library, Request classes do not perform client-side validation on their contents. The library relies on the rippled node to return appropriate error codes for malformed requests, maintaining a consistent pattern across all Request models.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#814
File: xrpl/core/binarycodec/types/number.py:77-97
Timestamp: 2025-03-06T22:45:59.640Z
Learning: The `to_bytes()` method in Python requires the `byteorder` parameter even for single-byte operations, despite endianness not functionally affecting single-byte representation. The XRPL Python library implementation of serialization methods like `add32` and `add64` need to specify this parameter.
Learnt from: khancode
PR: XRPLF/xrpl-py#732
File: xrpl/models/transactions/mptoken_issuance_create.py:78-84
Timestamp: 2024-12-11T01:47:28.074Z
Learning: In the `xrpl-py` codebase, within the models (e.g., in `xrpl/models/transactions/`), flag validation checks are not performed; flag checks are handled elsewhere outside of the models.
xrpl/models/transactions/clawback.py (8)
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/credential_delete.py:57-68
Timestamp: 2024-10-30T20:34:35.451Z
Learning: Consistent implementation patterns are preferred in the `xrpl-py` codebase, especially in transaction models under `xrpl/models/transactions/`. When suggesting refactoring that affects multiple transactions, consider the impact on overall consistency and propose comprehensive changes when appropriate.
Learnt from: khancode
PR: XRPLF/xrpl-py#732
File: xrpl/models/transactions/mptoken_issuance_create.py:70-76
Timestamp: 2024-12-10T20:35:09.762Z
Learning: In the `xrpl/models/transactions/mptoken_issuance_create.py` file, the `maximum_amount` field in the `MPTokenIssuanceCreate` class is a non-negative integer string and should be typed as `Optional[str]`.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#814
File: xrpl/models/amounts/mpt_amount.py:54-64
Timestamp: 2025-06-04T22:17:47.164Z
Learning: For MPTIssue class in xrpl-py, the user ckeshava confirmed that a simple class implementation without BaseModel inheritance works correctly for their current requirements, even though other currency types in the same Union (IssuedCurrency, MPTCurrency, XRP) extend BaseModel.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/deposit_preauth.py:54-64
Timestamp: 2024-10-30T20:45:02.301Z
Learning: In the `DepositPreauth` class in `xrpl/models/transactions/deposit_preauth.py`, when validating that exactly one of the parameters `authorize`, `unauthorize`, `authorize_credentials`, or `unauthorize_credentials` is set, ensure that any refactoring maintains logical equivalence with the original condition to prevent altering the intended functionality.
Learnt from: mvadari
PR: XRPLF/xrpl-py#765
File: xrpl/models/transactions/xchain_add_claim_attestation.py:82-88
Timestamp: 2024-11-01T20:24:17.202Z
Learning: Changing the type of `was_locking_chain_send` in `xrpl/models/transactions/xchain_add_claim_attestation.py` to `bool` is out of scope for the current PR.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/credential_delete.py:36-38
Timestamp: 2024-10-30T20:36:02.813Z
Learning: In `xrpl/models/transactions/credential_delete.py`, changing required field declarations from `credential_type: str = REQUIRED  # type: ignore` to `credential_type: str = field(default=REQUIRED)` can cause mypy errors due to type incompatibility. It's acceptable to use `# type: ignore` in such cases in the `xrpl-py` codebase.
Learnt from: khancode
PR: XRPLF/xrpl-py#732
File: xrpl/models/transactions/mptoken_issuance_create.py:78-84
Timestamp: 2024-12-11T01:47:28.074Z
Learning: In the `xrpl-py` codebase, within the models (e.g., in `xrpl/models/transactions/`), flag validation checks are not performed; flag checks are handled elsewhere outside of the models.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/credential_accept.py:27-39
Timestamp: 2024-10-30T20:32:03.246Z
Learning: In the `xrpl` codebase, when defining required fields in dataclasses (e.g., `account: str = REQUIRED`), it's necessary to include `# type: ignore` to prevent `mypy` errors.
tests/integration/transactions/test_single_asset_vault.py (10)
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/credential_delete.py:57-68
Timestamp: 2024-10-30T20:34:35.451Z
Learning: Consistent implementation patterns are preferred in the `xrpl-py` codebase, especially in transaction models under `xrpl/models/transactions/`. When suggesting refactoring that affects multiple transactions, consider the impact on overall consistency and propose comprehensive changes when appropriate.
Learnt from: mvadari
PR: XRPLF/xrpl-py#759
File: tests/integration/transactions/test_credential.py:61-63
Timestamp: 2024-11-01T16:20:50.192Z
Learning: In integration tests for xrpl-py, tests should only be testing the library, not rippled functionalities.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/deposit_preauth.py:54-64
Timestamp: 2024-10-30T20:45:02.301Z
Learning: In the `DepositPreauth` class in `xrpl/models/transactions/deposit_preauth.py`, when validating that exactly one of the parameters `authorize`, `unauthorize`, `authorize_credentials`, or `unauthorize_credentials` is set, ensure that any refactoring maintains logical equivalence with the original condition to prevent altering the intended functionality.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#773
File: tests/integration/reusable_values.py:112-119
Timestamp: 2025-01-15T00:41:02.631Z
Learning: In xrpl-py integration tests, errors during test setup should be allowed to terminate the test suite naturally to aid debugging, rather than being caught and wrapped in custom error handlers. This applies to functions like `sign_and_reliable_submission_async` which already have robust error handling.
Learnt from: mvadari
PR: XRPLF/xrpl-py#759
File: tests/unit/models/requests/test_deposit_authorized.py:7-15
Timestamp: 2024-11-01T18:53:01.394Z
Learning: In `tests/unit/models/requests/test_deposit_authorized.py`, additional tests for invalid credentials are unnecessary because `rippled` handles those checks, and the `xrpl-py` library does not include such checks.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: tests/unit/models/transactions/test_credential_create.py:107-114
Timestamp: 2024-10-30T20:26:32.925Z
Learning: In `tests/unit/models/transactions/test_credential_create.py`, when testing invalid inputs, avoid adding assertions on specific error messages if it increases the complexity and maintenance overhead of the tests.
Learnt from: mvadari
PR: XRPLF/xrpl-py#759
File: tests/unit/models/transactions/test_credential_create.py:13-22
Timestamp: 2024-11-01T20:41:08.207Z
Learning: In Python test files in the xrpl-py codebase (e.g., `tests/unit/models/transactions/test_credential_create.py`), docstrings are not required for test classes and methods if their names are self-explanatory enough.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: tests/integration/transactions/test_credential.py:37-108
Timestamp: 2024-10-30T20:28:45.649Z
Learning: In integration tests, setup and teardown are performed using the `CredentialCreate` and `CredentialDelete` transactions, and we prefer not to abstract these transactions into separate utility functions.
Learnt from: mvadari
PR: XRPLF/xrpl-py#765
File: xrpl/models/transactions/xchain_add_claim_attestation.py:82-88
Timestamp: 2024-11-01T20:24:17.202Z
Learning: Changing the type of `was_locking_chain_send` in `xrpl/models/transactions/xchain_add_claim_attestation.py` to `bool` is out of scope for the current PR.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#758
File: xrpl/transaction/__init__.py:8-8
Timestamp: 2024-10-17T17:45:46.828Z
Learning: In the xrpl-py project, importing private functions (indicated by a leading underscore) for integration testing purposes is acceptable when the methods are used internally.
xrpl/models/transactions/vault_create.py (27)
Learnt from: khancode
PR: XRPLF/xrpl-py#732
File: xrpl/models/transactions/mptoken_issuance_create.py:78-84
Timestamp: 2024-12-11T01:47:28.074Z
Learning: In the `xrpl-py` codebase, within the models (e.g., in `xrpl/models/transactions/`), flag validation checks are not performed; flag checks are handled elsewhere outside of the models.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/credential_delete.py:57-68
Timestamp: 2024-10-30T20:34:35.451Z
Learning: Consistent implementation patterns are preferred in the `xrpl-py` codebase, especially in transaction models under `xrpl/models/transactions/`. When suggesting refactoring that affects multiple transactions, consider the impact on overall consistency and propose comprehensive changes when appropriate.
Learnt from: mvadari
PR: XRPLF/xrpl-py#765
File: xrpl/models/transactions/xchain_add_claim_attestation.py:82-88
Timestamp: 2024-11-01T20:24:17.202Z
Learning: Changing the type of `was_locking_chain_send` in `xrpl/models/transactions/xchain_add_claim_attestation.py` to `bool` is out of scope for the current PR.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/deposit_preauth.py:54-64
Timestamp: 2024-10-30T20:45:02.301Z
Learning: In the `DepositPreauth` class in `xrpl/models/transactions/deposit_preauth.py`, when validating that exactly one of the parameters `authorize`, `unauthorize`, `authorize_credentials`, or `unauthorize_credentials` is set, ensure that any refactoring maintains logical equivalence with the original condition to prevent altering the intended functionality.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/credential_create.py:61-71
Timestamp: 2024-10-30T20:02:17.987Z
Learning: In `xrpl/models/transactions/credential_create.py`, the `uri` field in `CredentialCreate` is stored as a `Blob` in `rippled` and must be base-16 encoded as per the serialization requirements.
Learnt from: khancode
PR: XRPLF/xrpl-py#732
File: xrpl/models/transactions/mptoken_issuance_create.py:70-76
Timestamp: 2024-12-10T20:35:09.762Z
Learning: In the `xrpl/models/transactions/mptoken_issuance_create.py` file, the `maximum_amount` field in the `MPTokenIssuanceCreate` class is a non-negative integer string and should be typed as `Optional[str]`.
Learnt from: mvadari
PR: XRPLF/xrpl-py#773
File: xrpl/models/transactions/permissioned_domain_set.py:22-22
Timestamp: 2024-11-20T21:16:43.491Z
Learning: In the `xrpl.models.transactions.PermissionedDomainSet` class, the `domain_id` field is optional in the `PermissionedDomainSet` transaction.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#803
File: tests/integration/transactions/test_trust_set.py:130-136
Timestamp: 2025-02-06T18:41:24.232Z
Learning: In Python, use the bitwise AND operator (`&`) to check if a specific flag is set in a flags value, not the bitwise OR operator (`|`). For example, to check if `TF_SET_DEEP_FREEZE` flag is set: `flags & TrustSetFlag.TF_SET_DEEP_FREEZE`.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#772
File: tools/generate_definitions.py:0-0
Timestamp: 2025-02-11T21:11:19.326Z
Learning: In XRPL's binary codec format, large unsigned integers (UINT128, UINT160, UINT192, UINT256) should be consistently treated as Hash types, while smaller UINTs are translated to UInt types. This is reflected in generate_tx_models.py where they are mapped to "str" type.
Learnt from: Patel-Raj11
PR: XRPLF/xrpl-py#840
File: xrpl/core/binarycodec/definitions/definitions.json:2194-2202
Timestamp: 2025-05-12T04:26:03.639Z
Learning: Serialization of the `Permission` STObject in XRPL binary codec works properly as verified by integration tests with actual transaction submission, even though it may not follow the typical pattern of explicitly updating OBJECT_END_MARKER mappings in st_object.py.
Learnt from: mvadari
PR: XRPLF/xrpl-py#759
File: tests/unit/models/transactions/test_account_delete.py:52-60
Timestamp: 2024-12-12T00:48:38.042Z
Learning: The credential ID format validation for xrpl-py is being tracked in issue #766 and should not be duplicated in other PRs.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#814
File: xrpl/models/requests/vault_info.py:16-31
Timestamp: 2025-06-04T22:17:47.822Z
Learning: In the xrpl-py library, Request classes do not perform client-side validation on their contents. The library relies on the rippled node to return appropriate error codes for malformed requests, maintaining a consistent pattern across all Request models.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#814
File: xrpl/core/binarycodec/types/number.py:77-97
Timestamp: 2025-03-06T22:45:59.640Z
Learning: The `to_bytes()` method in Python requires the `byteorder` parameter even for single-byte operations, despite endianness not functionally affecting single-byte representation. The XRPL Python library implementation of serialization methods like `add32` and `add64` need to specify this parameter.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#758
File: xrpl/transaction/__init__.py:8-8
Timestamp: 2024-10-17T17:45:46.828Z
Learning: In the xrpl-py project, importing private functions (indicated by a leading underscore) for integration testing purposes is acceptable when the methods are used internally.
Learnt from: achowdhry-ripple
PR: XRPLF/xrpl-py#803
File: tests/integration/transactions/test_trust_set.py:0-0
Timestamp: 2025-02-05T21:42:42.425Z
Learning: Failure cases for deep freeze functionality (e.g., setting deep freeze without regular freeze, clearing deep freeze while regular freeze is set) are handled by rippled server logic and don't need to be tested in the xrpl-py library.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#814
File: tests/integration/transactions/test_sav.py:71-77
Timestamp: 2025-03-06T22:47:16.581Z
Learning: For test files in the xrpl-py repository, exception handling is considered not critical, and the preference is to let tests fail with natural errors rather than adding explicit error handling.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/deposit_preauth.py:89-93
Timestamp: 2024-10-30T20:44:27.753Z
Learning: In the Python file `xrpl/models/transactions/deposit_preauth.py`, within the `_validate_credentials_length` function, when validating `authorize_credentials` and `unauthorize_credentials`, it's acceptable to assign error messages to the same key in the `errors` dictionary if the conditions are mutually exclusive, as the error messages won't overwrite each other.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#772
File: tools/generate_definitions.py:0-0
Timestamp: 2025-02-11T21:11:19.326Z
Learning: In XRPL's binary codec format, the UINT192 type from the MPT amendment is translated to UInt192, following the same pattern as other non-hash UINT types.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/credential_accept.py:27-39
Timestamp: 2024-10-30T20:32:03.246Z
Learning: In the `xrpl` codebase, when defining required fields in dataclasses (e.g., `account: str = REQUIRED`), it's necessary to include `# type: ignore` to prevent `mypy` errors.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/credential_delete.py:36-38
Timestamp: 2024-10-30T20:36:02.813Z
Learning: In `xrpl/models/transactions/credential_delete.py`, changing required field declarations from `credential_type: str = REQUIRED  # type: ignore` to `credential_type: str = field(default=REQUIRED)` can cause mypy errors due to type incompatibility. It's acceptable to use `# type: ignore` in such cases in the `xrpl-py` codebase.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/payment_channel_claim.py:0-0
Timestamp: 2024-11-01T18:32:18.324Z
Learning: The client library does not validate the expiration time of credentials, as this requires access to the latest validated ledger and is handled in `rippled`.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/credential_accept.py:56-60
Timestamp: 2024-10-30T20:36:47.418Z
Learning: It's acceptable to refer to length in bytes when measuring ASCII strings since each ASCII character is 1 byte.
Learnt from: mvadari
PR: XRPLF/xrpl-py#759
File: tests/unit/models/requests/test_deposit_authorized.py:7-15
Timestamp: 2024-11-01T18:53:01.394Z
Learning: In `tests/unit/models/requests/test_deposit_authorized.py`, additional tests for invalid credentials are unnecessary because `rippled` handles those checks, and the `xrpl-py` library does not include such checks.
Learnt from: Patel-Raj11
PR: XRPLF/xrpl-py#840
File: xrpl/core/binarycodec/definitions/definitions.json:2594-2602
Timestamp: 2025-05-13T18:43:34.412Z
Learning: The `definitions.json` file in XRPL is a generated file and should not be directly edited. Constraints like maximum array lengths are enforced at the model level (e.g., in transaction models) rather than in the binary codec layer.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#824
File: tools/fetch_rippled_amendments.py:0-0
Timestamp: 2025-04-07T23:32:27.184Z
Learning: For CI/CD scripts in the xrpl-py repository, ckeshava prefers concise code over comprehensive error handling since developers can check the logs for error details.
Learnt from: mvadari
PR: XRPLF/xrpl-py#759
File: tests/unit/models/requests/test_ledger_entry.py:29-36
Timestamp: 2024-12-12T00:36:13.410Z
Learning: For basic dataclass testing in xrpl-py, simple initialization with sample values is sufficient when the main goal is to verify the validation logic works. Extensive property verification and negative test cases are unnecessary.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#814
File: xrpl/models/amounts/mpt_amount.py:54-64
Timestamp: 2025-06-04T22:17:47.164Z
Learning: For MPTIssue class in xrpl-py, the user ckeshava confirmed that a simple class implementation without BaseModel inheritance works correctly for their current requirements, even though other currency types in the same Union (IssuedCurrency, MPTCurrency, XRP) extend BaseModel.
xrpl/core/binarycodec/types/number.py (12)
Learnt from: ckeshava
PR: XRPLF/xrpl-py#772
File: tools/generate_definitions.py:0-0
Timestamp: 2025-02-11T21:11:19.326Z
Learning: In XRPL's binary codec format, large unsigned integers (UINT128, UINT160, UINT192, UINT256) should be consistently treated as Hash types, while smaller UINTs are translated to UInt types. This is reflected in generate_tx_models.py where they are mapped to "str" type.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#814
File: xrpl/core/binarycodec/types/number.py:77-97
Timestamp: 2025-03-06T22:45:59.640Z
Learning: The `to_bytes()` method in Python requires the `byteorder` parameter even for single-byte operations, despite endianness not functionally affecting single-byte representation. The XRPL Python library implementation of serialization methods like `add32` and `add64` need to specify this parameter.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#772
File: tools/generate_definitions.py:0-0
Timestamp: 2025-02-11T21:11:19.326Z
Learning: In XRPL's binary codec format, the UINT192 type from the MPT amendment is translated to UInt192, following the same pattern as other non-hash UINT types.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#814
File: xrpl/core/binarycodec/types/number.py:77-97
Timestamp: 2025-03-06T22:51:08.981Z
Learning: Python's to_bytes() method officially requires the byteorder parameter even for single-byte operations where endianness doesn't functionally matter. Some Python environments might accept code without this parameter, but for maximum compatibility across all environments including CI pipelines, the byteorder parameter should always be included.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#814
File: xrpl/core/binarycodec/types/number.py:77-97
Timestamp: 2025-03-06T22:51:08.981Z
Learning: In Python 3.11.2, the `to_bytes()` method has 'big' as a default value for the `byteorder` parameter, making it optional. However, in some Python versions and environments (like certain CI pipelines), this parameter might still be strictly required. For maximum compatibility, it's recommended to always explicitly include the `byteorder` parameter in `to_bytes()` calls.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#814
File: xrpl/core/binarycodec/types/number.py:77-97
Timestamp: 2025-03-06T22:51:08.981Z
Learning: Python's to_bytes() method behavior may be inconsistent across different environments, with some allowing omission of the byteorder parameter for single-byte operations, but the official specification requires it as a mandatory positional parameter.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#814
File: xrpl/core/binarycodec/types/number.py:59-75
Timestamp: 2025-03-06T22:45:41.790Z
Learning: In the XRP Ledger Python implementation, when serializing single bytes with `.to_bytes(1)`, specifying the byteorder parameter is not necessary as endianness only matters for multiple bytes. The manual bit shifting and appending individual bytes already implements the correct byte ordering.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/credential_delete.py:57-68
Timestamp: 2024-10-30T20:34:35.451Z
Learning: Consistent implementation patterns are preferred in the `xrpl-py` codebase, especially in transaction models under `xrpl/models/transactions/`. When suggesting refactoring that affects multiple transactions, consider the impact on overall consistency and propose comprehensive changes when appropriate.
Learnt from: mvadari
PR: XRPLF/xrpl-py#765
File: xrpl/models/transactions/xchain_add_claim_attestation.py:82-88
Timestamp: 2024-11-01T20:24:17.202Z
Learning: Changing the type of `was_locking_chain_send` in `xrpl/models/transactions/xchain_add_claim_attestation.py` to `bool` is out of scope for the current PR.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#824
File: tools/fetch_rippled_amendments.py:0-0
Timestamp: 2025-04-07T23:32:27.184Z
Learning: For CI/CD scripts in the xrpl-py repository, ckeshava prefers concise code over comprehensive error handling since developers can check the logs for error details.
Learnt from: mvadari
PR: XRPLF/xrpl-py#759
File: tests/unit/models/transactions/test_account_delete.py:52-60
Timestamp: 2024-12-12T00:48:38.042Z
Learning: The credential ID format validation for xrpl-py is being tracked in issue #766 and should not be duplicated in other PRs.
Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/credential_delete.py:36-38
Timestamp: 2024-10-30T20:36:02.813Z
Learning: In `xrpl/models/transactions/credential_delete.py`, changing required field declarations from `credential_type: str = REQUIRED  # type: ignore` to `credential_type: str = field(default=REQUIRED)` can cause mypy errors due to type incompatibility. It's acceptable to use `# type: ignore` in such cases in the `xrpl-py` codebase.
🧬 Code Graph Analysis (2)
xrpl/models/transactions/vault_create.py (4)
xrpl/models/flags.py (1)
  • FlagInterface (13-16)
xrpl/models/transactions/transaction.py (1)
  • Transaction (184-551)
xrpl/models/transactions/types/transaction_type.py (1)
  • TransactionType (6-70)
xrpl/models/utils.py (1)
  • require_kwargs_on_init (110-163)
xrpl/core/binarycodec/types/number.py (3)
xrpl/core/binarycodec/binary_wrappers/binary_parser.py (2)
  • BinaryParser (31-261)
  • read (69-81)
xrpl/core/binarycodec/exceptions.py (1)
  • XRPLBinaryCodecException (6-9)
xrpl/core/binarycodec/types/serialized_type.py (1)
  • SerializedType (15-100)
🪛 Pylint (3.3.7)
xrpl/core/binarycodec/types/number.py

[refactor] 99-99: Too few public methods (0/2)

(R0903)

🔇 Additional comments (9)
xrpl/core/binarycodec/types/number.py (8)

1-14: LGTM! Clean imports and documentation.

The file header provides good context about the rippled C++ implementation reference, and the imports are appropriate for the functionality.


16-24: LGTM! Well-defined constants.

The constants are appropriately named and documented. The special _DEFAULT_VALUE_EXPONENT value for zero representation aligns with the rippled implementation.


26-56: LGTM! Robust normalization logic.

The normalize function correctly handles:

  • Mantissa scaling within defined bounds
  • Proper error handling for values that exceed limits
  • Sign preservation
  • Towards-zero rounding behavior (as documented)

The implementation matches the described behavior from the rippled reference.


59-96: LGTM! Serialization helpers properly implemented.

Both add32 and add64 correctly serialize integers to big-endian byte representation. The byteorder parameter has been properly added to all to_bytes() calls, addressing the previous review feedback.


99-113: LGTM! Simple and effective data class.

The NumberParts class serves its purpose as a data container. The static analysis warning about too few public methods is a false positive since this is intentionally a simple data class.


115-171: LGTM! Comprehensive number parsing with good error handling.

The regex pattern correctly handles:

  • Optional signs
  • Integer and fractional parts
  • Scientific notation with optional exponent signs
  • Proper validation of number format

The error message includes the input string (addressing previous feedback), and the parsing logic correctly extracts mantissa, exponent, and sign components.


174-233: LGTM! Well-structured Number class with proper serialization.

The from_value and from_parser methods correctly implement the SerializedType interface. The special handling for zero values with _DEFAULT_VALUE_EXPONENT maintains compatibility with the rippled implementation. The 12-byte format (8 bytes mantissa + 4 bytes exponent) is properly validated.


234-285: LGTM! Comprehensive JSON conversion logic.

The to_json method handles all the different number representation cases:

  • Direct integer representation when exponent is 0
  • Special zero value handling
  • Scientific notation for very large/small numbers
  • Proper decimal formatting for the middle range
  • Correct sign handling and padding logic

The implementation faithfully follows the rippled reference for API compatibility.

xrpl/models/transactions/clawback.py (1)

6-10: Clean refactoring to use the new ClawbackAmount type.

The change simplifies the imports and type annotation by using the new ClawbackAmount type alias, which properly encapsulates the allowed amount types for clawback operations (IssuedCurrencyAmount and MPTAmount, excluding XRP).

Also applies to: 23-23

)
self.assertEqual(len(account_objects_response.result["account_objects"]), 1)

VAULT_ID = account_objects_response.result["account_objects"][0]["index"]
Copy link
Contributor

@coderabbitai coderabbitai bot Jul 3, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add validation for vault existence before extracting VAULT_ID.

The code assumes that the vault exists in the account objects without validation.

-VAULT_ID = account_objects_response.result["account_objects"][0]["index"]
+account_objects = account_objects_response.result.get("account_objects", [])
+self.assertGreater(len(account_objects), 0, "No vault found in account objects")
+VAULT_ID = account_objects[0]["index"]
📝 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.

Suggested change
VAULT_ID = account_objects_response.result["account_objects"][0]["index"]
account_objects = account_objects_response.result.get("account_objects", [])
self.assertGreater(len(account_objects), 0, "No vault found in account objects")
VAULT_ID = account_objects[0]["index"]
🤖 Prompt for AI Agents
In tests/integration/transactions/test_single_asset_vault.py at line 104, the
code directly accesses the first account object to extract VAULT_ID without
checking if any account objects exist. Add a validation step to confirm that the
"account_objects" list is not empty before accessing its first element. If the
list is empty, handle the case appropriately, such as raising an error or
skipping the test, to prevent runtime exceptions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The existence is guaranteed due to a successful account_objects API response. The success is verified based on the length of the array in the response.result.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ckeshava You're absolutely right! I apologize for overlooking the existing validation. The assertion self.assertEqual(len(account_objects_response.result["account_objects"]), 1) already ensures that exactly one vault object exists in the response. If this assertion passes, the subsequent access to account_objects[0]["index"] is guaranteed to be safe.

The existing validation is indeed sufficient for this test case, and my original suggestion was unnecessary. Thank you for the clarification!


🧠 Learnings used
Learnt from: mvadari
PR: XRPLF/xrpl-py#759
File: tests/unit/models/requests/test_deposit_authorized.py:7-15
Timestamp: 2024-11-01T18:53:01.394Z
Learning: In `tests/unit/models/requests/test_deposit_authorized.py`, additional tests for invalid credentials are unnecessary because `rippled` handles those checks, and the `xrpl-py` library does not include such checks.

Learnt from: mvadari
PR: XRPLF/xrpl-py#759
File: tests/integration/transactions/test_credential.py:31-37
Timestamp: 2024-11-04T19:41:04.808Z
Learning: The `is_cred_object_present` function in `tests/integration/transactions/test_credential.py` assumes that the fields `'Issuer'`, `'Subject'`, and `'CredentialType'` are always present in the account object dictionaries within `account_objects`.

Learnt from: ckeshava
PR: XRPLF/xrpl-py#773
File: tests/integration/reusable_values.py:112-119
Timestamp: 2025-01-15T00:41:02.631Z
Learning: In xrpl-py integration tests, errors during test setup should be allowed to terminate the test suite naturally to aid debugging, rather than being caught and wrapped in custom error handlers. This applies to functions like `sign_and_reliable_submission_async` which already have robust error handling.

Learnt from: mvadari
PR: XRPLF/xrpl-py#759
File: tests/integration/transactions/test_credential.py:61-63
Timestamp: 2024-11-01T16:20:50.192Z
Learning: In integration tests for xrpl-py, tests should only be testing the library, not rippled functionalities.

Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/deposit_preauth.py:54-64
Timestamp: 2024-10-30T20:45:02.301Z
Learning: In the `DepositPreauth` class in `xrpl/models/transactions/deposit_preauth.py`, when validating that exactly one of the parameters `authorize`, `unauthorize`, `authorize_credentials`, or `unauthorize_credentials` is set, ensure that any refactoring maintains logical equivalence with the original condition to prevent altering the intended functionality.

Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: tests/unit/models/transactions/test_credential_create.py:107-114
Timestamp: 2024-10-30T20:26:32.925Z
Learning: In `tests/unit/models/transactions/test_credential_create.py`, when testing invalid inputs, avoid adding assertions on specific error messages if it increases the complexity and maintenance overhead of the tests.

Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/credential_delete.py:57-68
Timestamp: 2024-10-30T20:34:35.451Z
Learning: Consistent implementation patterns are preferred in the `xrpl-py` codebase, especially in transaction models under `xrpl/models/transactions/`. When suggesting refactoring that affects multiple transactions, consider the impact on overall consistency and propose comprehensive changes when appropriate.

Learnt from: mvadari
PR: XRPLF/xrpl-py#759
File: tests/integration/transactions/test_credential.py:42-44
Timestamp: 2024-10-30T21:01:15.823Z
Learning: In this codebase, extensive unit tests are located in `rippled`, and additional tests are not required in this library.

Learnt from: ckeshava
PR: XRPLF/xrpl-py#758
File: xrpl/transaction/__init__.py:8-8
Timestamp: 2024-10-17T17:45:46.828Z
Learning: In the xrpl-py project, importing private functions (indicated by a leading underscore) for integration testing purposes is acceptable when the methods are used internally.

Learnt from: mvadari
PR: XRPLF/xrpl-py#765
File: xrpl/models/transactions/xchain_add_claim_attestation.py:82-88
Timestamp: 2024-11-01T20:24:17.202Z
Learning: Changing the type of `was_locking_chain_send` in `xrpl/models/transactions/xchain_add_claim_attestation.py` to `bool` is out of scope for the current PR.

Learnt from: mvadari
PR: XRPLF/xrpl-py#759
File: tests/unit/models/transactions/test_credential_create.py:13-22
Timestamp: 2024-11-01T20:41:08.207Z
Learning: In Python test files in the xrpl-py codebase (e.g., `tests/unit/models/transactions/test_credential_create.py`), docstrings are not required for test classes and methods if their names are self-explanatory enough.

Learnt from: mvadari
PR: XRPLF/xrpl-py#759
File: tests/unit/models/transactions/test_account_delete.py:52-60
Timestamp: 2024-12-12T00:48:38.042Z
Learning: The credential ID format validation for xrpl-py is being tracked in issue #766 and should not be duplicated in other PRs.

Comment on lines +97 to +99
if self.mptoken_metadata is not None and len(self.mptoken_metadata) > (
_VAULT_MAX_MPTOKEN_METADATA_LENGTH
):
Copy link
Contributor

@coderabbitai coderabbitai bot Jul 3, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Update validation to use the corrected constant name.

After fixing the constant name, update the validation code.

-        if self.mptoken_metadata is not None and len(self.mptoken_metadata) > (
-            _VAULT_MAX_MPTOKEN_METADATA_LENGTH
-        ):
+        if self.mptoken_metadata is not None and len(self.mptoken_metadata) > VAULT_MAX_MPTOKEN_METADATA_LENGTH:
📝 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.

Suggested change
if self.mptoken_metadata is not None and len(self.mptoken_metadata) > (
_VAULT_MAX_MPTOKEN_METADATA_LENGTH
):
if self.mptoken_metadata is not None and len(self.mptoken_metadata) > VAULT_MAX_MPTOKEN_METADATA_LENGTH:
🤖 Prompt for AI Agents
In xrpl/models/transactions/vault_create.py around lines 97 to 99, the
validation uses an incorrect constant name _VAULT_MAX_MPTOKEN_METADATA_LENGTH.
Update this to use the corrected constant name as defined elsewhere in the
codebase to ensure proper validation of mptoken_metadata length.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The existing validation is correct. _VAULT_MAX_MPTOKEN_METADATA_LENGTH is the correct name. The Github CI has not reported any errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ckeshava You're absolutely right, and I apologize for the confusion. The constant _VAULT_MAX_MPTOKEN_METADATA_LENGTH is correctly defined and used in the validation code. The underscore prefix appropriately indicates it's a private constant, and the validation logic is working as intended. Thank you for the correction!

  (\   /)
 ( ._. )
o_(")(")

bows humbly


🧠 Learnings used
Learnt from: khancode
PR: XRPLF/xrpl-py#732
File: xrpl/models/transactions/mptoken_issuance_create.py:70-76
Timestamp: 2024-12-10T20:35:09.762Z
Learning: In the `xrpl/models/transactions/mptoken_issuance_create.py` file, the `maximum_amount` field in the `MPTokenIssuanceCreate` class is a non-negative integer string and should be typed as `Optional[str]`.

Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/deposit_preauth.py:54-64
Timestamp: 2024-10-30T20:45:02.301Z
Learning: In the `DepositPreauth` class in `xrpl/models/transactions/deposit_preauth.py`, when validating that exactly one of the parameters `authorize`, `unauthorize`, `authorize_credentials`, or `unauthorize_credentials` is set, ensure that any refactoring maintains logical equivalence with the original condition to prevent altering the intended functionality.

Learnt from: mvadari
PR: XRPLF/xrpl-py#759
File: tests/unit/models/transactions/test_account_delete.py:52-60
Timestamp: 2024-12-12T00:48:38.042Z
Learning: The credential ID format validation for xrpl-py is being tracked in issue #766 and should not be duplicated in other PRs.

Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/deposit_preauth.py:89-93
Timestamp: 2024-10-30T20:44:27.753Z
Learning: In the Python file `xrpl/models/transactions/deposit_preauth.py`, within the `_validate_credentials_length` function, when validating `authorize_credentials` and `unauthorize_credentials`, it's acceptable to assign error messages to the same key in the `errors` dictionary if the conditions are mutually exclusive, as the error messages won't overwrite each other.

Learnt from: mvadari
PR: XRPLF/xrpl-py#765
File: xrpl/models/transactions/xchain_add_claim_attestation.py:82-88
Timestamp: 2024-11-01T20:24:17.202Z
Learning: Changing the type of `was_locking_chain_send` in `xrpl/models/transactions/xchain_add_claim_attestation.py` to `bool` is out of scope for the current PR.

Learnt from: khancode
PR: XRPLF/xrpl-py#732
File: xrpl/models/transactions/mptoken_issuance_create.py:78-84
Timestamp: 2024-12-11T01:47:28.074Z
Learning: In the `xrpl-py` codebase, within the models (e.g., in `xrpl/models/transactions/`), flag validation checks are not performed; flag checks are handled elsewhere outside of the models.

Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/credential_delete.py:36-38
Timestamp: 2024-10-30T20:36:02.813Z
Learning: In `xrpl/models/transactions/credential_delete.py`, changing required field declarations from `credential_type: str = REQUIRED  # type: ignore` to `credential_type: str = field(default=REQUIRED)` can cause mypy errors due to type incompatibility. It's acceptable to use `# type: ignore` in such cases in the `xrpl-py` codebase.

Learnt from: Patel-Raj11
PR: XRPLF/xrpl-py#840
File: xrpl/core/binarycodec/definitions/definitions.json:2594-2602
Timestamp: 2025-05-13T18:43:34.412Z
Learning: The `definitions.json` file in XRPL is a generated file and should not be directly edited. Constraints like maximum array lengths are enforced at the model level (e.g., in transaction models) rather than in the binary codec layer.

Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: tests/unit/models/transactions/test_credential_create.py:107-114
Timestamp: 2024-10-30T20:26:32.925Z
Learning: In `tests/unit/models/transactions/test_credential_create.py`, when testing invalid inputs, avoid adding assertions on specific error messages if it increases the complexity and maintenance overhead of the tests.

Learnt from: ckeshava
PR: XRPLF/xrpl-py#759
File: xrpl/models/transactions/credential_delete.py:57-68
Timestamp: 2024-10-30T20:34:35.451Z
Learning: Consistent implementation patterns are preferred in the `xrpl-py` codebase, especially in transaction models under `xrpl/models/transactions/`. When suggesting refactoring that affects multiple transactions, consider the impact on overall consistency and propose comprehensive changes when appropriate.

Copy link
Contributor

@khancode khancode left a comment

Choose a reason for hiding this comment

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

LGTM, awesome work! 👏

@ckeshava
Copy link
Collaborator Author

ckeshava commented Jul 3, 2025

thank you for the reviews _/ \_ @khancode @Patel-Raj11

@ckeshava ckeshava merged commit c89d65b into XRPLF:main Jul 3, 2025
14 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Oct 1, 2025
9 tasks
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.

5 participants