Skip to content

Commit ee6dc18

Browse files
committed
chore: resolve comments
Signed-off-by: nikolay <[email protected]>
1 parent 5e998f9 commit ee6dc18

File tree

2 files changed

+26
-39
lines changed

2 files changed

+26
-39
lines changed

packages/ws-server/tests/unit/controllers/subscribeController.spec.ts

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ import constants from '@hashgraph/json-rpc-relay/dist/lib/constants';
55
import { Relay } from '@hashgraph/json-rpc-relay/dist/lib/relay';
66
import { RequestDetails } from '@hashgraph/json-rpc-relay/dist/lib/types/RequestDetails';
77
import { IJsonRpcRequest } from '@hashgraph/json-rpc-server/dist/koaJsonRpc/lib/IJsonRpcRequest';
8-
import { expect } from 'chai';
8+
import chai, { expect } from 'chai';
9+
import chaiAsPromised from 'chai-as-promised';
910
import Koa from 'koa';
1011
import { Counter } from 'prom-client';
1112
import sinon from 'sinon';
1213

1314
import { contractAddress1, contractAddress2 } from '../../../../relay/tests/helpers';
14-
import Assertions from '../../../../server/tests/helpers/assertions';
1515
import { handleEthSubscribe } from '../../../dist/controllers/subscribeController';
1616
import WsMetricRegistry from '../../../dist/metrics/wsMetricRegistry';
1717
import { SubscriptionService } from '../../../dist/service/subscriptionService';
1818
import ConnectionLimiter from '../../../src/metrics/connectionLimiter';
1919
import { WS_CONSTANTS } from '../../../src/utils/constants';
20+
chai.use(chaiAsPromised);
2021

2122
function createMockContext(): Koa.Context {
2223
return {
@@ -114,26 +115,18 @@ describe('Subscribe Controller', function () {
114115
stubMirrorNodeClient.resolveEntityType.returns(true);
115116
stubSubscriptionService.subscribe.returns(subscriptionId);
116117

117-
try {
118-
await handleEthSubscribe({
118+
await expect(
119+
handleEthSubscribe({
119120
...defaultParams,
120121
params: [constants.SUBSCRIBE_EVENTS.LOGS, { address: [contractAddress1, contractAddress2] }],
121-
});
122-
Assertions.expectedError();
123-
} catch (e) {
124-
expect(e.code).to.equal(-32602);
125-
}
122+
}),
123+
).to.be.eventually.rejected.and.have.property('code', -32602);
126124
});
127125

128126
it('should not be able to subscribe to new heads if WS_NEW_HEADS_ENABLED is disabled', async function () {
129127
stubConfigService.withArgs('WS_NEW_HEADS_ENABLED').returns(false);
130128

131-
try {
132-
await handleEthSubscribe(defaultParams);
133-
Assertions.expectedError();
134-
} catch (e: any) {
135-
expect(e.code).to.equal(-32601);
136-
}
129+
await expect(handleEthSubscribe(defaultParams)).to.be.eventually.rejected.and.have.property('code', -32601);
137130
});
138131

139132
it('should be able to subscribe to new heads', async function () {
@@ -145,14 +138,12 @@ describe('Subscribe Controller', function () {
145138
});
146139

147140
it('should throw unsupported method for non-existing method', async function () {
148-
try {
149-
await handleEthSubscribe({
141+
await expect(
142+
handleEthSubscribe({
150143
...defaultParams,
151144
params: [nonExistingMethod, {}],
152-
});
153-
} catch (e: any) {
154-
expect(e.code).to.equal(-32601);
155-
}
145+
}),
146+
).to.be.eventually.rejected.and.have.property('code', -32601);
156147
});
157148
});
158149
});

packages/ws-server/tests/unit/validations.spec.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22

33
import { MirrorNodeClient } from '@hashgraph/json-rpc-relay/dist/lib/clients';
44
import { RequestDetails } from '@hashgraph/json-rpc-relay/dist/lib/types';
5-
import { expect } from 'chai';
5+
import chai, { expect } from 'chai';
66
import pino from 'pino';
77
import sinon from 'sinon';
88

9-
import { contractAddress1 } from '../../../relay/tests/helpers';
10-
import Assertions from '../../../server/tests/helpers/assertions';
9+
import { contractAddress1, contractAddress2 } from '../../../relay/tests/helpers';
1110
import { validateSubscribeEthLogsParams } from '../../dist/utils/validators';
1211
import { WS_CONSTANTS } from '../../src/utils/constants';
1312
import { validateJsonRpcRequest, verifySupportedMethod } from '../../src/utils/utils';
1413
import { WsTestHelper } from '../helper';
1514

1615
const logger = pino({ level: 'silent' });
1716

17+
import chaiAsPromised from 'chai-as-promised';
18+
chai.use(chaiAsPromised);
19+
1820
describe('validations unit test', async function () {
1921
const FAKE_REQUEST_ID = '3';
2022
const FAKE_CONNECTION_ID = '9';
@@ -107,35 +109,29 @@ describe('validations unit test', async function () {
107109
it('should throw error if passed address as string is non-existing', async function () {
108110
stubMirrorNodeClient.resolveEntityType.returns(false);
109111

110-
try {
111-
await validateSubscribeEthLogsParams(
112+
await expect(
113+
validateSubscribeEthLogsParams(
112114
{
113115
address: contractAddress1,
114116
},
115117
stubMirrorNodeClient,
116118
requestDetails,
117-
);
118-
Assertions.expectedError();
119-
} catch (e) {
120-
expect(e.code).to.equal(-32602);
121-
}
119+
),
120+
).to.be.eventually.rejected.and.have.property('code', -32602);
122121
});
123122

124123
it('should throw error if passed address as array is non-existing', async function () {
125124
stubMirrorNodeClient.resolveEntityType.returns(false);
126125

127-
try {
128-
await validateSubscribeEthLogsParams(
126+
await expect(
127+
validateSubscribeEthLogsParams(
129128
{
130-
address: [contractAddress1],
129+
address: [contractAddress1, contractAddress2],
131130
},
132131
stubMirrorNodeClient,
133132
requestDetails,
134-
);
135-
Assertions.expectedError();
136-
} catch (e) {
137-
expect(e.code).to.equal(-32602);
138-
}
133+
),
134+
).to.be.eventually.rejected.and.have.property('code', -32602);
139135
});
140136

141137
it('should be able to pass address as a string', async function () {

0 commit comments

Comments
 (0)