-
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: Handle MAX_INT_256 #9511
fix: Handle MAX_INT_256 #9511
Changes from 8 commits
efe4177
adf73ca
94b91e5
0a80ea9
3f284ea
202ee48
c3492be
161c111
d50db36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,16 +40,16 @@ func (s *intTestSuite) TestFromUint64() { | |
} | ||
|
||
func (s *intTestSuite) TestIntPanic() { | ||
// Max Int = 2^255-1 = 5.789e+76 | ||
// Min Int = -(2^255-1) = -5.789e+76 | ||
s.Require().NotPanics(func() { sdk.NewIntWithDecimal(1, 76) }) | ||
i1 := sdk.NewIntWithDecimal(1, 76) | ||
s.Require().NotPanics(func() { sdk.NewIntWithDecimal(2, 76) }) | ||
i2 := sdk.NewIntWithDecimal(2, 76) | ||
s.Require().NotPanics(func() { sdk.NewIntWithDecimal(3, 76) }) | ||
i3 := sdk.NewIntWithDecimal(3, 76) | ||
|
||
s.Require().Panics(func() { sdk.NewIntWithDecimal(6, 76) }) | ||
// Max Int = 2^256-1 = 1.1579209e+77 | ||
// Min Int = -(2^256-1) = -1.1579209e+77 | ||
s.Require().NotPanics(func() { sdk.NewIntWithDecimal(4, 76) }) | ||
i1 := sdk.NewIntWithDecimal(4, 76) | ||
s.Require().NotPanics(func() { sdk.NewIntWithDecimal(5, 76) }) | ||
i2 := sdk.NewIntWithDecimal(5, 76) | ||
s.Require().NotPanics(func() { sdk.NewIntWithDecimal(6, 76) }) | ||
i3 := sdk.NewIntWithDecimal(6, 76) | ||
|
||
s.Require().Panics(func() { sdk.NewIntWithDecimal(2, 77) }) | ||
s.Require().Panics(func() { sdk.NewIntWithDecimal(9, 80) }) | ||
|
||
// Overflow check | ||
|
@@ -69,7 +69,7 @@ func (s *intTestSuite) TestIntPanic() { | |
s.Require().Panics(func() { i2.Neg().Mul(i2.Neg()) }) | ||
s.Require().Panics(func() { i3.Neg().Mul(i3.Neg()) }) | ||
|
||
// Underflow check | ||
// // Underflow check | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By the way, this is not an underflow
|
||
i3n := i3.Neg() | ||
s.Require().NotPanics(func() { i3n.Sub(i1) }) | ||
s.Require().NotPanics(func() { i3n.Sub(i2) }) | ||
|
@@ -84,7 +84,7 @@ func (s *intTestSuite) TestIntPanic() { | |
s.Require().Panics(func() { i3.Mul(i3.Neg()) }) | ||
|
||
// Bound check | ||
intmax := sdk.NewIntFromBigInt(new(big.Int).Sub(new(big.Int).Exp(big.NewInt(2), big.NewInt(255), nil), big.NewInt(1))) | ||
intmax := sdk.NewIntFromBigInt(new(big.Int).Sub(new(big.Int).Exp(big.NewInt(2), big.NewInt(256), nil), big.NewInt(1))) | ||
intmin := intmax.Neg() | ||
s.Require().NotPanics(func() { intmax.Add(sdk.ZeroInt()) }) | ||
s.Require().NotPanics(func() { intmin.Sub(sdk.ZeroInt()) }) | ||
|
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.
why previously it was 255 instead of 256?