This repository was archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
test: add ipns tests #26
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9188ad4
test: add ipns tests
vasco-santos 2fc9bbc
fix: removed test
vasco-santos ec32e72
fix: ipns go -> js interoperable
vasco-santos 32f1714
chore: refactor
vasco-santos cae1689
fix: updated ipfs version
vasco-santos 65ef477
chore: update js-ipfs version
vasco-santos 634e937
fix: code review
vasco-santos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| /* 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 os = require('os') | ||
| const path = require('path') | ||
| const hat = require('hat') | ||
|
|
||
| const DaemonFactory = require('ipfsd-ctl') | ||
|
|
||
| const spawnJsDaemon = (dir, callback) => { | ||
| DaemonFactory.create({ type: 'js' }) | ||
| .spawn({ | ||
| repoPath: dir, | ||
| disposable: false, | ||
| initOptions: { bits: 512 }, | ||
| args: ['--offline'] | ||
| }, 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 stopPublisherAndStartResolverDaemon = (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) => sameDaemon ? cb() : stopPublisherAndStartResolverDaemon(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) | ||
vasco-santos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ], callback) | ||
| } | ||
|
|
||
| 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) { | ||
vasco-santos marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.timeout(120 * 1000) | ||
| const dir = path.join(os.tmpdir(), hat()) | ||
|
|
||
| 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) { | ||
vasco-santos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| this.timeout(160 * 1000) | ||
| const dir = path.join(os.tmpdir(), hat()) | ||
|
|
||
| spawnGoDaemon(dir, (err, goDaemon) => { | ||
| expect(err).to.not.exist() | ||
| 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) { | ||
vasco-santos marked this conversation as resolved.
Show resolved
Hide resolved
vasco-santos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| this.timeout(120 * 1000) | ||
| const dir = path.join(os.tmpdir(), hat()) | ||
|
|
||
| series([ | ||
| (cb) => spawnJsDaemon(dir, cb), | ||
| (cb) => spawnGoDaemon(dir, cb) | ||
| ], (err, daemons) => { | ||
| expect(err).to.not.exist() | ||
|
|
||
| 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) { | ||
vasco-santos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| this.timeout(160 * 1000) | ||
| const dir = path.join(os.tmpdir(), hat()) | ||
|
|
||
| series([ | ||
| (cb) => spawnGoDaemon(dir, cb), | ||
| (cb) => spawnJsDaemon(dir, cb) | ||
| ], (err, daemons) => { | ||
| expect(err).to.not.exist() | ||
|
|
||
| publishAndResolve(daemons[0], daemons[1], done) | ||
| }) | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.