From 9846a419db54acc812c156e116ea1c400b5981c5 Mon Sep 17 00:00:00 2001 From: Tian Qin Date: Thu, 1 Aug 2024 16:52:50 -0400 Subject: [PATCH] address comments --- protocol/x/vault/keeper/orders_test.go | 30 ++++++++++++-------- protocol/x/vault/types/errors.go | 38 +++++++++++++++----------- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/protocol/x/vault/keeper/orders_test.go b/protocol/x/vault/keeper/orders_test.go index b814b3dddae..02992095bbd 100644 --- a/protocol/x/vault/keeper/orders_test.go +++ b/protocol/x/vault/keeper/orders_test.go @@ -403,9 +403,13 @@ func TestRefreshVaultClobOrders(t *testing.T) { flippedClientIds[i] = orderId.ClientId ^ 1 } + // If corresponding clob pair doesn't exist, the vault should not place any orders. + _, found := tApp.App.ClobKeeper.GetClobPair(ctx, clobtypes.ClobPairId(tc.vaultId.Number)) + if !found { + require.Zero(t, len(tApp.App.ClobKeeper.GetAllStatefulOrders(ctx))) + return + } // Vault should place its initial orders (client IDs should be canonical). - initialOrders := tApp.App.ClobKeeper.GetAllStatefulOrders(ctx) - require.Len(t, initialOrders, int(params.Layers*2)) verifyVaultOrders( uint32(ctx.BlockTime().Unix())+params.OrderExpirationSeconds, canonicalClientIds, @@ -1000,27 +1004,30 @@ func TestGetVaultClobOrderIds(t *testing.T) { layers uint32 /* --- Expectations --- */ - // Expected error, if any. - expectedErr error + expectedNumOrders uint32 }{ "Vault Clob 0, 2 layers": { - vaultId: constants.Vault_Clob0, - layers: 2, + vaultId: constants.Vault_Clob0, + layers: 2, + expectedNumOrders: 4, }, "Vault Clob 1, 7 layers": { - vaultId: constants.Vault_Clob1, - layers: 7, + vaultId: constants.Vault_Clob1, + layers: 7, + expectedNumOrders: 14, }, "Vault Clob 0, 0 layers": { - vaultId: constants.Vault_Clob0, - layers: 0, + vaultId: constants.Vault_Clob0, + layers: 0, + expectedNumOrders: 0, }, "Vault Clob 797, 2 layers": { vaultId: vaulttypes.VaultId{ Type: vaulttypes.VaultType_VAULT_TYPE_CLOB, Number: 797, }, - layers: 2, + layers: 2, + expectedNumOrders: 4, }, } @@ -1054,6 +1061,7 @@ func TestGetVaultClobOrderIds(t *testing.T) { } // Verify order IDs. + require.Equal(t, tc.expectedNumOrders, uint32(len(expectedOrderIds))) require.Equal(t, expectedOrderIds, k.GetVaultClobOrderIds(ctx, tc.vaultId)) }) } diff --git a/protocol/x/vault/types/errors.go b/protocol/x/vault/types/errors.go index 8dc36313422..7fc398a207f 100644 --- a/protocol/x/vault/types/errors.go +++ b/protocol/x/vault/types/errors.go @@ -10,84 +10,90 @@ var ( 1, "Shares are negative", ) - ErrMarketParamNotFound = errorsmod.Register( + // Deprecated since v6.x + ErrClobPairNotFound = errorsmod.Register( ModuleName, 2, + "ClobPair not found", + ) + ErrMarketParamNotFound = errorsmod.Register( + ModuleName, + 3, "MarketParam not found", ) ErrInvalidDepositAmount = errorsmod.Register( ModuleName, - 3, + 4, "Deposit amount is invalid", ) ErrNonPositiveEquity = errorsmod.Register( ModuleName, - 4, + 5, "Equity is non-positive", ) ErrZeroDenominator = errorsmod.Register( ModuleName, - 5, + 6, "Denominator is zero", ) ErrNilFraction = errorsmod.Register( ModuleName, - 6, + 7, "Fraction is nil", ) ErrInvalidOrderSizePctPpm = errorsmod.Register( ModuleName, - 7, + 8, "OrderSizePctPpm must be strictly greater than 0", ) ErrInvalidOrderExpirationSeconds = errorsmod.Register( ModuleName, - 8, + 9, "OrderExpirationSeconds must be strictly greater than 0", ) ErrInvalidSpreadMinPpm = errorsmod.Register( ModuleName, - 9, + 10, "SpreadMinPpm must be strictly greater than 0", ) ErrInvalidLayers = errorsmod.Register( ModuleName, - 10, + 11, "Layers must be less than or equal to MaxUint8", ) ErrZeroSharesToMint = errorsmod.Register( ModuleName, - 11, + 12, "Cannot mint zero shares", ) ErrInvalidActivationThresholdQuoteQuantums = errorsmod.Register( ModuleName, - 12, + 13, "ActivationThresholdQuoteQuantums must be non-negative", ) ErrInvalidOrderSize = errorsmod.Register( ModuleName, - 13, + 14, "OrderSize is invalid", ) ErrInvalidOwner = errorsmod.Register( ModuleName, - 14, + 15, "Owner is invalid", ) ErrMismatchedTotalAndOwnerShares = errorsmod.Register( ModuleName, - 15, + 16, "TotalShares does not match sum of OwnerShares", ) ErrZeroMarketPrice = errorsmod.Register( ModuleName, - 16, + 17, "MarketPrice is zero", ) ErrOrdersAndOrderIdsDiffLen = errorsmod.Register( ModuleName, - 17, + 18, "Orders and OrderIds must have the same length", ) )