-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Unsigned conversion #2111 #2123
Unsigned conversion #2111 #2123
Conversation
- Update SafeCastMock - Add tests for SafeCast int256 to uint256
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.
Thanks a lot for your contribution @pepelu! I left some minor comments on the code.
About the tests, I noticed you copied the approach from the tests for the other functions. I think we could go with something much simpler: have a single describe
block for toUint256
and then test some simple cases, like:
- 0
- 1
- -1
- MAX_UINT256
- MIN_INT256
What do you think?
Apply suggestions from code review. Co-Authored-By: Nicolás Venturo <nicolas.venturo@gmail.com>
I completely agree with your updates. I'll look now into the tests. |
I can also add the inverse (unsigned to signed). I wanted to do just one first to see if everything was ok. |
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.
The new tests look great, thanks a lot @pepelu!
I'd say it makes sense to also have the inverse operation, yet. I'd suggest similar values for the tests:
- 0
- 1
- MAX_INT256
- MAX_INT256 + 1
- MAX_UINT256
- Change "downcasts" to "casts" - Move test closer to its function
- Add function - Add mock - Add test
- Update error in conversion to be more clear - Update constants in test to be powers of 2 instead of shifts
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.
Looks great @pepelu, thanks a lot! I added a changelog entry and left two small comments, once those are addressed we'll be ready to merge this!
- Add minus in INT256_MIN for clarity Co-Authored-By: Nicolás Venturo <nicolas.venturo@gmail.com>
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.
Thanks a lot for the hard work @pepelu!
Thanks for your guidance in my first PR @nventuro! |
Fixes #2111
Add signed to unsigned conversion to SafeCast and its corresponding tests.