-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
x/distribution: fix module's parameters validation (#8918)
* x/distribution: fix module's parameters validation closes: #8914 * Update x/distribution/types/params.go Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> * Update x/distribution/types/params_internal_test.go Co-authored-by: Robert Zaremba <robert@zaremba.ch> Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Robert Zaremba <robert@zaremba.ch>
- Loading branch information
1 parent
0c2d4a8
commit 1fddce7
Showing
4 changed files
with
70 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
package types | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/distribution/types" | ||
) | ||
|
||
func TestValidateGenesis(t *testing.T) { | ||
|
||
fp := InitialFeePool() | ||
fp := types.InitialFeePool() | ||
require.Nil(t, fp.ValidateGenesis()) | ||
|
||
fp2 := FeePool{CommunityPool: sdk.DecCoins{{Denom: "stake", Amount: sdk.NewDec(-1)}}} | ||
fp2 := types.FeePool{CommunityPool: sdk.DecCoins{{Denom: "stake", Amount: sdk.NewDec(-1)}}} | ||
require.NotNil(t, fp2.ValidateGenesis()) | ||
|
||
} |
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,34 @@ | ||
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}, | ||
{"empty sdk.Dec", 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 { | ||
tt := tt | ||
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) | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,34 +1,49 @@ | ||
package types | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/distribution/types" | ||
) | ||
|
||
func Test_validateAuxFuncs(t *testing.T) { | ||
type args struct { | ||
i interface{} | ||
func TestParams_ValidateBasic(t *testing.T) { | ||
toDec := sdk.MustNewDecFromStr | ||
|
||
type fields struct { | ||
CommunityTax sdk.Dec | ||
BaseProposerReward sdk.Dec | ||
BonusProposerReward sdk.Dec | ||
WithdrawAddrEnabled bool | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
fields fields | ||
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}, | ||
{"success", fields{toDec("0.1"), toDec("0.5"), toDec("0.4"), false}, false}, | ||
{"negative community tax", fields{toDec("-0.1"), toDec("0.5"), toDec("0.4"), false}, true}, | ||
{"negative base proposer reward", fields{toDec("0.1"), toDec("-0.5"), toDec("0.4"), false}, true}, | ||
{"negative bonus proposer reward", fields{toDec("0.1"), toDec("0.5"), toDec("-0.4"), false}, true}, | ||
{"total sum greater than 1", fields{toDec("0.2"), toDec("0.5"), toDec("0.4"), false}, true}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
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) | ||
p := types.Params{ | ||
CommunityTax: tt.fields.CommunityTax, | ||
BaseProposerReward: tt.fields.BaseProposerReward, | ||
BonusProposerReward: tt.fields.BonusProposerReward, | ||
WithdrawAddrEnabled: tt.fields.WithdrawAddrEnabled, | ||
} | ||
if err := p.ValidateBasic(); (err != nil) != tt.wantErr { | ||
t.Errorf("ValidateBasic() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestDefaultParams(t *testing.T) { | ||
require.NoError(t, types.DefaultParams().ValidateBasic()) | ||
} |