Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 68c2b97

Browse files
committed
fix: code review
1 parent 1da461e commit 68c2b97

File tree

3 files changed

+204
-189
lines changed

3 files changed

+204
-189
lines changed

test/ipns-dht.js

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const chai = require('chai')
5+
const dirtyChai = require('dirty-chai')
6+
const expect = chai.expect
7+
chai.use(dirtyChai)
8+
9+
const series = require('async/series')
10+
const parallel = require('async/parallel')
11+
const os = require('os')
12+
const path = require('path')
13+
const hat = require('hat')
14+
15+
const DaemonFactory = require('ipfsd-ctl')
16+
17+
const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU'
18+
19+
const spawnJsDaemon = (callback) => {
20+
DaemonFactory.create({ type: 'js' })
21+
.spawn({
22+
disposable: true,
23+
initOptions: { bits: 512 },
24+
args: ['--enable-dht-experiment'], // enable dht
25+
config: { Bootstrap: [] }
26+
}, callback)
27+
}
28+
29+
const spawnGoDaemon = (callback) => {
30+
DaemonFactory.create()
31+
.spawn({
32+
disposable: true,
33+
initOptions: { bits: 1024 },
34+
config: { Bootstrap: [] }
35+
}, callback)
36+
}
37+
38+
describe.only('ipns over dht', () => {
39+
let nodeAId
40+
let nodeBId
41+
let nodes = []
42+
43+
// Spawn daemons
44+
before(function (done) {
45+
// CI takes longer to instantiate the daemon, so we need to increase the timeout
46+
this.timeout(80 * 1000)
47+
series([
48+
(cb) => spawnGoDaemon(cb),
49+
(cb) => spawnJsDaemon(cb),
50+
(cb) => spawnGoDaemon(cb)
51+
], (err, daemons) => {
52+
expect(err).to.not.exist()
53+
nodes = daemons
54+
done()
55+
})
56+
})
57+
58+
// Get node ids
59+
before(function (done) {
60+
this.timeout(100 * 1000)
61+
parallel([
62+
(cb) => nodes[0].api.id(cb),
63+
(cb) => nodes[1].api.id(cb)
64+
], (err, ids) => {
65+
expect(err).to.not.exist()
66+
expect(ids).to.exist()
67+
expect(ids[0].id).to.exist()
68+
expect(ids[1].id).to.exist()
69+
nodeAId = ids[0]
70+
nodeBId = ids[1]
71+
parallel([
72+
(cb) => nodes[2].api.swarm.connect(ids[0].addresses[0], cb), // C => A
73+
(cb) => nodes[2].api.swarm.connect(ids[1].addresses[0], cb) // C => B
74+
], done)
75+
})
76+
})
77+
78+
after(function (done) {
79+
this.timeout(60 * 1000)
80+
parallel(nodes.map((node) => (cb) => node.stop(cb)), done)
81+
})
82+
83+
it('should publish the record to a go node and resolve it using a js node', function (done) {
84+
this.timeout(50 * 1000)
85+
series([
86+
(cb) => nodes[0].api.name.publish(ipfsRef, { resolve: false }, cb),
87+
(cb) => nodes[1].api.name.resolve(nodeAId.id, cb)
88+
], (err, res) => {
89+
expect(err).to.not.exist()
90+
expect(res).to.exist()
91+
expect(res[0].value).to.equal(ipfsRef)
92+
expect(res[0].name).to.equal(nodeAId.id)
93+
expect(res[1]).to.equal(ipfsRef)
94+
done()
95+
})
96+
})
97+
98+
it('should publish the record to a js node and resolve it using a go node', function (done) {
99+
this.timeout(50 * 1000)
100+
series([
101+
(cb) => nodes[1].api.name.publish(ipfsRef, { resolve: false }, cb),
102+
(cb) => nodes[0].api.name.resolve(nodeBId.id, cb)
103+
], (err, res) => {
104+
expect(err).to.not.exist()
105+
expect(res).to.exist()
106+
expect(res[0].value).to.equal(ipfsRef)
107+
expect(res[0].name).to.equal(nodeBId.id)
108+
expect(res[1]).to.equal(ipfsRef)
109+
done()
110+
})
111+
})
112+
})

0 commit comments

Comments
 (0)