From 68c9090d371bb8ac80ea9873e780af935f8a5b86 Mon Sep 17 00:00:00 2001 From: zale144 Date: Fri, 25 Oct 2024 21:09:52 +0200 Subject: [PATCH] fix(rollapp): validate order field when validating update app (#1351) --- x/eibc/keeper/msg_server_test.go | 2 -- x/rollapp/keeper/msg_server_app.go | 17 ++++++++++++----- x/rollapp/types/message_add_app.go | 4 ++++ x/rollapp/types/message_update_app.go | 4 ++++ 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/x/eibc/keeper/msg_server_test.go b/x/eibc/keeper/msg_server_test.go index e9580c758..1a4b98b61 100644 --- a/x/eibc/keeper/msg_server_test.go +++ b/x/eibc/keeper/msg_server_test.go @@ -214,7 +214,6 @@ func (suite *KeeperTestSuite) TestMsgFulfillOrderAuthorized() { NumBlocks: 1, Status: commontypes.Status_PENDING, }) - }, expectError: nil, expectOrderFulfilled: true, @@ -369,7 +368,6 @@ func (suite *KeeperTestSuite) TestMsgFulfillOrderAuthorized() { NumBlocks: 1, Status: commontypes.Status_PENDING, }) - }, expectError: types.ErrOrderNotSettlementValidated, expectOrderFulfilled: false, diff --git a/x/rollapp/keeper/msg_server_app.go b/x/rollapp/keeper/msg_server_app.go index 292daaa97..8e13ad6a6 100644 --- a/x/rollapp/keeper/msg_server_app.go +++ b/x/rollapp/keeper/msg_server_app.go @@ -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)) @@ -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") @@ -136,4 +138,9 @@ type appMsg interface { GetApp() types.App } +type appOrderMsg interface { + GetOrder() int32 + SetOrder(int32) +} + var _ types.MsgServer = msgServer{} diff --git a/x/rollapp/types/message_add_app.go b/x/rollapp/types/message_add_app.go index 3d4620904..599817acb 100644 --- a/x/rollapp/types/message_add_app.go +++ b/x/rollapp/types/message_add_app.go @@ -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 { diff --git a/x/rollapp/types/message_update_app.go b/x/rollapp/types/message_update_app.go index 0198919fc..bb2de2640 100644 --- a/x/rollapp/types/message_update_app.go +++ b/x/rollapp/types/message_update_app.go @@ -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 {