cosmos-sdk/x/params/types/table_test.go

47 lines
1.5 KiB
Go

package types_test
import (
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/x/params/types"
)
func TestKeyTable(t *testing.T) {
table := types.NewKeyTable()
require.Panics(t, func() { table.RegisterType(types.ParamSetPair{[]byte(""), nil, nil}) })
require.Panics(t, func() { table.RegisterType(types.ParamSetPair{[]byte("!@#$%"), nil, nil}) })
require.Panics(t, func() { table.RegisterType(types.ParamSetPair{[]byte("hello,"), nil, nil}) })
require.Panics(t, func() { table.RegisterType(types.ParamSetPair{[]byte("hello"), nil, nil}) })
require.NotPanics(t, func() {
table.RegisterType(types.ParamSetPair{keyBondDenom, string("stake"), validateBondDenom})
})
require.NotPanics(t, func() {
table.RegisterType(types.ParamSetPair{keyMaxValidators, uint16(100), validateMaxValidators})
})
require.Panics(t, func() {
table.RegisterType(types.ParamSetPair{keyUnbondingTime, time.Duration(1), nil})
})
require.NotPanics(t, func() {
table.RegisterType(types.ParamSetPair{keyUnbondingTime, time.Duration(1), validateMaxValidators})
})
require.NotPanics(t, func() {
newTable := types.NewKeyTable()
newTable.RegisterParamSet(&params{})
})
require.Panics(t, func() { table.RegisterParamSet(&params{}) })
require.Panics(t, func() { types.NewKeyTable(types.ParamSetPair{[]byte(""), nil, nil}) })
require.NotPanics(t, func() {
types.NewKeyTable(
types.ParamSetPair{[]byte("test"), string("stake"), validateBondDenom},
types.ParamSetPair{[]byte("test2"), uint16(100), validateMaxValidators},
)
})
}