-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
fix(x/tx/amino): special case for string represented decimals #22161
Conversation
📝 WalkthroughWalkthroughThe pull request introduces several enhancements to the testing framework and encoding logic within the aminojson package. A new test case is added to verify the JSON output equivalence between legacy and new encoders for governance parameters. Modifications include improved error handling in the encoder and updates to comments for clarity. Additionally, a new constant is defined, and function names are adjusted for consistency. Overall, these changes aim to refine the encoder's functionality and enhance test coverage. Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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
🧹 Outside diff range and nitpick comments (1)
tests/integration/tx/aminojson/aminojson_test.go (1)
261-265
: LGTM! Consider adding more test cases for governance parameters.The addition of the "gov/v1_params" test case is a good improvement to ensure parity between legacy and new amino JSON encoders for governance parameters. It specifically tests the encoding of the
Quorum
field with a decimal value.Consider adding more test cases with different
gov_v1_types.Params
fields to ensure comprehensive coverage of governance parameter encoding. For example, you could include cases forVotingPeriod
,MinDepositDenom
, and other relevant fields.
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
📒 Files selected for processing (4)
- tests/integration/tx/aminojson/aminojson_test.go (1 hunks)
- x/tx/signing/aminojson/encoder.go (2 hunks)
- x/tx/signing/aminojson/json_marshal.go (3 hunks)
- x/tx/signing/aminojson/options.go (3 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
tests/integration/tx/aminojson/aminojson_test.go (3)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Pattern
tests/**/*
: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"
Pattern
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"x/tx/signing/aminojson/encoder.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.x/tx/signing/aminojson/json_marshal.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.x/tx/signing/aminojson/options.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
🔇 Additional comments (6)
x/tx/signing/aminojson/encoder.go (3)
46-47
: Improved function comment accuracyThe updated comment now correctly reflects that this encoder only handles
cosmos.Dec
types, removing the mention ofcosmos.Int
. This change improves the accuracy of the documentation.
57-57
: Enhanced error handling for better debuggingThe error message has been improved to include the problematic string value, which will make debugging easier. This change follows best practices for error handling in Go.
Line range hint
46-57
: Summary of changes tocosmosDecEncoder
The modifications to
cosmosDecEncoder
improve both documentation accuracy and error handling:
- The function comment now correctly specifies that it only handles
cosmos.Dec
types.- Error handling for string unmarshalling has been enhanced, providing more context for debugging.
These changes align with the PR objectives and improve the overall code quality. The implementation adheres to the Uber Go Style Guide and maintains the existing logic of the function.
x/tx/signing/aminojson/json_marshal.go (3)
19-20
: LGTM: Good addition of a constant for "cosmos.Dec"The introduction of the
cosmosDecType
constant improves code maintainability and readability. It centralizes the string value "cosmos.Dec", making it easier to update if needed in the future.
73-74
: LGTM: Proper usage of the new constantThe replacement of the hardcoded string "cosmos.Dec" with the
cosmosDecType
constant is a good practice. It improves code consistency and makes future updates easier.
371-371
: LGTM: Improved method naming, verify usageThe renaming of
getFieldEncoding
togetFieldEncoder
enhances code clarity and maintains consistency with other "encoder" terminology in the file. This change improves the overall readability of the code.Please ensure that all calls to this method have been updated throughout the codebase. Run the following script to verify:
✅ Verification successful
LGTM: Improved method naming, usage verified
The renaming of
getFieldEncoding
togetFieldEncoder
has been successfully verified. No references togetFieldEncoding
remain, andgetFieldEncoder
is consistently used throughout the codebase.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for any remaining usage of getFieldEncoding method # Test: Search for getFieldEncoding. Expect: No results rg --type go 'getFieldEncoding' # Test: Confirm getFieldEncoder is now used. Expect: At least one result rg --type go 'getFieldEncoder'Length of output: 278
@@ -110,6 +122,18 @@ func (enc Encoder) getFieldEncoding(field protoreflect.FieldDescriptor) FieldEnc | |||
} | |||
if proto.HasExtension(opts, cosmos_proto.E_Scalar) { | |||
scalar := proto.GetExtension(opts, cosmos_proto.E_Scalar).(string) | |||
// do not handle encoding of fields tagged only with scalar which are not backed by a | |||
// LegacyDec custom type. This types are handled by the default encoding, as they are |
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.
Fix grammatical error in comment
There's a typo in the comment on line 126. The word "This" should be "These" to correct the grammatical error.
Apply this diff to fix the typo:
- // This types are handled by the default encoding, as they are
+ // These types are handled by the default encoding, as they are
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
// LegacyDec custom type. This types are handled by the default encoding, as they are | |
// LegacyDec custom type. These types are handled by the default encoding, as they are |
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.
nice, tACK
Description
Ref: #21853, #20935
Types which are flagged as
cosmos.Dec
but ARE NOT represented by a LegacyDec need special casing.Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.
I have...
Summary by CodeRabbit
New Features
cosmos.Dec
to improve code clarity and maintainability.Bug Fixes
cosmos.Dec
types.Documentation
Refactor