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