@@ -2,6 +2,7 @@ package v3
22
33import (
44 "errors"
5+ "fmt"
56 "time"
67
78 "cosmossdk.io/math"
@@ -21,31 +22,31 @@ var (
2122// Validate checks whether the Params fields are valid according to defined rules.
2223func (m * Params ) Validate () error {
2324 if err := validateMaxGigabytes (m .MaxGigabytes ); err != nil {
24- return err
25+ return fmt . Errorf ( "invalid max_gigabytes: %w" , err )
2526 }
2627
2728 if err := validateMinGigabytes (m .MinGigabytes ); err != nil {
28- return err
29+ return fmt . Errorf ( "invalid min_gigabytes: %w" , err )
2930 }
3031
3132 if err := validateMaxHours (m .MaxHours ); err != nil {
32- return err
33+ return fmt . Errorf ( "invalid max_hours: %w" , err )
3334 }
3435
3536 if err := validateMinHours (m .MinHours ); err != nil {
36- return err
37+ return fmt . Errorf ( "invalid min_hours: %w" , err )
3738 }
3839
3940 if err := validateProofVerificationEnabled (m .ProofVerificationEnabled ); err != nil {
40- return err
41+ return fmt . Errorf ( "invalid proof_verification_enabled: %w" , err )
4142 }
4243
4344 if err := validateStakingShare (m .StakingShare ); err != nil {
44- return err
45+ return fmt . Errorf ( "invalid staking_share: %w" , err )
4546 }
4647
4748 if err := validateStatusChangeDelay (m .StatusChangeDelay ); err != nil {
48- return err
49+ return fmt . Errorf ( "invalid status_change_delay: %w" , err )
4950 }
5051
5152 return nil
@@ -82,51 +83,51 @@ func DefaultParams() Params {
8283
8384// validateMaxGigabytes ensures maxGigabytes is a positive non-zero integer.
8485func validateMaxGigabytes (v int64 ) error {
85- if v < 0 {
86- return errors .New ("max_gigabytes cannot be negative " )
86+ if v == 0 {
87+ return errors .New ("value cannot be zero " )
8788 }
8889
89- if v == 0 {
90- return errors .New ("max_gigabytes cannot be zero " )
90+ if v < 0 {
91+ return errors .New ("value cannot be negative " )
9192 }
9293
9394 return nil
9495}
9596
9697// validateMinGigabytes ensures minGigabytes is a positive non-zero integer.
9798func validateMinGigabytes (v int64 ) error {
98- if v < 0 {
99- return errors .New ("min_gigabytes cannot be negative " )
99+ if v == 0 {
100+ return errors .New ("value cannot be zero " )
100101 }
101102
102- if v == 0 {
103- return errors .New ("min_gigabytes cannot be zero " )
103+ if v < 0 {
104+ return errors .New ("value cannot be negative " )
104105 }
105106
106107 return nil
107108}
108109
109110// validateMaxHours ensures maxHours is a positive non-zero integer.
110111func validateMaxHours (v int64 ) error {
111- if v < 0 {
112- return errors .New ("max_hours cannot be negative " )
112+ if v == 0 {
113+ return errors .New ("value cannot be zero " )
113114 }
114115
115- if v == 0 {
116- return errors .New ("max_hours cannot be zero " )
116+ if v < 0 {
117+ return errors .New ("value cannot be negative " )
117118 }
118119
119120 return nil
120121}
121122
122123// validateMinHours ensures minHours is a positive non-zero integer.
123124func validateMinHours (v int64 ) error {
124- if v < 0 {
125- return errors .New ("min_hours cannot be negative " )
125+ if v == 0 {
126+ return errors .New ("value cannot be zero " )
126127 }
127128
128- if v == 0 {
129- return errors .New ("min_hours cannot be zero " )
129+ if v < 0 {
130+ return errors .New ("value cannot be negative " )
130131 }
131132
132133 return nil
@@ -141,28 +142,28 @@ func validateProofVerificationEnabled(v bool) error {
141142// validateStakingShare ensures stakingShare is not nil, not negative, and ≤ 1.
142143func validateStakingShare (v math.LegacyDec ) error {
143144 if v .IsNil () {
144- return errors .New ("staking_share cannot be nil" )
145+ return errors .New ("value cannot be nil" )
145146 }
146147
147148 if v .IsNegative () {
148- return errors .New ("staking_share cannot be negative" )
149+ return errors .New ("value cannot be negative" )
149150 }
150151
151152 if v .GT (math .LegacyOneDec ()) {
152- return errors .New ("staking_share cannot be greater than 1" )
153+ return errors .New ("value cannot be greater than 1" )
153154 }
154155
155156 return nil
156157}
157158
158159// validateStatusChangeDelay ensures the delay is positive and non-zero.
159160func validateStatusChangeDelay (v time.Duration ) error {
160- if v < 0 {
161- return errors .New ("status_change_delay cannot be negative " )
161+ if v == 0 {
162+ return errors .New ("value cannot be zero " )
162163 }
163164
164- if v == 0 {
165- return errors .New ("status_change_delay cannot be zero " )
165+ if v < 0 {
166+ return errors .New ("value cannot be negative " )
166167 }
167168
168169 return nil
0 commit comments