Skip to content

Commit ad8bba6

Browse files
feat: raise orders volume limit to MAX_SAFE_INTEGER
1 parent 0078f22 commit ad8bba6

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

src/common/utils/validator.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,10 @@ export const stringNumberSchema = ({ message } = {}) =>
4747
export const integerSchema = () => number().integer();
4848

4949
export const positiveIntSchema = () =>
50-
integerSchema()
51-
.min(0)
52-
.max(Number.MAX_SAFE_INTEGER - 1);
50+
integerSchema().min(0).max(Number.MAX_SAFE_INTEGER);
5351

5452
export const positiveStrictIntSchema = () =>
55-
integerSchema()
56-
.min(1)
57-
.max(Number.MAX_SAFE_INTEGER - 1);
53+
integerSchema().min(1).max(Number.MAX_SAFE_INTEGER);
5854

5955
export const hexnumberSchema = () =>
6056
string()

test/lib/unit/validator.test.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('[positiveIntSchema]', () => {
7878
positiveIntSchema().validate('9007199254740992'),
7979
).rejects.toThrow(
8080
new ValidationError(
81-
'this must be less than or equal to 9007199254740990',
81+
'this must be less than or equal to 9007199254740991',
8282
),
8383
);
8484
});
@@ -87,7 +87,7 @@ describe('[positiveIntSchema]', () => {
8787
positiveIntSchema().validate('0xffffffffffffffffffff'),
8888
).rejects.toThrow(
8989
new ValidationError(
90-
'this must be less than or equal to 9007199254740990',
90+
'this must be less than or equal to 9007199254740991',
9191
),
9292
);
9393
});
@@ -96,7 +96,7 @@ describe('[positiveIntSchema]', () => {
9696
positiveIntSchema().validate(new BN('9007199254740992')),
9797
).rejects.toThrow(
9898
new ValidationError(
99-
'this must be less than or equal to 9007199254740990',
99+
'this must be less than or equal to 9007199254740991',
100100
),
101101
);
102102
});
@@ -115,8 +115,8 @@ describe('[positiveStrictIntSchema]', () => {
115115
});
116116
test('string int', async () => {
117117
await expect(
118-
positiveStrictIntSchema().validate('9007199254740990'),
119-
).resolves.toBe(9007199254740990);
118+
positiveStrictIntSchema().validate('9007199254740991'),
119+
).resolves.toBe(9007199254740991);
120120
});
121121
test('hex string', async () => {
122122
await expect(positiveStrictIntSchema().validate('0xff')).resolves.toBe(255);
@@ -161,7 +161,7 @@ describe('[positiveStrictIntSchema]', () => {
161161
positiveStrictIntSchema().validate('9007199254740992'),
162162
).rejects.toThrow(
163163
new ValidationError(
164-
'this must be less than or equal to 9007199254740990',
164+
'this must be less than or equal to 9007199254740991',
165165
),
166166
);
167167
});
@@ -170,7 +170,7 @@ describe('[positiveStrictIntSchema]', () => {
170170
positiveStrictIntSchema().validate('0xffffffffffffffffffff'),
171171
).rejects.toThrow(
172172
new ValidationError(
173-
'this must be less than or equal to 9007199254740990',
173+
'this must be less than or equal to 9007199254740991',
174174
),
175175
);
176176
});
@@ -179,7 +179,7 @@ describe('[positiveStrictIntSchema]', () => {
179179
positiveStrictIntSchema().validate(new BN('9007199254740992')),
180180
).rejects.toThrow(
181181
new ValidationError(
182-
'this must be less than or equal to 9007199254740990',
182+
'this must be less than or equal to 9007199254740991',
183183
),
184184
);
185185
});
@@ -197,14 +197,14 @@ describe('[uint256Schema]', () => {
197197
await expect(uint256Schema().validate(48)).resolves.toBe('48');
198198
});
199199
test('string int', async () => {
200-
await expect(uint256Schema().validate('9007199254740990')).resolves.toBe(
201-
'9007199254740990',
200+
await expect(uint256Schema().validate('9007199254740991')).resolves.toBe(
201+
'9007199254740991',
202202
);
203203
});
204204
test('BN', async () => {
205205
await expect(
206-
uint256Schema().validate(new BN('9007199254740990')),
207-
).resolves.toBe('9007199254740990');
206+
uint256Schema().validate(new BN('9007199254740991')),
207+
).resolves.toBe('9007199254740991');
208208
});
209209
test('string int > MAX_SAFE_INTEGER', async () => {
210210
await expect(uint256Schema().validate('9007199254740992')).resolves.toBe(
@@ -242,8 +242,8 @@ describe('[nRlcAmountSchema]', () => {
242242
});
243243
test('string int', async () => {
244244
await expect(
245-
nRlcAmountSchema().validate('00009007199254740990'),
246-
).resolves.toBe('9007199254740990');
245+
nRlcAmountSchema().validate('00009007199254740991'),
246+
).resolves.toBe('9007199254740991');
247247
});
248248
test('defaultUnit RLC', async () => {
249249
await expect(
@@ -275,8 +275,8 @@ describe('[nRlcAmountSchema]', () => {
275275
});
276276
test('BN', async () => {
277277
await expect(
278-
nRlcAmountSchema().validate(new BN('9007199254740990')),
279-
).resolves.toBe('9007199254740990');
278+
nRlcAmountSchema().validate(new BN('9007199254740991')),
279+
).resolves.toBe('9007199254740991');
280280
});
281281
test('string int > MAX_SAFE_INTEGER', async () => {
282282
await expect(nRlcAmountSchema().validate('9007199254740992')).resolves.toBe(
@@ -337,8 +337,8 @@ describe('[weiAmountSchema]', () => {
337337
});
338338
test('string int', async () => {
339339
await expect(
340-
weiAmountSchema().validate('00009007199254740990'),
341-
).resolves.toBe('9007199254740990');
340+
weiAmountSchema().validate('00009007199254740991'),
341+
).resolves.toBe('9007199254740991');
342342
});
343343
test('defaultUnit ether', async () => {
344344
await expect(
@@ -403,8 +403,8 @@ describe('[weiAmountSchema]', () => {
403403
});
404404
test('BN', async () => {
405405
await expect(
406-
weiAmountSchema().validate(new BN('9007199254740990')),
407-
).resolves.toBe('9007199254740990');
406+
weiAmountSchema().validate(new BN('9007199254740991')),
407+
).resolves.toBe('9007199254740991');
408408
});
409409
test('string int > MAX_SAFE_INTEGER', async () => {
410410
await expect(weiAmountSchema().validate('9007199254740992')).resolves.toBe(

0 commit comments

Comments
 (0)