-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix nil pointer dereference in x/distribution
Before checking Dec's value, one has to ensure the internal big.Int pointer is not nil first. Closes: #5621
- Loading branch information
Alessio Treglia
committed
Feb 7, 2020
1 parent
b0c6c75
commit 4d69262
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func Test_validateAuxFuncs(t *testing.T) { | ||
type args struct { | ||
i interface{} | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantErr bool | ||
}{ | ||
{"wrong type", args{10.5}, true}, | ||
{"nil Int pointer", args{sdk.Dec{}}, true}, | ||
{"negative", args{sdk.NewDec(-1)}, true}, | ||
{"one dec", args{sdk.NewDec(1)}, false}, | ||
{"two dec", args{sdk.NewDec(2)}, true}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
require.Equal(t, tt.wantErr, validateCommunityTax(tt.args.i) != nil) | ||
require.Equal(t, tt.wantErr, validateBaseProposerReward(tt.args.i) != nil) | ||
require.Equal(t, tt.wantErr, validateBonusProposerReward(tt.args.i) != nil) | ||
}) | ||
} | ||
} |