Skip to content

Commit

Permalink
fix(rollapp): validate order field when validating update app (#1351)
Browse files Browse the repository at this point in the history
  • Loading branch information
zale144 authored Oct 25, 2024
1 parent f80e912 commit 68c9090
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 0 additions & 2 deletions x/eibc/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ func (suite *KeeperTestSuite) TestMsgFulfillOrderAuthorized() {
NumBlocks: 1,
Status: commontypes.Status_PENDING,
})

},
expectError: nil,
expectOrderFulfilled: true,
Expand Down Expand Up @@ -369,7 +368,6 @@ func (suite *KeeperTestSuite) TestMsgFulfillOrderAuthorized() {
NumBlocks: 1,
Status: commontypes.Status_PENDING,
})

},
expectError: types.ErrOrderNotSettlementValidated,
expectOrderFulfilled: false,
Expand Down
17 changes: 12 additions & 5 deletions x/rollapp/keeper/msg_server_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ func (k msgServer) AddApp(goCtx context.Context, msg *types.MsgAddApp) (*types.M
return nil, err
}

// If order is not set by the client, all order will get -1 which will make it random.
if msg.Order == 0 {
msg.Order = -1
}

// charge the app registration fee
creator := sdk.MustAccAddressFromBech32(msg.Creator)
appFee := sdk.NewCoins(k.AppRegistrationFee(ctx))
Expand Down Expand Up @@ -105,6 +100,13 @@ func (k msgServer) checkInputs(ctx sdk.Context, msg appMsg) error {
}
switch msg.(type) {
case *types.MsgAddApp, *types.MsgUpdateApp:
// If order is not set by the client, all order will get -1 which will make it random.
if orderMsg, ok := msg.(appOrderMsg); ok {
if orderMsg.GetOrder() == 0 {
orderMsg.SetOrder(-1)
}
}

apps := k.GetRollappApps(ctx, app.GetRollappId())
if nameExists := k.appNameExists(apps, app); nameExists {
return errorsmod.Wrap(gerrc.ErrAlreadyExists, "app name already exists")
Expand Down Expand Up @@ -136,4 +138,9 @@ type appMsg interface {
GetApp() types.App
}

type appOrderMsg interface {
GetOrder() int32
SetOrder(int32)
}

var _ types.MsgServer = msgServer{}
4 changes: 4 additions & 0 deletions x/rollapp/types/message_add_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func (msg *MsgAddApp) GetApp() App {
)
}

func (msg *MsgAddApp) SetOrder(o int32) {
msg.Order = o
}

func (msg *MsgAddApp) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions x/rollapp/types/message_update_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func (msg *MsgUpdateApp) GetApp() App {
)
}

func (msg *MsgUpdateApp) SetOrder(o int32) {
msg.Order = o
}

func (msg *MsgUpdateApp) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
Expand Down

0 comments on commit 68c9090

Please sign in to comment.