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: parseTransactionFlags unintentionally modifies transaction #2825

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

Conversation

achowdhry-ripple
Copy link
Collaborator

@achowdhry-ripple achowdhry-ripple commented Nov 13, 2024

High Level Overview of Change

the parseTransactionFlags method unintentionally edited the Transaction object's flags when passed in as a parameter, because it used setTransactionFlagsToNumber inside. Instead, now it uses convertTxFlagsToNumber, which passes the numerical representation of flags back to the caller instead of automatically modifying the passed in object. This is clearer for a user, and avoids unexpected modification and reduces redundant need for both functions.

As cleanup, all uses of the setter were removed and moving forward we will be using the converter instead. The setter remains as a deprecated function for compatibility support since it is an exported function.

convertFlagsToNumber flags has been renamed to convertTxFlagsToNumber for clarity

Context of Change

Fix for #2823

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 HISTORY.md?

  • Yes
  • No, this change does not impact library users

Test Plan

Copy link

coderabbitai bot commented Nov 13, 2024

Walkthrough

The changes in this pull request involve significant updates to the Client class and transaction flag handling within the XRPL package. The setTransactionFlagsToNumber function has been deprecated and replaced with convertTxFlagsToNumber, which alters how transaction flags are processed. Error handling for connection management has been improved, particularly regarding disconnection scenarios. Additionally, the pagination logic now throws a NotFoundError if necessary markers are absent. The updates also include modifications to documentation and exports, enhancing clarity and functionality.

Changes

File Path Change Summary
packages/xrpl/src/client/index.ts - Replaced setTransactionFlagsToNumber with convertTxFlagsToNumber in the autofill method.
- Improved connection error handling for disconnections.
- Updated requestNextPage to throw NotFoundError for missing markers.
packages/xrpl/src/models/utils/flags.ts - Deprecated setTransactionFlagsToNumber, now using convertTxFlagsToNumber for setting tx.Flags.
- Enhanced convertTxFlagsToNumber to validate flags and return numeric representations.
- Updated parseTransactionFlags.
packages/xrpl/HISTORY.md - Renamed "Unreleased Changes" to "Unreleased".
- Added convertTxFlagsToNumber and noted deprecation of setTransactionFlagsToNumber in the changelog.
packages/xrpl/src/models/index.ts - Reintroduced setTransactionFlagsToNumber in exports and added convertTxFlagsToNumber.
packages/xrpl/src/models/transactions/transaction.ts - Updated import to use convertTxFlagsToNumber instead of setTransactionFlagsToNumber in the validate function.
packages/xrpl/test/models/utils.test.ts - Added tests for isFlagEnabled, setTransactionFlagsToNumber, parseAccountRootFlags, and parseTransactionFlags to validate their functionality and ensure correctness across various scenarios.

Possibly related issues

  • parseTransactionFlags unintentionally mutates Transaction object #2823: This issue addresses the unintended mutation of the Transaction object by parseTransactionFlags. The changes in this PR, particularly the deprecation of setTransactionFlagsToNumber and the introduction of convertTxFlagsToNumber, directly respond to this concern by eliminating the side effect.

Possibly related PRs

  • fix: make transaction-generating scripts more robust #2690: The changes in this PR involve the transaction.ts file, which is directly related to the handling of transaction flags, similar to the modifications made in the main PR regarding the convertTxFlagsToNumber function.
  • update Paths snippet test #2765: Although this PR focuses on testing paths, it involves transaction-related functionality, which may indirectly relate to the changes in transaction flag handling in the main PR.
  • remove bridge snippet test, the sidechain has been shut down #2773: This PR does not directly relate to the main PR's changes but involves the removal of outdated tests that could have included transaction-related functionality, indicating a broader context of transaction handling in the codebase.

Suggested reviewers

  • khancode
  • justinr1234

Poem

In the fields where flags do sway,
A rabbit hops, brightening the day.
With numbers clear, we dance and play,
No more mutations, come what may!
So here’s to changes, fresh and bright,
In the XRPL, all feels right! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

warning eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/config-array@0.13.0: Use @eslint/config-array instead
warning eslint > @humanwhocodes/config-array > @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning jest > jest-cli > jest-config > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-runtime > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/reporters > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/transform > babel-plugin-istanbul > test-exclude > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning lerna > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/exec@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/cli@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/cli > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/diff@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/diff > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/info@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/add@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/init@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/run@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/link@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/list@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/clean@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/import@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > npmlog > gauge@2.7.4: This package is no longer supported.
warning lerna > @lerna/bootstrap@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/add > @lerna/bootstrap@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/bootstrap > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/version@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/version > npmlog@4.1.2: This package is no longer supported.
warning lerna > npmlog > are-we-there-yet@1.1.7: This package is no longer supported.
warning lerna > @lerna/publish@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/version@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/changed@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/exec > @lerna/command@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/diff > @lerna/command@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/info > @lerna/command@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/add > @lerna/command@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/init > @lerna/command@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/run > @lerna/command@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/link > @lerna/command@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/list > @lerna/command@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/clean > @lerna/command@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/import > @lerna/command@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/create > @lerna/command@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/bootstrap > @lerna/command@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/version > @lerna/command@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/command@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/changed > @lerna/command@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/exec > @lerna/command > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/exec > @lerna/run-topologically@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/run > @lerna/run-topologically@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/bootstrap > @lerna/run-topologically@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/version > @lerna/run-topologically@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/run-topologically@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/exec > @lerna/filter-options@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/add > @lerna/filter-options@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/run > @lerna/filter-options@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/list > @lerna/filter-options@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/clean > @lerna/filter-options@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/bootstrap > @lerna/filter-options@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/exec > @lerna/filter-options > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/exec > @lerna/profiler@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/run > @lerna/profiler@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/exec > @lerna/profiler > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/exec > @lerna/validation-error@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/diff > @lerna/validation-error@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/add > @lerna/validation-error@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/run > @lerna/validation-error@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/import > @lerna/validation-error@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/create > @lerna/validation-error@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/bootstrap > @lerna/validation-error@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/version > @lerna/validation-error@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/validation-error@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/exec > @lerna/command > @lerna/validation-error@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/exec > @lerna/validation-error > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/cli > @lerna/global-options@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/info > @lerna/output@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/run > @lerna/output@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/list > @lerna/output@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/version > @lerna/output@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/output@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/changed > @lerna/output@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/info > @lerna/output > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/add > @lerna/npm-conf@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/create > @lerna/npm-conf@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/npm-conf@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/add > pacote > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
warning lerna > @lerna/run > @lerna/timer@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/run > @lerna/npm-run-script@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/run > @lerna/npm-run-script > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/link > @lerna/package-graph@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/bootstrap > @lerna/package-graph@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/exec > @lerna/command > @lerna/package-graph@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/link > @lerna/package-graph > @lerna/validation-error@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/link > @lerna/package-graph > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/link > @lerna/symlink-dependencies@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/bootstrap > @lerna/symlink-dependencies@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/clean > @lerna/prompt@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/import > @lerna/prompt@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/version > @lerna/prompt@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/prompt@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/clean > @lerna/prompt > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/list > @lerna/listable@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/changed > @lerna/listable@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/clean > @lerna/pulse-till-done@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/import > @lerna/pulse-till-done@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/bootstrap > @lerna/pulse-till-done@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/pulse-till-done@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/clean > @lerna/pulse-till-done > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/clean > @lerna/rimraf-dir@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/bootstrap > @lerna/rimraf-dir@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/clean > @lerna/rimraf-dir > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/clean > @lerna/rimraf-dir > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
warning lerna > @lerna/bootstrap > @lerna/has-npm-version@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/bootstrap > @lerna/npm-install@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/bootstrap > @lerna/npm-install > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/bootstrap > @lerna/run-lifecycle@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/version > @lerna/run-lifecycle@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/run-lifecycle@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/bootstrap > @lerna/run-lifecycle > @lerna/npm-conf@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/bootstrap > @lerna/run-lifecycle > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/bootstrap > read-package-tree@5.3.1: The functionality that this package provided is now in @npmcli/arborist
warning lerna > @lerna/bootstrap > @lerna/symlink-binary@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/link > @lerna/symlink-dependencies > @lerna/symlink-binary@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/version > @lerna/collect-updates@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/collect-updates@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/changed > @lerna/collect-updates@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/exec > @lerna/filter-options > @lerna/collect-updates@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/version > @lerna/collect-updates > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/version > @lerna/check-working-tree@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/check-working-tree@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/version > @lerna/check-working-tree > @lerna/validation-error@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/version > @lerna/conventional-commits@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/version > @lerna/conventional-commits > @lerna/validation-error@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/version > @lerna/conventional-commits > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/version > @lerna/github-client@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/version > @lerna/github-client > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/version > @lerna/prerelease-id-from-version@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/prerelease-id-from-version@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/link > @lerna/package-graph > @lerna/prerelease-id-from-version@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/describe-ref@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/version > @lerna/collect-updates > @lerna/describe-ref@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/version > @lerna/check-working-tree > @lerna/describe-ref@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/describe-ref > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/version > @lerna/gitlab-client@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/version > @lerna/gitlab-client > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/publish > @lerna/log-packed@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/log-packed > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/publish > @lerna/npm-publish@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/npm-publish > @lerna/run-lifecycle@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/npm-publish > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/publish > @lerna/pack-directory@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/pack-directory > @lerna/run-lifecycle@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/pack-directory > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/publish > @lerna/npm-dist-tag@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/npm-dist-tag > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/publish > @lerna/otplease@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/npm-publish > @lerna/otplease@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/npm-dist-tag > @lerna/otplease@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/otplease > @lerna/prompt@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/exec > @lerna/command > @lerna/write-log-file@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/exec > @lerna/command > @lerna/write-log-file > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/exec > @lerna/command > @lerna/project@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/exec > @lerna/command > @lerna/project > @lerna/validation-error@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/exec > @lerna/command > @lerna/project > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/exec > @lerna/run-topologically > @lerna/query-graph@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/list > @lerna/listable > @lerna/query-graph@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/exec > @lerna/run-topologically > @lerna/query-graph > @lerna/package-graph@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/exec > @lerna/filter-options > @lerna/filter-packages@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/exec > @lerna/filter-options > @lerna/filter-packages > @lerna/validation-error@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/exec > @lerna/filter-options > @lerna/filter-packages > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/add > pacote > cacache > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning lerna > @lerna/add > pacote > cacache > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
warning lerna > @lerna/add > pacote > npm-packlist > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning lerna > @lerna/run > @lerna/npm-run-script > @lerna/get-npm-exec-opts@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/bootstrap > @lerna/npm-install > @lerna/get-npm-exec-opts@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/run > @lerna/npm-run-script > @lerna/get-npm-exec-opts > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/link > @lerna/symlink-dependencies > @lerna/create-symlink@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/bootstrap > @lerna/symlink-binary > @lerna/create-symlink@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/link > @lerna/symlink-dependencies > @lerna/create-symlink > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/link > @lerna/symlink-dependencies > @lerna/resolve-symlink@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/link > @lerna/symlink-dependencies > @lerna/resolve-symlink > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/create > init-package-json > read-package-json@4.1.2: This package is no longer supported. Please use @npmcli/package-json instead.
warning lerna > @lerna/bootstrap > read-package-tree > read-package-json@2.1.2: This package is no longer supported. Please use @npmcli/package-json instead.
warning lerna > @lerna/publish > @lerna/npm-publish > read-package-json@3.0.1: This package is no longer supported. Please use @npmcli/package-json instead.
warning lerna > @lerna/create > init-package-json > read-package-json > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning lerna > @lerna/bootstrap > read-package-tree > read-package-json > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning lerna > @lerna/publish > @lerna/npm-publish > read-package-json > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning lerna > @lerna/bootstrap > read-package-tree > readdir-scoped-modules@1.1.0: This functionality has been moved to @npmcli/fs
warning lerna > @lerna/bootstrap > @lerna/run-lifecycle > npm-lifecycle@3.1.5: The lifecycle script runner used in npm is now @npmcli/run-script. Please use that module moving forward
warning lerna > @lerna/bootstrap > @lerna/symlink-binary > @lerna/package@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/publish > @lerna/pack-directory > @lerna/package@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/exec > @lerna/command > @lerna/project > @lerna/package@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/version > @lerna/check-working-tree > @lerna/collect-uncommitted@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/version > @lerna/check-working-tree > @lerna/collect-uncommitted > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/version > temp-write > uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
warning lerna > @lerna/publish > npm-registry-fetch > @npmcli/ci-detect@1.4.0: this package has been deprecated, use ci-info instead
warning lerna > @lerna/publish > @lerna/pack-directory > @lerna/get-packed@4.0.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/add > pacote > cacache > @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs
warning lerna > @lerna/add > pacote > cacache > @npmcli/move-file > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
warning lerna > @lerna/add > pacote > @npmcli/run-script > node-gyp > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning lerna > @lerna/add > pacote > @npmcli/run-script > node-gyp > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/add > pacote > @npmcli/run-script > node-gyp > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
warning lerna > @lerna/bootstrap > @lerna/run-lifecycle > npm-lifecycle > node-gyp > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning lerna > @lerna/bootstrap > @lerna/run-lifecycle > npm-lifecycle > node-gyp > npmlog@4.1.2: This package is no longer supported.
warning lerna > @lerna/bootstrap > @lerna/run-lifecycle > npm-lifecycle > node-gyp > rimraf@2.7.1: Rimraf versions prior to v4 are no longer supported
warning lerna > @lerna/bootstrap > @lerna/run-lifecycle > npm-lifecycle > node-gyp > rimraf > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning lerna > @lerna/bootstrap > read-package-tree > readdir-scoped-modules > debuglog@1.0.1: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning lerna > @lerna/bootstrap > @lerna/run-lifecycle > npm-lifecycle > uid-number@0.0.6: This package is no longer supported.
warning lerna > @lerna/version > @lerna/conventional-commits > conventional-changelog-angular > q@1.5.1: You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other.

(For a CapTP with native promises, see @endo/eventual-send and @endo/captp)
warning lerna > @lerna/version > @lerna/conventional-commits > conventional-changelog-core > q@1.5.1: You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other.

(For a CapTP with native promises, see @endo/eventual-send and @endo/captp)
warning lerna > @lerna/version > @lerna/conventional-commits > conventional-recommended-bump > q@1.5.1: You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other.

(For a CapTP with native promises, see @endo/eventual-send and @endo/captp)
warning lerna > @lerna/add > pacote > @npmcli/run-script > node-gyp > request@2.88.2: request has been deprecated, see request/request#3142
warning lerna > @lerna/bootstrap > @lerna/run-lifecycle > npm-lifecycle > node-gyp > request@2.88.2: request has been deprecated, see request/request#3142
warning lerna > @lerna/add > pacote > @npmcli/run-script > node-gyp > request > uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
warning lerna > @lerna/bootstrap > @lerna/run-lifecycle > npm-lifecycle > node-gyp > nopt > osenv@0.1.5: This package is no longer supported.
warning lerna > @lerna/add > pacote > @npmcli/run-script > node-gyp > request > har-validator@5.1.5: this library is no longer supported
warning workspace-aggregator-622ce38c-faff-4e12-9f19-fc3f47f1aa4b > eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options.
error eslint-plugin-jsdoc@39.9.1: The engine "node" is incompatible with this module. Expected version "^14 || ^16 || ^17 || ^18 || ^19". Got "22.9.0"
error Found incompatible module.


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.


// eslint-disable-next-line @typescript-eslint/no-explicit-any -- added ValidationError check for flagEnum
function convertFlagsToNumber(flags: GlobalFlags, flagEnum: any): number {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did convertFlagsToNumber need to change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My logic here was since it would now be exported as a public utility, we would need the checks that the setter used to have (checking if txToFlag[tx.TransactionType] exists, making sure flags exists). Also seemed simpler as a helper function if all the user had to do was pass in the transaction object like before, instead of having to always pass in tx.Flags now

Copy link
Collaborator

@mvadari mvadari left a comment

Choose a reason for hiding this comment

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

Please update the changelog.

@achowdhry-ripple achowdhry-ripple marked this pull request as draft November 13, 2024 18:24
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/src/models/utils/flags.ts (2)

75-79: Enhance error message for invalid flags.

The error message could be more helpful by including the transaction type and the actual flag value.

-          `flag ${flag} doesn't exist in flagEnum: ${JSON.stringify(flagEnum)}`,
+          `Invalid flag '${flag}' for transaction type '${tx.TransactionType}'. Valid flags are: ${Object.keys(flagEnum).join(", ")}`,

95-114: Consider improving type safety and documentation.

The function implementation looks good but could benefit from improved type safety and documentation updates:

  1. Update the JSDoc to reflect that the function now uses convertTxFlagsToNumber:
/**
 * Convert a Transaction flags property into a map for easy interpretation.
 *
+ * This function first converts the transaction's flags to their numeric representation
+ * using convertTxFlagsToNumber, then maps them to boolean values.
 *
 * @param tx - A transaction to parse flags for.
- * @returns A map with all flags as booleans.
+ * @returns An object mapping flag names to boolean values, or an empty object if no flags are set.
 */
  1. Add type safety for the flag map:
-  const booleanFlagMap = {}
+  const booleanFlagMap: Record<string, boolean> = {}

-  const transactionTypeFlags = txToFlag[tx.TransactionType]
+  const transactionTypeFlags = txToFlag[tx.TransactionType as keyof typeof txToFlag]
+  if (!transactionTypeFlags) {
+    return {}
+  }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 92eb809 and 95f46ce.

📒 Files selected for processing (2)
  • packages/xrpl/src/client/index.ts (2 hunks)
  • packages/xrpl/src/models/utils/flags.ts (2 hunks)
🔇 Additional comments (3)
packages/xrpl/src/models/utils/flags.ts (1)

64-85: LGTM! Successfully fixes the mutation issue.

The refactoring from setTransactionFlagsToNumber to convertTxFlagsToNumber correctly addresses the unintended mutation of the transaction object by returning a new value instead of modifying the input. This aligns with functional programming principles and fixes the issue described in PR #2823.

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

50-50: LGTM: Import change aligns with the fix.

The import change from setTransactionFlagsToNumber to convertTxFlagsToNumber reflects the intended behavior of converting flags without modifying the transaction object.


668-668: LGTM: Flag conversion change fixes the modification issue.

The change from setTransactionFlagsToNumber to convertTxFlagsToNumber ensures that transaction flags are converted without modifying the original transaction object, fixing the issue described in PR #2823.

Let's verify the transaction submission flow still works:

✅ Verification successful

Based on the extensive test results, I can now generate a final response. The tests show that the flag conversion is well-tested and the change from setTransactionFlagsToNumber to convertTxFlagsToNumber maintains the expected behavior while fixing the modification issue.

LGTM: Flag conversion change is safe and well-tested

The change to use convertTxFlagsToNumber is verified to be safe through extensive test coverage:

  • Multiple transaction types test flag conversion (Payment, OfferCreate, TrustSet, etc.)
  • Tests verify both numeric and boolean flag handling
  • Integration tests confirm transaction submission flow with flags
  • The function maintains the same behavior as the previous implementation but avoids modifying the original transaction
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any transaction submission tests or examples that might be affected

# Look for transaction submission tests
rg -A 5 "submit.*transaction" "**/*test*"

# Look for flag-related tests
rg -A 5 "transaction.*flags" "**/*test*"

# Look for examples using transaction flags
rg -A 5 "Flags.*=.*" "**/*example*"

Length of output: 277


Script:

#!/bin/bash
# Let's try more specific paths and patterns

# Look for transaction submission tests
rg -A 5 "submit.*transaction" packages/xrpl/test/
rg -A 5 "submit.*tx" packages/xrpl/test/

# Look for flag-related tests
rg -A 5 "transaction.*flags" packages/xrpl/test/
rg -A 5 "tx.*flags" packages/xrpl/test/

# Look for examples using transaction flags
fd -t f example packages/xrpl/ -x rg -A 5 "Flags.*=.*" {}

# Check test files specifically related to flags or transactions
fd -t f "(flag|transaction|tx).*test" packages/xrpl/test/

Length of output: 16123


Script:

#!/bin/bash
# Let's check the implementation and tests of flag conversion functions

# Look for flag conversion function implementations
ast-grep --pattern 'function convertTxFlagsToNumber($$$)'

# Check for flag-related tests specifically
rg -A 5 "convertTxFlagsToNumber" packages/xrpl/test/

# Look for any test files that might test flag conversion
fd -t f "flags.*test" packages/xrpl/test/

Length of output: 156


Script:

#!/bin/bash
# Let's try a broader search for flag conversion and tests

# Look for flag conversion implementations with different patterns
rg -A 10 "convertTxFlagsToNumber" packages/xrpl/src/
rg -A 10 "function.*Flags" packages/xrpl/src/

# Check for flag-related tests in models
rg -A 5 "flags" packages/xrpl/test/models/
rg -A 5 "Flags" packages/xrpl/test/models/

# Look for transaction flag tests
rg -A 5 "test.*flags" packages/xrpl/test/

Length of output: 58976

Comment on lines +69 to +70
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- safe member access
const flagEnum = txToFlag[tx.TransactionType]
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider improving type safety.

There are multiple eslint-disable comments for type safety. Consider adding type guards or assertions to handle these cases more safely:

-  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
-  const flagEnum = txToFlag[tx.TransactionType]
+  const flagEnum = txToFlag[tx.TransactionType as keyof typeof txToFlag]
+  if (!flagEnum) {
+    throw new ValidationError(
+      `Unsupported transaction type: ${tx.TransactionType}`
+    )
+  }

   if (flagEnum && tx.Flags) {
     return Object.keys(tx.Flags).reduce((resultFlags, flag) => {
-      // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
-      if (flagEnum[flag] == null) {
+      const flagValue = flagEnum[flag as keyof typeof flagEnum]
+      if (flagValue == null) {

Also applies to: 74-75, 81-82

Comment on lines +64 to +85
export function convertTxFlagsToNumber(tx: Transaction): number {
if (typeof tx.Flags === 'number') {
return
return tx.Flags
}

tx.Flags = txToFlag[tx.TransactionType]
? convertFlagsToNumber(tx.Flags, txToFlag[tx.TransactionType])
: 0
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- safe member access
const flagEnum = txToFlag[tx.TransactionType]

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- added ValidationError check for flagEnum
function convertFlagsToNumber(flags: GlobalFlags, flagEnum: any): number {
return Object.keys(flags).reduce((resultFlags, flag) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- safe member access
if (flagEnum[flag] == null) {
throw new ValidationError(
`flag ${flag} doesn't exist in flagEnum: ${JSON.stringify(flagEnum)}`,
)
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- safe member access
return flags[flag] ? resultFlags | flagEnum[flag] : resultFlags
}, 0)
if (flagEnum && tx.Flags) {
return Object.keys(tx.Flags).reduce((resultFlags, flag) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- safe member access
if (flagEnum[flag] == null) {
throw new ValidationError(
`flag ${flag} doesn't exist in flagEnum: ${JSON.stringify(flagEnum)}`,
)
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- safe member access
return tx.Flags?.[flag] ? resultFlags | flagEnum[flag] : resultFlags
}, 0)
}
return 0
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Update remaining references to setTransactionFlagsToNumber

The old function name setTransactionFlagsToNumber is still being used in several files:

  • packages/xrpl/src/models/index.ts
  • packages/xrpl/src/models/transactions/transaction.ts
  • packages/xrpl/test/models/utils.test.ts

The new function convertTxFlagsToNumber is correctly used in:

  • packages/xrpl/src/models/utils/flags.ts
  • packages/xrpl/src/client/index.ts
🔗 Analysis chain

Verify all usages of the renamed function.

The refactoring from setTransactionFlagsToNumber to convertTxFlagsToNumber looks good. Let's verify that all usages have been updated:

Also applies to: 95-114

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining uses of the old function name
rg "setTransactionFlagsToNumber" --type ts

# Search for all uses of the new function name to verify correct usage
rg "convertTxFlagsToNumber" --type ts -A 2

Length of output: 1774

@achowdhry-ripple
Copy link
Collaborator Author

Will push test changes once it is decided if/how to deprecate setTransactionFlagsToNumber

@achowdhry-ripple achowdhry-ripple marked this pull request as ready for review November 13, 2024 19:06
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 (7)
packages/xrpl/src/models/utils/flags.ts (3)

61-75: Enhance deprecation notice documentation.

Consider adding more details to help users migrate:

  • Add @since tag to indicate when it was deprecated
  • Add a link to migration guide if available
  • Consider adding an example of how to migrate to the new function
 /**
  * Sets a transaction's flags to its numeric representation.
  *
  * @deprecated
  * This utility function is deprecated.
  * Use convertTxFlagsToNumber() instead and use the returned value to modify the tx.Flags from the caller.
+ * @since 2.x.x
+ * @see https://xrpl.org/blog/migration-guide (if available)
+ * @example
+ * // Old way
+ * setTransactionFlagsToNumber(tx);
+ * // New way
+ * tx.Flags = convertTxFlagsToNumber(tx);
  *
  * @param tx - A transaction to set its flags to its numeric representation.
  */

95-98: Improve error message clarity.

The error message could be more descriptive to help users understand and fix the issue.

-          `flag ${flag} doesn't exist in flagEnum: ${JSON.stringify(flagEnum)}`,
+          `Invalid flag '${flag}' for transaction type '${tx.TransactionType}'. ` +
+          `Allowed flags are: ${Object.keys(flagEnum).join(', ')}`,

113-133: Consider using TypeScript generics for better type safety.

The function could be made more type-safe by using generics to specify the transaction type.

-export function parseTransactionFlags(tx: Transaction): object {
+export function parseTransactionFlags<T extends Transaction>(tx: T): Partial<Record<keyof typeof txToFlag[T['TransactionType']], boolean>> {
   const flags = convertTxFlagsToNumber(tx)
   if (flags === 0) {
     return {}
   }

-  const booleanFlagMap = {}
+  const booleanFlagMap: Partial<Record<keyof typeof txToFlag[T['TransactionType']], boolean>> = {}

   const transactionTypeFlags = txToFlag[tx.TransactionType]
   Object.values(transactionTypeFlags).forEach((flag) => {
     if (
       typeof flag === 'string' &&
       isFlagEnabled(flags, transactionTypeFlags[flag])
     ) {
       booleanFlagMap[flag] = true
     }
   })

   return booleanFlagMap
 }
packages/xrpl/test/models/utils.test.ts (3)

74-75: Test cases updated consistently, consider adding edge cases

All test cases have been properly updated to use convertTxFlagsToNumber. While the current test coverage is good, consider adding these edge cases:

  1. Test with undefined flags
  2. Test with null flags
  3. Test with empty transaction object

Example test case:

it('handles undefined flags gracefully', function () {
  const tx: OfferCreate = {
    Account: 'r3rhWeE31Jt5sWmi4QiGLMZnY3ENgqw96W',
    TransactionType: 'OfferCreate',
    // Flags intentionally omitted
  }
  const flagNum = convertTxFlagsToNumber(tx)
  assert.strictEqual(flagNum, 0)
})

Also applies to: 93-94, 113-114, 140-141, 151-152


Line range hint 234-236: Fix incorrect assertion in parseTransactionFlags tests

The tests for parseTransactionFlags are using assert.notStrictEqual, which is incorrect as it would pass even when the flags are equal. This should be assert.deepStrictEqual for object comparison.

Apply this fix:

-      assert.notStrictEqual(flagsMap, expected)
+      assert.deepStrictEqual(flagsMap, expected)

Also applies to: 257-259


Based on the gathered information, I can now provide the final response:

Test coverage missing for several transaction types with flags

The current test suite only covers flag conversion for:

  • OfferCreate
  • PaymentChannelClaim
  • Payment
  • TrustSet

However, the codebase defines flags for several other transaction types that lack test coverage:

  • AMMWithdraw
  • AMMDeposit
  • EnableAmendment
  • NFTokenCreateOffer
  • NFTokenMint
  • XChainModifyBridge
  • AccountSet (both AsfFlags and TfFlags)

These transaction types should have their flag conversion and parsing logic tested to ensure reliable behavior.

🔗 Analysis chain

Line range hint 1-276: Verify test coverage for all transaction types

Let's ensure we have test coverage for all transaction types that support flags.


Let me gather more specific information about the transaction types and their flag coverage.


Let me try a different approach to find the flag definitions and their test coverage.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if all transaction types with flags are covered in tests

# Search for all transaction types that have flags
echo "Searching for transaction types with flags..."
rg -l "Flags" --type ts | grep -v "test"

# Search for corresponding test coverage
echo "Checking test coverage..."
rg -l "TransactionType.*Flags" --type ts | grep "test"

Length of output: 2514


Script:

#!/bin/bash
# Check transaction types with flags and their test coverage

# Find all transaction types that define flags
echo "Transaction types with flag definitions:"
ast-grep --pattern 'export const enum $_Flags {
  $$$
}'

# Find flag usage in tests
echo -e "\nFlag testing in test files:"
rg "describe.*Flags" --type ts

Length of output: 349


Script:

#!/bin/bash

echo "Finding transaction flag definitions:"
rg "enum.*Flags" --type ts -A 5 --glob "!**/*.test.ts"

echo -e "\nFinding flag tests in test files:"
rg "sets.*Flags.*numeric" --type ts -B 1 -A 1

Length of output: 9297

packages/xrpl/HISTORY.md (1)

Line range hint 1-24: Consider adding SHA-256 checksums for browser builds

Previous releases included SHA-256 checksums for browser builds. Consider adding these for the latest changes to maintain consistency with historical releases.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 95f46ce and 951ba19.

📒 Files selected for processing (4)
  • packages/xrpl/HISTORY.md (1 hunks)
  • packages/xrpl/src/models/index.ts (1 hunks)
  • packages/xrpl/src/models/utils/flags.ts (2 hunks)
  • packages/xrpl/test/models/utils.test.ts (6 hunks)
🔇 Additional comments (4)
packages/xrpl/src/models/index.ts (1)

12-13: Consider adding JSDoc comments for the exported functions.

While the changes align with the PR objectives, adding JSDoc comments for both functions would help users understand:

  • That setTransactionFlagsToNumber is deprecated
  • Why they should use convertTxFlagsToNumber instead
  • The behavioral difference between the two functions (mutation vs. return)

Let's verify the deprecation warning implementation:

packages/xrpl/src/models/utils/flags.ts (1)

114-114: Changes successfully address the unintended modification issue.

The implementation now correctly uses convertTxFlagsToNumber without modifying the input transaction object, which aligns with the PR objectives.

packages/xrpl/test/models/utils.test.ts (1)

18-18: LGTM: Import statement updated correctly

The import statement has been properly updated to use the new convertTxFlagsToNumber function, aligning with the PR's objective.

packages/xrpl/HISTORY.md (1)

6-8: LGTM! The changes improve transaction flag handling

The changes look good and follow best practices:

  1. Fix prevents unintended mutation of transaction objects
  2. Clear deprecation notice for old function
  3. New utility function with clearer naming

* @param tx - A transaction to parse flags for
* @returns A numerical representation of a transaction's flags
*/
export function convertTxFlagsToNumber(tx: Transaction): number {
if (typeof tx.Flags === 'number') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

missing a null check

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is a check for nulls on line 91 before the conversion logic, do you mean a null check for the tx param as a whole?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe she's referring to the updated behavior of the setTransactionFlagsToNumber function.

In the existing code, if tx.Flags != null, then the tx object is not updated at all.
However, in your PR, the tx.Flags will be over-written with the output of the convertTxFlagsToNumber

Copy link
Collaborator Author

@achowdhry-ripple achowdhry-ripple Nov 13, 2024

Choose a reason for hiding this comment

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

I was under the impression that the numerical flag value 0 is equivalent to tx.Flags = null, which is what would be the result of the current code changes. Is representing a null tx.Flags value as null numerically what we would want instead? In that case I'd think we would want to throw an error here to show that it was a bad input, because if the user was expecting a number to be set then it could be misleading

@@ -71,8 +71,8 @@ describe('Models Utils', function () {
const { tfPassive, tfFillOrKill } = OfferCreateFlags
const expected: number = tfPassive | tfFillOrKill

setTransactionFlagsToNumber(tx)
assert.strictEqual(tx.Flags, expected)
const flagNum = convertTxFlagsToNumber(tx)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would leave the setTransactionFlagsToNumber in as well, until it gets removed. Just to ensure there's no other breaking changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Issue here is that the tests now fail because setTransactionFlagsToNumber was marked as deprecated. Is there a way to override this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@mvadari Why should we retain setTransactionFlagsToNumber inside a test file? How will that cause a breaking change?

@@ -3,6 +3,9 @@
Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xrpl-announce) for release announcements. We recommend that xrpl.js (ripple-lib) users stay up-to-date with the latest stable release.

## Unreleased Changes
* Fix for parseTransactionFlags to no longer modify a passed in transaction when returning a parsed mapping
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be under a heading that matches the actions - see https://keepachangelog.com/en/1.1.0/

parseAccountRootFlags,
setTransactionFlagsToNumber,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to remove this import of setTransactionFlagsToNumber ? That would ensure that packages/xrpl/src/models/* will always use the newer pure function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was intentionally left in since removing it would create a breaking change. To prevent this, I've added deprecated annotations that cause linting errors and a console warning to the method, and maybe it would be good to remove two releases from now (one so the community can see the deprecation warning and react, another to actually remove)

* @param tx - A transaction to parse flags for
* @returns A numerical representation of a transaction's flags
*/
export function convertTxFlagsToNumber(tx: Transaction): number {
if (typeof tx.Flags === 'number') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe she's referring to the updated behavior of the setTransactionFlagsToNumber function.

In the existing code, if tx.Flags != null, then the tx object is not updated at all.
However, in your PR, the tx.Flags will be over-written with the output of the convertTxFlagsToNumber

@khancode
Copy link
Collaborator

Looks like you'll need to ignore deprecation warnings like this:

xrpl: /home/runner/work/xrpl.js/xrpl.js/packages/xrpl/test/models/utils.test.ts
xrpl:    18:3  warning  Deprecated: This utility function is deprecated.
xrpl: Use convertTxFlagsToNumber() instead and use the returned value to modify the tx.Flags from the caller  import/no-deprecated``

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 (3)
packages/xrpl/test/models/utils.test.ts (3)

Line range hint 46-165: Fix assertion in parseTransactionFlags tests

The tests for parseTransactionFlags use assert.notStrictEqual for comparing objects, which might not work as intended. For object comparisons, consider using assert.deepEqual or assert.deepStrictEqual.

Apply this change to the assertions:

-      assert.notStrictEqual(flagsMap, expected)
+      assert.deepStrictEqual(flagsMap, expected)

Line range hint 167-214: Simplify complex assertion in parseAccountRootFlags test

The current assertion chain using multiple && operators could be simplified for better readability and maintenance.

Consider refactoring the assertion to use Object.entries:

-      assert.isTrue(
-        parsed.lsfDefaultRipple &&
-          parsed.lsfDepositAuth &&
-          parsed.lsfDisableMaster &&
-          parsed.lsfDisallowXRP &&
-          parsed.lsfGlobalFreeze &&
-          parsed.lsfNoFreeze &&
-          parsed.lsfPasswordSpent &&
-          parsed.lsfRequireAuth &&
-          parsed.lsfRequireDestTag &&
-          parsed.lsfDisallowIncomingNFTokenOffer &&
-          parsed.lsfDisallowIncomingCheck &&
-          parsed.lsfDisallowIncomingPayChan &&
-          parsed.lsfDisallowIncomingTrustline &&
-          parsed.lsfAllowTrustLineClawback,
-      )
+      Object.entries(parsed).forEach(([key, value]) => {
+        assert.isTrue(value, `Flag ${key} should be enabled`);
+      });

Line range hint 216-286: Fix inconsistencies in parseTransactionFlags tests

There are several issues in these tests:

  1. Test descriptions don't match the assertions (e.g., "all enabled" but only testing one flag)
  2. Using notStrictEqual instead of proper object comparison
  3. Missing test cases for other transaction types

Consider these improvements:

  1. Fix test descriptions:
-    it('parseTransactionFlags all enabled', function () {
+    it('parseTransactionFlags with tfRenew enabled', function () {
  1. Fix assertions:
-      assert.notStrictEqual(flagsMap, expected)
+      assert.deepStrictEqual(flagsMap, expected)
  1. Add test cases for other transaction types to match the coverage in setTransactionFlagsToNumber tests.

Would you like me to help generate additional test cases for other transaction types?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1a2d37f and 4b872ab.

📒 Files selected for processing (2)
  • packages/xrpl/src/models/utils/flags.ts (2 hunks)
  • packages/xrpl/test/models/utils.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/xrpl/src/models/utils/flags.ts
🔇 Additional comments (2)
packages/xrpl/test/models/utils.test.ts (2)

Line range hint 1-19: LGTM: Appropriate handling of deprecated function

The ESLint directive and comment clearly explain why the deprecated setTransactionFlagsToNumber is still being used in tests. This aligns with the discussion in previous reviews about maintaining backward compatibility.


Line range hint 28-44: LGTM: Comprehensive flag testing

The tests for isFlagEnabled are well-structured with:

  • Clear setup using beforeEach
  • Coverage of both enabled and disabled flag scenarios
  • Proper use of bitwise operations

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.

4 participants