-
Notifications
You must be signed in to change notification settings - Fork 7
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
Conversation
WalkthroughA new test module has been added to the codebase, specifically targeting the asynchronous behavior of the Changes
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
Suggested labels
Suggested reviewers
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. ✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
b049b99
to
47f9809
Compare
There was a problem hiding this 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
📒 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.
looks good but yes we should mock where can, also there are AI comments that haven't been responded to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comments
47f9809
to
81da866
Compare
There was a problem hiding this 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
📒 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 setupGreat 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 responsesThe test correctly validates that decode errors are properly caught and wrapped in
RemoteNetworkError::ReqwestError
. Usingmatches!
with theis_decode()
check is a good way to ensure the specific error type.
256-272
: Reliable connection error testGood 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 testingThis 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.
192a902
to
6fe57f3
Compare
There was a problem hiding this 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
There was a problem hiding this 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
📒 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 conditionerr.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!
witherr.is_decode()
ensures you're catching the specific decode error type.
Motivation
Solution
Checks
By submitting this for review, I'm confirming I've done the following:
Summary by CodeRabbit