github.com/cosmos/cosmos-sdk@v0.50.10/x/distribution/types/params_test.go (about) 1 package types_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 8 sdkmath "cosmossdk.io/math" 9 10 "github.com/cosmos/cosmos-sdk/x/distribution/types" 11 ) 12 13 func TestParams_ValidateBasic(t *testing.T) { 14 toDec := sdkmath.LegacyMustNewDecFromStr 15 16 type fields struct { 17 CommunityTax sdkmath.LegacyDec 18 BaseProposerReward sdkmath.LegacyDec 19 BonusProposerReward sdkmath.LegacyDec 20 WithdrawAddrEnabled bool 21 } 22 tests := []struct { 23 name string 24 fields fields 25 wantErr bool 26 }{ 27 {"success", fields{toDec("0.1"), toDec("0"), toDec("0"), false}, false}, 28 {"negative community tax", fields{toDec("-0.1"), toDec("0"), toDec("0"), false}, true}, 29 {"negative base proposer reward (must not matter)", fields{toDec("0.1"), toDec("0"), toDec("-0.1"), false}, false}, 30 {"negative bonus proposer reward (must not matter)", fields{toDec("0.1"), toDec("0"), toDec("-0.1"), false}, false}, 31 {"total sum greater than 1 (must not matter)", fields{toDec("0.2"), toDec("0.5"), toDec("0.4"), false}, false}, 32 {"community tax greater than 1", fields{toDec("1.1"), toDec("0"), toDec("0"), false}, true}, 33 {"community tax nil", fields{sdkmath.LegacyDec{}, toDec("0"), toDec("0"), false}, true}, 34 } 35 for _, tt := range tests { 36 t.Run(tt.name, func(t *testing.T) { 37 p := types.Params{ 38 CommunityTax: tt.fields.CommunityTax, 39 WithdrawAddrEnabled: tt.fields.WithdrawAddrEnabled, 40 } 41 if err := p.ValidateBasic(); (err != nil) != tt.wantErr { 42 t.Errorf("ValidateBasic() error = %v, wantErr %v", err, tt.wantErr) 43 } 44 }) 45 } 46 } 47 48 func TestDefaultParams(t *testing.T) { 49 require.NoError(t, types.DefaultParams().ValidateBasic()) 50 }