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 #1323

Merged
merged 3 commits into from
Mar 28, 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 @@ -72,6 +72,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 124 in x/mint/types/params.go

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L123 - L124 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 142 in x/mint/types/params.go

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L141 - L142 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 160 in x/mint/types/params.go

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L159 - L160 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 178 in x/mint/types/params.go

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L177 - L178 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 89 in x/slashing/types/params.go

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L88 - L89 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 120 in x/slashing/types/params.go

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L119 - L120 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 138 in x/slashing/types/params.go

View check run for this annotation

Codecov / codecov/patch

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

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