@@ -139,6 +139,29 @@ describe('KadDHT', () => {
139
139
expect ( dht ) . to . have . property ( 'routingTable' )
140
140
} )
141
141
142
+ it ( 'create with validators and selectors' , ( ) => {
143
+ const sw = new Switch ( peerInfos [ 0 ] , new PeerBook ( ) )
144
+ sw . transport . add ( 'tcp' , new TCP ( ) )
145
+ sw . connection . addStreamMuxer ( Mplex )
146
+ sw . connection . reuse ( )
147
+ const dht = new KadDHT ( sw , {
148
+ validators : {
149
+ ipns : {
150
+ func : ( key , record , cb ) => cb ( )
151
+ }
152
+ } ,
153
+ selectors : {
154
+ ipns : ( key , records ) => 0
155
+ }
156
+ } )
157
+
158
+ expect ( dht ) . to . have . property ( 'peerInfo' ) . eql ( peerInfos [ 0 ] )
159
+ expect ( dht ) . to . have . property ( 'switch' ) . eql ( sw )
160
+ expect ( dht ) . to . have . property ( 'routingTable' )
161
+ expect ( dht . validators ) . to . have . property ( 'ipns' )
162
+ expect ( dht . selectors ) . to . have . property ( 'ipns' )
163
+ } )
164
+
142
165
it ( 'should be able to start and stop' , function ( done ) {
143
166
const sw = new Switch ( peerInfos [ 0 ] , new PeerBook ( ) )
144
167
sw . transport . add ( 'tcp' , new TCP ( ) )
@@ -280,6 +303,39 @@ describe('KadDHT', () => {
280
303
} )
281
304
} )
282
305
306
+ it ( 'put - get using key from provided validator and selector' , function ( done ) {
307
+ this . timeout ( 10 * 1000 )
308
+ const tdht = new TestDHT ( )
309
+
310
+ tdht . spawn ( 2 , {
311
+ validators : {
312
+ ipns : {
313
+ func : ( key , record , cb ) => cb ( )
314
+ }
315
+ } ,
316
+ selectors : {
317
+ ipns : ( key , records ) => 0
318
+ }
319
+ } , ( err , dhts ) => {
320
+ expect ( err ) . to . not . exist ( )
321
+ const dhtA = dhts [ 0 ]
322
+ const dhtB = dhts [ 1 ]
323
+
324
+ waterfall ( [
325
+ ( cb ) => connect ( dhtA , dhtB , cb ) ,
326
+ ( cb ) => dhtA . put ( Buffer . from ( '/ipns/hello' ) , Buffer . from ( 'world' ) , cb ) ,
327
+ ( cb ) => dhtB . get ( Buffer . from ( '/ipns/hello' ) , { maxTimeout : 1000 } , cb ) ,
328
+ ( res , cb ) => {
329
+ expect ( res ) . to . eql ( Buffer . from ( 'world' ) )
330
+ cb ( )
331
+ }
332
+ ] , ( err ) => {
333
+ expect ( err ) . to . not . exist ( )
334
+ tdht . teardown ( done )
335
+ } )
336
+ } )
337
+ } )
338
+
283
339
it ( 'put - get should fail if unrecognized key prefix in get' , function ( done ) {
284
340
this . timeout ( 10 * 1000 )
285
341
const tdht = new TestDHT ( )
0 commit comments