feat: add uint IsNil method (#13381)

This commit is contained in:
Julien Robert 2022-09-25 11:19:50 +02:00 committed by GitHub
parent abdf61e292
commit 55373cb614
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 0 deletions

View File

@ -31,4 +31,5 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased]
* [#13381](https://github.com/cosmos/cosmos-sdk/pull/13381) Add uint `IsNil` method.
* [#12634](https://github.com/cosmos/cosmos-sdk/pull/12634) Move `sdk.Dec` to math package, call it `LegacyDec`.

View File

@ -18,6 +18,11 @@ func (u Uint) BigInt() *big.Int {
return new(big.Int).Set(u.i)
}
// IsNil returns true if Uint is uninitialized
func (u Uint) IsNil() bool {
return u.i == nil
}
// NewUintFromBigUint constructs Uint from big.Uint
func NewUintFromBigInt(i *big.Int) Uint {
u, err := checkNewUint(i)

View File

@ -91,6 +91,11 @@ func (s *uintTestSuite) TestUintPanics() {
s.Require().True(sdkmath.ZeroUint().LTE(sdkmath.OneUint()))
}
func (s *uintTestSuite) TestIsNil() {
s.Require().False(sdkmath.OneUint().IsNil())
s.Require().True(sdkmath.Uint{}.IsNil())
}
func (s *uintTestSuite) TestArithUint() {
for d := 0; d < 1000; d++ {
n1 := uint64(rand.Uint32())