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

Update the Paths snippet test #739

Closed
wants to merge 7 commits into from
Closed

Conversation

ckeshava
Copy link
Collaborator

@ckeshava ckeshava commented Aug 26, 2024

Create trust lines internally to demonstrate ripple_path_find RPC

High Level Overview of Change

The existing Paths snippets test depends on certain pre-requisite state of the test-net infrastructure. Upon a test-net reset, this state needs to be restored manually.

This process is error-prone, tedious. Moreover, tests must be self-contained i.e. Paths test must create the necessary blockchain state inside the test itself.

Context of Change

After this change, the effort needed to reset the test-net is lowered.

For instance, the Paths snippets test is currently failing with this error:

Attempting to fund address rf8Mp52EQtbaB6oYezPGTf8rjG57xea2Hg
Faucet fund successful.
Response(status=<ResponseStatus.ERROR: 'error'>, result={'error': 'actNotFound', 'error_code': 19, 'error_message': 'Account not found.', 'request': {'api_version': 2, 'command': 'ripple_path_find', 'destination_account': 'rKT4JX4cCof6LcDYRz8o3rGRu7qxzZ2Zwj', 'destination_amount': {'currency': 'USD', 'issuer': 'rVnYNK9yuxBz4uP8zC8LEFokM2nqH3poc', 'value': '0.001'}, 'source_account': 'rf8Mp52EQtbaB6oYezPGTf8rjG57xea2Hg', 'source_currencies': [{'currency': 'XRP'}]}}, id=None, type=<ResponseType.RESPONSE: 'response'>)
Traceback (most recent call last):
  File "/Users/ckeshavabs/xrpl-py/snippets/paths.py", line 36, in <module>
    paths = path_response.result["alternatives"][0]["paths_computed"]
            ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
KeyError: 'alternatives'

This PR ensures that the test completes successfully without a dependence on a set of accounts, trust-lines and account-related settings (like Default Rippling set on some accounts)

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
  • No, this change does not impact library users

Test Plan

Summary by CodeRabbit

  • New Features

    • Updated payment transaction parameters for Ripple, including a new destination account and currency.
    • Enhanced clarity with expanded comments detailing prerequisites for successful transactions.
  • Bug Fixes

    • Adjusted issuer details to ensure proper cross-currency exchanges.
  • Removed Features

    • Deleted the command-line interface for cross-chain asset transfers, including wallet creation and transaction management.

# References
# - https://xrpl.org/paths.html#paths
# - https://xrpl.org/ripple_path_find.html#ripple_path_find
# Note: This test is inspired from a unit test titled `indirect_paths_path_find` in the
Copy link
Collaborator

@pdp2121 pdp2121 Sep 4, 2024

Choose a reason for hiding this comment

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

The main purpose of a snippet is to provide working examples for users, not for testing even though we implement tests on those. This should be reworded

currency="USD",
issuer="rVnYNK9yuxBz4uP8zC8LEFokM2nqH3poc",
# these wallets will have 100 testnet XRP
alice = generate_faucet_wallet(client, debug=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we denote these as wallet somehow, just to avoid confusion?

# Extract out paths from the RipplePathFind response
paths = path_response.result["alternatives"][0]["paths_computed"]
print(paths)
submit_and_wait(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Before these submit_and_wait, can you print out a statement such as Submitting AccountSet transaction for ...` so that user can expect to wait, and also print result or some kind of message when done?


print("signed: ", autofill_and_sign(payment_tx, client, wallet))
print("Test passed successfully!")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto. This statement is not needed

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.

Snippets are documentation. The objective of this snippet is to make it easy to see how paths would work. I don't think setting up the whole system accomplishes that.

I understand that resets are difficult to work with, but we can either add some extra tokens to set up to the list every time, or use tokens that are already on that list.

)
response = client.request(request)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here. Some kind of statement should be printed out


# Check the source amount
source_amount = paths[0]["source_amount"]
assert source_amount["currency"] == "USD"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we using assert in other snippets since these are not tests?

@ckeshava
Copy link
Collaborator Author

ckeshava commented Sep 4, 2024

Snippets are documentation. The objective of this snippet is to make it easy to see how paths would work. I don't think setting up the whole system accomplishes that.

I understand that resets are difficult to work with, but we can either add some extra tokens to set up to the list every time, or use tokens that are already on that list.

What tokens and list are you referring to? If you are looking at theissuer and the destination account mentioned in the snippets test (rK... and rV...), those have not been instantiated properly. We do not have the private keys to at least one of those accounts.

@ckeshava
Copy link
Collaborator Author

ckeshava commented Sep 4, 2024

Are these snippets/ files being used (or) referenced anywhere in the documentation?

https://xrpl-py.readthedocs.io/en/stable/source/snippets.html -- this page is using a static, older version of the snippets files (possibly from 2021). Does it need to be dynamically linked to the github repository's snippets/ folder?

@ckeshava
Copy link
Collaborator Author

ckeshava commented Sep 9, 2024

@mvadari @pdp2121 I can incorporate your suggestions into the snippets test (i.e. use hard-coded account number for readability). But I don't understand how the tests were working before the testnet reset i.e. how was XRP converted into USD (this was the premise of the snippet) ? Was there a specific Offer or AMM that was used to perform this currency conversion?

We discovered that the account rVnYNK9yuxBz4uP8zC8LEFokM2nqH3poc is operated by Gatehub. I don't know what settings they use for this account. While this account has issued USD tokens, the current testnet state appears to break this snippet.

Have you guys saved the output from one of the older CI/CD runs? (I don't know if Github allows me to access really old logs) Do you know how this works?

@ckeshava
Copy link
Collaborator Author

@intelliot @justinr1234 Do any of you know how the snippets/paths.py was set up by Gatehub ? If so, I can replicate that setup with new accounts.

Specifically, how can a Payment transaction from account A -> C (Source currency: XRP, Destination currency: USD, Issued by B) succeed?

This must be the resulting path (output of ripple_path_find) A -> B -> C. This can be achieved through DEX offers/AMM and trust-lines. But I don't know how it was working in the past.

Copy link
Contributor

coderabbitai bot commented Sep 19, 2024

Walkthrough

The changes involve the removal of the snippets/bridge_transfer.py file, which implemented a command-line interface for cross-chain asset transfers between blockchain networks. Additionally, the snippets/paths.py file was modified to transition from a JsonRpcClient to a WebsocketClient for handling Ripple payments, updating destination account and currency details, and enhancing comments for clarity on transaction prerequisites.

Changes

File Change Summary
snippets/bridge_transfer.py Removed the implementation for a CLI facilitating cross-chain asset transfers, including wallet creation and transaction handling.
snippets/paths.py Updated to use WebsocketClient for Ripple payments; changed destination account and currency details; added comments on prerequisites for execution.

Poem

🐰 In the land of code where rabbits play,
A payment path found a new way.
With accounts that shift and currencies bright,
We hop through the changes, a joyful sight!
Trust lines and offers, all set to go,
A dance of transactions, watch them flow! 🌟


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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 requested review from mvadari and pdp2121 September 19, 2024 16:23
@ckeshava
Copy link
Collaborator Author

The changes created in this PR appears to have been included in other related PRs. I see an empty diff in the "Files" tab. Thanks for all the feedback. I'll close this PR.

@ckeshava ckeshava closed this Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants