3
3
4
4
const chai = require ( 'chai' )
5
5
chai . use ( require ( 'dirty-chai' ) )
6
+ chai . use ( require ( 'chai-as-promised' ) )
6
7
const { expect } = chai
7
8
const sinon = require ( 'sinon' )
8
9
@@ -87,13 +88,9 @@ describe('Dialing (via relay, TCP)', () => {
87
88
. encapsulate ( `/p2p/${ relayIdString } ` )
88
89
. encapsulate ( `/p2p-circuit/p2p/${ dstLibp2p . peerInfo . id . toString ( ) } ` )
89
90
90
- try {
91
- await srcLibp2p . dial ( dialAddr )
92
- expect . fail ( 'Dial should have failed' )
93
- } catch ( err ) {
94
- expect ( err ) . to . exist ( )
95
- expect ( err ) . to . have . property ( 'code' , Errors . ERR_HOP_REQUEST_FAILED )
96
- }
91
+ await expect ( srcLibp2p . dial ( dialAddr ) )
92
+ . to . eventually . be . rejected ( )
93
+ . and . to . have . property ( 'code' , Errors . ERR_HOP_REQUEST_FAILED )
97
94
} )
98
95
99
96
it ( 'should not stay connected to a relay when not already connected and HOP fails' , async ( ) => {
@@ -104,13 +101,9 @@ describe('Dialing (via relay, TCP)', () => {
104
101
. encapsulate ( `/p2p/${ relayIdString } ` )
105
102
. encapsulate ( `/p2p-circuit/p2p/${ dstLibp2p . peerInfo . id . toString ( ) } ` )
106
103
107
- try {
108
- await srcLibp2p . dial ( dialAddr )
109
- expect . fail ( 'Dial should have failed' )
110
- } catch ( err ) {
111
- expect ( err ) . to . exist ( )
112
- expect ( err ) . to . have . property ( 'code' , Errors . ERR_HOP_REQUEST_FAILED )
113
- }
104
+ await expect ( srcLibp2p . dial ( dialAddr ) )
105
+ . to . eventually . be . rejected ( )
106
+ . and . to . have . property ( 'code' , Errors . ERR_HOP_REQUEST_FAILED )
114
107
115
108
// We should not be connected to the relay, because we weren't before the dial
116
109
const srcToRelayConn = srcLibp2p . registrar . getConnection ( relayLibp2p . peerInfo )
@@ -125,16 +118,11 @@ describe('Dialing (via relay, TCP)', () => {
125
118
. encapsulate ( `/p2p/${ relayIdString } ` )
126
119
. encapsulate ( `/p2p-circuit/p2p/${ dstLibp2p . peerInfo . id . toString ( ) } ` )
127
120
128
- // Connect to the relay first
129
121
await srcLibp2p . dial ( relayAddr )
130
122
131
- try {
132
- await srcLibp2p . dial ( dialAddr )
133
- expect . fail ( 'Dial should have failed' )
134
- } catch ( err ) {
135
- expect ( err ) . to . exist ( )
136
- expect ( err ) . to . have . property ( 'code' , Errors . ERR_HOP_REQUEST_FAILED )
137
- }
123
+ await expect ( srcLibp2p . dial ( dialAddr ) )
124
+ . to . eventually . be . rejected ( )
125
+ . and . to . have . property ( 'code' , Errors . ERR_HOP_REQUEST_FAILED )
138
126
139
127
const srcToRelayConn = srcLibp2p . registrar . getConnection ( relayLibp2p . peerInfo )
140
128
expect ( srcToRelayConn ) . to . exist ( )
@@ -159,13 +147,9 @@ describe('Dialing (via relay, TCP)', () => {
159
147
buffer : Buffer . from ( 'an invalid multiaddr' )
160
148
} ] )
161
149
162
- try {
163
- await srcLibp2p . dial ( dialAddr )
164
- expect . fail ( 'Dial should have failed' )
165
- } catch ( err ) {
166
- expect ( err ) . to . exist ( )
167
- expect ( err ) . to . have . property ( 'code' , Errors . ERR_HOP_REQUEST_FAILED )
168
- }
150
+ await expect ( srcLibp2p . dial ( dialAddr ) )
151
+ . to . eventually . be . rejected ( )
152
+ . and . to . have . property ( 'code' , Errors . ERR_HOP_REQUEST_FAILED )
169
153
170
154
const dstToRelayConn = dstLibp2p . registrar . getConnection ( relayLibp2p . peerInfo )
171
155
expect ( dstToRelayConn ) . to . exist ( )
0 commit comments