Skip to content

Commit

Permalink
chore: improve validation of pool proposals (backport #74) (#94)
Browse files Browse the repository at this point in the history
Co-authored-by: Troy Kessler <[email protected]>
  • Loading branch information
mergify[bot] and troykessler authored Jun 14, 2023
1 parent 3567b4e commit adf2448
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
### Improvements

- (`x/bundles`) [#62](https://github.com/KYVENetwork/chain/pull/62) Payout storage cost directly to the bundle uploader.
- (`x/pool`) [#74](https://github.com/KYVENetwork/chain/pull/74) Improve parameter validation in pool proposals.
- (`x/stakers`) [#46](https://github.com/KYVENetwork/chain/pull/46) Allow protocol validator commission rewards to be claimed.

### Client Breaking
Expand Down
25 changes: 2 additions & 23 deletions x/pool/keeper/msg_server_update_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,33 +322,12 @@ var _ = Describe("msg_server_update_pool.go", Ordered, func() {
Expect(pool.Name).To(BeEmpty())
})

It("Update pool with invalid UploadInterval", func() {
// ARRANGE
msg := &types.MsgUpdatePool{
Authority: gov,
Id: 1,
Payload: "{\"UploadInterval\": 0}",
}

p, _ := BuildGovernanceTxs(s, []sdk.Msg{msg})

// ACT
_ = s.RunTxError(&p)
s.Commit()

// ASSERT
pool, found := s.App().PoolKeeper.GetPool(s.Ctx(), 0)

Expect(found).To(BeTrue())
Expect(pool.Name).To(BeEmpty())
})

It("Update pool with invalid OperatingCost", func() {
// ARRANGE
msg := &types.MsgUpdatePool{
Authority: gov,
Id: 1,
Payload: "{\"OperatingCost\": 0}",
Payload: "{\"OperatingCost\": -1}",
}

p, _ := BuildGovernanceTxs(s, []sdk.Msg{msg})
Expand All @@ -369,7 +348,7 @@ var _ = Describe("msg_server_update_pool.go", Ordered, func() {
msg := &types.MsgUpdatePool{
Authority: gov,
Id: 1,
Payload: "{\"MinDelegation\": 0}",
Payload: "{\"MinDelegation\": -1}",
}

p, _ := BuildGovernanceTxs(s, []sdk.Msg{msg})
Expand Down
18 changes: 14 additions & 4 deletions x/pool/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ func (msg *MsgCreatePool) ValidateBasic() error {
return errors.Wrapf(errorsTypes.ErrInvalidRequest, "invalid upload interval")
}

if err := util.ValidatePositiveNumber(msg.OperatingCost); err != nil {
if err := util.ValidateNumber(msg.OperatingCost); err != nil {
return errors.Wrapf(errorsTypes.ErrInvalidRequest, "invalid operating cost")
}

if err := util.ValidatePositiveNumber(msg.MinDelegation); err != nil {
if err := util.ValidateNumber(msg.MinDelegation); err != nil {
return errors.Wrapf(errorsTypes.ErrInvalidRequest, "invalid minimum delegation")
}

if err := util.ValidatePositiveNumber(msg.MaxBundleSize); err != nil {
return errors.Wrapf(errorsTypes.ErrInvalidRequest, "invalid max bundle size")
}

return nil
}

Expand Down Expand Up @@ -84,17 +88,23 @@ func (msg *MsgUpdatePool) ValidateBasic() error {
}

if payload.OperatingCost != nil {
if err := util.ValidatePositiveNumber(*payload.OperatingCost); err != nil {
if err := util.ValidateNumber(*payload.OperatingCost); err != nil {
return errors.Wrapf(errorsTypes.ErrInvalidRequest, "invalid operating cost")
}
}

if payload.MinDelegation != nil {
if err := util.ValidatePositiveNumber(*payload.MinDelegation); err != nil {
if err := util.ValidateNumber(*payload.MinDelegation); err != nil {
return errors.Wrapf(errorsTypes.ErrInvalidRequest, "invalid minimum delegation")
}
}

if payload.MaxBundleSize != nil {
if err := util.ValidatePositiveNumber(*payload.MaxBundleSize); err != nil {
return errors.Wrapf(errorsTypes.ErrInvalidRequest, "invalid max bundle size")
}
}

return nil
}

Expand Down

0 comments on commit adf2448

Please sign in to comment.