Skip to content

Commit

Permalink
Add in Canceled Order check
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Dusek committed May 26, 2024
1 parent 1cf06bc commit ffa5d54
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions x/market/keeper/msg_server_cancel_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func (k msgServer) CancelOrder(goCtx context.Context, msg *types.MsgCancelOrder)
return nil, sdkerrors.Wrapf(types.ErrOrderNotFound, "%s", msg.Uid)
}

if order.Status == "canceled" {
return nil, sdkerrors.Wrapf(types.ErrOrderCanceled, "%s", msg.Uid)
}

if order.Owner != msg.Creator {
return nil, sdkerrors.Wrapf(types.ErrNotOrderOwner, "%s", msg.Uid)
}
Expand Down
2 changes: 2 additions & 0 deletions x/market/keeper/msg_server_cancel_order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func TestCancelOrder_case1_stop(t *testing.T) {
var co = types.MsgCancelOrder{Creator: addr, Uid: Uid}
_, err = keeper.NewMsgServerImpl(*testInput.MarketKeeper).CancelOrder(sdk.WrapSDKContext(testInput.Context), &co)
require.NoError(t, err)
_, err = keeper.NewMsgServerImpl(*testInput.MarketKeeper).CancelOrder(sdk.WrapSDKContext(testInput.Context), &co)
require.Error(t, err)

// Validate GetMember
memberA, memberfound = testInput.MarketKeeper.GetMember(testInput.Context, orders.DenomBid, orders.DenomAsk)
Expand Down
2 changes: 2 additions & 0 deletions x/market/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ var (
ErrDenomExists = sdkerrors.Register(ModuleName, 22, "denom already exists") // nolint: gomnd
// DropNotActive - drop is no longer active
ErrDropNotActive = sdkerrors.Register(ModuleName, 23, "drop not active") // nolint: gomnd
// ErrOrderCanceled - order is already canceled
ErrOrderCanceled = sdkerrors.Register(ModuleName, 24, "order already canceled") // nolint: gomnd
)

0 comments on commit ffa5d54

Please sign in to comment.