diff --git a/README.md b/README.md index a933c8f..d76ead1 100644 --- a/README.md +++ b/README.md @@ -29,13 +29,23 @@ This repository will be used for interop tests. > npm test ``` -### Test with a non yet released version of js-ipfs +#### Testing local daemons -TODO +It is possible to test local versions of the go and js daemons exporting the respective path before running the tests. -### Test with a non yet released version of go-ipfs +**Specifying the go-libp2p daemon** +See the go-libp2p-daemon [install instructions](https://github.com/libp2p/go-libp2p-daemon#install) for building the local binary. -TODO +```sh +$ LIBP2P_GO_BIN=$GOPATH/bin/p2pd npm run test +``` + +**Specifying the js-libp2p daemon** +From the js-libp2p-daemon local repo checkout you can perform an `npm link` to create a binary, `jsp2pd` in the global npm space. + +```sh +$ LIBP2P_JS_BIN=$(which jsp2pd) npm run test +``` ## Contribute diff --git a/package.json b/package.json index 103fd58..360a8f9 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "cross-env": "^7.0.0", "dirty-chai": "^2.0.1", "go-libp2p-dep": "~0.5.0", - "libp2p-daemon": "^0.3.0", + "libp2p-daemon": "libp2p/js-libp2p-daemon#feat/noise", "libp2p-daemon-client": "^0.3.0", "multiaddr": "^7.2.1", "rimraf": "^3.0.0" diff --git a/src/daemon.js b/src/daemon.js index 37cdee0..e08b8ec 100644 --- a/src/daemon.js +++ b/src/daemon.js @@ -10,7 +10,7 @@ const path = require('path') const rimraf = require('rimraf') const Client = require('libp2p-daemon-client') -const { getMultiaddr, isWindows } = require('./utils') +const { getMultiaddr, isWindows, DEFAULT_CONFIG } = require('./utils') // process path const processPath = process.cwd() @@ -18,13 +18,13 @@ const processPath = process.cwd() // go-libp2p defaults const goDaemon = { defaultAddr: getMultiaddr('/tmp/p2pd-go.sock'), - bin: path.join('go-libp2p-dep', 'go-libp2p', isWindows ? 'p2pd.exe' : 'p2pd') + bin: process.env.LIBP2P_GO_BIN || path.join('go-libp2p-dep', 'go-libp2p', isWindows ? 'p2pd.exe' : 'p2pd') } // js-libp2p defaults const jsDaemon = { defaultAddr: getMultiaddr('/tmp/p2pd-js.sock'), - bin: path.join('libp2p-daemon', 'src', 'cli', 'bin.js') + bin: process.env.LIBP2P_JS_BIN || path.join('libp2p-daemon', 'src', 'cli', 'bin.js') } class Daemon { @@ -55,6 +55,10 @@ class Daemon { */ _getBinPath (type) { const depPath = type === 'go' ? goDaemon.bin : jsDaemon.bin + if (fs.existsSync(depPath)) { + return depPath + } + let npmPath = path.join(processPath, '../', depPath) if (fs.existsSync(npmPath)) { @@ -99,6 +103,7 @@ class Daemon { * @returns {Promise} */ _startDaemon (options) { + options = { ...DEFAULT_CONFIG, ...options } return new Promise((resolve, reject) => { let execOptions const addr = this._addr.toString() @@ -107,12 +112,16 @@ class Daemon { if (this._type === 'go') { execOptions = ['-listen', addr] + execOptions.push(`-secio=${options.secio}`) + execOptions.push(`-noise=${options.noise}`) options.dht && execOptions.push('-dht') options.pubsub && execOptions.push('-pubsub') options.pubsubRouter && execOptions.push('-pubsubRouter', options.pubsubRouter) } else { execOptions = ['--listen', addr] + execOptions.push(`--secio=${options.secio}`) + execOptions.push(`--noise=${options.noise}`) options.dht && execOptions.push('--dht') options.pubsub && execOptions.push('--pubsub') options.pubsubRouter && execOptions.push('--pubsubRouter', options.pubsubRouter) diff --git a/src/utils.js b/src/utils.js index 5d143d6..435f3cc 100644 --- a/src/utils.js +++ b/src/utils.js @@ -14,3 +14,9 @@ exports.getSockPath = (sockPath) => isWindows exports.getMultiaddr = (sockPath, port) => isWindows ? ma(`/ip4/0.0.0.0/tcp/${port || 8080}`) : ma(`/unix${path.resolve(os.tmpdir(), sockPath)}`) + +exports.DEFAULT_CONFIG = { + secio: true, + noise: false, + dht: false +} diff --git a/test/connect/go2go.js b/test/connect/go2go.js index 6b13e7f..2c150b5 100644 --- a/test/connect/go2go.js +++ b/test/connect/go2go.js @@ -8,46 +8,48 @@ const expect = chai.expect const spawnDaemons = require('../utils/spawnDaemons') -describe('connect', () => { - let daemons +module.exports = (name, config) => { + describe(`connect ${name}`, () => { + let daemons - // Start Daemons - before(async function () { - this.timeout(20 * 1000) + // Start Daemons + before(async function () { + this.timeout(20 * 1000) - daemons = await spawnDaemons(2, 'go') - }) + daemons = await spawnDaemons(2, 'go', config) + }) - // Stop daemons - after(async function () { - await Promise.all( - daemons.map((daemon) => daemon.stop()) - ) - }) + // Stop daemons + after(async function () { + await Promise.all( + daemons.map((daemon) => daemon.stop()) + ) + }) - it('go peer to go peer', async function () { - this.timeout(10 * 1000) + it('go peer to go peer', async function () { + this.timeout(10 * 1000) - const identify1 = await daemons[0].client.identify() - const identify2 = await daemons[1].client.identify() + const identify1 = await daemons[0].client.identify() + const identify2 = await daemons[1].client.identify() - // verify connected peers - const knownPeersBeforeConnect1 = await daemons[0].client.listPeers() - expect(knownPeersBeforeConnect1).to.have.lengthOf(0) + // verify connected peers + const knownPeersBeforeConnect1 = await daemons[0].client.listPeers() + expect(knownPeersBeforeConnect1).to.have.lengthOf(0) - const knownPeersBeforeConnect2 = await daemons[1].client.listPeers() - expect(knownPeersBeforeConnect2).to.have.lengthOf(0) + const knownPeersBeforeConnect2 = await daemons[1].client.listPeers() + expect(knownPeersBeforeConnect2).to.have.lengthOf(0) - // connect peers - await daemons[1].client.connect(identify1.peerId, identify1.addrs) + // connect peers + await daemons[1].client.connect(identify1.peerId, identify1.addrs) - // verify connected peers - const knownPeersAfterConnect1 = await daemons[0].client.listPeers() - expect(knownPeersAfterConnect1).to.have.lengthOf(1) - expect(knownPeersAfterConnect1[0].toB58String()).to.equal(identify2.peerId.toB58String()) + // verify connected peers + const knownPeersAfterConnect1 = await daemons[0].client.listPeers() + expect(knownPeersAfterConnect1).to.have.lengthOf(1) + expect(knownPeersAfterConnect1[0].toB58String()).to.equal(identify2.peerId.toB58String()) - const knownPeersAfterConnect2 = await daemons[1].client.listPeers() - expect(knownPeersAfterConnect2).to.have.lengthOf(1) - expect(knownPeersAfterConnect2[0].toB58String()).to.equal(identify1.peerId.toB58String()) + const knownPeersAfterConnect2 = await daemons[1].client.listPeers() + expect(knownPeersAfterConnect2).to.have.lengthOf(1) + expect(knownPeersAfterConnect2[0].toB58String()).to.equal(identify1.peerId.toB58String()) + }) }) -}) +} diff --git a/test/connect/go2js.js b/test/connect/go2js.js index 1fc2927..2ec387b 100644 --- a/test/connect/go2js.js +++ b/test/connect/go2js.js @@ -8,10 +8,10 @@ const expect = chai.expect const spawnDaemons = require('../utils/spawnDaemons') -const beforeConnect = (ctx, keyType) => { +const beforeConnect = (ctx, keyType, config) => { ctx.timeout(20 * 1000) - return spawnDaemons(2, [{ type: 'go', keyType }, { type: 'js', keyType }]) + return spawnDaemons(2, [{ type: 'go', keyType }, { type: 'js', keyType }], config) } const afterConnect = async (daemons) => { @@ -58,36 +58,38 @@ const performTest = async (ctx, daemons) => { expect(knownPeersAfterConnectJs[0].toB58String()).to.equal(goId) } -describe('connecting go peer to js peer', () => { - describe('with RSA keys', () => { - let daemons +module.exports = (name, config) => { + describe(`connecting go peer to js peer ${name}`, () => { + describe('with RSA keys', () => { + let daemons - before(async function () { - daemons = await beforeConnect(this, 'rsa') - }) + before(async function () { + daemons = await beforeConnect(this, 'rsa', config) + }) - after(async () => { - await afterConnect(daemons) - }) + after(async () => { + await afterConnect(daemons) + }) - it('should work', async function () { - await performTest(this, daemons) + it('should work', async function () { + await performTest(this, daemons) + }) }) - }) - describe('with SECP256k1 keys', () => { - let daemons + describe('with SECP256k1 keys', () => { + let daemons - before(async function () { - daemons = await beforeConnect(this, 'secp256k1') - }) + before(async function () { + daemons = await beforeConnect(this, 'secp256k1', config) + }) - after(async () => { - await afterConnect(daemons) - }) + after(async () => { + await afterConnect(daemons) + }) - it('should work', async function () { - await performTest(this, daemons) + it('should work', async function () { + await performTest(this, daemons) + }) }) }) -}) +} diff --git a/test/connect/index.js b/test/connect/index.js index dbe06c2..5a83077 100644 --- a/test/connect/index.js +++ b/test/connect/index.js @@ -1,6 +1,13 @@ 'use strict' -require('./go2go') -require('./go2js') -require('./js2go') -require('./js2js') +// Perform tests against secio +require('./go2go')('secio', { secio: true, noise: false }) +require('./go2js')('secio', { secio: true, noise: false }) +require('./js2go')('secio', { secio: true, noise: false }) +require('./js2js')('secio', { secio: true, noise: false }) + +// Perform tests against noise +require('./go2go')('noise', { secio: false, noise: true }) +require('./go2js')('noise', { secio: false, noise: true }) +require('./js2go')('noise', { secio: false, noise: true }) +require('./js2js')('noise', { secio: false, noise: true }) diff --git a/test/connect/js2go.js b/test/connect/js2go.js index 3f93828..1dddc7c 100644 --- a/test/connect/js2go.js +++ b/test/connect/js2go.js @@ -8,10 +8,10 @@ const expect = chai.expect const spawnDaemons = require('../utils/spawnDaemons') -const beforeConnect = (ctx, keyType) => { +const beforeConnect = (ctx, keyType, config) => { ctx.timeout(20 * 1000) - return spawnDaemons(2, [{ type: 'js', keyType }, { type: 'go', keyType }]) + return spawnDaemons(2, [{ type: 'js', keyType }, { type: 'go', keyType }], config) } const afterConnect = async (daemons) => { @@ -58,36 +58,38 @@ const performTest = async (ctx, daemons) => { expect(knownPeersAfterConnectGo[0].toB58String()).to.equal(jsId) } -describe('connecting js peer to go peer', () => { - describe('with RSA keys', () => { - let daemons +module.exports = (name, config) => { + describe(`connecting js peer to go peer ${name}`, () => { + describe('with RSA keys', () => { + let daemons - before(async function () { - daemons = await beforeConnect(this, 'rsa') - }) + before(async function () { + daemons = await beforeConnect(this, 'rsa', config) + }) - after(async () => { - await afterConnect(daemons) - }) + after(async () => { + await afterConnect(daemons) + }) - it('should work', async function () { - await performTest(this, daemons) + it('should work', async function () { + await performTest(this, daemons) + }) }) - }) - describe('with SECP256k1 keys', () => { - let daemons + describe('with SECP256k1 keys', () => { + let daemons - before(async function () { - daemons = await beforeConnect(this, 'secp256k1') - }) + before(async function () { + daemons = await beforeConnect(this, 'secp256k1', config) + }) - after(async () => { - await afterConnect(daemons) - }) + after(async () => { + await afterConnect(daemons) + }) - it('should work', async function () { - await performTest(this, daemons) + it('should work', async function () { + await performTest(this, daemons) + }) }) }) -}) +} diff --git a/test/connect/js2js.js b/test/connect/js2js.js index 29aeaf2..da6224a 100644 --- a/test/connect/js2js.js +++ b/test/connect/js2js.js @@ -8,49 +8,51 @@ const expect = chai.expect const spawnDaemons = require('../utils/spawnDaemons') -describe('connect', () => { - let daemons - - // Start Daemons - before(async function () { - this.timeout(20 * 1000) - - daemons = await spawnDaemons(2, 'go') - }) - - // Stop daemons - after(async function () { - await Promise.all( - daemons.map((daemon) => daemon.stop()) - ) +module.exports = (name, config) => { + describe(`connect ${name}`, () => { + let daemons + + // Start Daemons + before(async function () { + this.timeout(20 * 1000) + daemons = await spawnDaemons(2, 'js', config) + }) + + // Stop daemons + after(async function () { + await Promise.all( + daemons.map((daemon) => daemon.stop()) + ) + }) + + it('js peer to js peer', async function () { + this.timeout(10 * 1000) + + const identify1 = await daemons[0].client.identify() + const identify2 = await daemons[1].client.identify() + + // verify connected peers + const knownPeersBeforeConnect1 = await daemons[0].client.listPeers() + expect(knownPeersBeforeConnect1).to.have.lengthOf(0) + + const knownPeersBeforeConnect2 = await daemons[1].client.listPeers() + expect(knownPeersBeforeConnect2).to.have.lengthOf(0) + + // connect peers + await daemons[1].client.connect(identify1.peerId, identify1.addrs) + + // daemons[0] will take some time to get the peers + await new Promise(resolve => setTimeout(resolve, 1000)) + + // verify connected peers + const knownPeersAfterConnect1 = await daemons[0].client.listPeers() + expect(knownPeersAfterConnect1).to.have.lengthOf(1) + expect(knownPeersAfterConnect1[0].toB58String()).to.equal(identify2.peerId.toB58String()) + + const knownPeersAfterConnect2 = await daemons[1].client.listPeers() + expect(knownPeersAfterConnect2).to.have.lengthOf(1) + expect(knownPeersAfterConnect2[0].toB58String()).to.equal(identify1.peerId.toB58String()) + }) }) +} - it('js peer to js peer', async function () { - this.timeout(10 * 1000) - - const identify1 = await daemons[0].client.identify() - const identify2 = await daemons[1].client.identify() - - // verify connected peers - const knownPeersBeforeConnect1 = await daemons[0].client.listPeers() - expect(knownPeersBeforeConnect1).to.have.lengthOf(0) - - const knownPeersBeforeConnect2 = await daemons[1].client.listPeers() - expect(knownPeersBeforeConnect2).to.have.lengthOf(0) - - // connect peers - await daemons[1].client.connect(identify1.peerId, identify1.addrs) - - // daemons[0] will take some time to get the peers - await new Promise(resolve => setTimeout(resolve, 1000)) - - // verify connected peers - const knownPeersAfterConnect1 = await daemons[0].client.listPeers() - expect(knownPeersAfterConnect1).to.have.lengthOf(1) - expect(knownPeersAfterConnect1[0].toB58String()).to.equal(identify2.peerId.toB58String()) - - const knownPeersAfterConnect2 = await daemons[1].client.listPeers() - expect(knownPeersAfterConnect2).to.have.lengthOf(1) - expect(knownPeersAfterConnect2[0].toB58String()).to.equal(identify1.peerId.toB58String()) - }) -}) diff --git a/test/dht/content-routing/go2go.js b/test/dht/content-routing/go2go.js index de2e7d7..f6220c1 100644 --- a/test/dht/content-routing/go2go.js +++ b/test/dht/content-routing/go2go.js @@ -9,46 +9,48 @@ const expect = chai.expect const CID = require('cids') const spawnDaemons = require('../../utils/spawnDaemons') -describe('dht.contentRouting', () => { - let daemons - let identify0 +;[{ secio: true, noise: false }, { secio: false, noise: true }].forEach(config => { + describe('dht.contentRouting', () => { + let daemons + let identify0 - // Start Daemons - before(async function () { - this.timeout(20 * 1000) + // Start Daemons + before(async function () { + this.timeout(20 * 1000) - daemons = await spawnDaemons(2, 'go', { dht: true }) + daemons = await spawnDaemons(2, 'go', { dht: true }) - // connect them - identify0 = await daemons[0].client.identify() + // connect them + identify0 = await daemons[0].client.identify() - await daemons[1].client.connect(identify0.peerId, identify0.addrs) + await daemons[1].client.connect(identify0.peerId, identify0.addrs) - // get the peers in the table - await new Promise(resolve => setTimeout(resolve, 1000)) - }) + // get the peers in the table + await new Promise(resolve => setTimeout(resolve, 1000)) + }) - // Stop daemons - after(async function () { - await Promise.all( - daemons.map((daemon) => daemon.stop()) - ) - }) + // Stop daemons + after(async function () { + await Promise.all( + daemons.map((daemon) => daemon.stop()) + ) + }) - it('go peer to go peer', async function () { - const cid = new CID('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp39') + it('go peer to go peer', async function () { + const cid = new CID('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp39') - await daemons[0].client.dht.provide(cid) + await daemons[0].client.dht.provide(cid) - const findProviders = daemons[1].client.dht.findProviders(cid) - const providers = [] + const findProviders = daemons[1].client.dht.findProviders(cid) + const providers = [] - for await (const provider of findProviders) { - providers.push(provider) - } + for await (const provider of findProviders) { + providers.push(provider) + } - expect(providers).to.exist() - expect(providers[0]).to.exist() - expect(providers[0].id.toB58String()).to.equal(identify0.peerId.toB58String()) + expect(providers).to.exist() + expect(providers[0]).to.exist() + expect(providers[0].id.toB58String()).to.equal(identify0.peerId.toB58String()) + }) }) -}) +}) \ No newline at end of file diff --git a/test/dht/content-routing/js2go.js b/test/dht/content-routing/js2go.js index bae5604..26d7d40 100644 --- a/test/dht/content-routing/js2go.js +++ b/test/dht/content-routing/js2go.js @@ -9,46 +9,48 @@ const expect = chai.expect const CID = require('cids') const spawnDaemons = require('../../utils/spawnDaemons') -describe('dht.contentRouting', () => { - let daemons - let identify0 +;[{ secio: true, noise: false }, { secio: false, noise: true }].forEach(config => { + describe('dht.contentRouting', () => { + let daemons + let identify0 - // Start Daemons - before(async function () { - this.timeout(20 * 1000) + // Start Daemons + before(async function () { + this.timeout(20 * 1000) - daemons = await spawnDaemons(2, ['js', 'go'], { dht: true }) + daemons = await spawnDaemons(2, ['js', 'go'], { ...config, ...{ dht: true }}) - // connect them - identify0 = await daemons[0].client.identify() + // connect them + identify0 = await daemons[0].client.identify() - await daemons[1].client.connect(identify0.peerId, identify0.addrs) + await daemons[1].client.connect(identify0.peerId, identify0.addrs) - // get the peers in the table - await new Promise(resolve => setTimeout(resolve, 1000)) - }) + // get the peers in the table + await new Promise(resolve => setTimeout(resolve, 1000)) + }) - // Stop daemons - after(async function () { - await Promise.all( - daemons.map((daemon) => daemon.stop()) - ) - }) + // Stop daemons + after(async function () { + await Promise.all( + daemons.map((daemon) => daemon.stop()) + ) + }) - it('go peer to js peer', async function () { - const cid = new CID('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp39') + it('go peer to js peer', async function () { + const cid = new CID('QmVzw6MPsF96TyXBSRs1ptLoVMWRv5FCYJZZGJSVB2Hp39') - await daemons[0].client.dht.provide(cid) + await daemons[0].client.dht.provide(cid) - const findProviders = daemons[1].client.dht.findProviders(cid) - const providers = [] + const findProviders = daemons[1].client.dht.findProviders(cid) + const providers = [] - for await (const provider of findProviders) { - providers.push(provider) - } + for await (const provider of findProviders) { + providers.push(provider) + } - expect(providers).to.exist() - expect(providers[0]).to.exist() - expect(providers[0].id.toB58String()).to.equal(identify0.peerId.toB58String()) + expect(providers).to.exist() + expect(providers[0]).to.exist() + expect(providers[0].id.toB58String()).to.equal(identify0.peerId.toB58String()) + }) }) })