diff --git a/indexer/services/comlink/__tests__/lib/validation/schemas.test.ts b/indexer/services/comlink/__tests__/lib/validation/schemas.test.ts index 7e61a5bbc5..9c9ffb74fb 100644 --- a/indexer/services/comlink/__tests__/lib/validation/schemas.test.ts +++ b/indexer/services/comlink/__tests__/lib/validation/schemas.test.ts @@ -3,8 +3,11 @@ import { getQueryString, sendRequestToApp } from '../../helpers/helpers'; import { schemaTestApp } from './helpers'; import request from 'supertest'; import config from '../../../src/config'; -import { testConstants } from '@dydxprotocol-indexer/postgres'; -import { MAX_SUBACCOUNT_NUMBER } from '../../../src/constants'; +import { + testConstants, + MAX_PARENT_SUBACCOUNTS, + CHILD_SUBACCOUNT_MULTIPLIER, +} from '@dydxprotocol-indexer/postgres'; describe('schemas', () => { const positiveNonInteger: number = 3.2; @@ -19,25 +22,28 @@ describe('schemas', () => { 'missing subaccountNumber', { address: defaultAddress }, 'subaccountNumber', - 'subaccountNumber must be a non-negative integer less than 128', + 'subaccountNumber must be a non-negative integer less than 128001', ], [ 'non-integer subaccountNumber', { address: defaultAddress, subaccountNumber: positiveNonInteger }, 'subaccountNumber', - 'subaccountNumber must be a non-negative integer less than 128', + 'subaccountNumber must be a non-negative integer less than 128001', ], [ 'negative subaccountNumber', { address: defaultAddress, subaccountNumber: negativeInteger }, 'subaccountNumber', - 'subaccountNumber must be a non-negative integer less than 128', + 'subaccountNumber must be a non-negative integer less than 128001', ], [ 'subaccountNumber greater than maximum subaccount number', - { address: defaultAddress, subaccountNumber: MAX_SUBACCOUNT_NUMBER + 1 }, + { + address: defaultAddress, + subaccountNumber: MAX_PARENT_SUBACCOUNTS * CHILD_SUBACCOUNT_MULTIPLIER + 1, + }, 'subaccountNumber', - 'subaccountNumber must be a non-negative integer less than 128', + 'subaccountNumber must be a non-negative integer less than 128001', ], ])('Returns 400 when validation fails: %s', async ( _reason: string, diff --git a/indexer/services/comlink/src/lib/validation/schemas.ts b/indexer/services/comlink/src/lib/validation/schemas.ts index 5d43d0efb5..27e13a4d2c 100644 --- a/indexer/services/comlink/src/lib/validation/schemas.ts +++ b/indexer/services/comlink/src/lib/validation/schemas.ts @@ -1,8 +1,11 @@ -import { perpetualMarketRefresher } from '@dydxprotocol-indexer/postgres'; +import { + perpetualMarketRefresher, + MAX_PARENT_SUBACCOUNTS, + CHILD_SUBACCOUNT_MULTIPLIER, +} from '@dydxprotocol-indexer/postgres'; import { checkSchema, ParamSchema } from 'express-validator'; import config from '../../config'; -import { MAX_SUBACCOUNT_NUMBER } from '../../constants'; export const CheckSubaccountSchema = checkSchema({ address: { @@ -12,9 +15,9 @@ export const CheckSubaccountSchema = checkSchema({ subaccountNumber: { in: ['params', 'query'], isInt: { - options: { gt: -1, lt: MAX_SUBACCOUNT_NUMBER + 1 }, + options: { gt: -1, lt: MAX_PARENT_SUBACCOUNTS * CHILD_SUBACCOUNT_MULTIPLIER + 1 }, }, - errorMessage: 'subaccountNumber must be a non-negative integer less than 128', + errorMessage: 'subaccountNumber must be a non-negative integer less than 128001', }, }); @@ -26,7 +29,7 @@ export const CheckParentSubaccountSchema = checkSchema({ parentSubaccountNumber: { in: ['params', 'query'], isInt: { - options: { gt: -1, lt: MAX_SUBACCOUNT_NUMBER + 1 }, + options: { gt: -1, lt: MAX_PARENT_SUBACCOUNTS }, }, errorMessage: 'parentSubaccountNumber must be a non-negative integer less than 128', },