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

Commit 1c3f0db

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

File tree

6 files changed

+334
-14
lines changed

6 files changed

+334
-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: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
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+
jsRelayAddrs = res[0][1].map((a) => a.toString()).filter((a) => !a.includes('/p2p-circuit'))
66+
jsTCP = res[1][0]
67+
jsTCPAddrs = res[1][1].map((a) => a.toString()).filter((a) => a.includes('/p2p-circuit'))
68+
jsWS = res[2][0]
69+
jsWSAddrs = res[2][1].map((a) => a.toString()).filter((a) => a.includes('/p2p-circuit'))
70+
71+
goRelayDaemon = res[3][0]
72+
goRelayAddrs = res[3][1]
73+
goTCP = res[4][0].api
74+
goTCPDaemon = res[4][0]
75+
goTCPAddrs = res[4][1]
76+
goWS = res[5][0].api
77+
goWSDaemon = res[5][0]
78+
goWSAddrs = res[5][1]
79+
done()
80+
})
81+
})
82+
83+
afterEach((done) => {
84+
parallel([
85+
(cb) => factory.dismantle(cb),
86+
(cb) => goRelayDaemon.stop(cb),
87+
(cb) => goTCPDaemon.stop(cb),
88+
(cb) => goWSDaemon.stop(cb)
89+
], done)
90+
})
91+
92+
it('jsWS <-> jsRelay <-> jsTCP', function (done) {
93+
const data = crypto.randomBytes(128)
94+
series([
95+
(cb) => jsWS.swarm.connect(jsRelayAddrs[0], cb),
96+
(cb) => jsTCP.swarm.connect(jsRelayAddrs[1], cb),
97+
(cb) => setTimeout(cb, 1000),
98+
(cb) => jsTCP.swarm.connect(jsWSAddrs[0], cb)
99+
], (err) => {
100+
expect(err).to.not.exist()
101+
utils.addAndCat(data,
102+
jsWS,
103+
jsTCP,
104+
(err, data) => {
105+
expect(err).to.not.exist()
106+
expect(data).to.be.equal(data)
107+
done()
108+
})
109+
})
110+
})
111+
112+
it('goWS <-> jsRelay <-> goTCP', function (done) {
113+
const data = crypto.randomBytes(128)
114+
series([
115+
(cb) => goWS.swarm.connect(jsRelayAddrs[0], cb),
116+
(cb) => goTCP.swarm.connect(jsRelayAddrs[1], cb),
117+
(cb) => setTimeout(cb, 1000),
118+
(cb) => goTCP.swarm.connect(`/p2p-circuit/ipfs/${multiaddr(goWSAddrs[0]).getPeerId()}`, cb)
119+
], (err) => {
120+
expect(err).to.not.exist()
121+
utils.addAndCat(data,
122+
goWS,
123+
goTCP,
124+
(err, data) => {
125+
expect(err).to.not.exist()
126+
expect(data).to.be.equal(data)
127+
done()
128+
})
129+
})
130+
})
131+
132+
it('jsWS <-> jsRelay <-> goTCP', function (done) {
133+
const data = crypto.randomBytes(128)
134+
series([
135+
(cb) => jsWS.swarm.connect(jsRelayAddrs[0], cb),
136+
(cb) => goTCP.swarm.connect(jsRelayAddrs[1], cb),
137+
(cb) => setTimeout(cb, 1000),
138+
(cb) => goTCP.swarm.connect(jsWSAddrs[0], cb)
139+
], (err) => {
140+
expect(err).to.not.exist()
141+
utils.addAndCat(data,
142+
jsWS,
143+
goTCP,
144+
(err, data) => {
145+
expect(err).to.not.exist()
146+
expect(data).to.be.equal(data)
147+
done()
148+
})
149+
})
150+
})
151+
152+
it('jsTCP <-> goRelay <-> jsWS', function (done) {
153+
const data = crypto.randomBytes(128)
154+
series([
155+
(cb) => jsTCP.swarm.connect(goRelayAddrs[2], cb),
156+
(cb) => jsWS.swarm.connect(goRelayAddrs[0], cb),
157+
(cb) => setTimeout(cb, 1000),
158+
(cb) => jsWS.swarm.connect(jsTCPAddrs[0], cb)
159+
], (err) => {
160+
expect(err).to.not.exist()
161+
utils.addAndCat(data,
162+
jsWS,
163+
jsTCP,
164+
(err, data) => {
165+
expect(err).to.not.exist()
166+
expect(data).to.be.equal(data)
167+
done()
168+
})
169+
})
170+
})
171+
172+
it('goTCP <-> goRelay <-> goWS', function (done) {
173+
const data = crypto.randomBytes(128)
174+
console.log(`goRelayAddrs: ${goRelayAddrs.map((a) => a.toString())}`)
175+
console.log(`goTCPAddrs: ${JSON.stringify(goTCPAddrs)})`)
176+
series([
177+
(cb) => goWS.swarm.connect(goRelayAddrs[0], cb),
178+
(cb) => goTCP.swarm.connect(goRelayAddrs[2], cb),
179+
(cb) => setTimeout(cb, 1000),
180+
(cb) => goWS.swarm.connect(`/p2p-circuit/ipfs/${multiaddr(goTCPAddrs[0]).getPeerId()}`, cb)
181+
], (err) => {
182+
expect(err).to.not.exist()
183+
utils.addAndCat(data,
184+
goWS,
185+
goTCP,
186+
(err, data) => {
187+
expect(err).to.not.exist()
188+
expect(data).to.be.equal(data)
189+
done()
190+
})
191+
})
192+
})
193+
194+
it('jsWS <-> goRelay <-> goTCP', function (done) {
195+
const data = crypto.randomBytes(128)
196+
console.log(`goRelayAddrs: ${goRelayAddrs.map(a => a.toString())}`)
197+
series([
198+
(cb) => jsWS.swarm.connect(goRelayAddrs[0], cb),
199+
(cb) => goTCP.swarm.connect(goRelayAddrs[2], cb),
200+
(cb) => setTimeout(cb, 1000),
201+
(cb) => goTCP.swarm.connect(`/p2p-circuit/ipfs/${multiaddr(jsWSAddrs[0]).getPeerId()}`, cb)
202+
], (err) => {
203+
expect(err).to.not.exist()
204+
utils.addAndCat(data,
205+
jsWS,
206+
goTCP,
207+
(err, data) => {
208+
expect(err).to.not.exist()
209+
expect(data).to.be.equal(data)
210+
done()
211+
})
212+
})
213+
})
214+
})

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)