Skip to content

test common::subgraph #1742

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

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

test common::subgraph #1742

wants to merge 2 commits into from

Conversation

0xgleb
Copy link
Collaborator

@0xgleb 0xgleb commented May 6, 2025

Motivation

  • tests missing in common::subgraph
  • unnecessary use of async in to_subgraph_client

Solution

  • add tests
  • make to_subgraph_client not async

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Summary by CodeRabbit

  • Refactor

    • Improved performance by making client creation synchronous across order, trade, and vault commands.
    • Enhanced error handling and control flow by removing unnecessary asynchronous operations.
    • Added a method to access the client URL and enabled debug output for the subgraph client.
  • Tests

    • Introduced new tests to verify client creation and error scenarios for invalid URLs.

Copy link
Contributor

coderabbitai bot commented May 6, 2025

Warning

Rate limit exceeded

@0xgleb has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 10 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 3a5a42a and 2870984.

📒 Files selected for processing (13)
  • crates/cli/src/commands/order/detail.rs (1 hunks)
  • crates/cli/src/commands/order/list.rs (2 hunks)
  • crates/cli/src/commands/order/remove.rs (1 hunks)
  • crates/cli/src/commands/trade/detail.rs (1 hunks)
  • crates/cli/src/commands/trade/list.rs (2 hunks)
  • crates/cli/src/commands/vault/detail.rs (1 hunks)
  • crates/cli/src/commands/vault/list.rs (2 hunks)
  • crates/cli/src/commands/vault/list_balance_changes.rs (2 hunks)
  • crates/common/src/subgraph.rs (1 hunks)
  • crates/subgraph/src/orderbook_client.rs (2 hunks)
  • tauri-app/src-tauri/src/commands/order.rs (1 hunks)
  • tauri-app/src-tauri/src/commands/order_take.rs (1 hunks)
  • tauri-app/src-tauri/src/commands/vault.rs (2 hunks)

Walkthrough

The changes convert the to_subgraph_client() method from asynchronous to synchronous across multiple modules. All usages of .await on this method are removed, and error handling is updated to use the ? operator directly. Additionally, OrderbookSubgraphClient is now Debug, a new accessor method is added, and new tests are introduced for client creation and error cases.

Changes

File(s) Change Summary
crates/common/src/subgraph.rs Changed to_subgraph_client from async fn to synchronous fn; added tests for success and error cases.
crates/subgraph/src/orderbook_client.rs Derived Debug for OrderbookSubgraphClient; added public url(&self) -> &Url method.
crates/cli/src/commands/order/detail.rs
crates/cli/src/commands/order/list.rs
crates/cli/src/commands/order/remove.rs
crates/cli/src/commands/trade/detail.rs
crates/cli/src/commands/trade/list.rs
crates/cli/src/commands/vault/detail.rs
crates/cli/src/commands/vault/list.rs
crates/cli/src/commands/vault/list_balance_changes.rs
Removed .await from to_subgraph_client() calls; updated error handling to use synchronous result.
tauri-app/src-tauri/src/commands/order.rs
tauri-app/src-tauri/src/commands/order_take.rs
tauri-app/src-tauri/src/commands/vault.rs
Removed .await from to_subgraph_client() calls; updated error handling as synchronous.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant SubgraphArgs
    participant OrderbookSubgraphClient

    Caller->>SubgraphArgs: to_subgraph_client()
    activate SubgraphArgs
    SubgraphArgs-->>Caller: Result<OrderbookSubgraphClient, ParseError>
    deactivate SubgraphArgs
    Caller->>OrderbookSubgraphClient: (subsequent async calls, e.g., order_detail().await)
Loading

Previous Flow (for comparison):

sequenceDiagram
    participant Caller
    participant SubgraphArgs
    participant OrderbookSubgraphClient

    Caller->>SubgraphArgs: to_subgraph_client().await
    activate SubgraphArgs
    SubgraphArgs-->>Caller: Result<OrderbookSubgraphClient, ParseError>
    deactivate SubgraphArgs
    Caller->>OrderbookSubgraphClient: (subsequent async calls, e.g., order_detail().await)
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@0xgleb 0xgleb linked an issue May 6, 2025 that may be closed by this pull request
@0xgleb 0xgleb added this to the Test coverage, tech debt milestone May 6, 2025
@0xgleb 0xgleb force-pushed the test-common-subgraph branch from 7844b59 to 3a5a42a Compare May 8, 2025 17:08
@0xgleb 0xgleb marked this pull request as ready for review May 8, 2025 17:08
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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7d1b655 and 3a5a42a.

📒 Files selected for processing (13)
  • crates/cli/src/commands/order/detail.rs (1 hunks)
  • crates/cli/src/commands/order/list.rs (2 hunks)
  • crates/cli/src/commands/order/remove.rs (1 hunks)
  • crates/cli/src/commands/trade/detail.rs (1 hunks)
  • crates/cli/src/commands/trade/list.rs (2 hunks)
  • crates/cli/src/commands/vault/detail.rs (1 hunks)
  • crates/cli/src/commands/vault/list.rs (2 hunks)
  • crates/cli/src/commands/vault/list_balance_changes.rs (2 hunks)
  • crates/common/src/subgraph.rs (1 hunks)
  • crates/subgraph/src/orderbook_client.rs (2 hunks)
  • tauri-app/src-tauri/src/commands/order.rs (1 hunks)
  • tauri-app/src-tauri/src/commands/order_take.rs (1 hunks)
  • tauri-app/src-tauri/src/commands/vault.rs (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
crates/common/src/subgraph.rs (4)
crates/subgraph/src/orderbook_client.rs (2)
  • new (72-74)
  • url (76-78)
crates/cli/src/commands/order/list.rs (2)
  • subgraph_args (32-38)
  • subgraph_args (44-53)
crates/cli/src/commands/trade/list.rs (2)
  • subgraph_args (32-38)
  • subgraph_args (44-55)
crates/cli/src/commands/vault/list_balance_changes.rs (2)
  • subgraph_args (32-38)
  • subgraph_args (44-53)
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: git-clean
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: test
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: Deploy-Preview
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: build-tauri (ubuntu-22.04, true)
🔇 Additional comments (18)
crates/cli/src/commands/order/detail.rs (1)

19-20: Successfully converted subgraph client creation to synchronous

The change properly removes the .await call when creating the subgraph client, reflecting that to_subgraph_client has been refactored from an asynchronous to a synchronous function. The error handling using the ? operator is maintained correctly.

tauri-app/src-tauri/src/commands/order_take.rs (1)

16-17: Correct conversion to synchronous client creation

The change properly removes the .await call when creating the subgraph client, correctly handling the error propagation with the ? operator while preserving the asynchronous await for the subsequent order_trades_list_all call.

crates/cli/src/commands/order/remove.rs (1)

27-28: Client creation correctly converted to synchronous

The change appropriately removes the .await call when creating the subgraph client, maintaining proper error propagation with the ? operator. The function flow remains the same, with only the subgraph client creation becoming synchronous.

tauri-app/src-tauri/src/commands/order.rs (3)

19-20: Properly updated client creation to synchronous

The .await call has been correctly removed when creating the subgraph client, maintaining error handling with the ? operator. The subsequent orders_list_all call remains properly asynchronous.


62-73: Verify error handling in synchronous client creation

I notice that this section doesn't have any changed lines, but it's using the to_subgraph_client() method without .await. This section appears to have already been updated previously to use the synchronous version, handling errors with appropriate toast messages, which is consistent with the changes being made in this PR.


114-125: Consistent pattern for synchronous client creation

Similar to the previous section, this code is already using the synchronous version of to_subgraph_client() without .await, with proper error handling and user notifications. This maintains consistency with the changes being made in this PR.

crates/cli/src/commands/vault/detail.rs (1)

20-20: Successfully converted async client creation to synchronous.

The removal of .await from to_subgraph_client() correctly implements the PR objective of removing unnecessary async operations. This is a good simplification that maintains the same functionality while potentially improving performance by reducing async overhead.

crates/subgraph/src/orderbook_client.rs (2)

59-59: Appropriately added Debug trait derivation.

Adding the Debug trait to OrderbookSubgraphClient improves diagnostics and testing capabilities, which aligns well with the PR's goal of enhancing testability for the subgraph module.


76-78: Good addition of URL accessor method.

This accessor follows Rust best practices by:

  1. Returning a reference instead of cloning the URL
  2. Providing better visibility for testing
  3. Supporting the PR's goal of improved testability

The method will be useful for assertions in the new tests being added in this PR.

crates/cli/src/commands/trade/detail.rs (1)

22-22: Successfully converted async client creation to synchronous.

The removal of .await from to_subgraph_client() correctly implements the PR objective. This change is consistent with the pattern applied across other command modules.

crates/cli/src/commands/vault/list.rs (2)

34-35: Successfully converted async client creation to synchronous in vaults_list_all path.

The removal of .await from to_subgraph_client() correctly implements the PR objective while maintaining proper error handling with the ? operator.


48-49: Successfully converted async client creation to synchronous in vaults_list path.

The second instance of this change maintains consistency in both code paths (CSV and non-CSV output modes). This systematically applies the pattern throughout the file.

crates/cli/src/commands/order/list.rs (1)

33-33: Correctly converted asynchronous call to synchronous

The conversion of .to_subgraph_client().await? to .to_subgraph_client()? aligns with the PR objective of removing unnecessary async from the to_subgraph_client function. This change maintains proper error handling with the ? operator while making the client creation synchronous.

Also applies to: 45-45

tauri-app/src-tauri/src/commands/vault.rs (1)

23-23: Properly removed .await from subgraph client creation

The synchronous call to to_subgraph_client() with direct error propagation using ? is consistent with the changes across the codebase. This simplifies the code while maintaining the same error handling pattern.

Also applies to: 44-44

crates/cli/src/commands/trade/list.rs (1)

33-33: Correctly converted to synchronous client creation

The changes appropriately remove the async/await pattern from the client creation while preserving the asynchronous nature of the subsequent subgraph operations. This is consistent with the overall objective of making to_subgraph_client() synchronous.

Also applies to: 45-45

crates/cli/src/commands/vault/list_balance_changes.rs (1)

33-33: Successfully converted to synchronous client creation

The removal of .await from the to_subgraph_client() calls correctly implements the PR objective. The error handling approach with ? is maintained, ensuring that any client creation errors are still properly propagated while simplifying the code.

Also applies to: 45-45

crates/common/src/subgraph.rs (2)

11-11: Clean simplification from async to sync function

Good change to remove the unnecessary async keyword from this method. The function doesn't perform any I/O operations - it only parses a URL string and constructs a client - so making it synchronous is more appropriate. This will reduce overhead and improve clarity for callers.


16-52: Great test coverage for the subgraph client creation

The added tests comprehensively verify both successful and error cases:

  • Tests valid URL construction and verification
  • Tests multiple error scenarios including missing scheme, empty host, empty string, and malformed URL
  • Properly asserts the specific error types returned

This significantly improves the reliability of the codebase by ensuring URL parsing behaves as expected across various inputs.

@0xgleb 0xgleb force-pushed the test-common-subgraph branch from 3a5a42a to 2870984 Compare May 8, 2025 17:22
@0xgleb 0xgleb requested review from hardyjosh and findolor May 8, 2025 20:22
@0xgleb
Copy link
Collaborator Author

0xgleb commented May 8, 2025

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented May 8, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Collaborator

@findolor findolor left a comment

Choose a reason for hiding this comment

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

LGTM

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.

Missing test - Common crate - subgraph.rs
2 participants