Skip to content

Commit

Permalink
chore(x/upgrade): Use ValidateBasic for Plan in ReadUpgradeInfoFromDi…
Browse files Browse the repository at this point in the history
…sk (#18210)
  • Loading branch information
facundomedica authored Oct 24, 2023
1 parent c1f050f commit 458dd04
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions x/upgrade/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,10 @@ func (k Keeper) ReadUpgradeInfoFromDisk() (types.Plan, error) {
return upgradeInfo, err
}

if err := upgradeInfo.ValidateBasic(); err != nil {
return upgradeInfo, err
}

return upgradeInfo, nil
}

Expand Down
6 changes: 6 additions & 0 deletions x/upgrade/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ func (s *KeeperTestSuite) TestReadUpgradeInfoFromDisk() {
s.Require().NoError(err)
expected.Height = 101
s.Require().Equal(expected, ui)

// create invalid upgrade plan (with empty name)
expected.Name = ""
s.Require().NoError(s.upgradeKeeper.DumpUpgradeInfoToDisk(101, expected))
_, err = s.upgradeKeeper.ReadUpgradeInfoFromDisk()
s.Require().ErrorContains(err, "name cannot be empty: invalid request")
}

func (s *KeeperTestSuite) TestScheduleUpgrade() {
Expand Down
4 changes: 0 additions & 4 deletions x/upgrade/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ func (k msgServer) SoftwareUpgrade(ctx context.Context, msg *types.MsgSoftwareUp
return nil, errors.Wrapf(types.ErrInvalidSigner, "expected %s got %s", k.authority, msg.Authority)
}

if err := msg.Plan.ValidateBasic(); err != nil {
return nil, errors.Wrap(err, "plan")
}

err := k.ScheduleUpgrade(ctx, msg.Plan)
if err != nil {
return nil, err
Expand Down

0 comments on commit 458dd04

Please sign in to comment.