Skip to content

Test try from remote network config source #1713

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

Merged
merged 5 commits into from
May 15, 2025

Conversation

0xgleb
Copy link
Collaborator

@0xgleb 0xgleb commented Apr 29, 2025

Motivation

  • HTTP request and parsing logic are not tested

Solution

  • Add unit tests

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

  • Tests
    • Added asynchronous tests to verify handling of remote network configurations, covering successful parsing, invalid data, connection issues, and unsupported formats.

Copy link
Contributor

coderabbitai bot commented Apr 29, 2025

Walkthrough

A new test module has been added to the codebase, specifically targeting the asynchronous behavior of the RemoteNetworks::try_from_remote_network_config_source method. The tests are written using Tokio and cover multiple scenarios, including successful parsing of a remote network configuration, handling of HTTP decoding errors, connection errors due to invalid URLs, and error cases for unsupported or empty format strings. The tests assert the expected outcomes for each scenario and ensure that errors are correctly wrapped and reported.

Changes

File(s) Change Summary
crates/settings/src/remote/chains/mod.rs Added a private asynchronous test module for RemoteNetworks::try_from_remote_network_config_source, covering success and multiple error scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Function
    participant RemoteNetworks as RemoteNetworks::try_from_remote_network_config_source
    participant HTTP as HTTP Endpoint
    participant Error as Error Handling

    Test->>RemoteNetworks: Call with config source and format
    alt Successful "chainid" fetch
        RemoteNetworks->>HTTP: Fetch config source
        HTTP-->>RemoteNetworks: Return valid response
        RemoteNetworks-->>Test: Return parsed RemoteNetworks
    else HTTP decode error
        RemoteNetworks->>HTTP: Fetch config source
        HTTP-->>RemoteNetworks: Return undecodable response
        RemoteNetworks->>Error: Wrap as ReqwestError
        RemoteNetworks-->>Test: Return error
    else Connection error
        RemoteNetworks->>HTTP: Fetch config source (invalid URL)
        HTTP-->>RemoteNetworks: Connection error
        RemoteNetworks->>Error: Wrap as ReqwestError
        RemoteNetworks-->>Test: Return error
    else Unsupported/empty format
        RemoteNetworks->>Error: UnknownFormat error
        RemoteNetworks-->>Test: Return error
    end
Loading

Suggested labels

test

Suggested reviewers

  • hardyjosh

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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 force-pushed the test-try-from-remote-network-config-source branch from b049b99 to 47f9809 Compare April 29, 2025 17:49
@0xgleb 0xgleb marked this pull request as ready for review April 29, 2025 17:51
@0xgleb 0xgleb linked an issue Apr 29, 2025 that may be closed by this pull request
1 task
@0xgleb 0xgleb added this to the Test coverage, tech debt milestone Apr 29, 2025
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: 4

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9c4c519 and 47f9809.

📒 Files selected for processing (1)
  • crates/settings/src/remote/chains/mod.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: Deploy-Preview
  • 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-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: test
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: test
  • GitHub Check: git-clean
  • GitHub Check: test
🔇 Additional comments (1)
crates/settings/src/remote/chains/mod.rs (1)

97-124: Good test structure for multiple cases.

This test effectively covers multiple format string cases without making network calls, making it fast and reliable. The use of a vector to test multiple cases is a good pattern for similar test scenarios.

@hardyjosh hardyjosh self-requested a review May 1, 2025 11:39
@hardyjosh hardyjosh requested a review from findolor May 7, 2025 23:17
@hardyjosh
Copy link
Contributor

looks good but yes we should mock where can, also there are AI comments that haven't been responded to

Copy link
Contributor

@hardyjosh hardyjosh left a comment

Choose a reason for hiding this comment

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

see comments

@0xgleb 0xgleb force-pushed the test-try-from-remote-network-config-source branch from 47f9809 to 81da866 Compare May 8, 2025 16:57
@0xgleb 0xgleb requested a review from hardyjosh May 8, 2025 16:59
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 47f9809 and 81da866.

📒 Files selected for processing (1)
  • crates/settings/src/remote/chains/mod.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: git-clean
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: test
  • GitHub Check: Deploy-Preview
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-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, ob-rs-test, true)
🔇 Additional comments (4)
crates/settings/src/remote/chains/mod.rs (4)

37-42: Good choice of testing tools and setup

Great job setting up the tests with httpmock for mocking HTTP responses! This addresses the previous review comments about using mocks instead of real network calls. The imports are appropriate and provide all the necessary functionality for testing the remote network configuration source.


228-254: Good test for handling invalid JSON responses

The test correctly validates that decode errors are properly caught and wrapped in RemoteNetworkError::ReqwestError. Using matches! with the is_decode() check is a good way to ensure the specific error type.


256-272: Reliable connection error test

Good work addressing the previous review comment by using localhost:1 instead of a potentially unreliable domain. This ensures the test will consistently produce a connection error.


274-310: Comprehensive format error testing

This test effectively covers both empty and unknown format strings, verifying that the proper error is returned with the correct format string included in the error.

@0xgleb 0xgleb force-pushed the test-try-from-remote-network-config-source branch from 192a902 to 6fe57f3 Compare May 9, 2025 17:09
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.

Maybe we can also two more tests for

  • empty chain list
  • missing required fields in chain list

@0xgleb 0xgleb requested a review from findolor May 13, 2025 12:09
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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6fe57f3 and 345ff23.

📒 Files selected for processing (1)
  • crates/settings/src/remote/chains/mod.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: git-clean
  • GitHub Check: test
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: Deploy-Preview
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: build-tauri (ubuntu-22.04, true)
🔇 Additional comments (6)
crates/settings/src/remote/chains/mod.rs (6)

36-42: Well-structured test module setup with appropriate imports.

The test module setup is clean and well-organized. Your inclusion of essential dependencies like httpmock::MockServer for mocking HTTP responses is appropriate for unit testing network interactions. This approach follows best practices for isolating tests from external dependencies.


228-254: Good error handling test for invalid JSON responses.

This test correctly verifies how the system handles malformed JSON responses. The use of matches! macro with the condition err.is_decode() is a clear and effective way to assert on the specific error type and condition.


256-272: Appropriate connection error test with reliable error trigger.

The test uses http://localhost:1 as an invalid URL, which is a reliable way to simulate a connection error without relying on external network conditions. This follows best practices mentioned in previous review comments.


274-310: Thorough testing of format parsing error cases.

The approach of testing multiple invalid formats (empty string and "unknown") in a single test function with a loop is efficient and thorough. The error matching verifies both the error type and that the exact unexpected format string is preserved in the error.


312-335: Important edge case test for empty chain lists.

Testing the empty array case is important as it verifies graceful handling of valid but empty responses. This test ensures the system doesn't error out when no chains are returned, which is a valuable edge case to cover.


337-359: Crucial test for handling missing required fields.

This test verifies proper error handling when the JSON response is missing required fields, which is an important validation for robust parsing logic. Using matches! with err.is_decode() ensures you're catching the specific decode error type.

@hardyjosh hardyjosh enabled auto-merge May 15, 2025 11:27
@hardyjosh hardyjosh merged commit e8262bd into main May 15, 2025
17 checks passed
@0xgleb 0xgleb deleted the test-try-from-remote-network-config-source branch May 15, 2025 19:55
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 - Settings crate - remote/chains/mod.rs
3 participants