Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update param validation to fail on nil dec (backport #1323) #1325

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (types) [\#1313](https://github.com/Finschia/finschia-sdk/pull/1313) fix correctly coalesce coins even with repeated denominations(backport cosmos/cosmos-sdk#13265)
* (x/crypto) [\#1316](https://github.com/Finschia/finschia-sdk/pull/1316) error if incorrect ledger public key (backport cosmos/cosmos-sdk#14460, cosmos/cosmos-sdk#19691)
* (x/auth) [#1319](https://github.com/Finschia/finschia-sdk/pull/1319) prevent signing from wrong key in multisig
* (x/mint, x/slashing) [\#1323](https://github.com/Finschia/finschia-sdk/pull/1323) add missing nil check for params validation

### Removed

Expand Down
18 changes: 13 additions & 5 deletions x/mint/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"fmt"
"strings"

yaml "gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"

sdk "github.com/Finschia/finschia-sdk/types"
paramtypes "github.com/Finschia/finschia-sdk/x/params/types"
Expand Down Expand Up @@ -120,7 +120,9 @@
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNil() {
return fmt.Errorf("inflation rate change cannot be nil: %s", v)
}

Check warning on line 125 in x/mint/types/params.go

View check run for this annotation

Codecov / codecov/patch

x/mint/types/params.go#L123-L125

Added lines #L123 - L125 were not covered by tests
if v.IsNegative() {
return fmt.Errorf("inflation rate change cannot be negative: %s", v)
}
Expand All @@ -136,7 +138,9 @@
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNil() {
return fmt.Errorf("max inflation cannot be nil: %s", v)
}

Check warning on line 143 in x/mint/types/params.go

View check run for this annotation

Codecov / codecov/patch

x/mint/types/params.go#L141-L143

Added lines #L141 - L143 were not covered by tests
if v.IsNegative() {
return fmt.Errorf("max inflation cannot be negative: %s", v)
}
Expand All @@ -152,7 +156,9 @@
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNil() {
return fmt.Errorf("min inflation cannot be nil: %s", v)
}

Check warning on line 161 in x/mint/types/params.go

View check run for this annotation

Codecov / codecov/patch

x/mint/types/params.go#L159-L161

Added lines #L159 - L161 were not covered by tests
if v.IsNegative() {
return fmt.Errorf("min inflation cannot be negative: %s", v)
}
Expand All @@ -168,7 +174,9 @@
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNil() {
return fmt.Errorf("goal bonded cannot be nil: %s", v)
}

Check warning on line 179 in x/mint/types/params.go

View check run for this annotation

Codecov / codecov/patch

x/mint/types/params.go#L177-L179

Added lines #L177 - L179 were not covered by tests
if v.IsNegative() || v.IsZero() {
return fmt.Errorf("goal bonded must be positive: %s", v)
}
Expand Down
12 changes: 9 additions & 3 deletions x/slashing/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNil() {
return fmt.Errorf("min signed per window cannot be nil: %s", v)
}

Check warning on line 90 in x/slashing/types/params.go

View check run for this annotation

Codecov / codecov/patch

x/slashing/types/params.go#L88-L90

Added lines #L88 - L90 were not covered by tests
if v.IsNegative() {
return fmt.Errorf("min signed per window cannot be negative: %s", v)
}
Expand Down Expand Up @@ -114,7 +116,9 @@
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNil() {
return fmt.Errorf("double sign slash fraction cannot be nil: %s", v)
}

Check warning on line 121 in x/slashing/types/params.go

View check run for this annotation

Codecov / codecov/patch

x/slashing/types/params.go#L119-L121

Added lines #L119 - L121 were not covered by tests
if v.IsNegative() {
return fmt.Errorf("double sign slash fraction cannot be negative: %s", v)
}
Expand All @@ -130,7 +134,9 @@
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNil() {
return fmt.Errorf("downtime slash fraction cannot be nil: %s", v)
}

Check warning on line 139 in x/slashing/types/params.go

View check run for this annotation

Codecov / codecov/patch

x/slashing/types/params.go#L137-L139

Added lines #L137 - L139 were not covered by tests
if v.IsNegative() {
return fmt.Errorf("downtime slash fraction cannot be negative: %s", v)
}
Expand Down
Loading