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

Commit

Permalink
test: fixing circuit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov committed Jan 18, 2018
1 parent 9875c9d commit 762d9f4
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions test/circuit-relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function setupInProcNode (factory, addrs, hop, callback) {
}, (err, ipfsd) => {
expect(err).to.not.exist()
ipfsd.api.id((err, id) => {
callback(err, { ipfsd, addrs: circuitFilter(id.addresses) })
callback(err, { ipfsd, addrs: id.addresses })
})
})
}
Expand Down Expand Up @@ -84,7 +84,7 @@ function setUpJsNode (addrs, hop, callback) {
}, (err, ipfsd) => {
expect(err).to.not.exist()
ipfsd.api.id((err, id) => {
callback(err, { ipfsd, addrs: circuitFilter(id.addresses) })
callback(err, { ipfsd, addrs: id.addresses })
})
})
}
Expand All @@ -108,12 +108,11 @@ function setUpGoNode (addrs, hop, callback) {
}, (err, ipfsd) => {
expect(err).to.not.exist()
ipfsd.api.id((err, id) => {
callback(err, { ipfsd, addrs: circuitFilter(id.addresses) })
callback(err, { ipfsd, addrs: id.addresses })
})
})
}

const circuitFilter = (addrs) => addrs.map((a) => a.toString()).filter((a) => !a.includes('/p2p-circuit'))
const wsAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => a.includes('/ws'))
const tcpAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => !a.includes('/ws'))

Expand Down Expand Up @@ -340,6 +339,7 @@ function tests (relayType) {

let browserNode1
let jsTCP
let jsTCPNode
let jsTCPAddrs

before(function (done) {
Expand All @@ -348,22 +348,23 @@ function tests (relayType) {
(cb) => setUpJsNode([`${base}/35003`], cb)
], (err, nodes) => {
expect(err).to.not.exist()
browserNode1 = nodes[0]

jsTCP = nodes[1].ipfsd
browserNode1 = nodes[0].ipfsd.api
jsTCP = nodes[1].ipfsd.api
jsTCPNode = nodes[1].ipfsd
jsTCPAddrs = nodes[1].addrs

done()
})
})

after((done) => jsTCP.stop(done))
after((done) => jsTCPNode.stop(done))

it('should connect and transfer', function (done) {
it('should connect', function (done) {
series([
(cb) => browserNode1.swarm.connect(wsAddr(this.relayAddrs), cb),
(cb) => setTimeout(cb, 1000),
(cb) => jsTCP.api.swarm.connect(tcpAddr(this.relayAddrs), cb),
(cb) => jsTCP.swarm.connect(tcpAddr(this.relayAddrs), cb),
(cb) => setTimeout(cb, 1000),
(cb) => browserNode1.swarm.connect(jsTCPAddrs[0], cb)
], done)
Expand Down Expand Up @@ -391,6 +392,7 @@ function tests (relayType) {

let browserNode1
let goTCP
let goTCPNode
let goTCPAddrs

before(function (done) {
Expand All @@ -400,22 +402,22 @@ function tests (relayType) {
], (err, nodes) => {
expect(err).to.not.exist()

browserNode1 = nodes[0]

goTCP = nodes[1].ipfsd
browserNode1 = nodes[0].ipfsd.api
goTCP = nodes[1].ipfsd.api
goTCPNode = nodes[1].ipfsd
goTCPAddrs = nodes[1].addrs

done()
})
})

after((done) => goTCP.stop(done))
after((done) => goTCPNode.stop(done))

it('should connect', function (done) {
series([
(cb) => browserNode1.swarm.connect(wsAddr(this.relayAddrs), cb),
(cb) => setTimeout(cb, 1000),
(cb) => goTCP.api.swarm.connect(tcpAddr(this.relayAddrs), cb),
(cb) => goTCP.swarm.connect(tcpAddr(this.relayAddrs), cb),
(cb) => setTimeout(cb, 1000),
(cb) => browserNode1.swarm.connect(goTCPAddrs[0], cb)
], done)
Expand Down

0 comments on commit 762d9f4

Please sign in to comment.