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

Removed calls to deprecated utils function in tests #2845

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

Conversation

etienneoh
Copy link

@etienneoh etienneoh commented Dec 9, 2024

High Level Overview of Change

See #2698 .
Removed multiple calls to deprecated functions in the tests (convertStringToHex and convertHexToString) and replaced them with the new version (@xrplf/isomorphic/util's stringToHex and hexToString).
The deprecated functions where already just pointing to the new one.

Also updated the models/transactions/NFTokenMint.ts comments to point at the correct functions.

Context of Change

Simple refactor to follow best practices. The tests could be referenced by a user and he should always have the correct function used by default.

Type of Change

  • Refactor (non-breaking change that only restructures code)

Did you update HISTORY.md?

  • No, this change does not impact library users

Copy link

coderabbitai bot commented Dec 9, 2024

Caution

Review failed

The head commit changed during the review from 0b73dc2 to 6de1de4.

Walkthrough

The pull request introduces changes across multiple files to replace the convertStringToHex function with stringToHex from the @xrplf/isomorphic/utils package. This update affects the conversion of string representations to hexadecimal format in various contexts, including transaction fields and test cases. The overall logic and structure of the affected functions and tests remain unchanged, ensuring that the transition to the new utility function is seamless.

Changes

File Path Change Summary
packages/xrpl/snippets/src/multisigning.ts Updated Domain field to use stringToHex('example.com') instead of convertStringToHex.
packages/xrpl/src/models/transactions/NFTokenMint.ts Updated documentation for URI field to reference stringToHex instead of convertStringToHex.
packages/xrpl/test/integration/integration.test.ts Replaced convertStringToHex with stringToHex in the submit multisigned transaction test case.
packages/xrpl/test/integration/regularKey.test.ts Updated multiple test cases to use stringToHex for the Domain field.
packages/xrpl/test/integration/requests/submit.test.ts Updated Domain property to use stringToHex instead of convertStringToHex.
packages/xrpl/test/integration/requests/submitMultisigned.test.ts Changed the Domain field to use stringToHex in two test cases.
packages/xrpl/test/integration/requests/tx.test.ts Updated test cases to use stringToHex for Domain property.
packages/xrpl/test/integration/submitAndWait.test.ts Replaced convertStringToHex with stringToHex in multiple test cases.
packages/xrpl/test/integration/transactions/nftokenMint.test.ts Updated URI property to use stringToHex in the NFTokenMint test case.
packages/xrpl/test/models/NFTokenMint.test.ts Replaced convertStringToHex with stringToHex for URI field in multiple test cases.
packages/xrpl/test/utils/hexConversion.test.ts Updated function names from convertStringToHex to stringToHex and convertHexToString to hexToString.

Possibly related PRs

Suggested reviewers

  • mvadari
  • achowdhry-ripple
  • ckeshava
  • justinr1234
  • yinyiqian1

Poem

🐰 In the land of code where rabbits play,
We swapped our hex in a brand new way.
From convertStringToHex to stringToHex we cheer,
A hop in the logic, the path is now clear!
With every change, our code will sing,
A brighter future, let the hex strings ring! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @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.

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: 3

🧹 Outside diff range and nitpick comments (1)
packages/xrpl/test/utils/hexConversion.test.ts (1)

1-1: LGTM! Consider adding edge case tests.

The migration from deprecated utils to @xrplf/isomorphic/utils is correctly implemented. The test cases maintain proper coverage for both ASCII and Unicode strings.

Consider adding test cases for:

  • Empty strings
  • Strings with special characters
  • Very long strings
  • Invalid hex strings (for hexToString)

Also applies to: 7-7, 13-13, 23-23, 25-25

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e3188b8 and b363830.

📒 Files selected for processing (11)
  • packages/xrpl/snippets/src/multisigning.ts (2 hunks)
  • packages/xrpl/src/models/transactions/NFTokenMint.ts (1 hunks)
  • packages/xrpl/test/integration/integration.test.ts (2 hunks)
  • packages/xrpl/test/integration/regularKey.test.ts (5 hunks)
  • packages/xrpl/test/integration/requests/submit.test.ts (2 hunks)
  • packages/xrpl/test/integration/requests/submitMultisigned.test.ts (3 hunks)
  • packages/xrpl/test/integration/requests/tx.test.ts (3 hunks)
  • packages/xrpl/test/integration/submitAndWait.test.ts (5 hunks)
  • packages/xrpl/test/integration/transactions/nftokenMint.test.ts (2 hunks)
  • packages/xrpl/test/models/NFTokenMint.test.ts (4 hunks)
  • packages/xrpl/test/utils/hexConversion.test.ts (2 hunks)
🔇 Additional comments (12)
packages/xrpl/snippets/src/multisigning.ts (1)

1-1: LGTM! Import and usage correctly updated.

The migration to stringToHex from @xrplf/isomorphic/utils is properly implemented for the Domain field conversion.

Also applies to: 54-54

packages/xrpl/test/integration/transactions/nftokenMint.test.ts (1)

1-1: LGTM! Verify URI handling across NFT-related tests.

The migration to stringToHex is correctly implemented. Since URI handling is critical for NFT minting, let's verify consistency across related files.

Also applies to: 36-36

✅ Verification successful

Let me check the actual URI handling implementation in these files to verify consistency.


Let me try a different approach to check the URI handling implementation.


URI handling is consistent across NFT-related files

The verification shows that:

  • The model properly validates URI in hex format
  • Both model tests and integration tests consistently use stringToHex from @xrplf/isomorphic/utils for URI conversion
  • No deprecated conversion functions are used in NFT-related code
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check URI handling consistency across NFT-related files

# Search for URI-related hex conversions in NFT files
echo "Checking URI conversions in NFT-related files:"
rg -l "URI.*[Hh]ex.*" --type ts | grep -i "nft"

# Search for any remaining usage of deprecated conversion functions
echo -e "\nChecking for any remaining deprecated conversion calls:"
rg -i "convert(String|Hex)To(String|Hex)" --type ts

Length of output: 1019


Script:

#!/bin/bash
# Check URI handling implementation in NFT-related files
echo "NFTokenMint.ts implementation:"
ast-grep --pattern 'URI = $$$' packages/xrpl/src/models/transactions/NFTokenMint.ts

echo -e "\nNFTokenMint.test.ts model test:"
rg -A 5 "URI.*=" packages/xrpl/test/models/NFTokenMint.test.ts

echo -e "\nNFTokenMint integration test:"
rg -A 5 "URI.*=" packages/xrpl/test/integration/transactions/nftokenMint.test.ts

Length of output: 458


Script:

#!/bin/bash
# Check URI handling in NFT-related files with broader patterns
echo "NFTokenMint.ts implementation:"
rg -B2 -A2 "URI" packages/xrpl/src/models/transactions/NFTokenMint.ts

echo -e "\nModel test URI handling:"
rg -B2 -A2 "stringToHex" packages/xrpl/test/models/NFTokenMint.test.ts

echo -e "\nIntegration test URI handling:"
rg -B2 -A2 "stringToHex" packages/xrpl/test/integration/transactions/nftokenMint.test.ts

Length of output: 2007

packages/xrpl/test/integration/requests/submit.test.ts (1)

1-1: LGTM: Correctly migrated to stringToHex

The deprecated convertStringToHex function has been properly replaced with stringToHex from @xrplf/isomorphic/utils. The import and usage are correct.

Also applies to: 38-38

packages/xrpl/test/models/NFTokenMint.test.ts (2)

1-1: LGTM: Consistent migration to stringToHex across test cases

The deprecated function has been properly replaced with stringToHex across all test cases. The changes maintain the test coverage for URI validation, including hex format verification.

Also applies to: 28-28, 43-43, 63-63


Line range hint 73-108: Well-structured test coverage for URI validation

Excellent test coverage with cases for:

  • Empty URI validation
  • Non-hex format validation
    This ensures robust validation of the URI field format requirements.
packages/xrpl/test/integration/requests/tx.test.ts (1)

1-1: LGTM: Comprehensive migration across API versions

The deprecated function has been properly replaced with stringToHex in both the base test and API version 1 test. The changes maintain compatibility across different API versions while modernizing the code.

Also applies to: 38-38, 85-85

packages/xrpl/test/integration/integration.test.ts (1)

1-1: LGTM! Successfully migrated to stringToHex

The changes correctly replace the deprecated convertStringToHex with stringToHex from the isomorphic utils package, maintaining the same functionality.

Also applies to: 77-77

packages/xrpl/src/models/transactions/NFTokenMint.ts (1)

95-97: LGTM! Documentation updated correctly

The URI field documentation has been properly updated to reference the new stringToHex function from @xrplf/isomorphic/utils, maintaining consistency with the codebase changes.

packages/xrpl/test/integration/requests/submitMultisigned.test.ts (2)

1-1: LGTM: Import statement correctly added

The import of stringToHex from @xrplf/isomorphic/utils is properly placed at the top of the file.


78-78: LGTM: Consistent replacement of deprecated function

The Domain field in both test cases has been correctly updated to use stringToHex instead of the deprecated convertStringToHex function. The change maintains the same functionality while using the recommended utility function.

Also applies to: 151-151

packages/xrpl/test/integration/regularKey.test.ts (2)

1-1: LGTM: Import statement correctly added

The import of stringToHex from @xrplf/isomorphic/utils is properly placed at the top of the file.


88-88: LGTM: Consistent replacement of deprecated function across all test cases

The Domain field has been correctly updated to use stringToHex instead of the deprecated convertStringToHex function in all four test cases:

  1. "sign and submit with a regular key"
  2. "sign and submit using the master key of an account with a regular key"
  3. "submit_multisigned transaction with regular keys set"
  4. "try multisigning with the account address used to set up a regular key"

The changes maintain consistency across all test scenarios while using the recommended utility function.

Also applies to: 106-106, 262-262, 322-322

@@ -1,3 +1,4 @@
import { stringToHex } from '@xrplf/isomorphic/utils'
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Remove deprecated convertStringToHex function and its exports

The deprecated convertStringToHex function is still present in the codebase:

  • packages/xrpl/src/utils/stringConversion.ts: Function definition and export
  • packages/xrpl/src/utils/index.ts: Import and re-export

While the function internally uses the new stringToHex from @xrplf/isomorphic/utils, it should be removed to avoid confusion and maintain consistency. The PR's changes should include removing this deprecated function since direct usage of stringToHex from @xrplf/isomorphic/utils is now the standard.

🔗 Analysis chain

Verify complete removal of deprecated function

Let's ensure all instances of the deprecated convertStringToHex function have been removed from the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining usage of convertStringToHex
rg "convertStringToHex" --type ts

# Search for all string-to-hex conversion patterns to ensure consistency
rg "(?i)(convert|to).*hex.*string" --type ts

Length of output: 4665

@@ -1,6 +1,7 @@
import { stringToHex } from '@xrplf/isomorphic/utils'
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Migration to stringToHex is incomplete - Found additional instances to update

The deprecated convertStringToHex function is still present in the codebase:

  • It's defined in packages/xrpl/src/utils/stringConversion.ts (though it's now just a wrapper around stringToHex)
  • It's exported in packages/xrpl/src/utils/index.ts

These instances should also be removed to complete the migration to stringToHex.

🔗 Analysis chain

LGTM! Consistent migration across all test cases

The changes correctly replace all instances of the deprecated convertStringToHex with stringToHex from the isomorphic utils package. The migration is consistent across all test scenarios:

  • Unsigned transaction test
  • Validation error test
  • Signed transaction test
  • Extended wait test

Let's verify that we haven't missed any instances of the deprecated function:

Also applies to: 39-39, 93-93, 111-111, 134-134

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining instances of convertStringToHex
rg "convertStringToHex" --type ts

Length of output: 389


Script:

#!/bin/bash
# Let's check if there are any remaining usages of convertStringToHex in the codebase
rg "convertStringToHex\(" --type ts -A 2

# Also check for any imports of convertStringToHex
rg "import.*convertStringToHex" --type ts

Length of output: 412

@@ -1,3 +1,4 @@
import { stringToHex } from '@xrplf/isomorphic/utils'
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Migration is incomplete - convertStringToHex is still present in the codebase

The deprecated convertStringToHex function is still present in:

  • packages/xrpl/src/utils/stringConversion.ts (function definition)
  • packages/xrpl/src/utils/index.ts (import and re-export)

While the function internally uses stringToHex, its presence might confuse developers. Consider:

  1. Removing the deprecated function
  2. Updating any remaining imports to use stringToHex directly
🔗 Analysis chain

Verify complete migration from deprecated function

Let's ensure there are no remaining instances of the deprecated convertStringToHex function in the codebase.


Let me gather more information to understand if the old function is still being used or just defined.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for any remaining usage of the deprecated function
# Expected: No results, indicating complete migration

# Search for any remaining instances of convertStringToHex
rg "convertStringToHex" --type-add 'ts:*.{ts,tsx}' --type ts

# Search for new stringToHex usage to confirm migration
rg "stringToHex.*example\.com" --type-add 'ts:*.{ts,tsx}' --type ts

Length of output: 1937


Script:

#!/bin/bash
# Search for actual usage of convertStringToHex (not just definitions)
rg "convertStringToHex\(" --type-add 'ts:*.{ts,tsx}' --type ts -C 2

# Check if there are any imports of convertStringToHex in the codebase
rg "import.*convertStringToHex" --type-add 'ts:*.{ts,tsx}' --type ts

Length of output: 581

@pdp2121
Copy link
Collaborator

pdp2121 commented Dec 11, 2024

Would be great if we can change the call in this snippet as well:
https://github.com/XRPLF/xrpl.js/blob/main/packages/xrpl/snippets/src/multisigning.ts#L53

@etienneoh
Copy link
Author

Would be great if we can change the call in this snippet as well: https://github.com/XRPLF/xrpl.js/blob/main/packages/xrpl/snippets/src/multisigning.ts#L53

It is included on the first commit of this pull request ! @pdp2121

@mvadari
Copy link
Collaborator

mvadari commented Dec 12, 2024

IMO deprecated functions shouldn't be removed from tests until the functions are fully removed - just because they're deprecated doesn't mean they should fail.

@etienneoh
Copy link
Author

etienneoh commented Dec 12, 2024

I simply replaced them with the up-to-date functions. The deprecated functions themselves pointed to the new ones that I used, so nothing is failing !

I will update my pull request text, because I realise I was not specific enough.

@ckniffen
Copy link
Collaborator

IMO deprecated functions shouldn't be removed from tests until the functions are fully removed - just because they're deprecated doesn't mean they should fail.

I agree with @mvadari on this one. Maybe at least have one or two of the tests for the deprecated ones. It wouldn't hurt.

@mvadari
Copy link
Collaborator

mvadari commented Dec 12, 2024

I simply replaced them with the up-to-date functions. The deprecated functions themselves pointed to the new ones that I used, so nothing is failing !

If you roll back the changes to hexConversion.test.ts (and update the PR title), the remaining changes would be fine. Then you're only removing the places where convertHexToString are used incidentally, rather than the tests where they're actually being tested.

@etienneoh
Copy link
Author

Done ! Thanks for the feedback @mvadari , very appreciated

@pdp2121 pdp2121 self-requested a review December 16, 2024 17:18
@ckeshava
Copy link
Collaborator

ckeshava commented Jan 2, 2025

What is the expected notice period before a deprecated method can be removed from the codebase? Is it one major-version release cycle ?

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