@@ -11,9 +11,10 @@ const CID = require('cids')
11
11
const { spawnNodesWithId } = require ( './utils/spawn' )
12
12
13
13
module . exports = ( common ) => {
14
- describe ( '.dht' , function ( ) {
14
+ describe . only ( '.dht' , function ( ) {
15
15
this . timeout ( 80 * 1000 )
16
16
17
+ let withGo
17
18
let nodeA
18
19
let nodeB
19
20
let nodeC
@@ -47,7 +48,12 @@ module.exports = (common) => {
47
48
( cb ) => nodeE . swarm . connect ( nodeB . peerId . addresses [ 0 ] , cb ) ,
48
49
( cb ) => nodeD . swarm . connect ( nodeC . peerId . addresses [ 0 ] , cb ) ,
49
50
( cb ) => nodeE . swarm . connect ( nodeC . peerId . addresses [ 0 ] , cb ) ,
50
- ( cb ) => nodeD . swarm . connect ( nodeE . peerId . addresses [ 0 ] , cb )
51
+ ( cb ) => nodeD . swarm . connect ( nodeE . peerId . addresses [ 0 ] , cb ) ,
52
+ ( cb ) => nodeA . id ( ( err , id ) => {
53
+ expect ( err ) . to . not . exist ( )
54
+ withGo = id . agentVersion . startsWith ( 'go-ipfs' )
55
+ cb ( )
56
+ } )
51
57
] , done )
52
58
} )
53
59
} )
@@ -63,14 +69,19 @@ module.exports = (common) => {
63
69
} )
64
70
} )
65
71
66
- // TODO: fix - go-ipfs errors with Error: key was not found (type 6)
67
- // https://github.com/ipfs/go-ipfs/issues/3862
68
- it . skip ( 'fetches value after it was put on another node' , ( done ) => {
72
+ it ( 'fetches value after it was put on another node' , function ( done ) {
73
+ if ( withGo ) {
74
+ // go-ipfs errors with Error: key was not found (type 6)
75
+ // https://github.com/ipfs/go-ipfs/issues/3862
76
+ this . skip ( )
77
+ }
78
+
79
+ // TODO - this test needs to keep tryingl instead of the setTimeout
69
80
waterfall ( [
70
81
( cb ) => nodeB . object . new ( 'unixfs-dir' , cb ) ,
71
- ( node , cb ) => setTimeout ( ( ) => cb ( null , node ) , 1000 ) ,
72
- ( node , cb ) => {
73
- const multihash = node . toJSON ( ) . multihash
82
+ ( dagNode , cb ) => setTimeout ( ( ) => cb ( null , dagNode ) , 1000 ) ,
83
+ ( dagNode , cb ) => {
84
+ const multihash = dagNode . toJSON ( ) . multihash
74
85
75
86
nodeA . dht . get ( multihash , cb )
76
87
} ,
@@ -80,14 +91,6 @@ module.exports = (common) => {
80
91
}
81
92
] , done )
82
93
} )
83
-
84
- it ( 'Promises support' , ( done ) => {
85
- nodeA . dht . get ( 'non-existing' , { timeout : '100ms' } )
86
- . catch ( ( err ) => {
87
- expect ( err ) . to . exist ( )
88
- done ( )
89
- } )
90
- } )
91
94
} )
92
95
93
96
describe ( '.findpeer' , ( ) => {
@@ -100,9 +103,13 @@ module.exports = (common) => {
100
103
} )
101
104
} )
102
105
103
- // TODO checking what is exactly go-ipfs returning
104
- // https://github.com/ipfs/go-ipfs/issues/3862#issuecomment-294168090
105
- it . skip ( 'fails to find other peer, if peer doesnt exist()s' , ( done ) => {
106
+ it ( 'fails to find other peer, if peer does not exist' , function ( done ) {
107
+ if ( withGo ) {
108
+ // TODO checking what is exactly go-ipfs returning
109
+ // https://github.com/ipfs/go-ipfs/issues/3862#issuecomment-294168090
110
+ this . skip ( )
111
+ }
112
+
106
113
nodeA . dht . findpeer ( 'Qmd7qZS4T7xXtsNFdRoK1trfMs5zU94EpokQ9WFtxdPxsZ' , ( err , peer ) => {
107
114
expect ( err ) . to . not . exist ( )
108
115
expect ( peer ) . to . be . equal ( null )
@@ -177,37 +184,30 @@ module.exports = (common) => {
177
184
it . skip ( 'recursive' , ( ) => { } )
178
185
} )
179
186
180
- describe . skip ( 'findprovs' , ( ) => {
187
+ describe ( 'findprovs' , ( ) => {
181
188
it ( 'basic' , ( done ) => {
182
- const cid = new CID ( 'Qmd7qZS4T7xXtsNFdRoK1trfMs5zU94EpokQ9WFtxdPxxx' )
183
-
184
189
waterfall ( [
185
- ( cb ) => nodeB . dht . provide ( cid , cb ) ,
186
- ( cb ) => nodeC . dht . findprovs ( cid , cb ) ,
190
+ ( cb ) => nodeE . object . new ( 'unixfs-dir' , cb ) ,
191
+ ( dagNode , cb ) => {
192
+ const cidV0 = new CID ( dagNode . toJSON ( ) . multihash )
193
+ nodeE . dht . provide ( cidV0 , ( err ) => cb ( err , cidV0 ) )
194
+ } ,
195
+ ( cidV0 , cb ) => nodeC . dht . findprovs ( cidV0 , cb ) ,
187
196
( provs , cb ) => {
188
197
expect ( provs . map ( ( p ) => p . toB58String ( ) ) )
189
- . to . eql ( [ nodeB . peerId . id ] )
198
+ . to . eql ( [ nodeE . peerId . id ] )
190
199
cb ( )
191
200
}
192
201
] , done )
193
202
} )
194
-
195
- it ( 'Promises support' , ( done ) => {
196
- nodeB . dht . findprovs ( 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' )
197
- . then ( ( res ) => {
198
- expect ( res ) . to . be . an ( 'array' )
199
- done ( )
200
- } )
201
- . catch ( ( err ) => done ( err ) )
202
- } )
203
203
} )
204
204
205
205
describe ( '.query' , ( ) => {
206
206
it ( 'returns the other node in the query' , function ( done ) {
207
207
const timeout = 150 * 1000
208
208
this . timeout ( timeout )
209
209
210
- // This test is flaky . DHT works best with >= 20 nodes. Therefore a
210
+ // This test is meh . DHT works best with >= 20 nodes. Therefore a
211
211
// failure might happen, but we don't want to report it as such.
212
212
// Hence skip the test before the timeout is reached
213
213
const timeoutId = setTimeout ( function ( ) {
0 commit comments