Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
test: adding interop tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov committed Sep 12, 2017
1 parent c7e61d9 commit 6c9c23f
Show file tree
Hide file tree
Showing 6 changed files with 336 additions and 14 deletions.
8 changes: 0 additions & 8 deletions src/core/runtime/config-browser.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,5 @@
}
},
"Bootstrap": [
"/dns4/ams-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd",
"/dns4/lon-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3",
"/dns4/sfo-3.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
"/dns4/sgp-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
"/dns4/nyc-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm",
"/dns4/nyc-2.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",
"/dns4/wss0.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic",
"/dns4/wss1.bootstrap.libp2p.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6"
]
}
4 changes: 1 addition & 3 deletions test/core/circuit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ describe('circuit', function () {
parallel([
(cb) => ipfsSrc.swarm.connect(addr[0], cb),
(cb) => ipfsDst.swarm.connect(addr[1], cb)
], (err) => {
setTimeout(() => done(err), 2000)
})
], (err) => setTimeout(done, 2000, err))
})
})

Expand Down
216 changes: 216 additions & 0 deletions test/interop/circuit/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
/* eslint max-nested-callbacks: ["error", 8] */
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
const parallel = require('async/parallel')
const series = require('async/series')
const Factory = require('../../utils/ipfs-factory-daemon')

const crypto = require('crypto')
const utils = require('./utils')

const multiaddr = require('multiaddr')

chai.use(dirtyChai)

describe('circuit interop', function () {
this.timeout(20 * 1000)

let jsTCP
let jsTCPAddrs
let jsWS
let jsWSAddrs
let jsRelayAddrs
let factory = new Factory()

let goRelayAddrs
let goRelayDaemon

let goTCPAddrs
let goTCPDaemon
let goTCP

let goWSAddrs
let goWSDaemon
let goWS

beforeEach((done) => {
parallel([
(pCb) => utils.setupJsNode([
'/ip4/127.0.0.1/tcp/61454/ws',
'/ip4/127.0.0.1/tcp/61453'
], factory, true, pCb),
(pCb) => utils.setupJsNode([
'/ip4/127.0.0.1/tcp/9002'
], factory, pCb),
(pCb) => utils.setupJsNode([
'/ip4/127.0.0.1/tcp/9003/ws'
], factory, pCb),
(pCb) => utils.setupGoNode([
'/ip4/0.0.0.0/tcp/0/ws',
'/ip4/0.0.0.0/tcp/0'
], true, pCb),
(pCb) => utils.setupGoNode([
'/ip4/0.0.0.0/tcp/0'
], pCb),
(pCb) => utils.setupGoNode([
'/ip4/0.0.0.0/tcp/0/ws'
], pCb)
], (err, res) => {
expect(err).to.not.exist()

jsRelayPeer = res[0][0]
jsRelayAddrs = res[0][1].map((a) => a.toString()).filter((a) => !a.includes('/p2p-circuit'))
jsTCP = res[1][0]
jsTCPAddrs = res[1][1].map((a) => a.toString()).filter((a) => a.includes('/p2p-circuit'))
jsWS = res[2][0]
jsWSAddrs = res[2][1].map((a) => a.toString()).filter((a) => a.includes('/p2p-circuit'))

goRelay = res[3][0].api
goRelayDaemon = res[3][0]
goRelayAddrs = res[3][1]
goTCP = res[4][0].api
goTCPDaemon = res[4][0]
goTCPAddrs = res[4][1]
goWS = res[5][0].api
goWSDaemon = res[5][0]
goWSAddrs = res[5][1]
done()
})
})

afterEach((done) => {
parallel([
(cb) => factory.dismantle(cb),
(cb) => goRelayDaemon.stop(cb),
(cb) => goTCPDaemon.stop(cb),
(cb) => goWSDaemon.stop(cb)
], done)
})

it('jsWS <-> jsRelay <-> jsTCP', function (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()
utils.addAndCat(data,
jsWS,
jsTCP,
(err, data) => {
expect(err).to.not.exist()
expect(data).to.be.equal(data)
done()
})
})
})

it('goWS <-> jsRelay <-> goTCP', function (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()
utils.addAndCat(data,
goWS,
goTCP,
(err, data) => {
expect(err).to.not.exist()
expect(data).to.be.equal(data)
done()
})
})
})

it('jsWS <-> jsRelay <-> goTCP', function (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()
utils.addAndCat(data,
jsWS,
goTCP,
(err, data) => {
expect(err).to.not.exist()
expect(data).to.be.equal(data)
done()
})
})
})

it('jsTCP <-> goRelay <-> jsWS', function (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()
utils.addAndCat(data,
jsWS,
jsTCP,
(err, data) => {
expect(err).to.not.exist()
expect(data).to.be.equal(data)
done()
})
})
})

it('goTCP <-> goRelay <-> goWS', function (done) {
const data = crypto.randomBytes(128)
console.log(`goRelayAddrs: ${goRelayAddrs.map((a) => a.toString())}`)
console.log(`goTCPAddrs: ${JSON.stringify(goTCPAddrs)})`)
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()
utils.addAndCat(data,
goWS,
goTCP,
(err, data) => {
expect(err).to.not.exist()
expect(data).to.be.equal(data)
done()
})
})
})

it('jsWS <-> goRelay <-> goTCP', function (done) {
const data = crypto.randomBytes(128)
console.log(`goRelayAddrs: ${goRelayAddrs.map(a => a.toString())}`)
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()
utils.addAndCat(data,
jsWS,
goTCP,
(err, data) => {
expect(err).to.not.exist()
expect(data).to.be.equal(data)
done()
})
})
})
})
114 changes: 114 additions & 0 deletions test/interop/circuit/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/* eslint-env mocha */

'use strict'

const chai = require('chai')
const expect = chai.expect
const waterfall = require('async/waterfall')

const createTempRepo = require('../../utils/create-repo-nodejs')
const relayConfig = require('../../utils/ipfs-factory-daemon/default-config.json')

const GoDaemon = require('../daemons/go')

exports.setupGoNode = function setupGoNode (addrs, hop, cb) {
if (typeof hop === 'function') {
cb = hop
hop = false
}

const daemon = new GoDaemon({
disposable: true,
init: true,
config: {
Addresses: {
Swarm: addrs,
API: `/ip4/0.0.0.0/tcp/0`,
Gateway: `/ip4/0.0.0.0/tcp/0`
},
Swarm: {
AddrFilters: null,
DisableBandwidthMetrics: false,
DisableNatPortMap: false,
DisableRelay: false,
EnableRelayHop: hop
}
}
})

daemon.start((err) => {
expect(err).to.not.exist()
daemon.api.id((err, id) => {
expect(err).to.not.exist()
cb(null, daemon, id.addresses)
})
})
}

exports.setupJsNode = function setupJsNode (addrs, factory, hop, cb) {
let relayPeer
let relayAddrs

if (typeof hop === 'function') {
cb = hop
hop = false
}

cb = cb || (() => {})

waterfall([
(pCb) => {
factory.spawnNode(createTempRepo(), Object.assign(relayConfig, {
Addresses: {
Swarm: addrs,
API: `/ip4/0.0.0.0/tcp/0`,
Gateway: `/ip4/0.0.0.0/tcp/0`
},
EXPERIMENTAL: {
Relay: {
Enabled: true,
HOP: {
Enabled: hop,
Active: false
}
}
}
}), (err, node) => {
expect(err).to.not.exist()
relayPeer = node
pCb()
})
},
(pCb) => {
relayPeer.swarm.localAddrs((err, addrs) => {
expect(err).to.not.exist()
relayAddrs = addrs
pCb()
})
}], (err) => {
expect(err).to.not.exist()
cb(null, relayPeer, relayAddrs)
})
}

exports.addAndCat = function addAndCat (data, ipfsSrc, ipfsDst, callback) {
waterfall([
(cb) => ipfsDst.files.add(data, cb),
(res, cb) => ipfsSrc.files.cat(res[0].hash, function (err, stream) {
expect(err).to.be.null()
var res = ''

stream.on('data', function (chunk) {
res += chunk.toString()
})

stream.on('error', function (err) {
cb(err)
})

stream.on('end', function () {
cb(null, res)
})
})
], callback)
}
6 changes: 4 additions & 2 deletions test/interop/daemons/go.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ class GoDaemon {
this.disposable = opts.disposable
this.node = null
this.api = null
this.config = opts.config || {}
}

start (callback) {
waterfall([
(cb) => {
if (this.disposable) {
ctl.disposable({init: this.init}, cb)
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) {
Expand Down Expand Up @@ -52,7 +54,7 @@ class GoDaemon {
})
this.node._run(
['log', 'level', 'all', 'debug'],
{env: this.node.env},
{ env: this.node.env },
cb
)
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/interop/daemons/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class JsDaemon extends EventEmitter {
throw err
}
this._started = true
this.api = new IPFSAPI(this.node.apiMultiaddr, opts.config)
this.api = new IPFSAPI(this.node.apiMultiaddr)

this.emit('start')
})
Expand Down

0 comments on commit 6c9c23f

Please sign in to comment.