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

Commit b11ef11

Browse files
test(interop): add js to js test
1 parent 446259b commit b11ef11

File tree

2 files changed

+82
-7
lines changed

2 files changed

+82
-7
lines changed

test/interop/daemons/js.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,37 @@ const IPFSRepo = require('ipfs-repo')
99
const IPFS = require('../../../src/core')
1010
const HTTPAPI = require('../../../src/http-api')
1111

12+
function setPorts (ipfs, port, callback) {
13+
series([
14+
(cb) => ipfs.config.set(
15+
'Addresses.Gateway',
16+
'/ip4/127.0.0.1/tcp/' + (9090 + port),
17+
cb
18+
),
19+
(cb) => ipfs.config.set(
20+
'Addresses.API',
21+
'/ip4/127.0.0.1/tcp/' + (5002 + port),
22+
cb
23+
),
24+
(cb) => ipfs.config.set(
25+
'Addresses.Swarm',
26+
['/ip4/0.0.0.0/tcp/' + (4002 + port)],
27+
cb
28+
)
29+
], callback)
30+
}
31+
1232
class JsDaemon {
1333
constructor (opts) {
14-
opts = opts || {
34+
opts = Object.assign({}, {
1535
disposable: true,
1636
init: true
17-
}
37+
}, opts || {})
1838

1939
this.path = opts.path
2040
this.disposable = opts.disposable
2141
this.init = opts.init
42+
this.port = opts.port
2243

2344
this.path = opts.path || os.tmpdir() + `/${Math.ceil(Math.random() * 1000)}`
2445
if (this.init) {
@@ -41,6 +62,14 @@ class JsDaemon {
4162
cb()
4263
}
4364
},
65+
(cb) => {
66+
if (this.port) {
67+
console.log('setting to port', this.port)
68+
setPorts(this.ipfs, this.port, cb)
69+
} else {
70+
cb()
71+
}
72+
},
4473
(cb) => {
4574
this.node = new HTTPAPI(this.ipfs._repo)
4675
this.node.start(cb)

test/interop/index.js

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,25 @@ const JsDaemon = require('./daemons/js')
1414
describe('basic', () => {
1515
let goDaemon
1616
let jsDaemon
17+
let js2Daemon
1718

1819
before((done) => {
1920
goDaemon = new GoDaemon()
2021
jsDaemon = new JsDaemon()
22+
js2Daemon = new JsDaemon({port: 1})
2123

2224
parallel([
2325
(cb) => goDaemon.start(cb),
24-
(cb) => jsDaemon.start(cb)
26+
(cb) => jsDaemon.start(cb),
27+
(cb) => js2Daemon.start(cb)
2528
], done)
2629
})
2730

2831
after((done) => {
29-
parallel([
32+
series([
3033
(cb) => goDaemon.stop(cb),
31-
(cb) => jsDaemon.stop(cb)
34+
(cb) => jsDaemon.stop(cb),
35+
(cb) => js2Daemon.stop(cb)
3236
], done)
3337
})
3438

@@ -60,8 +64,36 @@ describe('basic', () => {
6064
], done)
6165
})
6266

67+
it('connect js <-> js', (done) => {
68+
let jsId
69+
let js2Id
70+
71+
series([
72+
(cb) => parallel([
73+
(cb) => jsDaemon.api.id(cb),
74+
(cb) => js2Daemon.api.id(cb)
75+
], (err, ids) => {
76+
expect(err).to.not.exist
77+
jsId = ids[0]
78+
js2Id = ids[1]
79+
cb()
80+
}),
81+
(cb) => js2Daemon.api.swarm.connect(jsId.addresses[0], cb),
82+
(cb) => jsDaemon.api.swarm.connect(js2Id.addresses[0], cb),
83+
(cb) => parallel([
84+
(cb) => js2Daemon.api.swarm.peers(cb),
85+
(cb) => jsDaemon.api.swarm.peers(cb)
86+
], (err, peers) => {
87+
expect(err).to.not.exist
88+
expect(peers[0].map((p) => p.peer.toB58String())).to.include(jsId.id)
89+
expect(peers[1].map((p) => p.peer.toB58String())).to.include(js2Id.id)
90+
cb()
91+
})
92+
], done)
93+
})
94+
6395
it('cat file: go -> js', (done) => {
64-
const data = crypto.randomBytes(1024 * 5)
96+
const data = crypto.randomBytes(1024 * 1024)
6597
waterfall([
6698
(cb) => goDaemon.api.add(data, cb),
6799
(res, cb) => jsDaemon.api.cat(res[0].hash, cb),
@@ -74,7 +106,8 @@ describe('basic', () => {
74106
})
75107

76108
it('cat file: js -> go', (done) => {
77-
const data = crypto.randomBytes(1024 * 5)
109+
// This will fail once the size is increased to 64512 = 1024 * 63
110+
const data = crypto.randomBytes(1024 * 63 - 1)
78111
waterfall([
79112
(cb) => jsDaemon.api.add(data, cb),
80113
(res, cb) => goDaemon.api.cat(res[0].hash, cb),
@@ -85,4 +118,17 @@ describe('basic', () => {
85118
done()
86119
})
87120
})
121+
122+
it('cat file: js -> js', (done) => {
123+
const data = crypto.randomBytes(1024 * 1024)
124+
waterfall([
125+
(cb) => js2Daemon.api.add(data, cb),
126+
(res, cb) => jsDaemon.api.cat(res[0].hash, cb),
127+
(stream, cb) => stream.pipe(bl(cb))
128+
], (err, file) => {
129+
expect(err).to.not.exist
130+
expect(file).to.be.eql(data)
131+
done()
132+
})
133+
})
88134
})

0 commit comments

Comments
 (0)