github.com/cosmos/cosmos-sdk@v0.50.10/x/params/types/common_test.go (about) 1 package types_test 2 3 import ( 4 "errors" 5 "fmt" 6 "time" 7 8 storetypes "cosmossdk.io/store/types" 9 10 "github.com/cosmos/cosmos-sdk/x/params/types" 11 ) 12 13 var ( 14 keyUnbondingTime = []byte("UnbondingTime") 15 keyMaxValidators = []byte("MaxValidators") 16 keyBondDenom = []byte("BondDenom") 17 keyMaxRedelegationEntries = []byte("MaxRedelegationEntries") 18 19 key = storetypes.NewKVStoreKey("storekey") 20 tkey = storetypes.NewTransientStoreKey("transientstorekey") 21 ) 22 23 type params struct { 24 UnbondingTime time.Duration `json:"unbonding_time" yaml:"unbonding_time"` 25 MaxValidators uint16 `json:"max_validators" yaml:"max_validators"` 26 BondDenom string `json:"bond_denom" yaml:"bond_denom"` 27 } 28 29 type paramsV2 struct { 30 UnbondingTime time.Duration `json:"unbonding_time" yaml:"unbonding_time"` 31 MaxValidators uint16 `json:"max_validators" yaml:"max_validators"` 32 BondDenom string `json:"bond_denom" yaml:"bond_denom"` 33 MaxRedelegationEntries uint32 `json:"max_redelegation_entries" yaml:"max_redelegation_entries"` 34 } 35 36 func validateUnbondingTime(i interface{}) error { 37 v, ok := i.(time.Duration) 38 if !ok { 39 return fmt.Errorf("invalid parameter type: %T", i) 40 } 41 42 if v < (24 * time.Hour) { 43 return fmt.Errorf("unbonding time must be at least one day") 44 } 45 46 return nil 47 } 48 49 func validateMaxValidators(i interface{}) error { 50 _, ok := i.(uint16) 51 if !ok { 52 return fmt.Errorf("invalid parameter type: %T", i) 53 } 54 55 return nil 56 } 57 58 func validateBondDenom(i interface{}) error { 59 v, ok := i.(string) 60 if !ok { 61 return fmt.Errorf("invalid parameter type: %T", i) 62 } 63 64 if len(v) == 0 { 65 return errors.New("denom cannot be empty") 66 } 67 68 return nil 69 } 70 71 func validateMaxRedelegationEntries(i interface{}) error { 72 _, ok := i.(uint32) 73 if !ok { 74 return fmt.Errorf("invalid parameter type: %T", i) 75 } 76 77 return nil 78 } 79 80 func (p *params) ParamSetPairs() types.ParamSetPairs { 81 return types.ParamSetPairs{ 82 {keyUnbondingTime, &p.UnbondingTime, validateUnbondingTime}, 83 {keyMaxValidators, &p.MaxValidators, validateMaxValidators}, 84 {keyBondDenom, &p.BondDenom, validateBondDenom}, 85 } 86 } 87 88 func (p *paramsV2) ParamSetPairs() types.ParamSetPairs { 89 return types.ParamSetPairs{ 90 {keyUnbondingTime, &p.UnbondingTime, validateUnbondingTime}, 91 {keyMaxValidators, &p.MaxValidators, validateMaxValidators}, 92 {keyBondDenom, &p.BondDenom, validateBondDenom}, 93 {keyMaxRedelegationEntries, &p.MaxRedelegationEntries, validateMaxRedelegationEntries}, 94 } 95 } 96 97 func paramKeyTable() types.KeyTable { 98 return types.NewKeyTable().RegisterParamSet(¶ms{}) 99 }