Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tqin7 committed Aug 1, 2024
1 parent 90e88d6 commit 9846a41
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
30 changes: 19 additions & 11 deletions protocol/x/vault/keeper/orders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
}

Expand Down Expand Up @@ -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))
})
}
Expand Down
38 changes: 22 additions & 16 deletions protocol/x/vault/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
)

0 comments on commit 9846a41

Please sign in to comment.