1
1
import { bootstrap } from "@libp2p/bootstrap" ;
2
+ import tests from "@libp2p/interface-peer-discovery-compliance-tests" ;
2
3
import {
3
4
Fleet ,
4
5
getPredefinedBootstrapNodes ,
5
6
} from "@waku/core/lib/predefined_bootstrap_nodes" ;
6
- import { createLightNode } from "@waku/create" ;
7
- import { PeerInfo } from "@waku/interfaces" ;
8
- import type { LightNode } from "@waku/interfaces" ;
7
+ import { createLightNode , Libp2pComponents } from "@waku/create" ;
8
+ import type { LightNode , PeerInfo } from "@waku/interfaces" ;
9
9
import {
10
10
PeerExchangeCodec ,
11
+ PeerExchangeDiscovery ,
11
12
WakuPeerExchange ,
12
13
wakuPeerExchangeDiscovery ,
13
14
} from "@waku/peer-exchange" ;
@@ -108,13 +109,16 @@ describe("Peer Exchange", () => {
108
109
109
110
await nwaku2 . waitForLog ( "Discovered px peers via discv5" , 10 ) ;
110
111
111
- // the ts-ignores are added ref: https://github.com/libp2p/js-libp2p-interfaces/issues/338#issuecomment-1431643645
112
- const peerExchange = new WakuPeerExchange ( {
113
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
114
- // @ts -ignore
115
- connectionManager : waku . libp2p . connectionManager ,
116
- peerStore : waku . libp2p . peerStore ,
117
- } ) ;
112
+ // the forced type casting is done in ref to https://github.com/libp2p/js-libp2p-interfaces/issues/338#issuecomment-1431643645
113
+ const { connectionManager, registrar, peerStore } =
114
+ waku . libp2p as unknown as Libp2pComponents ;
115
+ const components = {
116
+ connectionManager : connectionManager ,
117
+ registrar : registrar ,
118
+ peerStore : peerStore ,
119
+ } ;
120
+
121
+ const peerExchange = new WakuPeerExchange ( components ) ;
118
122
119
123
const numPeersToRequest = 1 ;
120
124
@@ -138,4 +142,64 @@ describe("Peer Exchange", () => {
138
142
expect ( waku . libp2p . peerStore . has ( await nwaku2 . getPeerId ( ) ) ) . to . be . true ;
139
143
} ) ;
140
144
} ) ;
145
+
146
+ describe ( "compliance test" , async function ( ) {
147
+ this . timeout ( 25_000 ) ;
148
+
149
+ let waku : LightNode ;
150
+ let nwaku1 : Nwaku ;
151
+ let nwaku2 : Nwaku ;
152
+
153
+ beforeEach ( async function ( ) {
154
+ nwaku1 = new Nwaku ( makeLogFileName ( this ) + "1" ) ;
155
+ nwaku2 = new Nwaku ( makeLogFileName ( this ) + "2" ) ;
156
+ } ) ;
157
+
158
+ tests ( {
159
+ async setup ( ) {
160
+ await nwaku1 . start ( {
161
+ discv5Discovery : true ,
162
+ peerExchange : true ,
163
+ } ) ;
164
+
165
+ const enr = ( await nwaku1 . info ( ) ) . enrUri ;
166
+
167
+ await nwaku2 . start ( {
168
+ discv5Discovery : true ,
169
+ peerExchange : true ,
170
+ discv5BootstrapNode : enr ,
171
+ } ) ;
172
+
173
+ waku = await createLightNode ( ) ;
174
+
175
+ await waku . start ( ) ;
176
+ const nwaku2Ma = await nwaku2 . getMultiaddrWithId ( ) ;
177
+
178
+ await waku . libp2p . dialProtocol ( nwaku2Ma , PeerExchangeCodec ) ;
179
+ await new Promise < void > ( ( resolve ) => {
180
+ waku . libp2p . peerStore . addEventListener ( "change:protocols" , ( evt ) => {
181
+ if ( evt . detail . protocols . includes ( PeerExchangeCodec ) ) {
182
+ resolve ( ) ;
183
+ }
184
+ } ) ;
185
+ } ) ;
186
+
187
+ // the forced type casting is done in ref to https://github.com/libp2p/js-libp2p-interfaces/issues/338#issuecomment-1431643645
188
+ const { connectionManager, registrar, peerStore } =
189
+ waku . libp2p as unknown as Libp2pComponents ;
190
+ const components = {
191
+ connectionManager : connectionManager ,
192
+ registrar : registrar ,
193
+ peerStore : peerStore ,
194
+ } ;
195
+
196
+ return new PeerExchangeDiscovery ( components ) ;
197
+ } ,
198
+ teardown : async ( ) => {
199
+ ! ! nwaku1 && nwaku1 . stop ( ) ;
200
+ ! ! nwaku2 && nwaku2 . stop ( ) ;
201
+ ! ! waku && ( await waku . stop ( ) ) ;
202
+ } ,
203
+ } ) ;
204
+ } ) ;
141
205
} ) ;
0 commit comments