github.com/Finschia/finschia-sdk@v0.48.1/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 sdk "github.com/Finschia/finschia-sdk/types" 9 "github.com/Finschia/finschia-sdk/x/distribution/types" 10 ) 11 12 func TestParams_ValidateBasic(t *testing.T) { 13 toDec := sdk.MustNewDecFromStr 14 15 type fields struct { 16 CommunityTax sdk.Dec 17 BaseProposerReward sdk.Dec 18 BonusProposerReward sdk.Dec 19 WithdrawAddrEnabled bool 20 } 21 tests := []struct { 22 name string 23 fields fields 24 wantErr bool 25 }{ 26 {"success", fields{toDec("0.1"), toDec("0.5"), toDec("0.4"), false}, false}, 27 {"negative community tax", fields{toDec("-0.1"), toDec("0.5"), toDec("0.4"), false}, true}, 28 {"negative base proposer reward", fields{toDec("0.1"), toDec("-0.5"), toDec("0.4"), false}, true}, 29 {"negative bonus proposer reward", fields{toDec("0.1"), toDec("0.5"), toDec("-0.4"), false}, true}, 30 {"total sum greater than 1", fields{toDec("0.2"), toDec("0.5"), toDec("0.4"), false}, true}, 31 } 32 for _, tt := range tests { 33 t.Run(tt.name, func(t *testing.T) { 34 p := types.Params{ 35 CommunityTax: tt.fields.CommunityTax, 36 BaseProposerReward: tt.fields.BaseProposerReward, 37 BonusProposerReward: tt.fields.BonusProposerReward, 38 WithdrawAddrEnabled: tt.fields.WithdrawAddrEnabled, 39 } 40 if err := p.ValidateBasic(); (err != nil) != tt.wantErr { 41 t.Errorf("ValidateBasic() error = %v, wantErr %v", err, tt.wantErr) 42 } 43 }) 44 } 45 } 46 47 func TestDefaultParams(t *testing.T) { 48 require.NoError(t, types.DefaultParams().ValidateBasic()) 49 }