Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jonfung-dydx committed Feb 27, 2024
1 parent 040422a commit cad3af4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion protocol/x/clob/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ var (
ErrInvalidBatchCancel = errorsmod.Register(
ModuleName,
45,
"Invalid Batch Cancel",
"Invalid batch cancel message",
)

// Liquidations errors.
Expand Down
15 changes: 14 additions & 1 deletion protocol/x/clob/types/message_batch_cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,22 @@ func (msg *MsgBatchCancel) ValidateBasic() (err error) {
}

cancelBatches := msg.GetShortTermCancels()
if len(cancelBatches) == 0 {
return errorsmod.Wrapf(
ErrInvalidBatchCancel,
"Batch cancel cannot have zero orders specified.",
)
}
totalNumberCancels := 0
for _, cancelBatch := range cancelBatches {
totalNumberCancels += len(cancelBatch.GetClientIds())
numClientIds := len(cancelBatch.GetClientIds())
if numClientIds == 0 {
return errorsmod.Wrapf(
ErrInvalidBatchCancel,
"Order Batch cannot have zero client ids.",
)
}
totalNumberCancels += numClientIds
seenClientIds := map[uint32]struct{}{}
for _, clientId := range cancelBatch.GetClientIds() {
if _, seen := seenClientIds[clientId]; seen {
Expand Down
29 changes: 25 additions & 4 deletions protocol/x/clob/types/message_batch_cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ func TestMsgBatchCancel_ValidateBasic(t *testing.T) {
[]types.OrderBatch{
{
ClobPairId: 0,
ClientIds: oneOverMax[:52],
ClientIds: oneOverMax[:types.MaxMsgBatchCancelBatchSize/2+2],
},
{
ClobPairId: 1,
ClientIds: oneOverMax[:52],
ClientIds: oneOverMax[:types.MaxMsgBatchCancelBatchSize/2+2],
},
},
10,
Expand All @@ -70,11 +70,11 @@ func TestMsgBatchCancel_ValidateBasic(t *testing.T) {
[]types.OrderBatch{
{
ClobPairId: 0,
ClientIds: oneOverMax[:50],
ClientIds: oneOverMax[:types.MaxMsgBatchCancelBatchSize/2],
},
{
ClobPairId: 1,
ClientIds: oneOverMax[:50],
ClientIds: oneOverMax[:types.MaxMsgBatchCancelBatchSize/2],
},
},
10,
Expand Down Expand Up @@ -109,6 +109,27 @@ func TestMsgBatchCancel_ValidateBasic(t *testing.T) {
),
err: types.ErrInvalidBatchCancel,
},
"zero batches in cancel batch": {
msg: *types.NewMsgBatchCancel(
constants.Alice_Num0,
[]types.OrderBatch{},
10,
),
err: types.ErrInvalidBatchCancel,
},
"zero client ids in cancel batch": {
msg: *types.NewMsgBatchCancel(
constants.Alice_Num0,
[]types.OrderBatch{
{
ClobPairId: 0,
ClientIds: []uint32{},
},
},
10,
),
err: types.ErrInvalidBatchCancel,
},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
Expand Down

0 comments on commit cad3af4

Please sign in to comment.