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 (backport #18210) (#18229)

Co-authored-by: Facundo Medica <[email protected]>
Co-authored-by: Julien Robert <[email protected]>
  • Loading branch information
3 people authored Oct 24, 2023
1 parent 42dbfc4 commit cabde7b
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 @@ -573,6 +573,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 @@ -88,6 +88,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(goCtx context.Context, msg *types.MsgSoftware
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")
}

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

0 comments on commit cabde7b

Please sign in to comment.