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

Commit 6c9c23f

Browse files
committed
test: adding interop tests
1 parent c7e61d9 commit 6c9c23f

File tree

6 files changed

+336
-14
lines changed

6 files changed

+336
-14
lines changed

src/core/runtime/config-browser.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,5 @@
1616
}
1717
},
1818
"Bootstrap": [
19-
"/dns4/ams-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd",
20-
"/dns4/lon-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3",
21-
"/dns4/sfo-3.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
22-
"/dns4/sgp-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
23-
"/dns4/nyc-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm",
24-
"/dns4/nyc-2.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",
25-
"/dns4/wss0.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic",
26-
"/dns4/wss1.bootstrap.libp2p.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6"
2719
]
2820
}

test/core/circuit.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ describe('circuit', function () {
111111
parallel([
112112
(cb) => ipfsSrc.swarm.connect(addr[0], cb),
113113
(cb) => ipfsDst.swarm.connect(addr[1], cb)
114-
], (err) => {
115-
setTimeout(() => done(err), 2000)
116-
})
114+
], (err) => setTimeout(done, 2000, err))
117115
})
118116
})
119117

test/interop/circuit/index.js

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
/* eslint max-nested-callbacks: ["error", 8] */
2+
/* eslint-env mocha */
3+
'use strict'
4+
5+
const chai = require('chai')
6+
const dirtyChai = require('dirty-chai')
7+
const expect = chai.expect
8+
const parallel = require('async/parallel')
9+
const series = require('async/series')
10+
const Factory = require('../../utils/ipfs-factory-daemon')
11+
12+
const crypto = require('crypto')
13+
const utils = require('./utils')
14+
15+
const multiaddr = require('multiaddr')
16+
17+
chai.use(dirtyChai)
18+
19+
describe('circuit interop', function () {
20+
this.timeout(20 * 1000)
21+
22+
let jsTCP
23+
let jsTCPAddrs
24+
let jsWS
25+
let jsWSAddrs
26+
let jsRelayAddrs
27+
let factory = new Factory()
28+
29+
let goRelayAddrs
30+
let goRelayDaemon
31+
32+
let goTCPAddrs
33+
let goTCPDaemon
34+
let goTCP
35+
36+
let goWSAddrs
37+
let goWSDaemon
38+
let goWS
39+
40+
beforeEach((done) => {
41+
parallel([
42+
(pCb) => utils.setupJsNode([
43+
'/ip4/127.0.0.1/tcp/61454/ws',
44+
'/ip4/127.0.0.1/tcp/61453'
45+
], factory, true, pCb),
46+
(pCb) => utils.setupJsNode([
47+
'/ip4/127.0.0.1/tcp/9002'
48+
], factory, pCb),
49+
(pCb) => utils.setupJsNode([
50+
'/ip4/127.0.0.1/tcp/9003/ws'
51+
], factory, pCb),
52+
(pCb) => utils.setupGoNode([
53+
'/ip4/0.0.0.0/tcp/0/ws',
54+
'/ip4/0.0.0.0/tcp/0'
55+
], true, pCb),
56+
(pCb) => utils.setupGoNode([
57+
'/ip4/0.0.0.0/tcp/0'
58+
], pCb),
59+
(pCb) => utils.setupGoNode([
60+
'/ip4/0.0.0.0/tcp/0/ws'
61+
], pCb)
62+
], (err, res) => {
63+
expect(err).to.not.exist()
64+
65+
jsRelayPeer = res[0][0]
66+
jsRelayAddrs = res[0][1].map((a) => a.toString()).filter((a) => !a.includes('/p2p-circuit'))
67+
jsTCP = res[1][0]
68+
jsTCPAddrs = res[1][1].map((a) => a.toString()).filter((a) => a.includes('/p2p-circuit'))
69+
jsWS = res[2][0]
70+
jsWSAddrs = res[2][1].map((a) => a.toString()).filter((a) => a.includes('/p2p-circuit'))
71+
72+
goRelay = res[3][0].api
73+
goRelayDaemon = res[3][0]
74+
goRelayAddrs = res[3][1]
75+
goTCP = res[4][0].api
76+
goTCPDaemon = res[4][0]
77+
goTCPAddrs = res[4][1]
78+
goWS = res[5][0].api
79+
goWSDaemon = res[5][0]
80+
goWSAddrs = res[5][1]
81+
done()
82+
})
83+
})
84+
85+
afterEach((done) => {
86+
parallel([
87+
(cb) => factory.dismantle(cb),
88+
(cb) => goRelayDaemon.stop(cb),
89+
(cb) => goTCPDaemon.stop(cb),
90+
(cb) => goWSDaemon.stop(cb)
91+
], done)
92+
})
93+
94+
it('jsWS <-> jsRelay <-> jsTCP', function (done) {
95+
const data = crypto.randomBytes(128)
96+
series([
97+
(cb) => jsWS.swarm.connect(jsRelayAddrs[0], cb),
98+
(cb) => jsTCP.swarm.connect(jsRelayAddrs[1], cb),
99+
(cb) => setTimeout(cb, 1000),
100+
(cb) => jsTCP.swarm.connect(jsWSAddrs[0], cb)
101+
], (err) => {
102+
expect(err).to.not.exist()
103+
utils.addAndCat(data,
104+
jsWS,
105+
jsTCP,
106+
(err, data) => {
107+
expect(err).to.not.exist()
108+
expect(data).to.be.equal(data)
109+
done()
110+
})
111+
})
112+
})
113+
114+
it('goWS <-> jsRelay <-> goTCP', function (done) {
115+
const data = crypto.randomBytes(128)
116+
series([
117+
(cb) => goWS.swarm.connect(jsRelayAddrs[0], cb),
118+
(cb) => goTCP.swarm.connect(jsRelayAddrs[1], cb),
119+
(cb) => setTimeout(cb, 1000),
120+
(cb) => goTCP.swarm.connect(`/p2p-circuit/ipfs/${multiaddr(goWSAddrs[0]).getPeerId()}`, cb)
121+
], (err) => {
122+
expect(err).to.not.exist()
123+
utils.addAndCat(data,
124+
goWS,
125+
goTCP,
126+
(err, data) => {
127+
expect(err).to.not.exist()
128+
expect(data).to.be.equal(data)
129+
done()
130+
})
131+
})
132+
})
133+
134+
it('jsWS <-> jsRelay <-> goTCP', function (done) {
135+
const data = crypto.randomBytes(128)
136+
series([
137+
(cb) => jsWS.swarm.connect(jsRelayAddrs[0], cb),
138+
(cb) => goTCP.swarm.connect(jsRelayAddrs[1], cb),
139+
(cb) => setTimeout(cb, 1000),
140+
(cb) => goTCP.swarm.connect(jsWSAddrs[0], cb)
141+
], (err) => {
142+
expect(err).to.not.exist()
143+
utils.addAndCat(data,
144+
jsWS,
145+
goTCP,
146+
(err, data) => {
147+
expect(err).to.not.exist()
148+
expect(data).to.be.equal(data)
149+
done()
150+
})
151+
})
152+
})
153+
154+
it('jsTCP <-> goRelay <-> jsWS', function (done) {
155+
const data = crypto.randomBytes(128)
156+
series([
157+
(cb) => jsTCP.swarm.connect(goRelayAddrs[2], cb),
158+
(cb) => jsWS.swarm.connect(goRelayAddrs[0], cb),
159+
(cb) => setTimeout(cb, 1000),
160+
(cb) => jsWS.swarm.connect(jsTCPAddrs[0], cb)
161+
], (err) => {
162+
expect(err).to.not.exist()
163+
utils.addAndCat(data,
164+
jsWS,
165+
jsTCP,
166+
(err, data) => {
167+
expect(err).to.not.exist()
168+
expect(data).to.be.equal(data)
169+
done()
170+
})
171+
})
172+
})
173+
174+
it('goTCP <-> goRelay <-> goWS', function (done) {
175+
const data = crypto.randomBytes(128)
176+
console.log(`goRelayAddrs: ${goRelayAddrs.map((a) => a.toString())}`)
177+
console.log(`goTCPAddrs: ${JSON.stringify(goTCPAddrs)})`)
178+
series([
179+
(cb) => goWS.swarm.connect(goRelayAddrs[0], cb),
180+
(cb) => goTCP.swarm.connect(goRelayAddrs[2], cb),
181+
(cb) => setTimeout(cb, 1000),
182+
(cb) => goWS.swarm.connect(`/p2p-circuit/ipfs/${multiaddr(goTCPAddrs[0]).getPeerId()}`, cb)
183+
], (err) => {
184+
expect(err).to.not.exist()
185+
utils.addAndCat(data,
186+
goWS,
187+
goTCP,
188+
(err, data) => {
189+
expect(err).to.not.exist()
190+
expect(data).to.be.equal(data)
191+
done()
192+
})
193+
})
194+
})
195+
196+
it('jsWS <-> goRelay <-> goTCP', function (done) {
197+
const data = crypto.randomBytes(128)
198+
console.log(`goRelayAddrs: ${goRelayAddrs.map(a => a.toString())}`)
199+
series([
200+
(cb) => jsWS.swarm.connect(goRelayAddrs[0], cb),
201+
(cb) => goTCP.swarm.connect(goRelayAddrs[2], cb),
202+
(cb) => setTimeout(cb, 1000),
203+
(cb) => goTCP.swarm.connect(`/p2p-circuit/ipfs/${multiaddr(jsWSAddrs[0]).getPeerId()}`, cb)
204+
], (err) => {
205+
expect(err).to.not.exist()
206+
utils.addAndCat(data,
207+
jsWS,
208+
goTCP,
209+
(err, data) => {
210+
expect(err).to.not.exist()
211+
expect(data).to.be.equal(data)
212+
done()
213+
})
214+
})
215+
})
216+
})

test/interop/circuit/utils.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/* eslint-env mocha */
2+
3+
'use strict'
4+
5+
const chai = require('chai')
6+
const expect = chai.expect
7+
const waterfall = require('async/waterfall')
8+
9+
const createTempRepo = require('../../utils/create-repo-nodejs')
10+
const relayConfig = require('../../utils/ipfs-factory-daemon/default-config.json')
11+
12+
const GoDaemon = require('../daemons/go')
13+
14+
exports.setupGoNode = function setupGoNode (addrs, hop, cb) {
15+
if (typeof hop === 'function') {
16+
cb = hop
17+
hop = false
18+
}
19+
20+
const daemon = new GoDaemon({
21+
disposable: true,
22+
init: true,
23+
config: {
24+
Addresses: {
25+
Swarm: addrs,
26+
API: `/ip4/0.0.0.0/tcp/0`,
27+
Gateway: `/ip4/0.0.0.0/tcp/0`
28+
},
29+
Swarm: {
30+
AddrFilters: null,
31+
DisableBandwidthMetrics: false,
32+
DisableNatPortMap: false,
33+
DisableRelay: false,
34+
EnableRelayHop: hop
35+
}
36+
}
37+
})
38+
39+
daemon.start((err) => {
40+
expect(err).to.not.exist()
41+
daemon.api.id((err, id) => {
42+
expect(err).to.not.exist()
43+
cb(null, daemon, id.addresses)
44+
})
45+
})
46+
}
47+
48+
exports.setupJsNode = function setupJsNode (addrs, factory, hop, cb) {
49+
let relayPeer
50+
let relayAddrs
51+
52+
if (typeof hop === 'function') {
53+
cb = hop
54+
hop = false
55+
}
56+
57+
cb = cb || (() => {})
58+
59+
waterfall([
60+
(pCb) => {
61+
factory.spawnNode(createTempRepo(), Object.assign(relayConfig, {
62+
Addresses: {
63+
Swarm: addrs,
64+
API: `/ip4/0.0.0.0/tcp/0`,
65+
Gateway: `/ip4/0.0.0.0/tcp/0`
66+
},
67+
EXPERIMENTAL: {
68+
Relay: {
69+
Enabled: true,
70+
HOP: {
71+
Enabled: hop,
72+
Active: false
73+
}
74+
}
75+
}
76+
}), (err, node) => {
77+
expect(err).to.not.exist()
78+
relayPeer = node
79+
pCb()
80+
})
81+
},
82+
(pCb) => {
83+
relayPeer.swarm.localAddrs((err, addrs) => {
84+
expect(err).to.not.exist()
85+
relayAddrs = addrs
86+
pCb()
87+
})
88+
}], (err) => {
89+
expect(err).to.not.exist()
90+
cb(null, relayPeer, relayAddrs)
91+
})
92+
}
93+
94+
exports.addAndCat = function addAndCat (data, ipfsSrc, ipfsDst, callback) {
95+
waterfall([
96+
(cb) => ipfsDst.files.add(data, cb),
97+
(res, cb) => ipfsSrc.files.cat(res[0].hash, function (err, stream) {
98+
expect(err).to.be.null()
99+
var res = ''
100+
101+
stream.on('data', function (chunk) {
102+
res += chunk.toString()
103+
})
104+
105+
stream.on('error', function (err) {
106+
cb(err)
107+
})
108+
109+
stream.on('end', function () {
110+
cb(null, res)
111+
})
112+
})
113+
], callback)
114+
}

test/interop/daemons/go.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ class GoDaemon {
1515
this.disposable = opts.disposable
1616
this.node = null
1717
this.api = null
18+
this.config = opts.config || {}
1819
}
1920

2021
start (callback) {
2122
waterfall([
2223
(cb) => {
2324
if (this.disposable) {
24-
ctl.disposable({init: this.init}, cb)
25+
const config = Object.assign({ init: this.init }, this.config)
26+
ctl.disposable(config, cb)
2527
} else if (this.init) {
2628
ctl.local(this.path, (err, node) => {
2729
if (err) {
@@ -52,7 +54,7 @@ class GoDaemon {
5254
})
5355
this.node._run(
5456
['log', 'level', 'all', 'debug'],
55-
{env: this.node.env},
57+
{ env: this.node.env },
5658
cb
5759
)
5860
} else {

test/interop/daemons/js.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class JsDaemon extends EventEmitter {
5252
throw err
5353
}
5454
this._started = true
55-
this.api = new IPFSAPI(this.node.apiMultiaddr, opts.config)
55+
this.api = new IPFSAPI(this.node.apiMultiaddr)
5656

5757
this.emit('start')
5858
})

0 commit comments

Comments
 (0)