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

Commit 30bc5db

Browse files
interop tests passing
1 parent 30a13d7 commit 30bc5db

File tree

9 files changed

+81
-74
lines changed

9 files changed

+81
-74
lines changed

src/core/components/libp2p.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const Node = require('libp2p-ipfs-nodejs')
44
const promisify = require('promisify-es6')
5+
const get = require('lodash.get')
56

67
module.exports = function libp2p (self) {
78
return {
@@ -14,9 +15,9 @@ module.exports = function libp2p (self) {
1415
}
1516

1617
const options = {
17-
mdns: config.Discovery.MDNS.Enabled,
18-
webRTCStar: config.Discovery.webRTCStar.Enabled,
19-
bootstrap: config.Bootstrap
18+
mdns: get(config, 'Discovery.MDNS.Enabled'),
19+
webRTCStar: get(config, 'Discovery.webRTCStar.Enabled'),
20+
bootstrap: get(config, 'Bootstrap')
2021
}
2122

2223
self._libp2pNode = new Node(self._peerInfo, self._peerInfoBook, options)

src/core/components/start.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ module.exports = (self) => {
1717
}
1818

1919
series([
20+
(cb) => {
21+
if (self._repo.closed) {
22+
self._repo.open(cb)
23+
} else {
24+
cb()
25+
}
26+
},
2027
(cb) => self.preStart(cb),
2128
(cb) => self.libp2p.start(cb)
2229
], (err) => {

test/http-api/over-ipfs-api/block.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ module.exports = (ctl) => {
2121

2222
waterfall([
2323
(cb) => ctl.block.put(data, cb),
24-
(block, cb) => block.key(cb),
25-
(key, cb) => {
26-
expect(key).to.eql(multihash.fromB58String(expectedResult.key))
24+
(block, cb) => {
25+
expect(block.cid.multihash).to.eql(
26+
multihash.fromB58String(expectedResult.key)
27+
)
2728
cb()
2829
}
2930
], done)

test/interop/daemons/go.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
const ctl = require('ipfsd-ctl')
44
const waterfall = require('async/waterfall')
55

6-
const flags = ['--enable-mplex-experiment']
7-
86
class GoDaemon {
97
constructor (opts) {
108
opts = opts || {
@@ -39,7 +37,7 @@ class GoDaemon {
3937
this.node = node
4038
this.node.setConfig('Bootstrap', '[]', cb)
4139
},
42-
(res, cb) => this.node.startDaemon(flags, cb),
40+
(res, cb) => this.node.startDaemon(cb),
4341
(api, cb) => {
4442
this.api = api
4543

test/interop/daemons/js.js

Lines changed: 48 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const EventEmitter = require('events').EventEmitter
34
const IPFSAPI = require('ipfs-api')
45
const series = require('async/series')
56
const rimraf = require('rimraf')
@@ -9,31 +10,22 @@ const tmpDir = require('../util').tmpDir
910
const IPFS = require('../../../src/core')
1011
const HTTPAPI = require('../../../src/http-api')
1112

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-
[
27-
'/ip4/0.0.0.0/tcp/' + (4003 + port),
28-
'/ip4/0.0.0.0/tcp/' + (4004 + port) + '/ws'
29-
],
30-
cb
31-
)
32-
], callback)
13+
function portConfig (port) {
14+
port = port + 5
15+
16+
return {
17+
Gateway: '/ip4/127.0.0.1/tcp/' + (9090 + port),
18+
API: '/ip4/127.0.0.1/tcp/' + (5002 + port),
19+
Swarm: [
20+
'/ip4/127.0.0.1/tcp/' + (4003 + port),
21+
'/ip4/127.0.0.1/tcp/' + (4104 + port) + '/ws'
22+
]
23+
}
3324
}
3425

35-
class JsDaemon {
26+
class JsDaemon extends EventEmitter {
3627
constructor (opts) {
28+
super()
3729
opts = Object.assign({}, {
3830
disposable: true,
3931
init: true
@@ -42,57 +34,60 @@ class JsDaemon {
4234
this.path = opts.path
4335
this.disposable = opts.disposable
4436
this.init = opts.init
45-
this.port = opts.port
37+
this.port = opts.port || 1
4638

4739
this.path = opts.path || tmpDir()
40+
4841
if (this.init) {
42+
const p = portConfig(this.port)
43+
4944
this.ipfs = new IPFS({
50-
repo: this.path
45+
repo: this.path,
46+
init: this.init,
47+
start: false,
48+
config: {
49+
Bootstrap: [],
50+
Addresses: p
51+
}
5152
})
5253
} else {
5354
const repo = new IPFSRepo(this.path)
5455
this.ipfs = new IPFS({
5556
repo: repo,
57+
init: this.init,
58+
start: false,
5659
EXPERIMENTAL: {
5760
pubsub: true
5861
}
5962
})
6063
}
61-
this.node = null
62-
this.api = null
63-
}
6464

65-
start (callback) {
66-
console.log('starting js', this.path)
67-
series([
68-
(cb) => {
69-
if (this.init) {
70-
this.ipfs.init(cb)
71-
} else {
72-
cb()
73-
}
74-
},
75-
(cb) => this.ipfs.config.set('Bootstrap', [], cb),
76-
(cb) => {
77-
if (this.port) {
78-
console.log('setting to port', this.port)
79-
setPorts(this.ipfs, this.port, cb)
80-
} else {
81-
cb()
65+
this._started = false
66+
67+
this.ipfs.once('ready', () => {
68+
this.node = new HTTPAPI(this.ipfs._repo)
69+
this.node.start((err) => {
70+
if (err) {
71+
throw err
8272
}
83-
},
84-
(cb) => {
85-
this.node = new HTTPAPI(this.ipfs._repo)
86-
this.node.start(cb)
87-
},
88-
(cb) => {
73+
this._started = true
8974
this.api = new IPFSAPI(this.node.apiMultiaddr)
90-
cb()
91-
}
92-
], (err) => callback(err))
75+
76+
this.emit('start')
77+
})
78+
})
79+
}
80+
81+
start (callback) {
82+
if (!this._started) {
83+
return this.once('start', callback)
84+
}
85+
86+
callback()
9387
}
9488

9589
stop (callback) {
90+
this._started = false
9691
series([
9792
(cb) => this.node.stop(cb),
9893
(cb) => {

test/interop/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ describe('basic', () => {
4949

5050
before((done) => {
5151
goDaemon = new GoDaemon()
52-
jsDaemon = new JsDaemon()
53-
js2Daemon = new JsDaemon({port: 1})
52+
jsDaemon = new JsDaemon({port: 1})
53+
js2Daemon = new JsDaemon({port: 2})
5454

5555
parallel([
5656
(cb) => goDaemon.start(cb),

test/interop/repo.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ function catAndCheck (daemon, hash, data, callback) {
2525
})
2626
}
2727

28-
// TODO: these are not working, will need to figure out why
29-
describe.skip('repo', () => {
28+
describe('repo', () => {
3029
it('read repo: go -> js', (done) => {
3130
const dir = os.tmpdir() + '/' + Math.ceil(Math.random() * 10000)
3231
const data = crypto.randomBytes(1024 * 5)
3332

34-
const goDaemon = new GoDaemon({init: true, disposable: false, path: dir})
33+
const goDaemon = new GoDaemon({
34+
init: true,
35+
disposable: false,
36+
path: dir
37+
})
3538
let jsDaemon
3639

3740
let hash
@@ -44,7 +47,11 @@ describe.skip('repo', () => {
4447
},
4548
(cb) => goDaemon.stop(cb),
4649
(cb) => {
47-
jsDaemon = new JsDaemon({init: false, disposable: false, path: dir})
50+
jsDaemon = new JsDaemon({
51+
init: false,
52+
disposable: false,
53+
path: dir
54+
})
4855
jsDaemon.start(cb)
4956
},
5057
(cb) => catAndCheck(goDaemon, hash, data, cb),

test/utils/create-repo-browser.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ function createTempRepo (repoPath) {
1414
const repo = new IPFSRepo(repoPath)
1515

1616
repo.teardown = (done) => {
17-
repo.close((err) => {
18-
if (err) {
19-
return done(err)
20-
}
17+
repo.close(() => {
2118
idb.deleteDatabase(repoPath)
2219
idb.deleteDatabase(repoPath + '/blocks')
2320
done()

test/utils/ipfs-factory-instance/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const PeerId = require('peer-id')
44
const series = require('async/series')
5+
const each = require('async/each')
56

67
const defaultConfig = require('./default-config.json')
78
const IPFS = require('../../../src/core')
@@ -76,8 +77,8 @@ function Factory () {
7677

7778
this.dismantle = function (callback) {
7879
series([
79-
(cb) => series(nodes.map((el) => el.ipfs.stop), cb),
80-
(cb) => series(nodes.map((el) => el.repo.teardown), cb)
80+
(cb) => each(nodes((el, cb) => el.ipfs.stop(cb)), cb),
81+
(cb) => each(nodes((el, cb) => el.repo.teardown(cb)), cb)
8182
], callback)
8283
}
8384
}

0 commit comments

Comments
 (0)