Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit d50acbd

Browse files
committed
feat: adopting latest changes to ipfsd-ctl
1 parent 78c4c10 commit d50acbd

File tree

3 files changed

+115
-81
lines changed

3 files changed

+115
-81
lines changed

.aegir.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
served: true,
1212
included: false
1313
}],
14-
singleRun: true,
14+
singleRun: false,
1515
browserNoActivityTimeout: 100 * 1000
1616
},
1717
hooks: {

test/circuit-relay.js

Lines changed: 112 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ const waterfall = require('async/waterfall')
1313
const multiaddr = require('multiaddr')
1414
const crypto = require('crypto')
1515
const IPFS = require('ipfs')
16-
const createRepo = require('./utils/create-repo-nodejs')
1716

1817
const isNode = require('detect-node')
1918

2019
const DaemonFactory = require('ipfsd-ctl')
21-
const df = DaemonFactory.create()
20+
const jsDf = DaemonFactory.create({ type: 'js' })
21+
const goDf = DaemonFactory.create({ type: 'go' })
22+
const procDf = DaemonFactory.create({ type: 'proc', exec: IPFS })
2223

2324
const baseConf = {
2425
Bootstrap: [],
@@ -38,9 +39,7 @@ function setupInProcNode (factory, addrs, hop, callback) {
3839
hop = false
3940
}
4041

41-
const node = new IPFS({
42-
repo: createRepo(),
43-
init: { bits: 1024 },
42+
procDf.spawn({
4443
config: Object.assign({}, baseConf, {
4544
Addresses: {
4645
Swarm: addrs
@@ -54,10 +53,11 @@ function setupInProcNode (factory, addrs, hop, callback) {
5453
}
5554
}
5655
})
57-
})
58-
59-
node.once('ready', () => {
60-
callback(null, node)
56+
}, (err, ipfsd) => {
57+
expect(err).to.not.exist()
58+
ipfsd.api.id((err, id) => {
59+
callback(err, { ipfsd, addrs: circuitFilter(id.addresses) })
60+
})
6161
})
6262
}
6363

@@ -67,8 +67,7 @@ function setUpJsNode (addrs, hop, callback) {
6767
hop = false
6868
}
6969

70-
df.spawn({
71-
type: 'js',
70+
jsDf.spawn({
7271
config: Object.assign({}, baseConf, {
7372
Addresses: {
7473
Swarm: addrs
@@ -84,8 +83,8 @@ function setUpJsNode (addrs, hop, callback) {
8483
})
8584
}, (err, ipfsd) => {
8685
expect(err).to.not.exist()
87-
ipfsd.api.swarm.localAddrs((err, addrs) => {
88-
callback(err, { ipfsd, addrs: circuitFilter(addrs) })
86+
ipfsd.api.id((err, id) => {
87+
callback(err, { ipfsd, addrs: circuitFilter(id.addresses) })
8988
})
9089
})
9190
}
@@ -96,7 +95,7 @@ function setUpGoNode (addrs, hop, callback) {
9695
hop = false
9796
}
9897

99-
df.spawn({
98+
goDf.spawn({
10099
config: Object.assign({}, baseConf, {
101100
Addresses: {
102101
Swarm: addrs
@@ -114,17 +113,6 @@ function setUpGoNode (addrs, hop, callback) {
114113
})
115114
}
116115

117-
function addAndCat (node1, node2, data, callback) {
118-
waterfall([
119-
(cb) => node1.files.add(data, cb),
120-
(res, cb) => node2.files.cat(res[0].hash, cb),
121-
(buffer, cb) => {
122-
expect(buffer).to.deep.equal(data)
123-
cb()
124-
}
125-
], callback)
126-
}
127-
128116
const circuitFilter = (addrs) => addrs.map((a) => a.toString()).filter((a) => !a.includes('/p2p-circuit'))
129117
const wsAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => a.includes('/ws'))
130118
const tcpAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => !a.includes('/ws'))
@@ -135,16 +123,17 @@ function tests (relayType) {
135123

136124
let goTCP
137125
let goTCPAddr
138-
let jsWSAddr
139126
let jsWS
127+
let jsWSAddr
140128
let jsWSCircuitAddr
141129

142130
let nodes
143-
before((done) => {
131+
132+
before(function (done) {
144133
parallel([
145134
(cb) => setUpGoNode([`${base}/35003`], cb),
146135
(cb) => setUpJsNode([`${base}/35004/ws`], cb)
147-
], (err, res) => {
136+
], function (err, res) {
148137
expect(err).to.not.exist()
149138
nodes = res.map((node) => node.ipfsd)
150139

@@ -161,18 +150,26 @@ function tests (relayType) {
161150

162151
after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done))
163152

164-
it('should connect and transfer', function (done) {
165-
const data = crypto.randomBytes(128)
153+
it('should connect', function (done) {
166154
series([
167155
(cb) => this.relay.api.swarm.connect(goTCPAddr, cb),
168156
(cb) => setTimeout(cb, 1000),
169157
(cb) => this.relay.api.swarm.connect(jsWSAddr, cb),
170158
(cb) => setTimeout(cb, 1000),
171159
(cb) => goTCP.swarm.connect(jsWSCircuitAddr, cb)
172-
], (err) => {
173-
expect(err).to.not.exist()
174-
addAndCat(goTCP, jsWS, data, done)
175-
})
160+
], done)
161+
})
162+
163+
it('should transfer', function (done) {
164+
const data = crypto.randomBytes(128)
165+
waterfall([
166+
(cb) => goTCP.files.add(data, cb),
167+
(res, cb) => jsWS.files.cat(res[0].hash, cb),
168+
(buffer, cb) => {
169+
expect(buffer).to.deep.equal(data)
170+
cb()
171+
}
172+
], done)
176173
})
177174
})
178175

@@ -207,18 +204,26 @@ function tests (relayType) {
207204

208205
after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done))
209206

210-
it('should connect and transfer', function (done) {
211-
const data = crypto.randomBytes(128)
207+
it('should connect', function (done) {
212208
series([
213209
(cb) => this.relay.api.swarm.connect(jsTCPAddr, cb),
214210
(cb) => setTimeout(cb, 1000),
215211
(cb) => this.relay.api.swarm.connect(jsWSAddr, cb),
216212
(cb) => setTimeout(cb, 1000),
217213
(cb) => jsWS.swarm.connect(jsTCPCircuitAddr, cb)
218-
], (err) => {
219-
expect(err).to.not.exist()
220-
addAndCat(jsTCP, jsWS, data, done)
221-
})
214+
], done)
215+
})
216+
217+
it('should transfer', function (done) {
218+
const data = crypto.randomBytes(128)
219+
waterfall([
220+
(cb) => jsTCP.files.add(data, cb),
221+
(res, cb) => jsWS.files.cat(res[0].hash, cb),
222+
(buffer, cb) => {
223+
expect(buffer).to.deep.equal(data)
224+
cb()
225+
}
226+
], done)
222227
})
223228
})
224229

@@ -253,18 +258,26 @@ function tests (relayType) {
253258

254259
after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done))
255260

256-
it('should connect and transfer', function (done) {
257-
const data = crypto.randomBytes(128)
261+
it('should connect', function (done) {
258262
series([
259263
(cb) => this.relay.api.swarm.connect(goTCPAddr, cb),
260264
(cb) => setTimeout(cb, 1000),
261265
(cb) => this.relay.api.swarm.connect(goWSAddr, cb),
262266
(cb) => setTimeout(cb, 1000),
263267
(cb) => goWS.swarm.connect(goTCPCircuitAddr, cb)
264-
], (err) => {
265-
expect(err).to.not.exist()
266-
addAndCat(goTCP, goWS, data, done)
267-
})
268+
], done)
269+
})
270+
271+
it('should transfer', function (done) {
272+
const data = crypto.randomBytes(128)
273+
waterfall([
274+
(cb) => goTCP.files.add(data, cb),
275+
(res, cb) => goWS.files.cat(res[0].hash, cb),
276+
(buffer, cb) => {
277+
expect(buffer).to.deep.equal(data)
278+
cb()
279+
}
280+
], done)
268281
})
269282
})
270283

@@ -287,28 +300,34 @@ function tests (relayType) {
287300
(cb) => setupInProcNode([], false, cb)
288301
], (err, nodes) => {
289302
expect(err).to.not.exist()
290-
browserNode1 = nodes[0]
291-
browserNode2 = nodes[1]
292-
browserNode2.id((err, id) => {
293-
expect(err).to.not.exist()
294-
browserNode2Addrs = id.addresses
295-
done()
296-
})
303+
browserNode1 = nodes[0].ipfsd.api
304+
browserNode2 = nodes[1].ipfsd.api
305+
306+
browserNode2Addrs = nodes[1].addrs
307+
done()
297308
})
298309
})
299310

300-
it('should connect and transfer', function (done) {
301-
const data = crypto.randomBytes(128)
311+
it('should connect', function (done) {
302312
series([
303313
(cb) => browserNode1.swarm.connect(wsAddr(this.relayAddrs), cb),
304314
(cb) => setTimeout(cb, 1000),
305315
(cb) => browserNode2.swarm.connect(wsAddr(this.relayAddrs), cb),
306316
(cb) => setTimeout(cb, 1000),
307317
(cb) => browserNode1.swarm.connect(browserNode2Addrs[0], cb)
308-
], (err) => {
309-
expect(err).to.not.exist()
310-
addAndCat(browserNode1, browserNode2, data, done)
311-
})
318+
], done)
319+
})
320+
321+
it('should transfer', function (done) {
322+
const data = crypto.randomBytes(128)
323+
waterfall([
324+
(cb) => browserNode1.files.add(data, cb),
325+
(res, cb) => browserNode2.files.cat(res[0].hash, cb),
326+
(buffer, cb) => {
327+
expect(buffer).to.deep.equal(data)
328+
cb()
329+
}
330+
], done)
312331
})
313332
})
314333

@@ -341,17 +360,25 @@ function tests (relayType) {
341360
after((done) => jsTCP.stop(done))
342361

343362
it('should connect and transfer', function (done) {
344-
const data = crypto.randomBytes(128)
345363
series([
346364
(cb) => browserNode1.swarm.connect(wsAddr(this.relayAddrs), cb),
347365
(cb) => setTimeout(cb, 1000),
348366
(cb) => jsTCP.api.swarm.connect(tcpAddr(this.relayAddrs), cb),
349367
(cb) => setTimeout(cb, 1000),
350368
(cb) => browserNode1.swarm.connect(jsTCPAddrs[0], cb)
351-
], (err) => {
352-
expect(err).to.not.exist()
353-
addAndCat(browserNode1, jsTCP.api, data, done)
354-
})
369+
], done)
370+
})
371+
372+
it('should transfer', function (done) {
373+
const data = crypto.randomBytes(128)
374+
waterfall([
375+
(cb) => browserNode1.files.add(data, cb),
376+
(res, cb) => jsTCP.files.cat(res[0].hash, cb),
377+
(buffer, cb) => {
378+
expect(buffer).to.deep.equal(data)
379+
cb()
380+
}
381+
], done)
355382
})
356383
})
357384

@@ -384,39 +411,47 @@ function tests (relayType) {
384411

385412
after((done) => goTCP.stop(done))
386413

387-
it('should connect and transfer', function (done) {
388-
const data = crypto.randomBytes(128)
414+
it('should connect', function (done) {
389415
series([
390416
(cb) => browserNode1.swarm.connect(wsAddr(this.relayAddrs), cb),
391417
(cb) => setTimeout(cb, 1000),
392418
(cb) => goTCP.api.swarm.connect(tcpAddr(this.relayAddrs), cb),
393419
(cb) => setTimeout(cb, 1000),
394420
(cb) => browserNode1.swarm.connect(goTCPAddrs[0], cb)
395-
], (err) => {
396-
expect(err).to.not.exist()
397-
addAndCat(browserNode1, goTCP.api, data, done)
398-
})
421+
], done)
422+
})
423+
424+
it('should transfer', function (done) {
425+
const data = crypto.randomBytes(128)
426+
waterfall([
427+
(cb) => browserNode1.files.add(data, cb),
428+
(res, cb) => goTCP.files.cat(res[0].hash, cb),
429+
(buffer, cb) => {
430+
expect(buffer).to.deep.equal(data)
431+
cb()
432+
}
433+
], done)
399434
})
400435
})
401436
}
402437

403-
describe('circuit', () => {
438+
describe.only('circuit', () => {
404439
describe('js relay', function () {
405440
this.relay = null
406441
this.relayAddrs = null
407442

408-
beforeEach(function (done) {
443+
before(function (done) {
409444
this.timeout(50 * 1000)
410445

411-
setUpJsNode([`${base}/35002`, `${base}/35001/ws`], true, (err, res) => {
446+
setUpJsNode([`${base}/35001/ws`, `${base}/35002`], true, (err, res) => {
412447
expect(err).to.not.exist()
413448
this.relay = res.ipfsd
414449
this.relayAddrs = res.addrs
415450
done()
416451
})
417452
})
418453

419-
afterEach(function (done) { this.relay.stop(done) })
454+
after(function (done) { this.relay.stop(done) })
420455

421456
describe('test js relay', function () {
422457
tests('jsRelay')
@@ -427,18 +462,18 @@ describe('circuit', () => {
427462
this.relay = null
428463
this.relayAddrs = null
429464

430-
beforeEach(function (done) {
465+
before(function (done) {
431466
this.timeout(50 * 1000)
432467

433-
setUpGoNode([`${base}/35002`, `${base}/35001/ws`], true, (err, res) => {
468+
setUpGoNode([`${base}/35001/ws`, `${base}/35002`], true, (err, res) => {
434469
expect(err).to.not.exist()
435470
this.relay = res.ipfsd
436471
this.relayAddrs = res.addrs
437472
done()
438473
})
439474
})
440475

441-
afterEach(function (done) { this.relay.stop(done) })
476+
after(function (done) { this.relay.stop(done) })
442477

443478
describe('test go relay', function () {
444479
tests('goRelay')

test/pubsub.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const series = require('async/series')
1010
const parallel = require('async/parallel')
1111

1212
const DaemonFactory = require('ipfsd-ctl')
13-
const df = DaemonFactory.create()
1413

1514
/*
1615
* Wait for a condition to become true. When its true, callback is called.
@@ -42,8 +41,8 @@ describe('pubsub', function () {
4241
this.timeout(50 * 1000)
4342

4443
parallel([
45-
(cb) => df.spawn({ args: ['--enable-pubsub-experiment'] }, cb),
46-
(cb) => df.spawn({ type: 'js', args: ['--enable-pubsub-experiment'] }, cb)
44+
(cb) => DaemonFactory.create().spawn({ args: ['--enable-pubsub-experiment'] }, cb),
45+
(cb) => DaemonFactory.create({ type: 'js' }).spawn({ args: ['--enable-pubsub-experiment'] }, cb)
4746
], (err, n) => {
4847
expect(err).to.not.exist()
4948
nodes = n

0 commit comments

Comments
 (0)