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

chore: improve validation of pool proposals #74

Merged
merged 3 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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())
})
troykessler marked this conversation as resolved.
Show resolved Hide resolved

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