Skip to content

Commit

Permalink
fix. params. test vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani committed Oct 16, 2024
1 parent 702afec commit 514efc0
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 107 deletions.
5 changes: 3 additions & 2 deletions x/launch/keeper/msg_update_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ func TestMsgUpdateParams(t *testing.T) {
name: "send enabled param",
input: &types.MsgUpdateParams{
Authority: k.GetAuthority(),
Params: types.Params{},
Params: types.Params{
RevertDelay: types.DefaultRevertDelay,
},
},
},
{
Expand All @@ -49,7 +51,6 @@ func TestMsgUpdateParams(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
_, err := ms.UpdateParams(ctx, tc.input)

if tc.err != nil {
require.Error(t, err)
require.ErrorIs(t, err, tc.err)
Expand Down
33 changes: 2 additions & 31 deletions x/launch/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package types

import (
"errors"
"fmt"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -75,21 +74,13 @@ func (p Params) Validate() error {
if err := validateRevertDelay(p.RevertDelay); err != nil {
return err
}
if err := validateMaxMetadataLength(p.MaxMetadataLength); err != nil {
return err
}
if err := p.ChainCreationFee.Validate(); err != nil {
return err
}
return p.RequestFee.Validate()
}

func validateLaunchTimeRange(i interface{}) error {
v, ok := i.(LaunchTimeRange)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

func validateLaunchTimeRange(v LaunchTimeRange) error {
// it is enough to check that minLaunchTime is positive since it must be that minLaunchTime < maxLaunchTime
if v.MinLaunchTime < 0 {
return errors.New("MinLaunchTime can't be negative")
Expand All @@ -106,12 +97,7 @@ func validateLaunchTimeRange(i interface{}) error {
return nil
}

func validateRevertDelay(i interface{}) error {
v, ok := i.(time.Duration)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

func validateRevertDelay(v time.Duration) error {
if v > MaxParametrableRevertDelay {
return errors.New("max parametrable revert delay reached")
}
Expand All @@ -123,21 +109,6 @@ func validateRevertDelay(i interface{}) error {
return nil
}

func validateRequestFee(i interface{}) error {
v, ok := i.(sdk.Coins)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
return v.Validate()
}

func validateMaxMetadataLength(i interface{}) error {
if _, ok := i.(uint64); !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
return nil
}

func (l *LaunchTimeRange) Equal(cmp *LaunchTimeRange) bool {
switch {
case l.GetMinLaunchTime().Nanoseconds() != cmp.GetMinLaunchTime().Nanoseconds():
Expand Down
35 changes: 5 additions & 30 deletions x/monitoringp/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,7 @@ func (p Params) Validate() error {
}

// validateLastBlockHeight validates last block height
func validateLastBlockHeight(i interface{}) error {
lastBlockHeight, ok := i.(int64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

func validateLastBlockHeight(lastBlockHeight int64) error {
if lastBlockHeight <= 0 {
return errors.New("last block height can't be 0 or negative")
}
Expand All @@ -75,12 +70,7 @@ func validateLastBlockHeight(i interface{}) error {
}

// validateConsumerConsensusState validates consumer consensus state
func validateConsumerConsensusState(i interface{}) error {
ccs, ok := i.(networktypes.ConsensusState)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

func validateConsumerConsensusState(ccs networktypes.ConsensusState) error {
// perform the verification only if the Consumer Consensus State is defined
// TODO: remove this check and set an official Network mainnet consensus state as default
if ccs.Timestamp != "" {
Expand All @@ -96,12 +86,7 @@ func validateConsumerConsensusState(i interface{}) error {
}

// validateConsumerChainID validates consumer chain ID
func validateConsumerChainID(i interface{}) error {
chainID, ok := i.(string)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

func validateConsumerChainID(chainID string) error {
_, _, err := chainid.ParseGenesisChainID(chainID)
if err != nil {
return errors.Wrap(err, "invalid chain ID param")
Expand All @@ -110,12 +95,7 @@ func validateConsumerChainID(i interface{}) error {
}

// validateConsumerUnbondingPeriod validates consumer unbonding period
func validateConsumerUnbondingPeriod(i interface{}) error {
unbondingPeriod, ok := i.(int64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

func validateConsumerUnbondingPeriod(unbondingPeriod int64) error {
if unbondingPeriod < networktypes.MinimalUnbondingPeriod {
return fmt.Errorf("minimal unbonding period is %d", networktypes.MinimalUnbondingPeriod)
}
Expand All @@ -124,12 +104,7 @@ func validateConsumerUnbondingPeriod(i interface{}) error {
}

// validateConsumerRevisionHeight validates consumer revision height
func validateConsumerRevisionHeight(i interface{}) error {
revisionHeight, ok := i.(uint64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

func validateConsumerRevisionHeight(revisionHeight uint64) error {
if revisionHeight == 0 {
return fmt.Errorf("minimal revision height is %d", 1)
}
Expand Down
2 changes: 1 addition & 1 deletion x/participation/keeper/msg_server_participate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func Test_msgServer_Participate(t *testing.T) {
AuctionID: auctionRegistrationPeriodID,
TierID: 1,
},
err: types.ErrInvalidAddress,
err: types.ErrInvalidSigner,
blockTime: validRegistrationTime,
},
{
Expand Down
6 changes: 5 additions & 1 deletion x/participation/keeper/msg_update_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ func TestMsgUpdateParams(t *testing.T) {
name: "send enabled param",
input: &types.MsgUpdateParams{
Authority: k.GetAuthority(),
Params: types.Params{},
Params: types.Params{
AllocationPrice: types.DefaultAllocationPrice,
RegistrationPeriod: types.DefaultRegistrationPeriod,
WithdrawalDelay: types.DefaultWithdrawalDelay,
},
},
},
{
Expand Down
23 changes: 4 additions & 19 deletions x/participation/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,7 @@ func (p Params) Validate() error {
}

// validateAllocationPrice validates the AllocationPrice param
func validateAllocationPrice(v interface{}) error {
allocationPrice, ok := v.(AllocationPrice)
if !ok {
return fmt.Errorf("invalid parameter type: %T", v)
}

func validateAllocationPrice(allocationPrice AllocationPrice) error {
if allocationPrice.Bonded.IsNil() {
return errors.New("value for 'bonded' should be set")
}
Expand All @@ -111,16 +106,11 @@ func validateAllocationPrice(v interface{}) error {
}

// validateParticipationTierList validates the ParticipationTierList param
func validateParticipationTierList(v interface{}) error {
participationTierList, ok := v.([]Tier)
if !ok {
return fmt.Errorf("invalid parameter type: %T", v)
}

func validateParticipationTierList(participationTierList []Tier) error {
tiersIndexMap := make(map[uint64]struct{})
for _, tier := range participationTierList {
// check IDs are unique
if _, ok = tiersIndexMap[tier.TierID]; ok {
if _, ok := tiersIndexMap[tier.TierID]; ok {
return fmt.Errorf("duplicated tier ID: %v", tier.TierID)
}
tiersIndexMap[tier.TierID] = struct{}{}
Expand Down Expand Up @@ -150,12 +140,7 @@ func validateTierBenefits(b TierBenefits) error {
}

// validateTimeDuration validates a time.Duration parameter
func validateTimeDuration(i interface{}) error {
v, ok := i.(time.Duration)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

func validateTimeDuration(v time.Duration) error {
if v <= 0 {
return fmt.Errorf("time frame must be positive")
}
Expand Down
25 changes: 2 additions & 23 deletions x/project/types/params.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package types

import (
"fmt"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -54,36 +52,17 @@ func (p Params) Validate() error {
if err := validateProjectCreationFee(p.ProjectCreationFee); err != nil {
return err
}
if err := validateMaxMetadataLength(p.MaxMetadataLength); err != nil {
return err
}

return p.ProjectCreationFee.Validate()
}

func validateTotalSupplyRange(i interface{}) error {
v, ok := i.(TotalSupplyRange)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
func validateTotalSupplyRange(v TotalSupplyRange) error {
if err := v.ValidateBasic(); err != nil {
return err
}

return nil
}

func validateProjectCreationFee(i interface{}) error {
v, ok := i.(sdk.Coins)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
func validateProjectCreationFee(v sdk.Coins) error {
return v.Validate()
}

func validateMaxMetadataLength(i interface{}) error {
if _, ok := i.(uint64); !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
return nil
}

0 comments on commit 514efc0

Please sign in to comment.