@@ -7,121 +7,219 @@ const expect = chai.expect
7
7
chai . use ( dirtyChai )
8
8
9
9
const series = require ( 'async/series' )
10
+ const parallel = require ( 'async/parallel' )
10
11
const os = require ( 'os' )
11
12
const path = require ( 'path' )
12
13
const hat = require ( 'hat' )
13
14
14
15
const DaemonFactory = require ( 'ipfsd-ctl' )
15
16
16
- const spawnJsDaemon = ( dir , callback ) => {
17
- DaemonFactory . create ( { type : 'js' } )
18
- . spawn ( {
19
- repoPath : dir ,
20
- disposable : false ,
21
- initOptions : { bits : 512 } ,
22
- args : [ '--offline' ]
23
- } , callback )
24
- }
25
-
26
- const spawnGoDaemon = ( dir , callback ) => {
27
- DaemonFactory . create ( )
28
- . spawn ( {
29
- repoPath : dir ,
30
- disposable : false ,
31
- initOptions : { bits : 1024 } ,
32
- args : [ '--offline' ]
33
- } , callback )
34
- }
35
-
36
17
const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU'
37
18
38
- const publishAndResolve = ( publisherDaemon , resolverDaemon , callback ) => {
39
- let nodeId
40
- let sameDaemon = false
41
-
42
- if ( typeof resolverDaemon === 'function' ) {
43
- callback = resolverDaemon
44
- resolverDaemon = publisherDaemon
45
- sameDaemon = true
46
- }
47
-
48
- const stopPublisherAndStartResolverDaemon = ( callback ) => {
49
- series ( [
50
- ( cb ) => publisherDaemon . stop ( cb ) ,
51
- ( cb ) => setTimeout ( cb , 2000 ) ,
52
- ( cb ) => resolverDaemon . start ( cb )
53
- ] , callback )
54
- }
55
-
56
- series ( [
57
- ( cb ) => publisherDaemon . init ( cb ) ,
58
- ( cb ) => publisherDaemon . start ( cb ) ,
59
- ( cb ) => publisherDaemon . api . id ( ( err , res ) => {
60
- expect ( err ) . to . not . exist ( )
61
- nodeId = res . id
62
- cb ( )
63
- } ) ,
64
- ( cb ) => publisherDaemon . api . name . publish ( ipfsRef , { resolve : false } , cb ) ,
65
- ( cb ) => sameDaemon ? cb ( ) : stopPublisherAndStartResolverDaemon ( cb ) ,
66
- ( cb ) => {
67
- resolverDaemon . api . name . resolve ( nodeId , { local : true } , ( err , res ) => {
19
+ describe ( 'ipns' , ( ) => {
20
+ describe ( 'ipns locally using the same repo across implementations' , ( ) => {
21
+ const spawnJsDaemon = ( dir , callback ) => {
22
+ DaemonFactory . create ( { type : 'js' } )
23
+ . spawn ( {
24
+ repoPath : dir ,
25
+ disposable : false ,
26
+ initOptions : { bits : 512 } ,
27
+ args : [ '--offline' ]
28
+ } , callback )
29
+ }
30
+
31
+ const spawnGoDaemon = ( dir , callback ) => {
32
+ DaemonFactory . create ( )
33
+ . spawn ( {
34
+ repoPath : dir ,
35
+ disposable : false ,
36
+ initOptions : { bits : 1024 } ,
37
+ args : [ '--offline' ]
38
+ } , callback )
39
+ }
40
+
41
+ const publishAndResolve = ( publisherDaemon , resolverDaemon , callback ) => {
42
+ let nodeId
43
+ let sameDaemon = false
44
+
45
+ if ( typeof resolverDaemon === 'function' ) {
46
+ callback = resolverDaemon
47
+ resolverDaemon = publisherDaemon
48
+ sameDaemon = true
49
+ }
50
+
51
+ const stopPublisherAndStartResolverDaemon = ( callback ) => {
52
+ series ( [
53
+ ( cb ) => publisherDaemon . stop ( cb ) ,
54
+ ( cb ) => setTimeout ( cb , 2000 ) ,
55
+ ( cb ) => resolverDaemon . start ( cb )
56
+ ] , callback )
57
+ }
58
+
59
+ series ( [
60
+ ( cb ) => publisherDaemon . init ( cb ) ,
61
+ ( cb ) => publisherDaemon . start ( cb ) ,
62
+ ( cb ) => publisherDaemon . api . id ( ( err , res ) => {
63
+ expect ( err ) . to . not . exist ( )
64
+ nodeId = res . id
65
+ cb ( )
66
+ } ) ,
67
+ ( cb ) => publisherDaemon . api . name . publish ( ipfsRef , { resolve : false } , cb ) ,
68
+ ( cb ) => sameDaemon ? cb ( ) : stopPublisherAndStartResolverDaemon ( cb ) ,
69
+ ( cb ) => {
70
+ resolverDaemon . api . name . resolve ( nodeId , { local : true } , ( err , res ) => {
71
+ expect ( err ) . to . not . exist ( )
72
+ expect ( res ) . to . equal ( ipfsRef )
73
+ cb ( )
74
+ } )
75
+ } ,
76
+ ( cb ) => resolverDaemon . stop ( cb ) ,
77
+ ( cb ) => setTimeout ( cb , 2000 ) ,
78
+ ( cb ) => resolverDaemon . cleanup ( cb )
79
+ ] , callback )
80
+ }
81
+
82
+ it ( 'should publish an ipns record to a js daemon and resolve it using the same js daemon' , function ( done ) {
83
+ this . timeout ( 120 * 1000 )
84
+ const dir = path . join ( os . tmpdir ( ) , hat ( ) )
85
+
86
+ spawnJsDaemon ( dir , ( err , jsDaemon ) => {
68
87
expect ( err ) . to . not . exist ( )
69
- expect ( res ) . to . equal ( ipfsRef )
70
- cb ( )
88
+ publishAndResolve ( jsDaemon , done )
71
89
} )
72
- } ,
73
- ( cb ) => resolverDaemon . stop ( cb ) ,
74
- ( cb ) => setTimeout ( cb , 2000 ) ,
75
- ( cb ) => resolverDaemon . cleanup ( cb )
76
- ] , callback )
77
- }
78
-
79
- describe ( 'ipns locally using the same repo across implementations' , ( ) => {
80
- it ( 'should publish an ipns record to a js daemon and resolve it using the same js daemon' , function ( done ) {
81
- this . timeout ( 120 * 1000 )
82
- const dir = path . join ( os . tmpdir ( ) , hat ( ) )
83
-
84
- spawnJsDaemon ( dir , ( err , jsDaemon ) => {
85
- expect ( err ) . to . not . exist ( )
86
- publishAndResolve ( jsDaemon , done )
87
90
} )
88
- } )
89
91
90
- it ( 'should publish an ipns record to a go daemon and resolve it using the same go daemon' , function ( done ) {
91
- this . timeout ( 160 * 1000 )
92
- const dir = path . join ( os . tmpdir ( ) , hat ( ) )
92
+ it ( 'should publish an ipns record to a go daemon and resolve it using the same go daemon' , function ( done ) {
93
+ this . timeout ( 160 * 1000 )
94
+ const dir = path . join ( os . tmpdir ( ) , hat ( ) )
93
95
94
- spawnGoDaemon ( dir , ( err , goDaemon ) => {
95
- expect ( err ) . to . not . exist ( )
96
- publishAndResolve ( goDaemon , done )
96
+ spawnGoDaemon ( dir , ( err , goDaemon ) => {
97
+ expect ( err ) . to . not . exist ( )
98
+ publishAndResolve ( goDaemon , done )
99
+ } )
97
100
} )
98
- } )
99
101
100
- it ( 'should publish an ipns record to a js daemon and resolve it using a go daemon through the reuse of the same repo' , function ( done ) {
101
- this . timeout ( 120 * 1000 )
102
- const dir = path . join ( os . tmpdir ( ) , hat ( ) )
102
+ it ( 'should publish an ipns record to a js daemon and resolve it using a go daemon through the reuse of the same repo' , function ( done ) {
103
+ this . timeout ( 120 * 1000 )
104
+ const dir = path . join ( os . tmpdir ( ) , hat ( ) )
105
+
106
+ series ( [
107
+ ( cb ) => spawnJsDaemon ( dir , cb ) ,
108
+ ( cb ) => spawnGoDaemon ( dir , cb )
109
+ ] , ( err , daemons ) => {
110
+ expect ( err ) . to . not . exist ( )
111
+
112
+ publishAndResolve ( daemons [ 0 ] , daemons [ 1 ] , done )
113
+ } )
114
+ } )
103
115
104
- series ( [
105
- ( cb ) => spawnJsDaemon ( dir , cb ) ,
106
- ( cb ) => spawnGoDaemon ( dir , cb )
107
- ] , ( err , daemons ) => {
108
- expect ( err ) . to . not . exist ( )
116
+ it ( 'should publish an ipns record to a go daemon and resolve it using a js daemon through the reuse of the same repo' , function ( done ) {
117
+ this . timeout ( 160 * 1000 )
118
+ const dir = path . join ( os . tmpdir ( ) , hat ( ) )
109
119
110
- publishAndResolve ( daemons [ 0 ] , daemons [ 1 ] , done )
120
+ series ( [
121
+ ( cb ) => spawnGoDaemon ( dir , cb ) ,
122
+ ( cb ) => spawnJsDaemon ( dir , cb )
123
+ ] , ( err , daemons ) => {
124
+ expect ( err ) . to . not . exist ( )
125
+
126
+ publishAndResolve ( daemons [ 0 ] , daemons [ 1 ] , done )
127
+ } )
111
128
} )
112
129
} )
113
130
114
- it ( 'should publish an ipns record to a go daemon and resolve it using a js daemon through the reuse of the same repo' , function ( done ) {
115
- this . timeout ( 160 * 1000 )
116
- const dir = path . join ( os . tmpdir ( ) , hat ( ) )
131
+ describe ( 'ipns over dht' , ( ) => {
132
+ const spawnJsDaemon = ( callback ) => {
133
+ DaemonFactory . create ( { type : 'js' } )
134
+ . spawn ( {
135
+ disposable : true ,
136
+ initOptions : { bits : 512 } ,
137
+ args : [ '--enable-dht-experiment' ] , // enable dht
138
+ config : { Bootstrap : [ ] }
139
+ } , callback )
140
+ }
141
+
142
+ const spawnGoDaemon = ( callback ) => {
143
+ DaemonFactory . create ( )
144
+ . spawn ( {
145
+ disposable : true ,
146
+ initOptions : { bits : 1024 } ,
147
+ config : { Bootstrap : [ ] }
148
+ } , callback )
149
+ }
150
+
151
+ let nodeAId
152
+ let nodeBId
153
+ let nodes = [ ]
154
+
155
+ // Spawn daemons
156
+ before ( function ( done ) {
157
+ // CI takes longer to instantiate the daemon, so we need to increase the timeout
158
+ this . timeout ( 80 * 1000 )
159
+ series ( [
160
+ ( cb ) => spawnGoDaemon ( cb ) ,
161
+ ( cb ) => spawnJsDaemon ( cb ) ,
162
+ ( cb ) => spawnGoDaemon ( cb )
163
+ ] , ( err , daemons ) => {
164
+ expect ( err ) . to . not . exist ( )
165
+ nodes = daemons
166
+ done ( )
167
+ } )
168
+ } )
117
169
118
- series ( [
119
- ( cb ) => spawnGoDaemon ( dir , cb ) ,
120
- ( cb ) => spawnJsDaemon ( dir , cb )
121
- ] , ( err , daemons ) => {
122
- expect ( err ) . to . not . exist ( )
170
+ // Get node ids
171
+ before ( function ( done ) {
172
+ this . timeout ( 100 * 1000 )
173
+ parallel ( [
174
+ ( cb ) => nodes [ 0 ] . api . id ( cb ) ,
175
+ ( cb ) => nodes [ 1 ] . api . id ( cb )
176
+ ] , ( err , ids ) => {
177
+ expect ( err ) . to . not . exist ( )
178
+ expect ( ids ) . to . exist ( )
179
+ expect ( ids [ 0 ] . id ) . to . exist ( )
180
+ expect ( ids [ 1 ] . id ) . to . exist ( )
181
+ nodeAId = ids [ 0 ]
182
+ nodeBId = ids [ 1 ]
183
+ parallel ( [
184
+ ( cb ) => nodes [ 2 ] . api . swarm . connect ( ids [ 0 ] . addresses [ 0 ] , cb ) , // C => A
185
+ ( cb ) => nodes [ 2 ] . api . swarm . connect ( ids [ 1 ] . addresses [ 0 ] , cb ) // C => B
186
+ ] , done )
187
+ } )
188
+ } )
189
+
190
+ after ( function ( done ) {
191
+ this . timeout ( 60 * 1000 )
192
+ parallel ( nodes . map ( ( node ) => ( cb ) => node . stop ( cb ) ) , done )
193
+ } )
123
194
124
- publishAndResolve ( daemons [ 0 ] , daemons [ 1 ] , done )
195
+ it ( 'should publish the record to a go node and resolve it using a js node' , function ( done ) {
196
+ this . timeout ( 50 * 1000 )
197
+ series ( [
198
+ ( cb ) => nodes [ 0 ] . api . name . publish ( ipfsRef , { resolve : false } , cb ) ,
199
+ ( cb ) => nodes [ 1 ] . api . name . resolve ( nodeAId . id , cb )
200
+ ] , ( err , res ) => {
201
+ expect ( err ) . to . not . exist ( )
202
+ expect ( res ) . to . exist ( )
203
+ expect ( res [ 0 ] . value ) . to . equal ( ipfsRef )
204
+ expect ( res [ 0 ] . name ) . to . equal ( nodeAId . id )
205
+ expect ( res [ 1 ] ) . to . equal ( ipfsRef )
206
+ done ( )
207
+ } )
208
+ } )
209
+
210
+ it ( 'should publish the record to a js node and resolve it using a go node' , function ( done ) {
211
+ this . timeout ( 50 * 1000 )
212
+ series ( [
213
+ ( cb ) => nodes [ 1 ] . api . name . publish ( ipfsRef , { resolve : false } , cb ) ,
214
+ ( cb ) => nodes [ 0 ] . api . name . resolve ( nodeBId . id , cb )
215
+ ] , ( err , res ) => {
216
+ expect ( err ) . to . not . exist ( )
217
+ expect ( res ) . to . exist ( )
218
+ expect ( res [ 0 ] . value ) . to . equal ( ipfsRef )
219
+ expect ( res [ 0 ] . name ) . to . equal ( nodeBId . id )
220
+ expect ( res [ 1 ] ) . to . equal ( ipfsRef )
221
+ done ( )
222
+ } )
125
223
} )
126
224
} )
127
225
} )
0 commit comments