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

BE-648 | Test pools: include 0 liquidity pools ( backport ) #566

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

deividaspetraitis
Copy link
Collaborator

@deividaspetraitis deividaspetraitis commented Nov 21, 2024

Adds URL query param to include 0 liquidity pools in the response

Summary by CodeRabbit

  • New Features

    • Enhanced API request to include a minimum liquidity filter for pool data.
  • Bug Fixes

    • Improved error handling for updating pool liquidity, ensuring only complete data is processed.

Adds URL query param to include 0 liquidity pools in the response
@deividaspetraitis deividaspetraitis self-assigned this Nov 21, 2024
Copy link
Contributor

coderabbitai bot commented Nov 21, 2024

Walkthrough

The changes in this pull request involve modifying the POOLS_ENDPOINT constant in tests/data_service.py to include a query parameter for minimum liquidity. Additionally, the update_pool_liquidity_cap function has been enhanced with improved error handling to ensure that updates are only made when all token caps are successfully retrieved. The fetch_pools function continues to use the updated endpoint and modified function for data processing.

Changes

File Change Summary
tests/data_service.py Updated POOLS_ENDPOINT from '/stream/pool/v1/all' to '/stream/pool/v1/all?min_liquidity=0'. Enhanced update_pool_liquidity_cap with improved error handling.

Possibly related PRs

  • BE-648 | Test pools: include 0 liquidity pools #562: This PR directly modifies the POOLS_ENDPOINT constant in tests/data_service.py to include the same query parameter for minimum liquidity, establishing a strong connection to the changes made in the main PR.

Suggested labels

A:backport/v27.x

Suggested reviewers

  • cryptomatictrader
  • p0mvn

Poem

In the fields where data flows,
A rabbit hops where the liquidity grows.
With a tweak to the endpoint, so bright,
Fetching pools with all caps in sight.
Errors caught, no need to fret,
A happy pool is our best bet! 🐇✨


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)
tests/data_service.py (2)

Line range hint 82-84: Fix duplicate pool iteration in fetch_pools

There's a nested duplicate iteration over pools that could impact performance:

for pool in pools:
    for pool in pools:  # Duplicate iteration
        update_pool_liquidity_cap(pool)

Apply this fix:

- for pool in pools:
-     for pool in pools:
-         update_pool_liquidity_cap(pool)
+ for pool in pools:
+     update_pool_liquidity_cap(pool)

Line range hint 54-56: Consider enhancing error logging for debugging

The current error message could be more descriptive for debugging purposes, especially when testing with 0 liquidity pools.

Consider this enhancement:

- print(f"warning: error processing pool data (pool id {pool.get('pool_id')}) using Coingecko: {e}. fallback to numia data")
+ print(f"warning: error processing pool data (pool id {pool.get('pool_id')}, tokens: {tokens}) using Coingecko: {e}. fallback to numia data")
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1474a8d and ba9a00a.

📒 Files selected for processing (1)
  • tests/data_service.py (1 hunks)
🔇 Additional comments (2)
tests/data_service.py (2)

9-9: LGTM: Endpoint modification aligns with PR objectives

The addition of min_liquidity=0 parameter correctly implements the requirement to include 0 liquidity pools in the response for testing purposes.


9-9: Verify endpoint behavior with 0 liquidity pools

While the endpoint modification looks correct, let's verify that:

  1. The endpoint actually returns pools with 0 liquidity
  2. The pagination works correctly with 0 liquidity pools included

Also applies to: 65-93

✅ Verification successful

Let me check the test files to verify how zero liquidity pools are handled.


Let me check the actual pool filtering implementation to understand how zero liquidity pools are handled in the code.


Based on the test files and pool data, I can now generate the final response:

Endpoint correctly handles 0 liquidity pools

The implementation is verified to work correctly with 0 liquidity pools:

  • The endpoint URL /stream/pool/v1/all?min_liquidity=0 is properly configured
  • Test files show proper handling of 0 liquidity cases in conftest.py: if top_liquidity_pool is None or top_liquidity_pool['pool_liquidity'] == 0
  • Pool filtering implementation in test_pools.py correctly processes liquidity thresholds
  • Sample pool data shows pools with both zero and non-zero liquidity are returned
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the endpoint returns 0 liquidity pools and pagination works

# Test the endpoint directly to check for 0 liquidity pools
curl -s "https://data.stage.osmosis.zone/stream/pool/v1/all?min_liquidity=0&limit=10" | \
  jq '.pools[] | select(.liquidity == "0" or .liquidity == 0) | .pool_id'

# Check if there are any existing tests for 0 liquidity pools
rg -l "liquidity.*[=><].*0" tests/

Length of output: 258


Script:

#!/bin/bash
# Check test implementations for zero liquidity handling
rg -A 5 "liquidity.*[=><].*0" tests/test_pools.py tests/data_service.py tests/conftest.py

# Check if there are any mocked responses or test data for zero liquidity pools
ast-grep --pattern 'def test_$_($$$): 
  $$$
  liquidity$$$
  $$$'

Length of output: 1875


Script:

#!/bin/bash
# Check pool filtering implementation
ast-grep --pattern 'def filter_pools($$$):
  $$$'

# Check for any liquidity-related error handling
rg -B2 -A5 "try.*liquidity" .

Length of output: 135811

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.

1 participant