diff --git a/.aegir.js b/.aegir.js index 827b37d2..f11e51ff 100644 --- a/.aegir.js +++ b/.aegir.js @@ -1,36 +1,23 @@ 'use strict' -const parallel = require('async/parallel') -const ads = require('./test/utils/another-daemon-spawner') -const js = ads.spawnJsNode -const go = ads.spawnGoNode -const stop = ads.stopNodes - -/* - * spawns a daemon with ports numbers starting in 10 and ending in `num` - */ -function start (done) { - const base = '/ip4/127.0.0.1/tcp' - parallel([ - (cb) => go([`${base}/10027`, `${base}/20027/ws`], true, 33027, 44027, cb), - (cb) => go([`${base}/10028`, `${base}/20028/ws`], true, 33028, 44028, cb), - (cb) => go([`${base}/10031`, `${base}/20031/ws`], true, 33031, 44031, cb), - (cb) => go([`${base}/10032`, `${base}/20032/ws`], true, 33032, 44032, cb) - ], done) -} +const createServer = require('ipfsd-ctl').createServer +const server = createServer() module.exports = { karma: { files: [{ - pattern: 'node_modules/interface-ipfs-core/test/fixtures/**/*', + pattern: 'test/fixtures/**/*', watched: false, served: true, - included: false, - singleRun: false - }] + included: false + }], + singleRun: true, + browserNoActivityTimeout: 100 * 1000 }, hooks: { - pre: start, - post: stop + browser: { + pre: server.start.bind(server), + post: server.stop.bind(server) + } } } diff --git a/package.json b/package.json index 9e9eddd9..59156ad8 100644 --- a/package.json +++ b/package.json @@ -17,9 +17,9 @@ }, "scripts": { "lint": "aegir lint", - "test": "aegir test -t node", - "test:nodejs": "aegir test -t node -f test/node.js", - "test:browser": "aegir test -t browser -f test/browser.js" + "test": "aegir test -t node -t browser --no-cors", + "test:node": "aegir test -t node -f test/node.js", + "test:browser": "aegir test -t browser --no-cors -f test/browser.js" }, "pre-commit": [ "lint" @@ -51,10 +51,11 @@ "eslint-plugin-react": "^7.5.1", "expose-loader": "^0.7.4", "form-data": "^2.3.1", + "go-ipfs-dep": "^0.4.13", "hat": "0.0.3", - "ipfs": "^0.27.5", + "ipfs": "~0.27.7", "ipfs-api": "^17.2.4", - "ipfsd-ctl": "~0.26.0", + "ipfsd-ctl": "~0.27.0", "left-pad": "^1.2.0", "lodash": "^4.17.4", "mocha": "^4.0.1", diff --git a/test/browser.js b/test/browser.js index 40a2a297..e1398b8c 100644 --- a/test/browser.js +++ b/test/browser.js @@ -1,10 +1,7 @@ /* eslint-env mocha */ 'use strict' -describe('browser interop tests', () => { - it('need to get written', function (done) { - this.timeout(10 * 1000) - // for teardown time - setTimeout(done, 5 * 1000) - }) -}) +// require('./exchange-files') +// require('./pubsub') +require('./kad-dht') +require('./repo') diff --git a/test/circuit-relay.js b/test/circuit-relay.js deleted file mode 100644 index 3c60bfbb..00000000 --- a/test/circuit-relay.js +++ /dev/null @@ -1,167 +0,0 @@ -/* eslint max-nested-callbacks: ["error", 8] */ -/* eslint-env mocha */ -'use strict' - -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) -const parallel = require('async/parallel') -const series = require('async/series') -const bl = require('bl') -const waterfall = require('async/waterfall') -const multiaddr = require('multiaddr') -const crypto = require('crypto') - -const ads = require('./utils/another-daemon-spawner') -const js = ads.spawnJsNode -const go = ads.spawnGoNode -const stop = ads.stopNodes - -describe.skip('circuit interop', () => { - let jsTCP - let jsTCPAddrs - let jsWS - let jsWSAddrs - let jsRelayAddrs - - let goRelayAddrs - - let goTCPAddrs - let goTCP - - let goWSAddrs - let goWS - - beforeEach((done) => { - const base = '/ip4/127.0.0.1/tcp' - - parallel([ - (cb) => js([`${base}/61454/ws`, `${base}/61453`], true, cb), - (cb) => js([`${base}/9002`], cb), - (cb) => js([`${base}/9003/ws`], cb), - (cb) => go([`${base}/0/ws`, `${base}/0`], true, cb), - (cb) => go([`${base}/0`], cb), - (cb) => go([`${base}/0/ws`], cb) - ], (err, nodes) => { - expect(err).to.not.exist() - - jsRelayAddrs = nodes[0][1].map((a) => a.toString()).filter((a) => !a.includes('/p2p-circuit')) - jsTCP = nodes[1][0] - jsTCPAddrs = nodes[1][1].map((a) => a.toString()).filter((a) => a.includes('/p2p-circuit')) - jsWS = nodes[2][0] - jsWSAddrs = nodes[2][1].map((a) => a.toString()).filter((a) => a.includes('/p2p-circuit')) - - goRelayAddrs = nodes[3][1] - goTCP = nodes[4][0].api - goTCPAddrs = nodes[4][1] - goWS = nodes[5][0].api - goWSAddrs = nodes[5][1] - done() - }) - }) - - afterEach(() => stop()) - - it('jsWS <-> jsRelay <-> jsTCP', (done) => { - const data = crypto.randomBytes(128) - series([ - (cb) => jsWS.swarm.connect(jsRelayAddrs[0], cb), - (cb) => jsTCP.swarm.connect(jsRelayAddrs[1], cb), - (cb) => setTimeout(cb, 1000), - (cb) => jsTCP.swarm.connect(jsWSAddrs[0], cb) - ], (err) => { - expect(err).to.not.exist() - waterfall([ - (cb) => jsTCP.files.add(data, cb), - (res, cb) => jsWS.files.cat(res[0].hash, cb), - (stream, cb) => stream.pipe(bl(cb)) - ], done) - }) - }) - - it('goWS <-> jsRelay <-> goTCP', (done) => { - const data = crypto.randomBytes(128) - series([ - (cb) => goWS.swarm.connect(jsRelayAddrs[0], cb), - (cb) => goTCP.swarm.connect(jsRelayAddrs[1], cb), - (cb) => setTimeout(cb, 1000), - (cb) => goTCP.swarm.connect(`/p2p-circuit/ipfs/${multiaddr(goWSAddrs[0]).getPeerId()}`, cb) - ], (err) => { - expect(err).to.not.exist() - waterfall([ - (cb) => goTCP.files.add(data, cb), - (res, cb) => goWS.files.cat(res[0].hash, cb), - (stream, cb) => stream.pipe(bl(cb)) - ], done) - }) - }) - - it('jsWS <-> jsRelay <-> goTCP', (done) => { - const data = crypto.randomBytes(128) - series([ - (cb) => jsWS.swarm.connect(jsRelayAddrs[0], cb), - (cb) => goTCP.swarm.connect(jsRelayAddrs[1], cb), - (cb) => setTimeout(cb, 1000), - (cb) => goTCP.swarm.connect(jsWSAddrs[0], cb) - ], (err) => { - expect(err).to.not.exist() - waterfall([ - (cb) => goTCP.files.add(data, cb), - (res, cb) => jsWS.files.cat(res[0].hash, cb), - (stream, cb) => stream.pipe(bl(cb)) - ], done) - }) - }) - - it('jsTCP <-> goRelay <-> jsWS', (done) => { - const data = crypto.randomBytes(128) - series([ - (cb) => jsTCP.swarm.connect(goRelayAddrs[2], cb), - (cb) => jsWS.swarm.connect(goRelayAddrs[0], cb), - (cb) => setTimeout(cb, 1000), - (cb) => jsWS.swarm.connect(jsTCPAddrs[0], cb) - ], (err) => { - expect(err).to.not.exist() - waterfall([ - (cb) => jsTCP.files.add(data, cb), - (res, cb) => jsWS.files.cat(res[0].hash, cb), - (stream, cb) => stream.pipe(bl(cb)) - ], done) - }) - }) - - it('goTCP <-> goRelay <-> goWS', (done) => { - const data = crypto.randomBytes(128) - series([ - (cb) => goWS.swarm.connect(goRelayAddrs[0], cb), - (cb) => goTCP.swarm.connect(goRelayAddrs[2], cb), - (cb) => setTimeout(cb, 1000), - (cb) => goWS.swarm.connect(`/p2p-circuit/ipfs/${multiaddr(goTCPAddrs[0]).getPeerId()}`, cb) - ], (err) => { - expect(err).to.not.exist() - waterfall([ - (cb) => goTCP.files.add(data, cb), - (res, cb) => goWS.files.cat(res[0].hash, cb), - (stream, cb) => stream.pipe(bl(cb)) - ], done) - }) - }) - - it('jsWS <-> goRelay <-> goTCP', (done) => { - const data = crypto.randomBytes(128) - series([ - (cb) => jsWS.swarm.connect(goRelayAddrs[0], cb), - (cb) => goTCP.swarm.connect(goRelayAddrs[2], cb), - (cb) => setTimeout(cb, 1000), - (cb) => goTCP.swarm.connect(`/p2p-circuit/ipfs/${multiaddr(jsWSAddrs[0]).getPeerId()}`, cb) - ], (err) => { - expect(err).to.not.exist() - waterfall([ - (cb) => goTCP.files.add(data, cb), - (res, cb) => jsWS.files.cat(res[0].hash, cb), - (stream, cb) => stream.pipe(bl(cb)) - ], done) - }) - }) -}) diff --git a/test/exchange-files.js b/test/exchange-files.js index 7c1e65e8..4b85c0c3 100644 --- a/test/exchange-files.js +++ b/test/exchange-files.js @@ -13,12 +13,18 @@ const pretty = require('pretty-bytes') const randomFs = require('random-fs') const promisify = require('promisify-es6') const rimraf = require('rimraf') +const join = require('path').join +const os = require('os') +const hat = require('hat') const rmDir = promisify(rimraf) -const tmpDir = require('./utils/interop-daemon-spawner/util').tmpDir -const GoDaemon = require('./utils/interop-daemon-spawner/go') -const JsDaemon = require('./utils/interop-daemon-spawner/js') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +function tmpDir () { + return join(os.tmpdir(), `ipfs_${hat()}`) +} const sizes = [ 1024, @@ -40,35 +46,35 @@ const dirs = [ 100 ] -describe('exchange files', function () { - this.timeout(20 * 1000) - +describe('exchange files', () => { let goDaemon let jsDaemon let js2Daemon + let nodes + before(function (done) { - this.timeout(15 * 1000) - goDaemon = new GoDaemon() - jsDaemon = new JsDaemon({port: 1}) - js2Daemon = new JsDaemon({port: 2}) + this.timeout(50 * 1000) parallel([ - (cb) => goDaemon.start(cb), - (cb) => jsDaemon.start(cb), - (cb) => js2Daemon.start(cb) - ], done) + (cb) => df.spawn(cb), + (cb) => df.spawn({ type: 'js' }, cb), + (cb) => df.spawn({ type: 'js' }, cb) + ], (err, n) => { + expect(err).to.not.exist() + nodes = n + goDaemon = nodes[0] + jsDaemon = nodes[1] + js2Daemon = nodes[2] + done() + }) }) - after((done) => { - series([ - (cb) => goDaemon.stop(cb), - (cb) => jsDaemon.stop(cb), - (cb) => js2Daemon.stop(cb) - ], done) - }) + after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done)) + + it('connect go <-> js', function (done) { + this.timeout(50 * 1000) - it('connect go <-> js', (done) => { let jsId let goId @@ -96,7 +102,9 @@ describe('exchange files', function () { ], done) }) - it('connect js <-> js', (done) => { + it('connect js <-> js', function (done) { + this.timeout(50 * 1000) + let jsId let js2Id @@ -125,7 +133,8 @@ describe('exchange files', function () { }) describe('cat file', () => sizes.forEach((size) => { - it(`go -> js: ${pretty(size)}`, (done) => { + it(`go -> js: ${pretty(size)}`, function (done) { + this.timeout(50 * 1000) const data = crypto.randomBytes(size) waterfall([ (cb) => goDaemon.api.add(data, cb), @@ -137,7 +146,8 @@ describe('exchange files', function () { }) }) - it(`js -> go: ${pretty(size)}`, (done) => { + it(`js -> go: ${pretty(size)}`, function (done) { + this.timeout(50 * 1000) const data = crypto.randomBytes(size) waterfall([ (cb) => jsDaemon.api.add(data, cb), @@ -149,7 +159,8 @@ describe('exchange files', function () { }) }) - it(`js -> js: ${pretty(size)}`, (done) => { + it(`js -> js: ${pretty(size)}`, function (done) { + this.timeout(20 * 1000) const data = crypto.randomBytes(size) waterfall([ (cb) => js2Daemon.api.add(data, cb), @@ -164,7 +175,8 @@ describe('exchange files', function () { // TODO these tests are not fetching the full dir?? describe('get directory', () => dirs.forEach((num) => { - it(`go -> js: depth: 5, num: ${num}`, () => { + it(`go -> js: depth: 5, num: ${num}`, function () { + this.timeout(50 * 1000) const dir = tmpDir() return randomFs({ path: dir, @@ -181,7 +193,9 @@ describe('exchange files', function () { }) }) - it(`js -> go: depth: 5, num: ${num}`, () => { + it(`js -> go: depth: 5, num: ${num}`, function () { + this.timeout(50 * 1000) + const dir = tmpDir() return randomFs({ path: dir, @@ -198,7 +212,9 @@ describe('exchange files', function () { }) }) - it(`js -> js: depth: 5, num: ${num}`, () => { + it(`js -> js: depth: 5, num: ${num}`, function () { + this.timeout(80 * 1000) + const dir = tmpDir() return randomFs({ path: dir, diff --git a/test/kad-dht.js b/test/kad-dht.js index 1bd5fdba..5cf2c022 100644 --- a/test/kad-dht.js +++ b/test/kad-dht.js @@ -11,8 +11,8 @@ const parallel = require('async/parallel') const waterfall = require('async/waterfall') const bl = require('bl') -const GODaemon = require('./utils/interop-daemon-spawner/go') -const JSDaemon = require('./utils/interop-daemon-spawner/js') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() describe.skip('kad-dht', () => { describe('a JS node in the land of Go', () => { @@ -22,18 +22,19 @@ describe.skip('kad-dht', () => { let goD3 before((done) => { - goD1 = new GODaemon() - goD2 = new GODaemon() - goD3 = new GODaemon() - - jsD = new JSDaemon({ port: 40 }) - parallel([ - (cb) => goD1.start(cb), - (cb) => goD2.start(cb), - (cb) => goD3.start(cb), - (cb) => jsD.start(cb) - ], done) + (cb) => df.spawn(cb), + (cb) => df.spawn(cb), + (cb) => df.spawn(cb), + (cb) => df.spawn({ type: 'js' }, cb) + ], (err, nodes) => { + expect(err).to.not.exist() + goD1 = nodes[0] + goD2 = nodes[1] + goD3 = nodes[2] + jsD = nodes[3] + done() + }) }) after((done) => { diff --git a/test/node.js b/test/node.js index 7e4a5134..f42c5a11 100644 --- a/test/node.js +++ b/test/node.js @@ -3,6 +3,5 @@ require('./repo') require('./exchange-files') -require('./circuit-relay') require('./kad-dht') require('./pubsub') diff --git a/test/pubsub.js b/test/pubsub.js index a497b76e..eb20c63e 100644 --- a/test/pubsub.js +++ b/test/pubsub.js @@ -5,11 +5,11 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) + const series = require('async/series') const parallel = require('async/parallel') -const GoDaemon = require('./utils/interop-daemon-spawner/go') -const JSDaemon = require('./utils/interop-daemon-spawner/js') +const DaemonFactory = require('ipfsd-ctl') /* * Wait for a condition to become true. When its true, callback is called. @@ -36,29 +36,25 @@ describe('pubsub', function () { let jsId let goId + let nodes = [] before(function (done) { this.timeout(50 * 1000) - goD = new GoDaemon({ - disposable: true, - init: true, - flags: ['--enable-pubsub-experiment'] - }) - jsD = new JSDaemon() - parallel([ - (cb) => goD.start(cb), - (cb) => jsD.start(cb) - ], (done)) + (cb) => DaemonFactory.create().spawn({ args: ['--enable-pubsub-experiment'] }, cb), + (cb) => DaemonFactory.create({ type: 'js' }).spawn({ args: ['--enable-pubsub-experiment'] }, cb) + ], (err, n) => { + expect(err).to.not.exist() + nodes = n + goD = nodes[0] + jsD = nodes[1] + done() + }) }) after(function (done) { this.timeout(50 * 1000) - - parallel([ - (cb) => goD.stop(cb), - (cb) => jsD.stop(cb) - ], done) + parallel(nodes.map((node) => (cb) => node.stop(cb)), done) }) it('make connections', (done) => { diff --git a/test/repo.js b/test/repo.js index 6e348eb7..c54ad0cc 100644 --- a/test/repo.js +++ b/test/repo.js @@ -5,17 +5,18 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const waterfall = require('async/waterfall') + +const series = require('async/series') const crypto = require('crypto') const os = require('os') const path = require('path') const hat = require('hat') -const GoDaemon = require('./utils/interop-daemon-spawner/go') -const JsDaemon = require('./utils/interop-daemon-spawner/js') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() -function catAndCheck (daemon, hash, data, callback) { - daemon.api.cat(hash, (err, fileData) => { +function catAndCheck (api, hash, data, callback) { + api.cat(hash, (err, fileData) => { expect(err).to.not.exist() expect(fileData).to.eql(data) callback() @@ -23,62 +24,79 @@ function catAndCheck (daemon, hash, data, callback) { } describe('repo', () => { - it('read repo: go -> js', (done) => { + it('read repo: go -> js', function (done) { + this.timeout(50 * 1000) + const dir = path.join(os.tmpdir(), hat()) const data = crypto.randomBytes(1024 * 5) - const goDaemon = new GoDaemon({ - init: true, - disposable: false, - path: dir - }) + let goDaemon let jsDaemon let hash - waterfall([ + series([ + (cb) => df.spawn({ + repoPath: dir, + disposable: false + }, (err, node) => { + expect(err).to.not.exist() + goDaemon = node + goDaemon.init(cb) + }), (cb) => goDaemon.start(cb), - (cb) => goDaemon.api.add(data, cb), - (res, cb) => { + (cb) => goDaemon.api.add(data, (err, res) => { + expect(err).to.not.exist() hash = res[0].hash - catAndCheck(goDaemon, hash, data, cb) - }, + cb() + }), + (cb) => catAndCheck(goDaemon.api, hash, data, cb), (cb) => goDaemon.stop(cb), - (cb) => { - jsDaemon = new JsDaemon({ - init: false, - disposable: false, - path: dir - }) - jsDaemon.start(cb) - }, - (cb) => catAndCheck(goDaemon, hash, data, cb), - (cb) => jsDaemon.stop(cb) + (cb) => df.spawn({ + type: 'js', + repoPath: dir, + disposable: false + }, (err, node) => { + expect(err).to.not.exist() + jsDaemon = node + cb() + }), + (cb) => jsDaemon.start(cb), + (cb) => catAndCheck(jsDaemon.api, hash, data, cb), + (cb) => jsDaemon.stop(cb), + (cb) => setTimeout(cb, 10500), + (cb) => jsDaemon.cleanup(cb) ], done) }) // This was last due to an update on go-ipfs that changed how datastore is // configured - it.skip('read repo: js -> go', (done) => { + it.skip('read repo: js -> go', function (done) { + this.timeout(50 * 1000) const dir = path.join(os.tmpdir(), hat()) const data = crypto.randomBytes(1024 * 5) - const jsDaemon = new JsDaemon({init: true, disposable: false, path: dir}) + let jsDaemon let goDaemon let hash - waterfall([ - (cb) => jsDaemon.start(cb), + series([ + (cb) => df.spawn({ type: 'js', repoPath: dir }, cb), + (node, cb) => { + jsDaemon = node + cb() + }, (cb) => jsDaemon.api.add(data, cb), (res, cb) => { hash = res[0].hash - catAndCheck(jsDaemon, hash, data, cb) + catAndCheck(jsDaemon.api, hash, data, cb) }, (cb) => jsDaemon.stop(cb), - (cb) => { - goDaemon = new GoDaemon({init: false, disposable: false, path: dir}) - goDaemon.start(cb) + (cb) => df.spawn({ repoPath: dir }, cb), + (node, cb) => { + goDaemon = node + cb() }, - (cb) => catAndCheck(goDaemon, hash, data, cb), + (cb) => catAndCheck(goDaemon.api, hash, data, cb), (cb) => goDaemon.stop(cb) ], done) }) diff --git a/test/utils/another-daemon-spawner.js b/test/utils/another-daemon-spawner.js deleted file mode 100644 index c8d2295c..00000000 --- a/test/utils/another-daemon-spawner.js +++ /dev/null @@ -1,124 +0,0 @@ -/* eslint-env mocha */ - -'use strict' - -const waterfall = require('async/waterfall') -const series = require('async/series') - -const relayConfig = require('./ipfs-factory-daemon/default-config.json') -const Factory = require('./ipfs-factory-daemon') -const GoDaemon = require('./interop-daemon-spawner/go') - -const nodes = [] -const factory = new Factory() -exports = module.exports - -exports.spawnGoNode = (addrs, hop, api, gateway, callback) => { - if (typeof hop === 'function') { - callback = hop - hop = false - } - if (typeof api === 'function') { - callback = api - api = 0 - } - if (typeof gateway === 'function') { - callback = gateway - gateway = 0 - } - - api = api || 0 - gateway = gateway || 0 - - const daemon = new GoDaemon({ - disposable: true, - init: true, - config: { - Addresses: { - Swarm: addrs, - API: `/ip4/0.0.0.0/tcp/${api}`, - Gateway: `/ip4/0.0.0.0/tcp/${gateway}` - }, - Swarm: { - AddrFilters: null, - DisableBandwidthMetrics: false, - DisableNatPortMap: false, - DisableRelay: false, - EnableRelayHop: hop - } - } - }) - - daemon.start((err) => { - if (err) { - return callback(err) - } - daemon.api.id((err, id) => { - if (err) { - return callback(err) - } - nodes.push(daemon) - callback(null, daemon, id.addresses) - }) - }) -} - -exports.spawnJsNode = (addrs, hop, api, gateway, callback) => { - let relayPeer - let relayAddrs - - if (typeof hop === 'function') { - callback = hop - hop = false - } - if (typeof api === 'function') { - callback = api - api = 0 - } - if (typeof gateway === 'function') { - callback = gateway - gateway = 0 - } - - api = api || 0 - gateway = gateway || 0 - - callback = callback || function noop () {} - - waterfall([ - (cb) => factory.spawnNode(null, Object.assign(relayConfig, { - Addresses: { - Swarm: addrs, - API: `/ip4/0.0.0.0/tcp/${api}`, - Gateway: `/ip4/0.0.0.0/tcp/${gateway}` - }, - EXPERIMENTAL: { - Swarm: { - DisableRelay: false, - EnableRelayHop: hop - } - } - }), cb), - (node, cb) => { - relayPeer = node - relayPeer.swarm.localAddrs(cb) - }, - (addrs, cb) => { - relayAddrs = addrs - cb() - } - ], (err) => { - if (err) { - return callback(err) - } - callback(null, relayPeer, relayAddrs) - }) -} - -exports.stopNodes = (callback) => { - series([ - (cb) => factory.dismantle(cb) - ].concat(nodes.map((node) => (cb) => { - setTimeout(() => node.stop(cb), 100) - })), callback) -} diff --git a/test/utils/interop-daemon-spawner/go.js b/test/utils/interop-daemon-spawner/go.js deleted file mode 100644 index 8010724d..00000000 --- a/test/utils/interop-daemon-spawner/go.js +++ /dev/null @@ -1,73 +0,0 @@ -'use strict' - -const ctl = require('ipfsd-ctl') -const waterfall = require('async/waterfall') - -class GoDaemon { - constructor (opts) { - opts = opts || { - disposable: true, - init: true - } - - this.init = opts.init - this.path = opts.path - this.disposable = opts.disposable - this.node = null - this.api = null - this.config = opts.config || {} - this.flags = opts.flags || {} - } - - start (callback) { - waterfall([ - (cb) => { - if (this.disposable) { - const config = Object.assign({ init: this.init }, this.config) - ctl.disposable(config, cb) - } else if (this.init) { - ctl.local(this.path, (err, node) => { - if (err) { - return cb(err) - } - node.init((err) => cb(err, node)) - }) - } else { - ctl.local(this.path, cb) - } - }, - (node, cb) => { - this.node = node - this.node.setConfig('Bootstrap', '[]', cb) - }, - (res, cb) => this.node.startDaemon(this.flags, cb), - (api, cb) => { - this.api = api - - if (process.env.DEBUG) { - this.api.log.tail((err, stream) => { - if (err) { - return console.error(err) - } - stream.on('data', (chunk) => { - console.log('go-log: %s.%s %s (%s)', chunk.system, chunk.subsystem || '', chunk.event, chunk.error) - }) - }) - this.node._run( - ['log', 'level', 'all', 'debug'], - {env: this.node.env}, - cb - ) - } else { - cb() - } - } - ], (err) => callback(err)) - } - - stop (callback) { - this.node.stopDaemon(callback) - } -} - -module.exports = GoDaemon diff --git a/test/utils/interop-daemon-spawner/js.js b/test/utils/interop-daemon-spawner/js.js deleted file mode 100644 index 0a191417..00000000 --- a/test/utils/interop-daemon-spawner/js.js +++ /dev/null @@ -1,87 +0,0 @@ -'use strict' - -const EventEmitter = require('events').EventEmitter -const IPFSAPI = require('ipfs-api') -const series = require('async/series') -const rimraf = require('rimraf') -const tmpDir = require('./util').tmpDir - -const HttpApi = require('ipfs/src/http') - -function portConfig (port) { - port = port + 5 - - return { - Gateway: '/ip4/127.0.0.1/tcp/' + (9090 + port), - API: '/ip4/127.0.0.1/tcp/' + (5002 + port), - Swarm: [ - '/ip4/127.0.0.1/tcp/' + (4003 + port), - '/ip4/127.0.0.1/tcp/' + (4104 + port) + '/ws' - ] - } -} - -class JsDaemon extends EventEmitter { - constructor (opts) { - super() - opts = Object.assign({}, { - disposable: true, - init: true - }, opts || {}) - - this.path = opts.path - this.disposable = opts.disposable - this.init = opts.init - this.port = opts.port || 1 - - this.path = opts.path || tmpDir() - this._started = false - - const extras = { - enablePubsubExperiment: true - } - if (this.init) { - const p = portConfig(this.port) - this.node = new HttpApi(this.path, { - Bootstrap: [], - Addresses: p - }, extras) - } else { - this.node = new HttpApi(this.path, null, extras) - } - - this.node.start(this.init, (err) => { - if (err) { - throw err - } - this._started = true - this.api = new IPFSAPI(this.node.apiMultiaddr) - - this.emit('start') - }) - } - - start (callback) { - if (!this._started) { - return this.once('start', callback) - } - - callback() - } - - stop (callback) { - this._started = false - series([ - (cb) => this.node.stop(cb), - (cb) => { - if (this.disposable) { - rimraf(this.path, cb) - } else { - cb() - } - } - ], (err) => callback(err)) - } -} - -module.exports = JsDaemon diff --git a/test/utils/interop-daemon-spawner/util.js b/test/utils/interop-daemon-spawner/util.js deleted file mode 100644 index 11b47f57..00000000 --- a/test/utils/interop-daemon-spawner/util.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict' - -const os = require('os') -const path = require('path') -const hat = require('hat') - -exports.tmpDir = (prefix) => { - return path.join(os.tmpdir(), prefix || 'js-ipfs-interop', hat()) -} diff --git a/test/utils/ipfs-factory-daemon/default-config.json b/test/utils/ipfs-factory-daemon/default-config.json deleted file mode 100644 index f2203594..00000000 --- a/test/utils/ipfs-factory-daemon/default-config.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "Identity": { - "PeerID": "", - "PrivKey": "" - }, - "Addresses": { - "Swarm": [ - "/ip4/127.0.0.1/tcp/0" - ], - "API": "/ip4/127.0.0.1/tcp/0", - "Gateway": "/ip4/127.0.0.1/tcp/0" - }, - "Version": { - "Current": "jsipfs-dev", - "Check": "error", - "CheckDate": "0001-01-01T00:00:00Z", - "CheckPeriod": "172800000000000", - "AutoUpdate": "minor" - }, - "Discovery": { - "MDNS": { - "Enabled": false, - "Interval": 10 - }, - "webRTCStar": { - "Enabled": false - } - }, - "Bootstrap": [], - "Gateway": { - "HTTPHeaders": null, - "RootRedirect": "", - "Writable": false - }, - "API": { - "HTTPHeaders": null - }, - "Swarm": { - "AddrFilters": null - } -} diff --git a/test/utils/ipfs-factory-daemon/index.js b/test/utils/ipfs-factory-daemon/index.js deleted file mode 100644 index 1c973789..00000000 --- a/test/utils/ipfs-factory-daemon/index.js +++ /dev/null @@ -1,79 +0,0 @@ -'use strict' - -const PeerId = require('peer-id') -const IPFSAPI = require('ipfs-api') -const clean = require('../clean') -const HttpApi = require('ipfs/src/http') -const series = require('async/series') -const eachSeries = require('async/eachSeries') -const defaultConfig = require('./default-config.json') -const os = require('os') -const hat = require('hat') - -class Factory { - constructor () { - this.daemonsSpawned = [] - } - - /* yields a new started node */ - spawnNode (repoPath, suppliedConfig, callback) { - if (typeof repoPath === 'function') { - callback = repoPath - repoPath = undefined - } - if (typeof suppliedConfig === 'function') { - callback = suppliedConfig - suppliedConfig = {} - } - - repoPath = repoPath || os.tmpdir() + '/ipfs-' + hat() - - let daemon - let ctl - let config - - series([ - (cb) => { - // prepare config for node - - config = Object.assign({}, defaultConfig, suppliedConfig) - - PeerId.create({ bits: 1024 }, (err, id) => { - if (err) { return cb(err) } - - const peerId = id.toJSON() - config.Identity.PeerID = peerId.id - config.Identity.PrivKey = peerId.privKey - cb() - }) - }, - (cb) => { - daemon = new HttpApi(repoPath, config, {enablePubsubExperiment: true}) - daemon.repoPath = repoPath - this.daemonsSpawned.push(daemon) - - daemon.start(true, cb) - }, - (cb) => { - ctl = IPFSAPI(daemon.apiMultiaddr) - ctl.repoPath = repoPath - ctl.apiMultiaddr = daemon.apiMultiaddr - cb() - } - ], (err) => callback(err, ctl)) - } - - dismantle (callback) { - eachSeries(this.daemonsSpawned, (d, cb) => { - d.stop((err) => { - clean(d.repoPath) - if (err) { - console.error('error stopping', err) - } - cb(err) - }) - }, callback) - } -} - -module.exports = Factory diff --git a/test/utils/ipfs-factory-instance/default-config.json b/test/utils/ipfs-factory-instance/default-config.json deleted file mode 100644 index 677c7c85..00000000 --- a/test/utils/ipfs-factory-instance/default-config.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "Addresses": { - "Swarm": [ - "/ip4/127.0.0.1/tcp/0" - ], - "API": "/ip4/127.0.0.1/tcp/0", - "Gateway": "/ip4/127.0.0.1/tcp/0" - }, - "Version": { - "Current": "jsipfs-dev", - "Check": "error", - "CheckDate": "0001-01-01T00:00:00Z", - "CheckPeriod": "172800000000000", - "AutoUpdate": "minor" - }, - "Discovery": { - "MDNS": { - "Enabled": false, - "Interval": 10 - }, - "webRTCStar": { - "Enabled": false - } - }, - "Bootstrap": [], - "API": { - "HTTPHeaders": null - } -} diff --git a/test/utils/ipfs-factory-instance/index.js b/test/utils/ipfs-factory-instance/index.js deleted file mode 100644 index 568a1710..00000000 --- a/test/utils/ipfs-factory-instance/index.js +++ /dev/null @@ -1,63 +0,0 @@ -'use strict' - -const series = require('async/series') -const each = require('async/each') -const hat = require('hat') -const os = require('os') -const path = require('path') - -const defaultConfig = require('./default-config.json') -const IPFS = require('../../../src/core') -const createTempRepo = require('../create-repo-nodejs') - -module.exports = Factory - -function Factory () { - if (!(this instanceof Factory)) { - return new Factory() - } - - const nodes = [] - - /* yields a new started node instance */ - this.spawnNode = (repoPath, suppliedConfig, callback) => { - if (typeof repoPath === 'function') { - callback = repoPath - repoPath = undefined - } - - if (typeof suppliedConfig === 'function') { - callback = suppliedConfig - suppliedConfig = {} - } - - if (!repoPath) { - repoPath = path.join(os.tmpdir(), '.ipfs-' + hat()) - } - - const config = Object.assign({}, defaultConfig, suppliedConfig) - - const repo = createTempRepo(repoPath) - const node = new IPFS({ - repo: repo, - init: { bits: 1024 }, - config: config, - EXPERIMENTAL: { - pubsub: true, - dht: true - } - }) - - node.once('ready', () => { - nodes.push({ repo: repo, ipfs: node }) - callback(null, node) - }) - } - - this.dismantle = function (callback) { - series([ - (cb) => each(nodes, (el, cb) => el.ipfs.stop(cb), cb), - (cb) => each(nodes, (el, cb) => el.repo.teardown(cb), cb) - ], callback) - } -}