From 9188ad4fc41b2668350011729ea590eca1bbcf08 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Sat, 7 Jul 2018 13:08:50 +0100 Subject: [PATCH 1/7] test: add ipns tests --- test/ipns.js | 328 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 328 insertions(+) create mode 100644 test/ipns.js diff --git a/test/ipns.js b/test/ipns.js new file mode 100644 index 00000000..c13d68cc --- /dev/null +++ b/test/ipns.js @@ -0,0 +1,328 @@ +/* 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 goDf = DaemonFactory.create() +const jsDf = DaemonFactory.create({ type: 'js' }) + +describe('ipns', () => { + it('should publish an ipns record to a js daemon and resolve it using the same js daemon', function (done) { + this.timeout(100 * 1000) + + const dir = path.join(os.tmpdir(), hat()) + const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU' + + let jsDaemon + let jsId + + console.log('ipfsRepo', dir) + + series([ + (cb) => jsDf.spawn({ + repoPath: dir, + disposable: false, + initOptions: { bits: 512 } + }, (err, node) => { + expect(err).to.not.exist() + jsDaemon = node + jsDaemon.init(cb) + }), + (cb) => jsDaemon.start(cb), + (cb) => jsDaemon.api.id((err, res) => { + expect(err).to.not.exist() + jsId = res.id + cb() + }), + (cb) => jsDaemon.api.name.publish(ipfsRef, { resolve: false }, cb), + (cb) => { + jsDaemon.api.name.resolve(jsId, (err, res) => { + expect(err).to.not.exist() + expect(res).to.equal(ipfsRef) + cb() + }) + }, + (cb) => jsDaemon.stop(cb) + // (cb) => setTimeout(cb, 10500) + ], done) + }) + + it('should publish an ipns record to a go daemon and resolve it using the same go daemon', function (done) { + this.timeout(100 * 1000) + + const dir = path.join(os.tmpdir(), hat()) + const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU' + + let goDaemon1 + let goDaemon2 + let goId1 + + parallel([ + (cb) => goDf.spawn({ + repoPath: dir, + initOptions: { bits: 1024 } + }, cb), + (cb) => goDf.spawn({ initOptions: { bits: 1024 } }, cb) + ], (err, nodes) => { + expect(err).to.not.exist() + + goDaemon1 = nodes[0] + goDaemon2 = nodes[1] + + parallel([ + (cb) => goDaemon1.start(cb), + (cb) => goDaemon2.start(cb) + ], (err, nodes) => { + expect(err).to.not.exist() + + series([ + (cb) => goDaemon1.api.id((err, res) => { + expect(err).to.not.exist() + goId1 = res + cb() + }), + (cb) => goDaemon1.api.name.publish(ipfsRef, { resolve: false }, cb), + (cb) => { + goDaemon1.api.name.resolve(goId1, { resolve: false }, (err, res) => { + expect(err).to.not.exist() + expect(res).to.equal(ipfsRef) + cb() + }) + }, + (cb) => goDaemon1.stop(cb), + (cb) => goDaemon2.stop(cb) + ], done) + }) + }) + + // Error: failed to find any peer in table + /* + series([ + (cb) => goDf.spawn({ + repoPath: dir, + initOptions: { bits: 1024 }, + }, (err, node) => { + expect(err).to.not.exist() + goDaemon1 = node + cb() + }), + (cb) => goDaemon1.start(cb), + (cb) => goDaemon1.api.id((err, res) => { + expect(err).to.not.exist() + goId1 = res + cb() + }), + (cb) => goDaemon1.api.name.publish(ipfsRef, { resolve: false }, cb), + (cb) => { + goDaemon1.api.name.resolve(jsId, (err, res) => { + expect(err).to.not.exist() + expect(res).to.equal(ipfsRef) + cb() + }) + }, + (cb) => goDaemon1.stop(cb), + ], done) */ + }) + + it('should publish an ipns record to a js daemon and resolve it using a go daemon through the reuse of the same repo', function (done) { + this.timeout(100 * 1000) + + const dir = path.join(os.tmpdir(), hat()) + const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU' + + let goDaemon1 + let goDaemon2 + let jsDaemon + let jsId + + series([ + (cb) => jsDf.spawn({ + repoPath: dir, + disposable: false, + initOptions: { bits: 512 } + }, (err, node) => { + expect(err).to.not.exist() + jsDaemon = node + jsDaemon.init(cb) + }), + (cb) => jsDaemon.start(cb), + (cb) => jsDaemon.api.id((err, res) => { + expect(err).to.not.exist() + jsId = res.id + cb() + }), + (cb) => jsDaemon.api.name.publish(ipfsRef, { resolve: false }, cb), + (cb) => jsDaemon.stop(cb), + (cb) => setTimeout(cb, 2000), + (cb) => goDf.spawn({ + repoPath: dir, + // disposable: false, // SHOULD BE NON DISPOSABLE BUT THE START FAILS (CHECK repo.js) + initOptions: { bits: 1024 } + }, (err, node) => { + expect(err).to.not.exist() + goDaemon1 = node + cb() + }), + (cb) => goDf.spawn({ initOptions: { bits: 1024 } }, (err, node) => { + expect(err).to.not.exist() + goDaemon2 = node + cb() + }), + (cb) => goDaemon1.start(cb), + (cb) => goDaemon2.start(cb), + (cb) => goDaemon1.api.id((err, res) => { + expect(err).to.not.exist() + console.log('diff id', res.id, res.id === jsId) // ID different because of non disposable + cb() + }), + (cb) => { + goDaemon1.api.name.resolve(jsId, (err, res) => { + console.log('err', err) // Different repo + console.log('res', res) + cb() + }) + }, + (cb) => goDaemon1.stop(cb), + (cb) => goDaemon2.stop(cb) + ], done) + }) + + it('should publish cenas', function (done) { + this.timeout(100 * 1000) + + const dir = path.join(os.tmpdir(), hat()) + const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU' + + console.log('dir', dir) + + let goDaemon1 + let goDaemon2 + let jsDaemon + let peerId + + parallel([ + (cb) => goDf.spawn({ + repoPath: dir, + disposable: false, + initOptions: { bits: 1024 } + }, cb), + (cb) => goDf.spawn({ initOptions: { bits: 1024 } }, cb) + ], (err, nodes) => { + expect(err).to.not.exist() + + goDaemon1 = nodes[0] + goDaemon2 = nodes[1] + + series([ + (cb) => goDaemon1.init(cb), + (cb) => goDaemon1.start(cb), + (cb) => goDaemon2.start(cb), + (cb) => goDaemon1.api.id((err, res) => { + expect(err).to.not.exist() + peerId = res.id + cb() + }), + // (cb) => goDaemon1.api.name.publish(ipfsRef, { resolve: false }, cb), + // (cb) => goDaemon1.api.name.publish(ipfsRef, { resolve: false }, cb), + (cb) => goDaemon1.stop(cb), + (cb) => goDaemon2.stop(cb), + (cb) => jsDf.spawn({ + repoPath: dir, + disposable: false, + initOptions: { bits: 512 } + }, (err, node) => { + expect(err).to.not.exist() + jsDaemon = node + cb() + }), + (cb) => jsDaemon.start(cb), + (cb) => jsDaemon.api.id((err, res) => { + expect(err).to.not.exist() + console.log('peer id js', res.id, peerId === res.id) + cb() + }), + (cb) => setTimeout(() => cb(), 2000), + (cb) => jsDaemon.api.name.publish(ipfsRef, { resolve: false }, cb), + (cb) => jsDaemon.stop(cb), + (cb) => setTimeout(cb, 2000), + (cb) => jsDaemon.cleanup(cb) + ], done) + }) + }) + + it('should publish an ipns record to a go daemon and resolve it using a js daemon through the reuse of the same repo', function (done) { + this.timeout(50 * 1000) + + const dir = path.join(os.tmpdir(), `test-ipfs-${hat()}`) + const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU' + + let goDaemon1 + let goDaemon2 + let jsDaemon + let peerId + + parallel([ + (cb) => goDf.spawn({ + repoPath: dir, + disposable: false, + initOptions: { bits: 1024 } + }, cb), + (cb) => goDf.spawn({ initOptions: { bits: 1024 } }, cb) + ], (err, nodes) => { + expect(err).to.not.exist() + + goDaemon1 = nodes[0] + goDaemon2 = nodes[1] + + series([ + (cb) => goDaemon1.init(cb), + (cb) => goDaemon1.start(cb), + (cb) => goDaemon2.start(cb), + (cb) => goDaemon1.api.id((err, res) => { + expect(err).to.not.exist() + peerId = res.id + cb() + }), + (cb) => goDaemon1.api.name.publish(ipfsRef, { resolve: false }, cb), + (cb) => goDaemon1.stop(cb), + (cb) => goDaemon2.stop(cb), + (cb) => jsDf.spawn({ + repoPath: dir, + disposable: false, + initOptions: { bits: 512 } + }, (err, node) => { + expect(err).to.not.exist() + jsDaemon = node + cb() + }), + (cb) => jsDaemon.start(cb), + (cb) => jsDaemon.api.id((err, res) => { + expect(err).to.not.exist() + console.log('peer id js', res.id, peerId === res.id) + cb() + }), + (cb) => { + jsDaemon.api.name.resolve(peerId, (err, res) => { + console.log('peerId', peerId) + console.log('res', res) + console.log('err', err) + cb() + }) + }, + (cb) => jsDaemon.stop(cb), + (cb) => setTimeout(cb, 2000), + (cb) => jsDaemon.cleanup(cb) + ], done) + }) + }) +}) From 2fc9bbcb530d4f80de81bf882cac7ce83c460793 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Tue, 17 Jul 2018 14:44:45 +0100 Subject: [PATCH 2/7] fix: removed test --- test/ipns.js | 63 ---------------------------------------------------- 1 file changed, 63 deletions(-) diff --git a/test/ipns.js b/test/ipns.js index c13d68cc..829bf729 100644 --- a/test/ipns.js +++ b/test/ipns.js @@ -197,69 +197,6 @@ describe('ipns', () => { ], done) }) - it('should publish cenas', function (done) { - this.timeout(100 * 1000) - - const dir = path.join(os.tmpdir(), hat()) - const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU' - - console.log('dir', dir) - - let goDaemon1 - let goDaemon2 - let jsDaemon - let peerId - - parallel([ - (cb) => goDf.spawn({ - repoPath: dir, - disposable: false, - initOptions: { bits: 1024 } - }, cb), - (cb) => goDf.spawn({ initOptions: { bits: 1024 } }, cb) - ], (err, nodes) => { - expect(err).to.not.exist() - - goDaemon1 = nodes[0] - goDaemon2 = nodes[1] - - series([ - (cb) => goDaemon1.init(cb), - (cb) => goDaemon1.start(cb), - (cb) => goDaemon2.start(cb), - (cb) => goDaemon1.api.id((err, res) => { - expect(err).to.not.exist() - peerId = res.id - cb() - }), - // (cb) => goDaemon1.api.name.publish(ipfsRef, { resolve: false }, cb), - // (cb) => goDaemon1.api.name.publish(ipfsRef, { resolve: false }, cb), - (cb) => goDaemon1.stop(cb), - (cb) => goDaemon2.stop(cb), - (cb) => jsDf.spawn({ - repoPath: dir, - disposable: false, - initOptions: { bits: 512 } - }, (err, node) => { - expect(err).to.not.exist() - jsDaemon = node - cb() - }), - (cb) => jsDaemon.start(cb), - (cb) => jsDaemon.api.id((err, res) => { - expect(err).to.not.exist() - console.log('peer id js', res.id, peerId === res.id) - cb() - }), - (cb) => setTimeout(() => cb(), 2000), - (cb) => jsDaemon.api.name.publish(ipfsRef, { resolve: false }, cb), - (cb) => jsDaemon.stop(cb), - (cb) => setTimeout(cb, 2000), - (cb) => jsDaemon.cleanup(cb) - ], done) - }) - }) - it('should publish an ipns record to a go daemon and resolve it using a js daemon through the reuse of the same repo', function (done) { this.timeout(50 * 1000) From ec32e72ba7477fa707dbf31729427671cb871298 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 23 Jul 2018 15:44:45 +0100 Subject: [PATCH 3/7] fix: ipns go -> js interoperable --- test/ipns.js | 76 +++++++++++++++------------------------------------- test/node.js | 1 + test/repo.js | 3 ++- 3 files changed, 24 insertions(+), 56 deletions(-) diff --git a/test/ipns.js b/test/ipns.js index 829bf729..9f1dcc79 100644 --- a/test/ipns.js +++ b/test/ipns.js @@ -26,8 +26,6 @@ describe('ipns', () => { let jsDaemon let jsId - console.log('ipfsRepo', dir) - series([ (cb) => jsDf.spawn({ repoPath: dir, @@ -53,7 +51,7 @@ describe('ipns', () => { }) }, (cb) => jsDaemon.stop(cb) - // (cb) => setTimeout(cb, 10500) + // TODO cleanup repo ], done) }) @@ -101,41 +99,15 @@ describe('ipns', () => { }, (cb) => goDaemon1.stop(cb), (cb) => goDaemon2.stop(cb) + // TODO cleanup repo + // TODO check need for 2 daemons ], done) }) }) - - // Error: failed to find any peer in table - /* - series([ - (cb) => goDf.spawn({ - repoPath: dir, - initOptions: { bits: 1024 }, - }, (err, node) => { - expect(err).to.not.exist() - goDaemon1 = node - cb() - }), - (cb) => goDaemon1.start(cb), - (cb) => goDaemon1.api.id((err, res) => { - expect(err).to.not.exist() - goId1 = res - cb() - }), - (cb) => goDaemon1.api.name.publish(ipfsRef, { resolve: false }, cb), - (cb) => { - goDaemon1.api.name.resolve(jsId, (err, res) => { - expect(err).to.not.exist() - expect(res).to.equal(ipfsRef) - cb() - }) - }, - (cb) => goDaemon1.stop(cb), - ], done) */ }) it('should publish an ipns record to a js daemon and resolve it using a go daemon through the reuse of the same repo', function (done) { - this.timeout(100 * 1000) + this.timeout(1000 * 1000) const dir = path.join(os.tmpdir(), hat()) const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU' @@ -143,7 +115,7 @@ describe('ipns', () => { let goDaemon1 let goDaemon2 let jsDaemon - let jsId + let peerId series([ (cb) => jsDf.spawn({ @@ -152,13 +124,15 @@ describe('ipns', () => { initOptions: { bits: 512 } }, (err, node) => { expect(err).to.not.exist() + jsDaemon = node jsDaemon.init(cb) }), (cb) => jsDaemon.start(cb), (cb) => jsDaemon.api.id((err, res) => { expect(err).to.not.exist() - jsId = res.id + peerId = res.id + cb() }), (cb) => jsDaemon.api.name.publish(ipfsRef, { resolve: false }, cb), @@ -166,7 +140,7 @@ describe('ipns', () => { (cb) => setTimeout(cb, 2000), (cb) => goDf.spawn({ repoPath: dir, - // disposable: false, // SHOULD BE NON DISPOSABLE BUT THE START FAILS (CHECK repo.js) + disposable: false, initOptions: { bits: 1024 } }, (err, node) => { expect(err).to.not.exist() @@ -180,27 +154,23 @@ describe('ipns', () => { }), (cb) => goDaemon1.start(cb), (cb) => goDaemon2.start(cb), - (cb) => goDaemon1.api.id((err, res) => { - expect(err).to.not.exist() - console.log('diff id', res.id, res.id === jsId) // ID different because of non disposable - cb() - }), (cb) => { - goDaemon1.api.name.resolve(jsId, (err, res) => { - console.log('err', err) // Different repo - console.log('res', res) + goDaemon1.api.name.resolve(peerId, { resolve: false, local: true }, (err, res) => { + expect(err).to.not.exist() + expect(res).to.equal(ipfsRef) cb() }) }, (cb) => goDaemon1.stop(cb), (cb) => goDaemon2.stop(cb) + // TODO cleanup repo ], done) }) it('should publish an ipns record to a go daemon and resolve it using a js daemon through the reuse of the same repo', function (done) { - this.timeout(50 * 1000) + this.timeout(1000 * 1000) - const dir = path.join(os.tmpdir(), `test-ipfs-${hat()}`) + const dir = path.join(os.tmpdir(), hat()) const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU' let goDaemon1 @@ -227,6 +197,7 @@ describe('ipns', () => { (cb) => goDaemon2.start(cb), (cb) => goDaemon1.api.id((err, res) => { expect(err).to.not.exist() + peerId = res.id cb() }), @@ -239,26 +210,21 @@ describe('ipns', () => { initOptions: { bits: 512 } }, (err, node) => { expect(err).to.not.exist() + jsDaemon = node cb() }), (cb) => jsDaemon.start(cb), - (cb) => jsDaemon.api.id((err, res) => { - expect(err).to.not.exist() - console.log('peer id js', res.id, peerId === res.id) - cb() - }), (cb) => { jsDaemon.api.name.resolve(peerId, (err, res) => { - console.log('peerId', peerId) - console.log('res', res) - console.log('err', err) + expect(err).to.not.exist() + expect(res).to.equal(ipfsRef) cb() }) }, (cb) => jsDaemon.stop(cb), - (cb) => setTimeout(cb, 2000), - (cb) => jsDaemon.cleanup(cb) + (cb) => setTimeout(cb, 2000) + // TODO cleanup repo ], done) }) }) diff --git a/test/node.js b/test/node.js index a83c4c90..3c613449 100644 --- a/test/node.js +++ b/test/node.js @@ -8,3 +8,4 @@ require('./exchange-files') require('./kad-dht') require('./pin') require('./files') +require('./ipns') diff --git a/test/repo.js b/test/repo.js index 47123203..98b79964 100644 --- a/test/repo.js +++ b/test/repo.js @@ -76,6 +76,8 @@ describe('repo', () => { ], done) }) + // This was last due to an update on go-ipfs that changed how datastore is + // configured it('read repo: js -> go', function (done) { this.timeout(80 * 1000) const dir = path.join(os.tmpdir(), hat()) @@ -97,7 +99,6 @@ describe('repo', () => { jsDaemon.init(cb) }), (cb) => jsDaemon.start(cb), - (cb) => jsDaemon.api.add(data, (err, res) => { expect(err).to.not.exist() From 32f17146fc56701575f8de68690a02abe29a1b28 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 8 Aug 2018 11:56:11 +0100 Subject: [PATCH 4/7] chore: refactor --- test/ipns.js | 271 ++++++++++++++++----------------------------------- test/repo.js | 31 +++--- 2 files changed, 96 insertions(+), 206 deletions(-) diff --git a/test/ipns.js b/test/ipns.js index 9f1dcc79..31f820b7 100644 --- a/test/ipns.js +++ b/test/ipns.js @@ -13,219 +13,118 @@ const path = require('path') const hat = require('hat') const DaemonFactory = require('ipfsd-ctl') -const goDf = DaemonFactory.create() -const jsDf = DaemonFactory.create({ type: 'js' }) + +const spawnJsDaemon = (dir, callback) => { + DaemonFactory.create({ type: 'js' }) + .spawn({ + repoPath: dir, + disposable: false, + initOptions: { bits: 512 } + }, callback) +} + +const spawnGoDaemon = (dir, callback) => { + DaemonFactory.create() + .spawn({ + repoPath: dir, + disposable: false, + initOptions: { bits: 1024 }, + args: ['--offline'] + }, callback) +} + +const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU' + +const publishAndResolve = (publisherDaemon, resolverDaemon, callback) => { + let nodeId + let sameDaemon = false + + if (typeof resolverDaemon === 'function') { + callback = resolverDaemon + resolverDaemon = publisherDaemon + sameDaemon = true + } + + const stopAndStartSecondDaemon = (callback) => { + if (sameDaemon) { + return callback() + } + series([ + (cb) => publisherDaemon.stop(cb), + (cb) => setTimeout(cb, 2000), + (cb) => resolverDaemon.start(cb) + ], callback) + } + + series([ + (cb) => publisherDaemon.init(cb), + (cb) => publisherDaemon.start(cb), + (cb) => publisherDaemon.api.id((err, res) => { + expect(err).to.not.exist() + nodeId = res.id + cb() + }), + (cb) => publisherDaemon.api.name.publish(ipfsRef, { resolve: false }, cb), + (cb) => stopAndStartSecondDaemon(cb), + (cb) => { + resolverDaemon.api.name.resolve(nodeId, { local: true }, (err, res) => { + expect(err).to.not.exist() + expect(res).to.equal(ipfsRef) + cb() + }) + }, + (cb) => resolverDaemon.stop(cb), + (cb) => setTimeout(cb, 2000), + (cb) => resolverDaemon.cleanup(cb) + ], callback) +} describe('ipns', () => { it('should publish an ipns record to a js daemon and resolve it using the same js daemon', function (done) { this.timeout(100 * 1000) - const dir = path.join(os.tmpdir(), hat()) - const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU' - - let jsDaemon - let jsId - series([ - (cb) => jsDf.spawn({ - repoPath: dir, - disposable: false, - initOptions: { bits: 512 } - }, (err, node) => { - expect(err).to.not.exist() - jsDaemon = node - jsDaemon.init(cb) - }), - (cb) => jsDaemon.start(cb), - (cb) => jsDaemon.api.id((err, res) => { - expect(err).to.not.exist() - jsId = res.id - cb() - }), - (cb) => jsDaemon.api.name.publish(ipfsRef, { resolve: false }, cb), - (cb) => { - jsDaemon.api.name.resolve(jsId, (err, res) => { - expect(err).to.not.exist() - expect(res).to.equal(ipfsRef) - cb() - }) - }, - (cb) => jsDaemon.stop(cb) - // TODO cleanup repo - ], done) + spawnJsDaemon(dir, (err, jsDaemon) => { + expect(err).to.not.exist() + publishAndResolve(jsDaemon, done) + }) }) it('should publish an ipns record to a go daemon and resolve it using the same go daemon', function (done) { - this.timeout(100 * 1000) - + this.timeout(120 * 1000) const dir = path.join(os.tmpdir(), hat()) - const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU' - - let goDaemon1 - let goDaemon2 - let goId1 - parallel([ - (cb) => goDf.spawn({ - repoPath: dir, - initOptions: { bits: 1024 } - }, cb), - (cb) => goDf.spawn({ initOptions: { bits: 1024 } }, cb) - ], (err, nodes) => { + spawnGoDaemon(dir, (err, goDaemon) => { expect(err).to.not.exist() - - goDaemon1 = nodes[0] - goDaemon2 = nodes[1] - - parallel([ - (cb) => goDaemon1.start(cb), - (cb) => goDaemon2.start(cb) - ], (err, nodes) => { - expect(err).to.not.exist() - - series([ - (cb) => goDaemon1.api.id((err, res) => { - expect(err).to.not.exist() - goId1 = res - cb() - }), - (cb) => goDaemon1.api.name.publish(ipfsRef, { resolve: false }, cb), - (cb) => { - goDaemon1.api.name.resolve(goId1, { resolve: false }, (err, res) => { - expect(err).to.not.exist() - expect(res).to.equal(ipfsRef) - cb() - }) - }, - (cb) => goDaemon1.stop(cb), - (cb) => goDaemon2.stop(cb) - // TODO cleanup repo - // TODO check need for 2 daemons - ], done) - }) + publishAndResolve(goDaemon, done) }) }) it('should publish an ipns record to a js daemon and resolve it using a go daemon through the reuse of the same repo', function (done) { - this.timeout(1000 * 1000) - + this.timeout(100 * 1000) const dir = path.join(os.tmpdir(), hat()) - const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU' - - let goDaemon1 - let goDaemon2 - let jsDaemon - let peerId - series([ - (cb) => jsDf.spawn({ - repoPath: dir, - disposable: false, - initOptions: { bits: 512 } - }, (err, node) => { - expect(err).to.not.exist() - - jsDaemon = node - jsDaemon.init(cb) - }), - (cb) => jsDaemon.start(cb), - (cb) => jsDaemon.api.id((err, res) => { - expect(err).to.not.exist() - peerId = res.id + parallel([ + (cb) => spawnJsDaemon(dir, cb), + (cb) => spawnGoDaemon(dir, cb) + ], (err, daemons) => { + expect(err).to.not.exist() - cb() - }), - (cb) => jsDaemon.api.name.publish(ipfsRef, { resolve: false }, cb), - (cb) => jsDaemon.stop(cb), - (cb) => setTimeout(cb, 2000), - (cb) => goDf.spawn({ - repoPath: dir, - disposable: false, - initOptions: { bits: 1024 } - }, (err, node) => { - expect(err).to.not.exist() - goDaemon1 = node - cb() - }), - (cb) => goDf.spawn({ initOptions: { bits: 1024 } }, (err, node) => { - expect(err).to.not.exist() - goDaemon2 = node - cb() - }), - (cb) => goDaemon1.start(cb), - (cb) => goDaemon2.start(cb), - (cb) => { - goDaemon1.api.name.resolve(peerId, { resolve: false, local: true }, (err, res) => { - expect(err).to.not.exist() - expect(res).to.equal(ipfsRef) - cb() - }) - }, - (cb) => goDaemon1.stop(cb), - (cb) => goDaemon2.stop(cb) - // TODO cleanup repo - ], done) + publishAndResolve(daemons[0], daemons[1], done) + }) }) it('should publish an ipns record to a go daemon and resolve it using a js daemon through the reuse of the same repo', function (done) { - this.timeout(1000 * 1000) - + this.timeout(120 * 1000) const dir = path.join(os.tmpdir(), hat()) - const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU' - - let goDaemon1 - let goDaemon2 - let jsDaemon - let peerId parallel([ - (cb) => goDf.spawn({ - repoPath: dir, - disposable: false, - initOptions: { bits: 1024 } - }, cb), - (cb) => goDf.spawn({ initOptions: { bits: 1024 } }, cb) - ], (err, nodes) => { + (cb) => spawnGoDaemon(dir, cb), + (cb) => spawnJsDaemon(dir, cb) + ], (err, daemons) => { expect(err).to.not.exist() - goDaemon1 = nodes[0] - goDaemon2 = nodes[1] - - series([ - (cb) => goDaemon1.init(cb), - (cb) => goDaemon1.start(cb), - (cb) => goDaemon2.start(cb), - (cb) => goDaemon1.api.id((err, res) => { - expect(err).to.not.exist() - - peerId = res.id - cb() - }), - (cb) => goDaemon1.api.name.publish(ipfsRef, { resolve: false }, cb), - (cb) => goDaemon1.stop(cb), - (cb) => goDaemon2.stop(cb), - (cb) => jsDf.spawn({ - repoPath: dir, - disposable: false, - initOptions: { bits: 512 } - }, (err, node) => { - expect(err).to.not.exist() - - jsDaemon = node - cb() - }), - (cb) => jsDaemon.start(cb), - (cb) => { - jsDaemon.api.name.resolve(peerId, (err, res) => { - expect(err).to.not.exist() - expect(res).to.equal(ipfsRef) - cb() - }) - }, - (cb) => jsDaemon.stop(cb), - (cb) => setTimeout(cb, 2000) - // TODO cleanup repo - ], done) + publishAndResolve(daemons[0], daemons[1], done) }) }) }) diff --git a/test/repo.js b/test/repo.js index 98b79964..d267412e 100644 --- a/test/repo.js +++ b/test/repo.js @@ -76,10 +76,8 @@ describe('repo', () => { ], done) }) - // This was last due to an update on go-ipfs that changed how datastore is - // configured it('read repo: js -> go', function (done) { - this.timeout(80 * 1000) + this.timeout(50 * 1000) const dir = path.join(os.tmpdir(), hat()) const data = crypto.randomBytes(1024 * 5) @@ -90,33 +88,26 @@ describe('repo', () => { series([ (cb) => jsDf.spawn({ repoPath: dir, - disposable: false, initOptions: { bits: 512 } - }, (err, node) => { - expect(err).to.not.exist() - + }, cb), + (node, cb) => { jsDaemon = node - jsDaemon.init(cb) - }), - (cb) => jsDaemon.start(cb), - (cb) => jsDaemon.api.add(data, (err, res) => { - expect(err).to.not.exist() - + cb() + }, + (cb) => jsDaemon.api.add(data, cb), + (res, cb) => { hash = res[0].hash catAndCheck(jsDaemon.api, hash, data, cb) - }), + }, (cb) => jsDaemon.stop(cb), (cb) => goDf.spawn({ repoPath: dir, - disposable: false, initOptions: { bits: 1024 } - }, (err, node) => { - expect(err).to.not.exist() - + }, cb), + (node, cb) => { goDaemon = node cb() - }), - (cb) => goDaemon.start(cb), + }, (cb) => catAndCheck(goDaemon.api, hash, data, cb), (cb) => goDaemon.stop(cb) ], done) From cae16892dad245a27415a6c44a50e3b9fa307c9d Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 12 Sep 2018 21:39:12 +0100 Subject: [PATCH 5/7] fix: updated ipfs version --- test/ipns.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/ipns.js b/test/ipns.js index 31f820b7..e2d78b69 100644 --- a/test/ipns.js +++ b/test/ipns.js @@ -81,7 +81,7 @@ const publishAndResolve = (publisherDaemon, resolverDaemon, callback) => { describe('ipns', () => { it('should publish an ipns record to a js daemon and resolve it using the same js daemon', function (done) { - this.timeout(100 * 1000) + this.timeout(120 * 1000) const dir = path.join(os.tmpdir(), hat()) spawnJsDaemon(dir, (err, jsDaemon) => { @@ -91,7 +91,7 @@ describe('ipns', () => { }) it('should publish an ipns record to a go daemon and resolve it using the same go daemon', function (done) { - this.timeout(120 * 1000) + this.timeout(160 * 1000) const dir = path.join(os.tmpdir(), hat()) spawnGoDaemon(dir, (err, goDaemon) => { @@ -101,7 +101,7 @@ describe('ipns', () => { }) it('should publish an ipns record to a js daemon and resolve it using a go daemon through the reuse of the same repo', function (done) { - this.timeout(100 * 1000) + this.timeout(120 * 1000) const dir = path.join(os.tmpdir(), hat()) parallel([ @@ -115,7 +115,7 @@ describe('ipns', () => { }) it('should publish an ipns record to a go daemon and resolve it using a js daemon through the reuse of the same repo', function (done) { - this.timeout(120 * 1000) + this.timeout(160 * 1000) const dir = path.join(os.tmpdir(), hat()) parallel([ From 65ef477f0c14c21e909f9c03dbb6ab334cb64bd6 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Sat, 29 Sep 2018 22:21:13 +0100 Subject: [PATCH 6/7] chore: update js-ipfs version --- test/ipns.js | 4 ++-- test/node.js | 2 +- test/repo.js | 30 +++++++++++++++++++----------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/test/ipns.js b/test/ipns.js index e2d78b69..56bdf9d7 100644 --- a/test/ipns.js +++ b/test/ipns.js @@ -45,7 +45,7 @@ const publishAndResolve = (publisherDaemon, resolverDaemon, callback) => { sameDaemon = true } - const stopAndStartSecondDaemon = (callback) => { + const stopPublisherAndStartResolverDaemon = (callback) => { if (sameDaemon) { return callback() } @@ -65,7 +65,7 @@ const publishAndResolve = (publisherDaemon, resolverDaemon, callback) => { cb() }), (cb) => publisherDaemon.api.name.publish(ipfsRef, { resolve: false }, cb), - (cb) => stopAndStartSecondDaemon(cb), + (cb) => stopPublisherAndStartResolverDaemon(cb), (cb) => { resolverDaemon.api.name.resolve(nodeId, { local: true }, (err, res) => { expect(err).to.not.exist() diff --git a/test/node.js b/test/node.js index 3c613449..2d4fbbe0 100644 --- a/test/node.js +++ b/test/node.js @@ -5,7 +5,7 @@ require('./pubsub') require('./circuit') require('./repo') require('./exchange-files') +require('./ipns') require('./kad-dht') require('./pin') require('./files') -require('./ipns') diff --git a/test/repo.js b/test/repo.js index d267412e..47123203 100644 --- a/test/repo.js +++ b/test/repo.js @@ -77,7 +77,7 @@ describe('repo', () => { }) it('read repo: js -> go', function (done) { - this.timeout(50 * 1000) + this.timeout(80 * 1000) const dir = path.join(os.tmpdir(), hat()) const data = crypto.randomBytes(1024 * 5) @@ -88,26 +88,34 @@ describe('repo', () => { series([ (cb) => jsDf.spawn({ repoPath: dir, + disposable: false, initOptions: { bits: 512 } - }, cb), - (node, cb) => { + }, (err, node) => { + expect(err).to.not.exist() + jsDaemon = node - cb() - }, - (cb) => jsDaemon.api.add(data, cb), - (res, cb) => { + jsDaemon.init(cb) + }), + (cb) => jsDaemon.start(cb), + + (cb) => jsDaemon.api.add(data, (err, res) => { + expect(err).to.not.exist() + hash = res[0].hash catAndCheck(jsDaemon.api, hash, data, cb) - }, + }), (cb) => jsDaemon.stop(cb), (cb) => goDf.spawn({ repoPath: dir, + disposable: false, initOptions: { bits: 1024 } - }, cb), - (node, cb) => { + }, (err, node) => { + expect(err).to.not.exist() + goDaemon = node cb() - }, + }), + (cb) => goDaemon.start(cb), (cb) => catAndCheck(goDaemon.api, hash, data, cb), (cb) => goDaemon.stop(cb) ], done) From 634e937549b61c936ad79d90f4cd41340dbb1c07 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 17 Oct 2018 17:46:59 +0100 Subject: [PATCH 7/7] fix: code review --- test/ipns.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/test/ipns.js b/test/ipns.js index 56bdf9d7..6c549ddb 100644 --- a/test/ipns.js +++ b/test/ipns.js @@ -7,7 +7,6 @@ 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') @@ -19,7 +18,8 @@ const spawnJsDaemon = (dir, callback) => { .spawn({ repoPath: dir, disposable: false, - initOptions: { bits: 512 } + initOptions: { bits: 512 }, + args: ['--offline'] }, callback) } @@ -46,9 +46,6 @@ const publishAndResolve = (publisherDaemon, resolverDaemon, callback) => { } const stopPublisherAndStartResolverDaemon = (callback) => { - if (sameDaemon) { - return callback() - } series([ (cb) => publisherDaemon.stop(cb), (cb) => setTimeout(cb, 2000), @@ -65,7 +62,7 @@ const publishAndResolve = (publisherDaemon, resolverDaemon, callback) => { cb() }), (cb) => publisherDaemon.api.name.publish(ipfsRef, { resolve: false }, cb), - (cb) => stopPublisherAndStartResolverDaemon(cb), + (cb) => sameDaemon ? cb() : stopPublisherAndStartResolverDaemon(cb), (cb) => { resolverDaemon.api.name.resolve(nodeId, { local: true }, (err, res) => { expect(err).to.not.exist() @@ -79,7 +76,7 @@ const publishAndResolve = (publisherDaemon, resolverDaemon, callback) => { ], callback) } -describe('ipns', () => { +describe('ipns locally using the same repo across implementations', () => { it('should publish an ipns record to a js daemon and resolve it using the same js daemon', function (done) { this.timeout(120 * 1000) const dir = path.join(os.tmpdir(), hat()) @@ -104,7 +101,7 @@ describe('ipns', () => { this.timeout(120 * 1000) const dir = path.join(os.tmpdir(), hat()) - parallel([ + series([ (cb) => spawnJsDaemon(dir, cb), (cb) => spawnGoDaemon(dir, cb) ], (err, daemons) => { @@ -118,7 +115,7 @@ describe('ipns', () => { this.timeout(160 * 1000) const dir = path.join(os.tmpdir(), hat()) - parallel([ + series([ (cb) => spawnGoDaemon(dir, cb), (cb) => spawnJsDaemon(dir, cb) ], (err, daemons) => {