Skip to content

Commit 62ab4d8

Browse files
committed
removed obsolete tests
Signed-off-by: Simeon Nakov <[email protected]>
1 parent ca83544 commit 62ab4d8

File tree

3 files changed

+81
-341
lines changed

3 files changed

+81
-341
lines changed

packages/relay/tests/lib/errors/JsonRpcError.spec.ts

Lines changed: 81 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -212,56 +212,45 @@ describe('Errors', () => {
212212
});
213213

214214
describe('predefined.MIRROR_NODE_UPSTREAM_FAIL', () => {
215-
it('Constructs correctly with error code and message', () => {
216-
const errCode = 500;
217-
const errMessage = 'Internal Server Error';
218-
const error = predefined.MIRROR_NODE_UPSTREAM_FAIL(errCode, errMessage);
219-
expect(error.code).to.eq(-32020);
220-
expect(error.message).to.eq(`Mirror node upstream failure: statusCode=${errCode}, message=${errMessage}`);
221-
expect(error.data).to.eq(errCode.toString());
222-
});
223-
224-
it('Constructs correctly with different error code and message', () => {
225-
const errCode = 404;
226-
const errMessage = 'Not Found';
227-
const error = predefined.MIRROR_NODE_UPSTREAM_FAIL(errCode, errMessage);
228-
expect(error.code).to.eq(-32020);
229-
expect(error.message).to.eq(`Mirror node upstream failure: statusCode=${errCode}, message=${errMessage}`);
230-
expect(error.data).to.eq(errCode.toString());
215+
const testCases = [
216+
{ errCode: 500, errMessage: 'Internal Server Error' },
217+
{ errCode: 404, errMessage: 'Not Found' },
218+
];
219+
220+
testCases.forEach(({ errCode, errMessage }) => {
221+
it(`Constructs correctly with error code ${errCode} and message "${errMessage}"`, () => {
222+
const error = predefined.MIRROR_NODE_UPSTREAM_FAIL(errCode, errMessage);
223+
expect(error.code).to.eq(-32020);
224+
expect(error.message).to.eq(`Mirror node upstream failure: statusCode=${errCode}, message=${errMessage}`);
225+
expect(error.data).to.eq(errCode.toString());
226+
});
231227
});
232228
});
233229

234230
describe('predefined.IP_RATE_LIMIT_EXCEEDED', () => {
235-
it('Constructs correctly with method name', () => {
236-
const methodName = 'eth_getBalance';
237-
const error = predefined.IP_RATE_LIMIT_EXCEEDED(methodName);
238-
expect(error.code).to.eq(-32605);
239-
expect(error.message).to.eq(`IP Rate limit exceeded on ${methodName}`);
240-
});
231+
const testCases = ['eth_getBalance', 'eth_call'];
241232

242-
it('Constructs correctly with different method name', () => {
243-
const methodName = 'eth_call';
244-
const error = predefined.IP_RATE_LIMIT_EXCEEDED(methodName);
245-
expect(error.code).to.eq(-32605);
246-
expect(error.message).to.eq(`IP Rate limit exceeded on ${methodName}`);
233+
testCases.forEach((methodName) => {
234+
it(`Constructs correctly with method name: ${methodName}`, () => {
235+
const error = predefined.IP_RATE_LIMIT_EXCEEDED(methodName);
236+
expect(error.code).to.eq(-32605);
237+
expect(error.message).to.eq(`IP Rate limit exceeded on ${methodName}`);
238+
});
247239
});
248240
});
249241

250242
describe('predefined.REQUEST_BEYOND_HEAD_BLOCK', () => {
251-
it('Constructs correctly with requested and latest block numbers', () => {
252-
const requested = 1000;
253-
const latest = 500;
254-
const error = predefined.REQUEST_BEYOND_HEAD_BLOCK(requested, latest);
255-
expect(error.code).to.eq(-32000);
256-
expect(error.message).to.eq(`Request beyond head block: requested ${requested}, head ${latest}`);
257-
});
258-
259-
it('Constructs correctly with different block numbers', () => {
260-
const requested = 2500;
261-
const latest = 2000;
262-
const error = predefined.REQUEST_BEYOND_HEAD_BLOCK(requested, latest);
263-
expect(error.code).to.eq(-32000);
264-
expect(error.message).to.eq(`Request beyond head block: requested ${requested}, head ${latest}`);
243+
const testCases = [
244+
{ requested: 1000, latest: 500 },
245+
{ requested: 2500, latest: 2000 },
246+
];
247+
248+
testCases.forEach(({ requested, latest }) => {
249+
it(`Constructs correctly with requested ${requested} and latest ${latest}`, () => {
250+
const error = predefined.REQUEST_BEYOND_HEAD_BLOCK(requested, latest);
251+
expect(error.code).to.eq(-32000);
252+
expect(error.message).to.eq(`Request beyond head block: requested ${requested}, head ${latest}`);
253+
});
265254
});
266255
});
267256

@@ -273,93 +262,75 @@ describe('Errors', () => {
273262
expect(error.message).to.eq(`Non Existing Contract Address: ${address}. Expected a Contract or Token Address.`);
274263
});
275264

276-
it('Constructs correctly with empty address', () => {
277-
const address = '';
278-
const error = predefined.NON_EXISTING_CONTRACT(address);
279-
expect(error.code).to.eq(-32013);
280-
expect(error.message).to.eq(`Non Existing Contract Address: ${address}.`);
281-
});
282-
283-
it('Constructs correctly with null address', () => {
284-
const address = null;
285-
const error = predefined.NON_EXISTING_CONTRACT(address);
286-
expect(error.code).to.eq(-32013);
287-
expect(error.message).to.eq(`Non Existing Contract Address: ${address}.`);
288-
});
265+
const invalidAddresses: any[] = [
266+
{ address: '', description: 'empty string' },
267+
{ address: null, description: 'null' },
268+
{ address: undefined, description: 'undefined' },
269+
];
289270

290-
it('Constructs correctly with undefined address', () => {
291-
const address = undefined;
292-
const error = predefined.NON_EXISTING_CONTRACT(address);
293-
expect(error.code).to.eq(-32013);
294-
expect(error.message).to.eq(`Non Existing Contract Address: ${address}.`);
271+
invalidAddresses.forEach(({ address, description }) => {
272+
it(`Constructs correctly with ${description} address`, () => {
273+
const error = predefined.NON_EXISTING_CONTRACT(address);
274+
expect(error.code).to.eq(-32013);
275+
expect(error.message).to.eq(`Non Existing Contract Address: ${address}.`);
276+
});
295277
});
296278
});
297279

298280
describe('predefined.UNSUPPORTED_HISTORICAL_EXECUTION', () => {
299-
it('Constructs correctly with block identifier', () => {
300-
const blockId = 'earliest';
301-
const error = predefined.UNSUPPORTED_HISTORICAL_EXECUTION(blockId);
302-
expect(error.code).to.eq(-32609);
303-
expect(error.message).to.eq(`Unsupported historical block identifier encountered: ${blockId}`);
304-
});
281+
const testCases = ['earliest', '0x123abc'];
305282

306-
it('Constructs correctly with different block identifier', () => {
307-
const blockId = '0x123abc';
308-
const error = predefined.UNSUPPORTED_HISTORICAL_EXECUTION(blockId);
309-
expect(error.code).to.eq(-32609);
310-
expect(error.message).to.eq(`Unsupported historical block identifier encountered: ${blockId}`);
283+
testCases.forEach((blockId) => {
284+
it(`Constructs correctly with block identifier: ${blockId}`, () => {
285+
const error = predefined.UNSUPPORTED_HISTORICAL_EXECUTION(blockId);
286+
expect(error.code).to.eq(-32609);
287+
expect(error.message).to.eq(`Unsupported historical block identifier encountered: ${blockId}`);
288+
});
311289
});
312290
});
313291

314292
describe('predefined.UNSUPPORTED_OPERATION', () => {
315-
it('Constructs correctly with operation message', () => {
316-
const message = 'This operation is not supported in this version';
317-
const error = predefined.UNSUPPORTED_OPERATION(message);
318-
expect(error.code).to.eq(-32610);
319-
expect(error.message).to.eq(`Unsupported operation. ${message}`);
320-
});
321-
322-
it('Constructs correctly with different operation message', () => {
323-
const message = 'Feature disabled in current configuration';
324-
const error = predefined.UNSUPPORTED_OPERATION(message);
325-
expect(error.code).to.eq(-32610);
326-
expect(error.message).to.eq(`Unsupported operation. ${message}`);
293+
const testCases = [
294+
'This operation is not supported in this version',
295+
'Feature disabled in current configuration',
296+
];
297+
298+
testCases.forEach((message) => {
299+
it(`Constructs correctly with operation message: "${message}"`, () => {
300+
const error = predefined.UNSUPPORTED_OPERATION(message);
301+
expect(error.code).to.eq(-32610);
302+
expect(error.message).to.eq(`Unsupported operation. ${message}`);
303+
});
327304
});
328305
});
329306

330307
describe('predefined.BATCH_REQUESTS_AMOUNT_MAX_EXCEEDED', () => {
331-
it('Constructs correctly with amount and max values', () => {
332-
const amount = 150;
333-
const max = 100;
334-
const error = predefined.BATCH_REQUESTS_AMOUNT_MAX_EXCEEDED(amount, max);
335-
expect(error.code).to.eq(-32203);
336-
expect(error.message).to.eq(`Batch request amount ${amount} exceeds max ${max}`);
337-
});
338-
339-
it('Constructs correctly with different amount and max values', () => {
340-
const amount = 250;
341-
const max = 200;
342-
const error = predefined.BATCH_REQUESTS_AMOUNT_MAX_EXCEEDED(amount, max);
343-
expect(error.code).to.eq(-32203);
344-
expect(error.message).to.eq(`Batch request amount ${amount} exceeds max ${max}`);
308+
const testCases = [
309+
{ amount: 150, max: 100 },
310+
{ amount: 250, max: 200 },
311+
];
312+
313+
testCases.forEach(({ amount, max }) => {
314+
it(`Constructs correctly with amount ${amount} and max ${max}`, () => {
315+
const error = predefined.BATCH_REQUESTS_AMOUNT_MAX_EXCEEDED(amount, max);
316+
expect(error.code).to.eq(-32203);
317+
expect(error.message).to.eq(`Batch request amount ${amount} exceeds max ${max}`);
318+
});
345319
});
346320
});
347321

348322
describe('predefined.WS_BATCH_REQUESTS_AMOUNT_MAX_EXCEEDED', () => {
349-
it('Constructs correctly with amount and max values', () => {
350-
const amount = 25;
351-
const max = 20;
352-
const error = predefined.WS_BATCH_REQUESTS_AMOUNT_MAX_EXCEEDED(amount, max);
353-
expect(error.code).to.eq(-32206);
354-
expect(error.message).to.eq(`Batch request amount ${amount} exceeds max ${max}`);
355-
});
356-
357-
it('Constructs correctly with different amount and max values', () => {
358-
const amount = 50;
359-
const max = 30;
360-
const error = predefined.WS_BATCH_REQUESTS_AMOUNT_MAX_EXCEEDED(amount, max);
361-
expect(error.code).to.eq(-32206);
362-
expect(error.message).to.eq(`Batch request amount ${amount} exceeds max ${max}`);
323+
const testCases = [
324+
{ amount: 25, max: 20 },
325+
{ amount: 50, max: 30 },
326+
];
327+
328+
testCases.forEach(({ amount, max }) => {
329+
it(`Constructs correctly with amount ${amount} and max ${max}`, () => {
330+
const error = predefined.WS_BATCH_REQUESTS_AMOUNT_MAX_EXCEEDED(amount, max);
331+
expect(error.code).to.eq(-32206);
332+
expect(error.message).to.eq(`Batch request amount ${amount} exceeds max ${max}`);
333+
});
363334
});
364335
});
365336
});

0 commit comments

Comments
 (0)