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(rest-api): /destinationTokens returns empty list when bridgeable token doesnt exist in bridge map #3314

Merged
merged 1 commit into from
Oct 20, 2024

Conversation

abtestingalpha
Copy link
Collaborator

@abtestingalpha abtestingalpha commented Oct 20, 2024

Description
Not all bridgeable tokens exist in bridgemap, so this handles the case by returning an empty list.

Summary by CodeRabbit

  • New Features

    • Enhanced error handling and response logic in the destination tokens functionality.
    • Added a new test case to verify behavior when no destination tokens are available.
  • Bug Fixes

    • Improved response consistency with explicit return statements in the error handling.
  • Tests

    • Introduced a new test scenario for empty responses while maintaining existing test checks.

Copy link
Contributor

coderabbitai bot commented Oct 20, 2024

Walkthrough

The changes involve modifications to the destinationTokensController in destinationTokensController.ts, enhancing its logic and error handling. A new variable payload is introduced to manage response data, with conditions to set its value based on the presence of fromTokenInfo. The response handling is updated to ensure consistent return statements. Additionally, the test suite in destinationTokensRoute.test.ts is expanded with a new test case to verify behavior when no destination tokens are available, while existing tests remain intact.

Changes

File Path Change Summary
packages/rest-api/src/controllers/destinationTokensController.ts Modified logic to introduce payload, updated response handling to ensure consistent return statements.
packages/rest-api/src/tests/destinationTokensRoute.test.ts Added new import ONEETH and a test case for scenarios with no destination tokens, preserving existing tests.

Possibly related PRs

Suggested labels

size/s, Sol, Typescript

Suggested reviewers

  • Defi-Moses
  • trajan0x

Poem

In the code where tokens play,
A rabbit hops to light the way.
With payloads bright and tests anew,
We check for chains, both old and true.
So let us code, and let us cheer,
For every change brings us near! 🐇✨


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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
packages/rest-api/src/controllers/destinationTokensController.ts (1)

20-26: LGTM: Improved handling of non-existent tokens.

This change effectively addresses the PR objective by returning an empty list when a bridgeable token doesn't exist in the bridge map. The logic handles both cases appropriately.

For improved clarity, consider adding a comment explaining the significance of an empty fromTokenInfo:

 if (!fromTokenInfo) {
+  // Return an empty list if the token doesn't exist or is not bridgeable
   payload = []
 } else {
   const constructedKey = `${fromTokenInfo.symbol}-${fromChain}`
   payload = BRIDGE_ROUTE_MAPPING[constructedKey]
 }
packages/rest-api/src/tests/destinationTokensRoute.test.ts (1)

84-93: LGTM: New test case for empty destination tokens list

The new test case is well-structured and covers an important scenario where no destination tokens are available. It aligns with the PR objectives and enhances the test coverage.

Suggestion for improvement:
Consider adding a comment explaining the significance of chain ID 1666600000 (Harmony Mainnet) and why it's expected to return an empty list. This would enhance the test's readability and maintainability.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7f44c5d and 5084e97.

📒 Files selected for processing (2)
  • packages/rest-api/src/controllers/destinationTokensController.ts (1 hunks)
  • packages/rest-api/src/tests/destinationTokensRoute.test.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (5)
packages/rest-api/src/controllers/destinationTokensController.ts (3)

13-14: LGTM: Introduction of payload variable improves code structure.

The addition of the payload variable enhances code readability and maintainability by providing a consistent structure for the response data throughout the function.


33-33: LGTM: Improved response handling.

The explicit return statement ensures that the function exits immediately after sending the response. This change improves control flow and prevents potential issues with code execution after the response has been sent.


Line range hint 40-44: LGTM: Consistent error response handling.

The explicit return statement in the error handling block is consistent with the improvement made in the successful response handling. This ensures that the function exits immediately after sending the error response, improving the overall control flow of the function.

packages/rest-api/src/tests/destinationTokensRoute.test.ts (2)

6-6: LGTM: New import added for ONEETH

The new import for ONEETH is consistent with the existing import style and is necessary for the new test case.


Line range hint 1-161: Overall improvement in test coverage

The changes to this file enhance the test suite by adding coverage for the scenario where no destination tokens are available. This aligns well with the PR objectives and improves the robustness of the tests. The existing tests remain intact, ensuring that previously covered scenarios are still validated.

Copy link

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5084e97
Status: ✅  Deploy successful!
Preview URL: https://1b86e0bb.sanguine-fe.pages.dev
Branch Preview URL: https://rest-api-handle-tokens-not-i.sanguine-fe.pages.dev

View logs

Copy link

codecov bot commented Oct 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 26.98386%. Comparing base (6415acd) to head (5084e97).
Report is 12 commits behind head on master.

Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #3314         +/-   ##
===================================================
- Coverage   31.92469%   26.98386%   -4.94083%     
===================================================
  Files            238         178         -60     
  Lines          14553       11833       -2720     
  Branches         356          82        -274     
===================================================
- Hits            4646        3193       -1453     
+ Misses          9614        8357       -1257     
+ Partials         293         283         -10     
Flag Coverage Δ
packages 90.44834% <ø> (ø)
promexporter ?
solidity ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@abtestingalpha abtestingalpha merged commit 98a3a69 into master Oct 20, 2024
36 checks passed
@abtestingalpha abtestingalpha deleted the rest-api/handle-tokens-not-in-bridgemap branch October 20, 2024 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant