github.com/Finschia/finschia-sdk@v0.48.1/x/params/types/table_test.go (about) 1 package types_test 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/stretchr/testify/require" 8 9 "github.com/Finschia/finschia-sdk/x/params/types" 10 ) 11 12 func TestKeyTable(t *testing.T) { 13 table := types.NewKeyTable() 14 15 require.Panics(t, func() { table.RegisterType(types.ParamSetPair{[]byte(""), nil, nil}) }) 16 require.Panics(t, func() { table.RegisterType(types.ParamSetPair{[]byte("!@#$%"), nil, nil}) }) 17 require.Panics(t, func() { table.RegisterType(types.ParamSetPair{[]byte("hello,"), nil, nil}) }) 18 require.Panics(t, func() { table.RegisterType(types.ParamSetPair{[]byte("hello"), nil, nil}) }) 19 20 require.NotPanics(t, func() { 21 table.RegisterType(types.ParamSetPair{keyBondDenom, string("stake"), validateBondDenom}) 22 }) 23 require.NotPanics(t, func() { 24 table.RegisterType(types.ParamSetPair{keyMaxValidators, uint16(100), validateMaxValidators}) 25 }) 26 require.Panics(t, func() { 27 table.RegisterType(types.ParamSetPair{keyUnbondingTime, time.Duration(1), nil}) 28 }) 29 require.NotPanics(t, func() { 30 table.RegisterType(types.ParamSetPair{keyUnbondingTime, time.Duration(1), validateMaxValidators}) 31 }) 32 require.NotPanics(t, func() { 33 newTable := types.NewKeyTable() 34 newTable.RegisterParamSet(¶ms{}) 35 }) 36 37 require.Panics(t, func() { table.RegisterParamSet(¶ms{}) }) 38 require.Panics(t, func() { types.NewKeyTable(types.ParamSetPair{[]byte(""), nil, nil}) }) 39 40 require.NotPanics(t, func() { 41 types.NewKeyTable( 42 types.ParamSetPair{[]byte("test"), string("stake"), validateBondDenom}, 43 types.ParamSetPair{[]byte("test2"), uint16(100), validateMaxValidators}, 44 ) 45 }) 46 }