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

Commit

Permalink
fix: code review
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Jan 3, 2019
1 parent d73c6d2 commit 49e5528
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 191 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"form-data": "^2.3.3",
"go-ipfs-dep": "~0.4.18",
"hat": "0.0.3",
"ipfs": "ipfs/js-ipfs#feat/ipns-over-dht",
"ipfs": "0.34.0-rc.0",
"ipfs-api": "^26.1.2",
"ipfs-unixfs": "~0.1.16",
"ipfsd-ctl": "~0.40.0",
Expand Down
112 changes: 112 additions & 0 deletions test/ipns-dht.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)

const series = require('async/series')
const parallel = require('async/parallel')
const os = require('os')
const path = require('path')
const hat = require('hat')

const DaemonFactory = require('ipfsd-ctl')

const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU'

const spawnJsDaemon = (callback) => {
DaemonFactory.create({ type: 'js' })
.spawn({
disposable: true,
initOptions: { bits: 512 },
args: ['--enable-dht-experiment'], // enable dht
config: { Bootstrap: [] }
}, callback)
}

const spawnGoDaemon = (callback) => {
DaemonFactory.create()
.spawn({
disposable: true,
initOptions: { bits: 1024 },
config: { Bootstrap: [] }
}, callback)
}

describe.only('ipns over dht', () => {
let nodeAId
let nodeBId
let nodes = []

// Spawn daemons
before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the timeout
this.timeout(80 * 1000)
series([
(cb) => spawnGoDaemon(cb),
(cb) => spawnJsDaemon(cb),
(cb) => spawnGoDaemon(cb)
], (err, daemons) => {
expect(err).to.not.exist()
nodes = daemons
done()
})
})

// Get node ids
before(function (done) {
this.timeout(100 * 1000)
parallel([
(cb) => nodes[0].api.id(cb),
(cb) => nodes[1].api.id(cb)
], (err, ids) => {
expect(err).to.not.exist()
expect(ids).to.exist()
expect(ids[0].id).to.exist()
expect(ids[1].id).to.exist()
nodeAId = ids[0]
nodeBId = ids[1]
parallel([
(cb) => nodes[2].api.swarm.connect(ids[0].addresses[0], cb), // C => A
(cb) => nodes[2].api.swarm.connect(ids[1].addresses[0], cb) // C => B
], done)
})
})

after(function (done) {
this.timeout(60 * 1000)
parallel(nodes.map((node) => (cb) => node.stop(cb)), done)
})

it('should publish the record to a go node and resolve it using a js node', function (done) {
this.timeout(50 * 1000)
series([
(cb) => nodes[0].api.name.publish(ipfsRef, { resolve: false }, cb),
(cb) => nodes[1].api.name.resolve(nodeAId.id, cb)
], (err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
expect(res[0].value).to.equal(ipfsRef)
expect(res[0].name).to.equal(nodeAId.id)
expect(res[1]).to.equal(ipfsRef)
done()
})
})

it('should publish the record to a js node and resolve it using a go node', function (done) {
this.timeout(50 * 1000)
series([
(cb) => nodes[1].api.name.publish(ipfsRef, { resolve: false }, cb),
(cb) => nodes[0].api.name.resolve(nodeBId.id, cb)
], (err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
expect(res[0].value).to.equal(ipfsRef)
expect(res[0].name).to.equal(nodeBId.id)
expect(res[1]).to.equal(ipfsRef)
done()
})
})
})
Loading

0 comments on commit 49e5528

Please sign in to comment.