@@ -7,9 +7,6 @@ const dirtyChai = require('dirty-chai')
77const expect = chai . expect
88chai . use ( dirtyChai )
99
10- const series = require ( 'async/series' )
11- const parallel = require ( 'async/parallel' )
12- const waterfall = require ( 'async/waterfall' )
1310const crypto = require ( 'crypto' )
1411const pretty = require ( 'pretty-bytes' )
1512const randomFs = require ( 'random-fs' )
@@ -124,69 +121,66 @@ describe('exchange files', function () {
124121 daemon2 = nodes [ 1 ]
125122 } )
126123
127- before ( 'connect' , function ( done ) {
128- series ( [
129- ( cb ) => parallel ( [
130- ( cb ) => daemon1 . api . id ( cb ) ,
131- ( cb ) => daemon2 . api . id ( cb )
132- ] , ( err , ids ) => {
133- expect ( err ) . to . not . exist ( )
134- id1 = ids [ 0 ]
135- id2 = ids [ 1 ]
136- cb ( )
137- } ) ,
138- ( cb ) => daemon1 . api . swarm . connect ( id2 . addresses [ 0 ] , cb ) ,
139- ( cb ) => daemon2 . api . swarm . connect ( id1 . addresses [ 0 ] , cb ) ,
140- ( cb ) => parallel ( [
141- ( cb ) => daemon1 . api . swarm . peers ( cb ) ,
142- ( cb ) => daemon2 . api . swarm . peers ( cb )
143- ] , ( err , peers ) => {
144- expect ( err ) . to . not . exist ( )
145- expect ( peers [ 0 ] . map ( ( p ) => p . peer . toB58String ( ) ) ) . to . include ( id2 . id )
146- expect ( peers [ 1 ] . map ( ( p ) => p . peer . toB58String ( ) ) ) . to . include ( id1 . id )
147- cb ( )
148- } )
149- ] , done )
124+ before ( 'connect' , async function ( ) {
125+ this . timeout ( timeout )
126+
127+ const ids = await Promise . all ( [
128+ daemon1 . api . id ( ) ,
129+ daemon2 . api . id ( )
130+ ] )
131+
132+ id1 = ids [ 0 ]
133+ id2 = ids [ 1 ]
134+
135+ await daemon1 . api . swarm . connect ( id2 . addresses [ 0 ] )
136+ await daemon2 . api . swarm . connect ( id1 . addresses [ 0 ] )
137+
138+ const peers = await Promise . all ( [
139+ daemon1 . api . swarm . peers ( ) ,
140+ daemon2 . api . swarm . peers ( )
141+ ] )
142+
143+ expect ( peers [ 0 ] . map ( ( p ) => p . peer . toB58String ( ) ) ) . to . include ( id2 . id )
144+ expect ( peers [ 1 ] . map ( ( p ) => p . peer . toB58String ( ) ) ) . to . include ( id1 . id )
150145 } )
151146
152147 after ( 'stop nodes' , function ( ) {
153148 return Promise . all ( [ daemon1 , daemon2 ] . map ( ( node ) => node . stop ( ) ) )
154149 } )
155150
156151 describe ( 'cat file' , ( ) => sizes . forEach ( ( size ) => {
157- it ( `${ name } : ${ pretty ( size ) } ` , function ( done ) {
152+ it ( `${ name } : ${ pretty ( size ) } ` , async function ( ) {
153+ this . timeout ( timeout )
154+
158155 const data = crypto . randomBytes ( size )
159156
160- waterfall ( [
161- ( cb ) => daemon1 . api . add ( data , cb ) ,
162- ( res , cb ) => daemon2 . api . cat ( res [ 0 ] . hash , cb )
163- ] , ( err , file ) => {
164- expect ( err ) . to . not . exist ( )
165- expect ( file ) . to . eql ( data )
166- done ( )
167- } )
157+ const res = await daemon1 . api . add ( data )
158+ const file = await daemon2 . api . cat ( res [ 0 ] . hash )
159+
160+ expect ( file ) . to . eql ( data )
168161 } )
169162 } ) )
170163
171164 if ( isWindows ( ) ) { return }
172165 // TODO fix dir tests on Windows
173166
174167 describe ( 'get directory' , ( ) => depth . forEach ( ( d ) => dirs . forEach ( ( num ) => {
175- it ( `${ name } : depth: ${ d } , num: ${ num } ` , function ( ) {
168+ it ( `${ name } : depth: ${ d } , num: ${ num } ` , async function ( ) {
169+ this . timeout ( timeout )
170+
176171 const dir = tmpDir ( )
177- return randomFs ( {
172+
173+ await randomFs ( {
178174 path : dir ,
179175 depth : d ,
180176 number : num
181- } ) . then ( ( ) => {
182- return daemon1 . api . addFromFs ( dir , { recursive : true } )
183- } ) . then ( ( res ) => {
184- const hash = res [ res . length - 1 ] . hash
185- return daemon2 . api . get ( hash )
186- } ) . then ( ( res ) => {
187- expect ( res ) . to . exist ( )
188- return rmDir ( dir )
189177 } )
178+ const res = await daemon1 . api . addFromFs ( dir , { recursive : true } )
179+ const hash = res [ res . length - 1 ] . hash
180+ const getRes = await daemon2 . api . get ( hash )
181+ expect ( getRes ) . to . exist ( )
182+
183+ return rmDir ( dir )
190184 } )
191185 } ) ) )
192186 } )
0 commit comments