github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/distribution/types/params_test.go (about) 1 package types 2 3 import ( 4 "testing" 5 6 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 7 "github.com/stretchr/testify/require" 8 ) 9 10 const ( 11 strExpected = `Distribution Params: 12 Community Tax: 0.020000000000000000 13 Withdraw Addr Enabled: true 14 Distribution Type: 0 15 Withdraw Reward Enabled: true 16 Reward Truncate Precision: 0` 17 ) 18 19 func TestParams(t *testing.T) { 20 defaultState := DefaultGenesisState() 21 defaultParams := defaultState.Params 22 require.Equal(t, sdk.NewDecWithPrec(2, 2), defaultParams.CommunityTax) 23 require.Equal(t, true, defaultParams.WithdrawAddrEnabled) 24 25 require.Equal(t, strExpected, defaultParams.String()) 26 yamlStr, err := defaultParams.MarshalYAML() 27 require.NoError(t, err) 28 require.Equal(t, strExpected, yamlStr) 29 } 30 31 func Test_validateAuxFuncs(t *testing.T) { 32 type args struct { 33 i interface{} 34 } 35 36 testCases := []struct { 37 name string 38 args args 39 wantErr bool 40 }{ 41 {"wrong type", args{10.5}, true}, 42 {"nil Int pointer", args{sdk.Dec{}}, true}, 43 {"negative", args{sdk.NewDec(-1)}, true}, 44 {"one dec", args{sdk.NewDec(1)}, false}, 45 {"two dec", args{sdk.NewDec(2)}, true}, 46 } 47 48 for _, tc := range testCases { 49 stc := tc 50 51 t.Run(stc.name, func(t *testing.T) { 52 require.Equal(t, stc.wantErr, validateCommunityTax(stc.args.i) != nil) 53 }) 54 } 55 }