-
Notifications
You must be signed in to change notification settings - Fork 127
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
refactor: simplify error messages in test cases #795
refactor: simplify error messages in test cases #795
Conversation
Warning Rate limit exceeded@panmini has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 33 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. WalkthroughThis pull request introduces modifications to various test files, focusing on the formatting of expected error messages in multiple test cases. The changes involve replacing the use of Changes
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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
Documentation and Community
|
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.yaml
Review profile: CHILL
📒 Files selected for processing (5)
- x/logic/predicate/bank_test.go (3 hunks)
- x/logic/predicate/crypto_test.go (2 hunks)
- x/logic/predicate/did_test.go (1 hunks)
- x/logic/predicate/encoding_test.go (1 hunks)
- x/logic/predicate/uri_test.go (1 hunks)
🧰 Additional context used
📓 Learnings (1)
x/logic/predicate/bank_test.go (4)
Learnt from: ccamel PR: axone-protocol/axoned#769 File: x/logic/predicate/bank_test.go:170-172 Timestamp: 2024-10-05T09:28:45.913Z Learning: In test cases, error messages may involve transformations like `strings.Join(strings.Split(...))` because error messages used to be atoms, but now they are strings (lists of characters). This transformation was initially implemented to update the tests without much hassle.
Learnt from: ccamel PR: axone-protocol/axoned#769 File: x/logic/predicate/bank_test.go:170-172 Timestamp: 2024-10-08T17:06:13.771Z Learning: In test cases, error messages may involve transformations like `strings.Join(strings.Split(...))` because error messages used to be atoms, but now they are strings (lists of characters). This transformation was initially implemented to update the tests without much hassle.
Learnt from: ccamel PR: axone-protocol/axoned#769 File: x/logic/predicate/bank_test.go:465-466 Timestamp: 2024-10-05T08:52:06.607Z Learning: In the tests in the `x/logic/predicate/bank_test.go` file, setting the Bech32 prefix using `sdk.GetConfig().SetBech32PrefixForAccount` is acceptable, even though it modifies global configuration, because it's part of a third-party library and the team considers this state as shared across all tests.
Learnt from: ccamel PR: axone-protocol/axoned#769 File: x/logic/predicate/bank_test.go:465-466 Timestamp: 2024-10-08T17:06:13.771Z Learning: In the tests in the `x/logic/predicate/bank_test.go` file, setting the Bech32 prefix using `sdk.GetConfig().SetBech32PrefixForAccount` is acceptable, even though it modifies global configuration, because it's part of a third-party library and the team considers this state as shared across all tests.
🔇 Additional comments (7)
x/logic/predicate/encoding_test.go (1)
61-61
: LGTM! Improved error message readability.The simplified error message format is clearer and more direct compared to the previous
strings.Join
approach. This change aligns well with the PR's objective of enhancing test case maintainability.x/logic/predicate/did_test.go (1)
82-82
: LGTM! Error message simplification looks good.The simplified error message format improves readability while maintaining the necessary error information.
Let's verify the consistency of error message formatting across related files:
✅ Verification successful
Error message format is consistent with codebase patterns
The search results confirm that the error message format in the test case follows the established pattern across the codebase:
- Domain errors consistently use the format
error(domain_error(type, value), [message], predicate)
- The simplified error message
[invalid DID]
aligns with similar error messages in other test files- Other DID-related errors in the same file follow the same structure
- The change maintains consistency with error handling patterns in related predicates (uri_encoded, hex_bytes, bank_balances)
The error message simplification is appropriate and maintains the established error formatting conventions throughout the codebase.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for similar error message patterns in other test files # to ensure consistent formatting approach # Search for error message patterns in test files rg -g '*_test.go' 'error\(domain_error\([^)]+\),\[[^\]]+\],'Length of output: 62
Script:
#!/bin/bash # Let's try a broader search pattern to find error message patterns in test files # First, let's look for domain_error patterns rg -g '*_test.go' 'domain_error' -B 1 -A 1 # Also search for wantError patterns in test files to see the general error formatting rg -g '*_test.go' 'wantError.*fmt\.Errorf' -B 1 -A 1Length of output: 21822
x/logic/predicate/uri_test.go (2)
Line range hint
1-200
: LGTM! Test coverage is comprehensive and well-structured.The test suite demonstrates thorough coverage of the
uri_encoded
predicate, including:
- Various URI component types (path, query_value, segment, fragment)
- Special character handling
- Error cases and invalid inputs
- Type checking and variable bindings
170-170
: LGTM! Error message format is now more explicit and informative.The updated error message format provides clearer context by including the specific invalid URL escape sequence. This change aligns well with the PR's objective of improving error message readability.
Let's verify the consistency of error message formats across similar predicates:
✅ Verification successful
The previous command failed because of incorrect glob pattern. Let's try with specific paths and a broader search to understand the error message patterns in the codebase.
The previous search gave us one instance of the domain_error pattern, but we need to see more context from other test files to verify consistency. Let's first locate all test files and then search for error patterns within them.
Error message format is consistent with codebase patterns
The updated error message in
uri_test.go
follows the established error pattern used throughout the codebase:
- It uses the standard
error(error_type(...), [details], predicate/arity)
format- The domain_error pattern is consistently used for encoding errors across different predicates (uri, hex, bech32)
- The error details are consistently enclosed in square brackets
- The predicate reference with arity is always included at the end
The change aligns perfectly with similar error messages found in other predicate tests, particularly matching the pattern seen in
did_test.go
,hex_test.go
, andbank_test.go
for domain-specific encoding errors.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for similar domain_error patterns in test files # Expected: Similar error message patterns in other predicate tests # Search for domain_error patterns in test files rg -A 2 "domain_error\(" "**/*_test.go"Length of output: 94
Script:
#!/bin/bash # Let's try a more precise search for domain_error patterns in test files rg -A 2 "domain_error" "x/logic/predicate/uri_test.go" # Also search for similar error patterns in other test files within the predicate directory rg -A 2 "error\(" "x/logic/predicate/*_test.go"Length of output: 302
Script:
#!/bin/bash # Let's find all test files in the x/logic/predicate directory first fd "_test.go$" x/logic/predicate/ # Then search for error patterns in all test files fd "_test.go$" x/logic/predicate/ -x rg -A 2 "error\("Length of output: 7747
x/logic/predicate/crypto_test.go (2)
207-207
: LGTM! Improved error message readability.The simplified error message format is clearer while maintaining the same semantic meaning.
258-258
: LGTM! Improved error message readability.The simplified error message format is clearer while maintaining the same semantic meaning.
x/logic/predicate/bank_test.go (1)
176-176
: LGTM! Error messages have been simplified effectively.The changes successfully simplify the error messages by removing unnecessary string transformations while maintaining consistency across different test cases. This aligns well with the PR's objective of enhancing readability and maintainability.
Also applies to: 310-310, 454-454
354a3eb
to
602ff84
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅ @@ Coverage Diff @@
## main #795 +/- ##
=======================================
Coverage 42.73% 42.73%
=======================================
Files 111 111
Lines 6273 6273
=======================================
Hits 2681 2681
Misses 3468 3468
Partials 124 124 |
602ff84
to
d0830d1
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.
Great! Thanks so much for your contribution 👍
@panmini Looks like your commits aren’t linked to your github identity, and they’ll need to be signed to go into our codebase. Here’s a quick way to squash everything into one signed commit: # (on your branch)
git reset --soft $(git merge-base main HEAD)
git commit -S -m "test(logic): simplify error messages in test cases"
git push --force This should do the trick! |
782c51c
to
796e96d
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: 0
🧹 Outside diff range and nitpick comments (1)
x/logic/predicate/crypto_test.go (1)
161-164
: LGTM! Consider adding documentation.The introduction of these constants improves code readability by removing inline string manipulations. The naming is clear and descriptive.
Consider adding a brief comment explaining the comma-separated format of these error messages for future maintainers:
const ( + // Error messages are stored as comma-separated characters for compatibility with the error formatting system badPublicKeyLength = "e,d,2,5,5,1,9,:, ,b,a,d, ,p,u,b,l,i,c, ,k,e,y, ,l,e,n,g,t,h,:, ,3,3" failedToParsePublicKey = "f,a,i,l,e,d, ,t,o, ,p,a,r,s,e, ,c,o,m,p,r,e,s,s,e,d, ,p,u,b,l,i,c, ,k,e,y, ,(,f,i,r,s,t, ,1,0, ,b,y,t,e,s,),:, ,0,2,1,3,c,8,4,2,6,b,e,4,7,1,e,5,5,5,0,6" )
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (5)
x/logic/predicate/bank_test.go
(4 hunks)x/logic/predicate/crypto_test.go
(3 hunks)x/logic/predicate/did_test.go
(2 hunks)x/logic/predicate/encoding_test.go
(2 hunks)x/logic/predicate/uri_test.go
(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
- x/logic/predicate/bank_test.go
- x/logic/predicate/did_test.go
- x/logic/predicate/encoding_test.go
- x/logic/predicate/uri_test.go
🔇 Additional comments (2)
x/logic/predicate/crypto_test.go (2)
211-211
: LGTM! Error message constant is properly used.
The usage of badPublicKeyLength
constant in the EdDSA test case improves readability while maintaining the same error validation.
262-262
: LGTM! Error message constant is properly used.
The usage of failedToParsePublicKey
constant in the ECDSA test case improves readability while maintaining the same error validation.
796e96d
to
5882814
Compare
Thanks @panmini ❤️ |
Pull Request: Simplify Error Messages in Test Cases
Description:
This pull request aims to improve the readability and maintainability of the error messages in the test cases.
Changes Made:
Related Issues:
Testing:
Additional Notes:
Summary by CodeRabbit
These changes ensure that error messages are more straightforward, providing better context for users when issues arise.