From e73f7c27886b2f3fa81320a6c6ab1be79ec1dc60 Mon Sep 17 00:00:00 2001 From: Jonathan Fung Date: Wed, 13 Mar 2024 00:09:31 -0700 Subject: [PATCH] basic tests with only batch cancel orders submitted --- protocol/x/clob/e2e/app_test.go | 41 +++++++++++++++++++ protocol/x/clob/e2e/rate_limit_test.go | 56 +++++++++++++++++++++----- 2 files changed, 88 insertions(+), 9 deletions(-) diff --git a/protocol/x/clob/e2e/app_test.go b/protocol/x/clob/e2e/app_test.go index 33037954fb..eadd46b0a8 100644 --- a/protocol/x/clob/e2e/app_test.go +++ b/protocol/x/clob/e2e/app_test.go @@ -223,6 +223,47 @@ var ( constants.ConditionalOrder_Alice_Num1_Id0_Clob0_Sell5_Price10_GTB15, testapp.DefaultGenesis(), )) + + BatchCancel_Alice_Num0_Clob0_1_2_3_GTB5 = *clobtypes.NewMsgBatchCancel( + constants.Alice_Num0, + []clobtypes.OrderBatch{ + { + ClobPairId: 0, + ClientIds: []uint32{1, 2, 3}, + }, + }, + 5, + ) + BatchCancel_Alice_Num0_Clob0_1_2_3_GTB27 = *clobtypes.NewMsgBatchCancel( + constants.Alice_Num0, + []clobtypes.OrderBatch{ + { + ClobPairId: 0, + ClientIds: []uint32{1, 2, 3}, + }, + }, + 27, + ) + BatchCancel_Alice_Num0_Clob0_1_2_3_GTB20 = *clobtypes.NewMsgBatchCancel( + constants.Alice_Num0, + []clobtypes.OrderBatch{ + { + ClobPairId: 0, + ClientIds: []uint32{1, 2, 3}, + }, + }, + 20, + ) + BatchCancel_Alice_Num1_Clob0_1_2_3_GTB20 = *clobtypes.NewMsgBatchCancel( + constants.Alice_Num1, + []clobtypes.OrderBatch{ + { + ClobPairId: 0, + ClientIds: []uint32{1, 2, 3}, + }, + }, + 20, + ) ) // We place 300 orders that match and 700 orders followed by their cancellations concurrently. diff --git a/protocol/x/clob/e2e/rate_limit_test.go b/protocol/x/clob/e2e/rate_limit_test.go index d1a85cd0c4..2616853964 100644 --- a/protocol/x/clob/e2e/rate_limit_test.go +++ b/protocol/x/clob/e2e/rate_limit_test.go @@ -19,12 +19,12 @@ import ( func TestRateLimitingOrders_RateLimitsAreEnforced(t *testing.T) { tests := map[string]struct { - blockRateLimitConifg clobtypes.BlockRateLimitConfiguration + blockRateLimitConfig clobtypes.BlockRateLimitConfiguration firstMsg sdktypes.Msg secondMsg sdktypes.Msg }{ "Short term orders with same subaccounts": { - blockRateLimitConifg: clobtypes.BlockRateLimitConfiguration{ + blockRateLimitConfig: clobtypes.BlockRateLimitConfiguration{ MaxShortTermOrdersAndCancelsPerNBlocks: []clobtypes.MaxPerNBlocksRateLimit{ { NumBlocks: 2, @@ -36,7 +36,7 @@ func TestRateLimitingOrders_RateLimitsAreEnforced(t *testing.T) { secondMsg: &PlaceOrder_Alice_Num0_Id0_Clob1_Buy5_Price10_GTB20, }, "Short term orders with different subaccounts": { - blockRateLimitConifg: clobtypes.BlockRateLimitConfiguration{ + blockRateLimitConfig: clobtypes.BlockRateLimitConfiguration{ MaxShortTermOrdersAndCancelsPerNBlocks: []clobtypes.MaxPerNBlocksRateLimit{ { NumBlocks: 2, @@ -48,7 +48,7 @@ func TestRateLimitingOrders_RateLimitsAreEnforced(t *testing.T) { secondMsg: &PlaceOrder_Alice_Num1_Id0_Clob0_Buy5_Price10_GTB20, }, "Stateful orders with same subaccounts": { - blockRateLimitConifg: clobtypes.BlockRateLimitConfiguration{ + blockRateLimitConfig: clobtypes.BlockRateLimitConfiguration{ MaxStatefulOrdersPerNBlocks: []clobtypes.MaxPerNBlocksRateLimit{ { NumBlocks: 2, @@ -60,7 +60,7 @@ func TestRateLimitingOrders_RateLimitsAreEnforced(t *testing.T) { secondMsg: &LongTermPlaceOrder_Alice_Num0_Id0_Clob1_Buy5_Price10_GTBT5, }, "Stateful orders with different subaccounts": { - blockRateLimitConifg: clobtypes.BlockRateLimitConfiguration{ + blockRateLimitConfig: clobtypes.BlockRateLimitConfiguration{ MaxStatefulOrdersPerNBlocks: []clobtypes.MaxPerNBlocksRateLimit{ { NumBlocks: 2, @@ -72,7 +72,7 @@ func TestRateLimitingOrders_RateLimitsAreEnforced(t *testing.T) { secondMsg: &LongTermPlaceOrder_Alice_Num1_Id0_Clob0_Buy5_Price10_GTBT5, }, "Short term order cancellations with same subaccounts": { - blockRateLimitConifg: clobtypes.BlockRateLimitConfiguration{ + blockRateLimitConfig: clobtypes.BlockRateLimitConfiguration{ MaxShortTermOrdersAndCancelsPerNBlocks: []clobtypes.MaxPerNBlocksRateLimit{ { NumBlocks: 2, @@ -84,7 +84,7 @@ func TestRateLimitingOrders_RateLimitsAreEnforced(t *testing.T) { secondMsg: &CancelOrder_Alice_Num0_Id0_Clob0_GTB20, }, "Short term order cancellations with different subaccounts": { - blockRateLimitConifg: clobtypes.BlockRateLimitConfiguration{ + blockRateLimitConfig: clobtypes.BlockRateLimitConfiguration{ MaxShortTermOrdersAndCancelsPerNBlocks: []clobtypes.MaxPerNBlocksRateLimit{ { NumBlocks: 2, @@ -95,6 +95,30 @@ func TestRateLimitingOrders_RateLimitsAreEnforced(t *testing.T) { firstMsg: &CancelOrder_Alice_Num0_Id0_Clob1_GTB5, secondMsg: &CancelOrder_Alice_Num1_Id0_Clob0_GTB20, }, + "Batch cancellations with same subaccounts": { + blockRateLimitConfig: clobtypes.BlockRateLimitConfiguration{ + MaxShortTermOrdersAndCancelsPerNBlocks: []clobtypes.MaxPerNBlocksRateLimit{ + { + NumBlocks: 2, + Limit: 1, + }, + }, + }, + firstMsg: &BatchCancel_Alice_Num0_Clob0_1_2_3_GTB5, + secondMsg: &BatchCancel_Alice_Num0_Clob0_1_2_3_GTB20, + }, + "Batch cancellations with different subaccounts": { + blockRateLimitConfig: clobtypes.BlockRateLimitConfiguration{ + MaxShortTermOrdersAndCancelsPerNBlocks: []clobtypes.MaxPerNBlocksRateLimit{ + { + NumBlocks: 2, + Limit: 1, + }, + }, + }, + firstMsg: &BatchCancel_Alice_Num0_Clob0_1_2_3_GTB5, + secondMsg: &BatchCancel_Alice_Num1_Clob0_1_2_3_GTB20, + }, } for name, tc := range tests { @@ -107,7 +131,7 @@ func TestRateLimitingOrders_RateLimitsAreEnforced(t *testing.T) { testapp.UpdateGenesisDocWithAppStateForModule( &genesis, func(genesisState *clobtypes.GenesisState) { - genesisState.BlockRateLimitConfig = tc.blockRateLimitConifg + genesisState.BlockRateLimitConfig = tc.blockRateLimitConfig }, ) testapp.UpdateGenesisDocWithAppStateForModule( @@ -514,6 +538,20 @@ func TestRateLimitingShortTermOrders_GuardedAgainstReplayAttacks(t *testing.T) { firstValidGTB: &CancelOrder_Alice_Num0_Id0_Clob0_GTB20, secondValidGTB: &CancelOrder_Alice_Num1_Id0_Clob0_GTB20, }, + "Batch cancellations": { + blockRateLimitConfig: clobtypes.BlockRateLimitConfiguration{ + MaxShortTermOrdersAndCancelsPerNBlocks: []clobtypes.MaxPerNBlocksRateLimit{ + { + NumBlocks: 1, + Limit: 3, // TODO FIX THIS ONCE WEIGHTS ARE DECIDED + }, + }, + }, + replayLessGTB: &BatchCancel_Alice_Num0_Clob0_1_2_3_GTB5, + replayGreaterGTB: &BatchCancel_Alice_Num0_Clob0_1_2_3_GTB27, + firstValidGTB: &BatchCancel_Alice_Num0_Clob0_1_2_3_GTB20, + secondValidGTB: &BatchCancel_Alice_Num0_Clob0_1_2_3_GTB20, + }, } for name, tc := range tests { @@ -586,7 +624,7 @@ func TestRateLimitingShortTermOrders_GuardedAgainstReplayAttacks(t *testing.T) { resp = tApp.CheckTx(secondCheckTx) require.Conditionf(t, resp.IsErr, "Expected CheckTx to error. Response: %+v", resp) require.Equal(t, clobtypes.ErrBlockRateLimitExceeded.ABCICode(), resp.Code) - require.Contains(t, resp.Log, "Rate of 2 exceeds configured block rate limit") + require.Contains(t, resp.Log, "exceeds configured block rate limit") }) } }