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.
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.Intvalue that is passed as an argument to theNewUintFromBigIntfunction. This is achieved by creating a newbig.Intinstance 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
TestNewUintFromBigIntis well written and covers the expected behavior of theNewUintFromBigIntfunction. It checks both the initial conversion frombig.Inttosdkmath.Uintand the immutability of thesdkmath.Uintinstance when the originalbig.Intis modified. This test will help ensure that theNewUintFromBigIntfunction behaves as expected and does not introduce any unexpected side effects.
There was a problem hiding this comment.
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
TestNewUintFromBigIntis well written and covers the expected behavior of theNewUintFromBigIntfunction. It checks that the originalbig.Intand thesdkmath.Uinthave the same value after conversion, and that modifying the originalbig.Intdoes not affect thesdkmath.Uint. This test ensures that theNewUintFromBigIntfunction does not mutate the originalbig.Intvalue, 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.mdmake lintandmake testReviewers 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
NewUIntFromBigIntfunction to ensure that modifying the input does not affect the returned value, providing a more stable and predictable user experience.RelativePowfunction to return 1 when raising 0 to the power of 0, improving mathematical consistency.ApproxRootfunction to use banker's rounding universally, ensuring more accurate results.NewUintFromBigIntandTestParseUintfunctions, increasing the robustness of our testing suite.