This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 124
feat: ipns working locally #327
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 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
This file contains 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,9 @@ | ||
'use strict' | ||
const { createSuite } = require('../utils/suite') | ||
|
||
const tests = { | ||
publish: require('./publish'), | ||
resolve: require('./resolve') | ||
} | ||
|
||
module.exports = createSuite(tests) |
This file contains 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,103 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const hat = require('hat') | ||
|
||
const { fixture } = require('./utils') | ||
const { spawnNodeWithId } = require('../utils/spawn') | ||
const { getDescribe, getIt, expect } = require('../utils/mocha') | ||
|
||
module.exports = (createCommon, options) => { | ||
const describe = getDescribe(options) | ||
const it = getIt(options) | ||
const common = createCommon() | ||
|
||
describe('.name.publish', function () { | ||
const keyName = hat() | ||
let ipfs | ||
let nodeId | ||
|
||
before(function (done) { | ||
// CI takes longer to instantiate the daemon, so we need to increase the | ||
// timeout for the before step | ||
this.timeout(60 * 1000) | ||
|
||
common.setup((err, factory) => { | ||
expect(err).to.not.exist() | ||
|
||
spawnNodeWithId(factory, (err, node) => { | ||
expect(err).to.not.exist() | ||
|
||
ipfs = node | ||
nodeId = node.peerId.id | ||
|
||
ipfs.files.add(fixture.data, { pin: false }, done) | ||
}) | ||
}) | ||
}) | ||
|
||
after((done) => common.teardown(done)) | ||
|
||
it('should publish an IPNS record with the default params', function (done) { | ||
this.timeout(50 * 1000) | ||
|
||
const value = fixture.cid | ||
|
||
ipfs.name.publish(value, (err, res) => { | ||
expect(err).to.not.exist() | ||
expect(res).to.exist() | ||
expect(res.name).to.equal(nodeId) | ||
expect(res.value).to.equal(`/ipfs/${value}`) | ||
|
||
done() | ||
}) | ||
}) | ||
|
||
it('should publish correctly when the file was not added but resolve is disabled', function (done) { | ||
this.timeout(50 * 1000) | ||
|
||
const value = 'QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU' | ||
|
||
const options = { | ||
resolve: false, | ||
lifetime: '1m', | ||
ttl: '10s', | ||
key: 'self' | ||
} | ||
|
||
ipfs.name.publish(value, options, (err, res) => { | ||
expect(err).to.not.exist() | ||
expect(res).to.exist() | ||
expect(res.name).to.equal(nodeId) | ||
expect(res.value).to.equal(`/ipfs/${value}`) | ||
|
||
done() | ||
}) | ||
}) | ||
|
||
it('should publish with a key received as param, instead of using the key of the node', function (done) { | ||
this.timeout(90 * 1000) | ||
|
||
const value = fixture.cid | ||
const options = { | ||
resolve: false, | ||
lifetime: '24h', | ||
ttl: '10s', | ||
key: keyName | ||
} | ||
|
||
ipfs.key.gen(keyName, { type: 'rsa', size: 2048 }, function (err, key) { | ||
expect(err).to.not.exist() | ||
|
||
ipfs.name.publish(value, options, (err, res) => { | ||
expect(err).to.not.exist() | ||
expect(res).to.exist() | ||
expect(res.name).to.equal(key.id) | ||
expect(res.value).to.equal(`/ipfs/${value}`) | ||
|
||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |
This file contains 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,137 @@ | ||
/* eslint max-nested-callbacks: ["error", 6] */ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const hat = require('hat') | ||
|
||
const { fixture } = require('./utils') | ||
const { spawnNodeWithId } = require('../utils/spawn') | ||
const { getDescribe, getIt, expect } = require('../utils/mocha') | ||
|
||
module.exports = (createCommon, options) => { | ||
const describe = getDescribe(options) | ||
const it = getIt(options) | ||
const common = createCommon() | ||
|
||
describe('.name.resolve', function () { | ||
const keyName = hat() | ||
let ipfs | ||
let nodeId | ||
let keyId | ||
|
||
before(function (done) { | ||
// CI takes longer to instantiate the daemon, so we need to increase the | ||
// timeout for the before step | ||
this.timeout(60 * 1000) | ||
|
||
common.setup((err, factory) => { | ||
expect(err).to.not.exist() | ||
|
||
spawnNodeWithId(factory, (err, node) => { | ||
expect(err).to.not.exist() | ||
|
||
ipfs = node | ||
nodeId = node.peerId.id | ||
|
||
ipfs.files.add(fixture.data, { pin: false }, done) | ||
}) | ||
}) | ||
}) | ||
|
||
after((done) => common.teardown(done)) | ||
|
||
it('should resolve a record with the default params after a publish', function (done) { | ||
this.timeout(50 * 1000) | ||
|
||
const value = fixture.cid | ||
|
||
ipfs.name.publish(value, (err, res) => { | ||
expect(err).to.not.exist() | ||
expect(res).to.exist() | ||
|
||
ipfs.name.resolve(nodeId, (err, res) => { | ||
expect(err).to.not.exist() | ||
expect(res).to.exist() | ||
expect(res.path).to.equal(`/ipfs/${value}`) | ||
|
||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
it('should not get the entry if its validity time expired', function (done) { | ||
this.timeout(50 * 1000) | ||
|
||
const value = fixture.cid | ||
const publishOptions = { | ||
resolve: true, | ||
lifetime: '1ms', | ||
ttl: '10s', | ||
key: 'self' | ||
} | ||
|
||
ipfs.name.publish(value, publishOptions, (err, res) => { | ||
expect(err).to.not.exist() | ||
expect(res).to.exist() | ||
|
||
// guarantee that the record has an expired validity. | ||
setTimeout(function () { | ||
ipfs.name.resolve(nodeId, (err, res) => { | ||
expect(err).to.exist() | ||
expect(err.message).to.equal('record has expired') | ||
expect(res).to.not.exist() | ||
|
||
done() | ||
}) | ||
}, 1) | ||
}) | ||
}) | ||
|
||
it('should recursively resolve to an IPFS hash', function (done) { | ||
this.timeout(100 * 1000) | ||
|
||
const value = fixture.cid | ||
const publishOptions = { | ||
resolve: false, | ||
lifetime: '24h', | ||
ttl: '10s', | ||
key: 'self' | ||
} | ||
|
||
// Generate new key | ||
ipfs.key.gen(keyName, { type: 'rsa', size: 2048 }, (err, key) => { | ||
expect(err).to.not.exist() | ||
|
||
keyId = key.id | ||
|
||
// publish ipfs | ||
ipfs.name.publish(value, publishOptions, (err, res) => { | ||
expect(err).to.not.exist() | ||
expect(res).to.exist() | ||
|
||
publishOptions.key = keyName | ||
|
||
// publish ipns with the generated key | ||
ipfs.name.publish(`/ipns/${nodeId}`, publishOptions, (err, res) => { | ||
expect(err).to.not.exist() | ||
expect(res).to.exist() | ||
|
||
const resolveOptions = { | ||
nocache: false, | ||
recursive: true | ||
} | ||
|
||
// recursive resolve (will get ipns first, and will resolve again to find the ipfs) | ||
ipfs.name.resolve(keyId, resolveOptions, (err, res) => { | ||
expect(err).to.not.exist() | ||
expect(res).to.exist() | ||
expect(res.path).to.equal(`/ipfs/${value}`) | ||
|
||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |
This file contains 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,8 @@ | ||
'use strict' | ||
|
||
const loadFixture = require('aegir/fixtures') | ||
|
||
exports.fixture = Object.freeze({ | ||
data: loadFixture('js/test/fixtures/testfile.txt', 'interface-ipfs-core'), | ||
cid: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' | ||
}) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an error message we can assert on here (would have to be the same for go-ipfs and js-ipfs)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I am using the same message as
go-ipfs
and I will add an assertion for it.