-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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(math): NewUintFromBigInt argument mutation #18214
Conversation
WalkthroughThe changes primarily focus on enhancing the robustness and correctness of the Changes
TipsChat with CodeRabbit Bot (
|
This comment has been minimized.
This comment has been minimized.
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- math/uint.go (1 hunks)
- math/uint_test.go (1 hunks)
Additional comments (Suppressed): 2
math/uint.go (1)
- 238-239: The change here is to prevent mutation of the original
big.Int
value that is passed as an argument to theNewUintFromBigInt
function. This is achieved by creating a newbig.Int
instance and setting its value to the input argument. This is a good practice as it ensures that the function does not have any side effects on its input arguments.- return Uint{i}, nil + return Uint{new(big.Int).Set(i)}, nilmath/uint_test.go (1)
- 264-272: The new test
TestNewUintFromBigInt
is well written and covers the expected behavior of theNewUintFromBigInt
function. It checks both the initial conversion frombig.Int
tosdkmath.Uint
and the immutability of thesdkmath.Uint
instance when the originalbig.Int
is modified. This test will help ensure that theNewUintFromBigInt
function behaves as expected and does not introduce any unexpected side effects.
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- math/CHANGELOG.md (1 hunks)
- math/uint.go (1 hunks)
Files skipped from review due to trivial changes (1)
- math/uint.go
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (3)
- math/CHANGELOG.md (1 hunks)
- math/uint.go (1 hunks)
- math/uint_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
- math/uint.go
Additional comments (Suppressed): 1
math/uint_test.go (1)
- 264-272: The new test
TestNewUintFromBigInt
is well written and covers the expected behavior of theNewUintFromBigInt
function. It checks that the originalbig.Int
and thesdkmath.Uint
have the same value after conversion, and that modifying the originalbig.Int
does not affect thesdkmath.Uint
. This test ensures that theNewUintFromBigInt
function does not mutate the originalbig.Int
value, which is a crucial aspect of its functionality.
(cherry picked from commit bbf2faa) # Conflicts: # math/CHANGELOG.md
(cherry picked from commit bbf2faa) # Conflicts: # math/CHANGELOG.md
… feature/v.0.47.x-ics-lsm branch (cosmos#19293)
Description
same as #17352 but for NewUintFromBigInt
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...
!
to the type prefix if API or client breaking changeCHANGELOG.md
make lint
andmake test
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.
I have...
!
in the type prefix if API or client breaking changeSummary by CodeRabbit
NewUIntFromBigInt
function to ensure that modifying the input does not affect the returned value, providing a more stable and predictable user experience.RelativePow
function to return 1 when raising 0 to the power of 0, improving mathematical consistency.ApproxRoot
function to use banker's rounding universally, ensuring more accurate results.NewUintFromBigInt
andTestParseUint
functions, increasing the robustness of our testing suite.