@@ -5,18 +5,19 @@ import constants from '@hashgraph/json-rpc-relay/dist/lib/constants';
5
5
import { Relay } from '@hashgraph/json-rpc-relay/dist/lib/relay' ;
6
6
import { RequestDetails } from '@hashgraph/json-rpc-relay/dist/lib/types/RequestDetails' ;
7
7
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' ;
9
10
import Koa from 'koa' ;
10
11
import { Counter } from 'prom-client' ;
11
12
import sinon from 'sinon' ;
12
13
13
14
import { contractAddress1 , contractAddress2 } from '../../../../relay/tests/helpers' ;
14
- import Assertions from '../../../../server/tests/helpers/assertions' ;
15
15
import { handleEthSubscribe } from '../../../dist/controllers/subscribeController' ;
16
16
import WsMetricRegistry from '../../../dist/metrics/wsMetricRegistry' ;
17
17
import { SubscriptionService } from '../../../dist/service/subscriptionService' ;
18
18
import ConnectionLimiter from '../../../src/metrics/connectionLimiter' ;
19
19
import { WS_CONSTANTS } from '../../../src/utils/constants' ;
20
+ chai . use ( chaiAsPromised ) ;
20
21
21
22
function createMockContext ( ) : Koa . Context {
22
23
return {
@@ -114,26 +115,18 @@ describe('Subscribe Controller', function () {
114
115
stubMirrorNodeClient . resolveEntityType . returns ( true ) ;
115
116
stubSubscriptionService . subscribe . returns ( subscriptionId ) ;
116
117
117
- try {
118
- await handleEthSubscribe ( {
118
+ await expect (
119
+ handleEthSubscribe ( {
119
120
...defaultParams ,
120
121
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 ) ;
126
124
} ) ;
127
125
128
126
it ( 'should not be able to subscribe to new heads if WS_NEW_HEADS_ENABLED is disabled' , async function ( ) {
129
127
stubConfigService . withArgs ( 'WS_NEW_HEADS_ENABLED' ) . returns ( false ) ;
130
128
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 ) ;
137
130
} ) ;
138
131
139
132
it ( 'should be able to subscribe to new heads' , async function ( ) {
@@ -145,14 +138,12 @@ describe('Subscribe Controller', function () {
145
138
} ) ;
146
139
147
140
it ( 'should throw unsupported method for non-existing method' , async function ( ) {
148
- try {
149
- await handleEthSubscribe ( {
141
+ await expect (
142
+ handleEthSubscribe ( {
150
143
...defaultParams ,
151
144
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 ) ;
156
147
} ) ;
157
148
} ) ;
158
149
} ) ;
0 commit comments