Skip to content

Commit

Permalink
Fix subaccount validation to account for updated subaccount limit. (#…
Browse files Browse the repository at this point in the history
…1513) (#1515)

(cherry picked from commit b6a6c55)

Co-authored-by: vincentwschau <[email protected]>
  • Loading branch information
mergify[bot] and vincentwschau authored May 14, 2024
1 parent 296208d commit 8bafa65
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
20 changes: 13 additions & 7 deletions indexer/services/comlink/__tests__/lib/validation/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
13 changes: 8 additions & 5 deletions indexer/services/comlink/src/lib/validation/schemas.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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',
},
});

Expand All @@ -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',
},
Expand Down

0 comments on commit 8bafa65

Please sign in to comment.