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

Commit 1c35510

Browse files
committed
feat: name circuit relay test
1 parent e6e736c commit 1c35510

File tree

1 file changed

+58
-56
lines changed

1 file changed

+58
-56
lines changed

test/core/circuit-relay.js

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -62,65 +62,67 @@ function setupInProcNode (addrs, hop, callback) {
6262
const wsAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => a.includes('/ws'))
6363
const tcpAddr = (addrs) => addrs.map((a) => a.toString()).find((a) => !a.includes('/ws'))
6464

65-
describe(`A <-> R <-> B`, function () {
66-
this.timeout(80 * 1000)
67-
68-
let nodeA
69-
let nodeAAddr
70-
let nodeB
71-
let nodeBAddr
72-
let nodeBCircuitAddr
73-
74-
let relayNode
75-
76-
let nodes
77-
before(function (done) {
78-
parallel([
79-
(cb) => setupInProcNode([
80-
'/ip4/0.0.0.0/tcp/0',
81-
'/ip4/0.0.0.0/tcp/0/ws'
82-
], true, cb),
83-
(cb) => setupInProcNode(['/ip4/0.0.0.0/tcp/0'], cb),
84-
(cb) => setupInProcNode(['/ip4/0.0.0.0/tcp/0/ws'], cb)
85-
], function (err, res) {
86-
expect(err).to.not.exist()
87-
nodes = res.map((node) => node.ipfsd)
88-
89-
relayNode = res[0].ipfsd
90-
91-
nodeAAddr = tcpAddr(res[1].addrs)
92-
nodeA = res[0].ipfsd.api
93-
94-
nodeBAddr = wsAddr(res[2].addrs)
95-
96-
nodeB = res[1].ipfsd.api
97-
nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(nodeBAddr).getPeerId()}`
98-
99-
done()
65+
describe('circuit relay', () => {
66+
describe(`A <-> R <-> B`, function () {
67+
this.timeout(80 * 1000)
68+
69+
let nodeA
70+
let nodeAAddr
71+
let nodeB
72+
let nodeBAddr
73+
let nodeBCircuitAddr
74+
75+
let relayNode
76+
77+
let nodes
78+
before(function (done) {
79+
parallel([
80+
(cb) => setupInProcNode([
81+
'/ip4/0.0.0.0/tcp/0',
82+
'/ip4/0.0.0.0/tcp/0/ws'
83+
], true, cb),
84+
(cb) => setupInProcNode(['/ip4/0.0.0.0/tcp/0'], cb),
85+
(cb) => setupInProcNode(['/ip4/0.0.0.0/tcp/0/ws'], cb)
86+
], function (err, res) {
87+
expect(err).to.not.exist()
88+
nodes = res.map((node) => node.ipfsd)
89+
90+
relayNode = res[0].ipfsd
91+
92+
nodeAAddr = tcpAddr(res[1].addrs)
93+
nodeA = res[0].ipfsd.api
94+
95+
nodeBAddr = wsAddr(res[2].addrs)
96+
97+
nodeB = res[1].ipfsd.api
98+
nodeBCircuitAddr = `/p2p-circuit/ipfs/${multiaddr(nodeBAddr).getPeerId()}`
99+
100+
done()
101+
})
100102
})
101-
})
102103

103-
after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done))
104+
after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done))
104105

105-
it('should connect', function (done) {
106-
series([
107-
(cb) => relayNode.api.swarm.connect(nodeAAddr, cb),
108-
(cb) => setTimeout(cb, 1000),
109-
(cb) => relayNode.api.swarm.connect(nodeBAddr, cb),
110-
(cb) => setTimeout(cb, 1000),
111-
(cb) => nodeA.swarm.connect(nodeBCircuitAddr, cb)
112-
], done)
113-
})
106+
it('should connect', function (done) {
107+
series([
108+
(cb) => relayNode.api.swarm.connect(nodeAAddr, cb),
109+
(cb) => setTimeout(cb, 1000),
110+
(cb) => relayNode.api.swarm.connect(nodeBAddr, cb),
111+
(cb) => setTimeout(cb, 1000),
112+
(cb) => nodeA.swarm.connect(nodeBCircuitAddr, cb)
113+
], done)
114+
})
114115

115-
it('should transfer', function (done) {
116-
const data = crypto.randomBytes(128)
117-
waterfall([
118-
(cb) => nodeA.files.add(data, cb),
119-
(res, cb) => nodeB.files.cat(res[0].hash, cb),
120-
(buffer, cb) => {
121-
expect(buffer).to.deep.equal(data)
122-
cb()
123-
}
124-
], done)
116+
it('should transfer', function (done) {
117+
const data = crypto.randomBytes(128)
118+
waterfall([
119+
(cb) => nodeA.files.add(data, cb),
120+
(res, cb) => nodeB.files.cat(res[0].hash, cb),
121+
(buffer, cb) => {
122+
expect(buffer).to.deep.equal(data)
123+
cb()
124+
}
125+
], done)
126+
})
125127
})
126128
})

0 commit comments

Comments
 (0)