Skip to content

Commit e3be331

Browse files
committed
feat: cleanup tests
1 parent 6f8b324 commit e3be331

File tree

2 files changed

+113
-111
lines changed

2 files changed

+113
-111
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"chai": "^4.1.2",
5252
"dirty-chai": "^2.0.1",
5353
"cids": "~0.5.1",
54-
"dirty-chai": "^2.0.1",
5554
"electron-webrtc": "^0.3.0",
5655
"libp2p-circuit": "^0.1.0",
5756
"libp2p-kad-dht": "~0.5.0",

test/nodejs-bundle/circuit.js

+113-110
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
const pull = require('pull-stream')
55
const waterfall = require('async/waterfall')
6+
const series = require('async/series')
67
const parallel = require('async/parallel')
78
const utils = require('./utils')
89
const Circuit = require('libp2p-circuit')
@@ -38,22 +39,15 @@ describe(`circuit`, function () {
3839
node.start((err) => {
3940
expect(err).to.not.exist()
4041

41-
if (node.swarm.transports[Circuit.tag]) {
42-
handlerSpies.push(sinon.spy(node
43-
.swarm
44-
.transports[Circuit.tag]
45-
.listeners[0]
46-
.hopHandler,
47-
'handle'))
48-
}
49-
42+
handlerSpies.push(sinon.spy(node.swarm.transports[Circuit.tag].listeners[0].hopHandler, 'handle'))
5043
cb(node)
5144
})
5245
})
5346
}
5447

5548
before((done) => {
5649
waterfall([
50+
// set up passive relay
5751
(cb) => setupNode([
5852
`/ip4/0.0.0.0/tcp/9010/ws`,
5953
`/ip4/0.0.0.0/tcp/9011`
@@ -69,6 +63,7 @@ describe(`circuit`, function () {
6963
relayNode1 = node
7064
cb()
7165
}),
66+
// setup active relay
7267
(cb) => setupNode([
7368
`/ip4/0.0.0.0/tcp/9110/ws`,
7469
`/ip4/0.0.0.0/tcp/9111`
@@ -77,64 +72,68 @@ describe(`circuit`, function () {
7772
enabled: true,
7873
hop: {
7974
enabled: true,
80-
active: true // active relay
75+
active: false // passive relay
8176
}
8277
}
8378
}, (node) => {
8479
relayNode2 = node
8580
cb()
8681
}),
87-
(cb) => setupNode([`/ip4/0.0.0.0/tcp/9210/ws`],
88-
{
89-
relay: {
90-
enabled: true
91-
}
92-
},
93-
(node) => {
94-
nodeWS1 = node
95-
cb()
96-
}),
97-
(cb) => setupNode([`/ip4/0.0.0.0/tcp/9410/ws`],
98-
{
99-
relay: {
100-
enabled: true
101-
}
102-
},
103-
(node) => {
104-
nodeWS2 = node
105-
cb()
106-
}),
82+
// setup node with WS
83+
(cb) => setupNode([
84+
`/ip4/0.0.0.0/tcp/9210/ws`
85+
], {
86+
relay: {
87+
enabled: true
88+
}
89+
}, (node) => {
90+
nodeWS1 = node
91+
cb()
92+
}),
93+
// setup node with WS
94+
(cb) => setupNode([
95+
`/ip4/0.0.0.0/tcp/9410/ws`
96+
], {
97+
relay: {
98+
enabled: true
99+
}
100+
}, (node) => {
101+
nodeWS2 = node
102+
cb()
103+
}),
104+
// set up node with TCP and listening on relay1
107105
(cb) => setupNode([
108106
`/ip4/0.0.0.0/tcp/9211`,
109-
`/ipfs/${relayNode1.peerInfo.id.toB58String()}/p2p-circuit`],
110-
{
111-
relay: {
112-
enabled: true
113-
}
114-
},
115-
(node) => {
116-
nodeTCP1 = node
117-
cb()
118-
}),
107+
`/ipfs/${relayNode1.peerInfo.id.toB58String()}/p2p-circuit`
108+
], {
109+
relay: {
110+
enabled: true
111+
}
112+
}, (node) => {
113+
nodeTCP1 = node
114+
cb()
115+
}),
116+
// set up node with TCP and listening on relay2 over TCP transport
119117
(cb) => setupNode([
120118
`/ip4/0.0.0.0/tcp/9311`,
121119
`/ip4/0.0.0.0/tcp/9111/ipfs/${relayNode2.peerInfo.id.toB58String()}/p2p-circuit`
122-
],
123-
(node) => {
124-
nodeTCP2 = node
125-
cb()
126-
})],
127-
(err) => {
128-
expect(err).to.not.exist()
120+
], {
121+
relay: {
122+
enabled: true
123+
}
124+
}, (node) => {
125+
nodeTCP2 = node
126+
cb()
127+
})
128+
], (err) => {
129+
expect(err).to.not.exist()
129130

130-
waterfall([
131-
(cb) => nodeWS1.dial(relayNode1.peerInfo, cb),
132-
(conn, cb) => nodeWS1.dial(relayNode2.peerInfo, cb),
133-
(conn, cb) => nodeTCP1.dial(relayNode1.peerInfo, cb),
134-
(conn, cb) => nodeTCP2.dial(relayNode2.peerInfo, cb)
135-
], done)
136-
}
137-
)
131+
series([
132+
(cb) => nodeWS1.dial(relayNode1.peerInfo, cb),
133+
(cb) => nodeWS1.dial(relayNode2.peerInfo, cb),
134+
(cb) => nodeTCP1.dial(relayNode1.peerInfo, cb)
135+
], done)
136+
})
138137
})
139138

140139
after((done) => {
@@ -148,68 +147,72 @@ describe(`circuit`, function () {
148147
], done)
149148
})
150149

151-
it('should dial from WS1 to TCP1 over any R', function (done) {
152-
nodeWS1.dial(nodeTCP1.peerInfo, '/echo/1.0.0', (err, conn) => {
153-
expect(err).to.not.exist()
154-
expect(conn).to.exist()
155-
156-
pull(
157-
pull.values(['hello']),
158-
conn,
159-
pull.collect((e, result) => {
160-
expect(e).to.not.exist()
161-
expect(result[0].toString()).to.equal('hello')
162-
done()
163-
})
164-
)
150+
describe(`any relay`, function () {
151+
it('should dial from WS1 to TCP1 over any R', function (done) {
152+
nodeWS1.dial(nodeTCP1.peerInfo, '/echo/1.0.0', (err, conn) => {
153+
expect(err).to.not.exist()
154+
expect(conn).to.exist()
155+
156+
pull(
157+
pull.values(['hello']),
158+
conn,
159+
pull.collect((e, result) => {
160+
expect(e).to.not.exist()
161+
expect(result[0].toString()).to.equal('hello')
162+
done()
163+
})
164+
)
165+
})
165166
})
166-
})
167167

168-
it('should dial from WS1 to TCP1 over R1', function (done) {
169-
nodeWS1.dial(nodeTCP1.peerInfo, '/echo/1.0.0', (err, conn) => {
170-
expect(err).to.not.exist()
171-
expect(conn).to.exist()
172-
173-
pull(
174-
pull.values(['hello']),
175-
conn,
176-
pull.collect((e, result) => {
177-
expect(e).to.not.exist()
178-
expect(result[0].toString()).to.equal('hello')
179-
180-
const addr = multiaddr(handlerSpies[0].args[2][0].dstPeer.addrs[0]).toString()
181-
expect(addr).to.equal(`/ipfs/${nodeTCP1.peerInfo.id.toB58String()}`)
182-
done()
183-
})
184-
)
168+
it(`should not dial - no R from WS2 to TCP1`, function (done) {
169+
nodeWS2.dial(nodeTCP2.peerInfo, '/echo/1.0.0', (err, conn) => {
170+
expect(err).to.exist()
171+
expect(conn).to.not.exist()
172+
done()
173+
})
185174
})
186175
})
187176

188-
it(`should dial from WS1 to TCP2 over R2`, function (done) {
189-
nodeWS1.dial(nodeTCP2.peerInfo, '/echo/1.0.0', (err, conn) => {
190-
expect(err).to.not.exist()
191-
expect(conn).to.exist()
192-
193-
pull(
194-
pull.values(['hello']),
195-
conn,
196-
pull.collect((e, result) => {
197-
expect(e).to.not.exist()
198-
expect(result[0].toString()).to.equal('hello')
199-
200-
const addr = multiaddr(handlerSpies[1].args[2][0].dstPeer.addrs[0]).toString()
201-
expect(addr).to.equal(`/ipfs/${nodeTCP2.peerInfo.id.toB58String()}`)
202-
done()
203-
})
204-
)
177+
describe(`explicit relay`, function () {
178+
it('should dial from WS1 to TCP1 over R1', function (done) {
179+
nodeWS1.dial(nodeTCP1.peerInfo, '/echo/1.0.0', (err, conn) => {
180+
expect(err).to.not.exist()
181+
expect(conn).to.exist()
182+
183+
pull(
184+
pull.values(['hello']),
185+
conn,
186+
pull.collect((e, result) => {
187+
expect(e).to.not.exist()
188+
expect(result[0].toString()).to.equal('hello')
189+
190+
const addr = multiaddr(handlerSpies[0].args[2][0].dstPeer.addrs[0]).toString()
191+
expect(addr).to.equal(`/ipfs/${nodeTCP1.peerInfo.id.toB58String()}`)
192+
done()
193+
})
194+
)
195+
})
205196
})
206-
})
207197

208-
it(`should not dial - no R from WS2 to TCP1`, function (done) {
209-
nodeWS2.dial(nodeTCP2.peerInfo, '/echo/1.0.0', (err, conn) => {
210-
expect(err).to.exist()
211-
expect(conn).to.not.exist()
212-
done()
198+
it(`should dial from WS1 to TCP2 over R2`, function (done) {
199+
nodeWS1.dial(nodeTCP2.peerInfo, '/echo/1.0.0', (err, conn) => {
200+
expect(err).to.not.exist()
201+
expect(conn).to.exist()
202+
203+
pull(
204+
pull.values(['hello']),
205+
conn,
206+
pull.collect((e, result) => {
207+
expect(e).to.not.exist()
208+
expect(result[0].toString()).to.equal('hello')
209+
210+
const addr = multiaddr(handlerSpies[1].args[2][0].dstPeer.addrs[0]).toString()
211+
expect(addr).to.equal(`/ipfs/${nodeTCP2.peerInfo.id.toB58String()}`)
212+
done()
213+
})
214+
)
215+
})
213216
})
214217
})
215218
})

0 commit comments

Comments
 (0)