This repository has been archived by the owner on Feb 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
feat: support PeerInfo.create(IdJSON, cb) as well #61
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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
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 |
---|---|---|
|
@@ -5,28 +5,29 @@ const chai = require('chai') | |
const dirtyChai = require('dirty-chai') | ||
chai.use(dirtyChai) | ||
const expect = chai.expect | ||
const PeerId = require('peer-id') | ||
const Id = require('peer-id') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the renames from PeerId -> Id and PeerInfo -> Info? Previous names were more clearer (without context) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed there were multiple errors where |
||
const Multiaddr = require('multiaddr') | ||
const PeerInfo = require('../src') | ||
const Info = require('../src') | ||
const peerIdJSON = require('./peer-test.json') | ||
|
||
describe('peer-info', () => { | ||
let pi | ||
|
||
beforeEach((done) => { | ||
PeerId.create({bits: 512}, (err, id) => { | ||
Id.create({bits: 512}, (err, id) => { | ||
if (err) { | ||
return done(err) | ||
} | ||
pi = new PeerInfo(id) | ||
pi = new Info(id) | ||
done() | ||
}) | ||
}) | ||
|
||
it('create with Id', (done) => { | ||
PeerId.create({bits: 512}, (err, id) => { | ||
it('create with Id class', (done) => { | ||
Id.create({bits: 512}, (err, id) => { | ||
expect(err).to.not.exist() | ||
const pi = new PeerInfo(id) | ||
const pi2 = new PeerInfo(id) | ||
const pi = new Info(id) | ||
const pi2 = new Info(id) | ||
expect(pi.id).to.exist() | ||
expect(pi.id).to.eql(id) | ||
expect(pi2).to.exist() | ||
|
@@ -37,27 +38,37 @@ describe('peer-info', () => { | |
}) | ||
|
||
it('throws when not passing an Id', () => { | ||
expect(() => new PeerInfo()).to.throw() | ||
expect(() => new Info()).to.throw() | ||
}) | ||
|
||
it('isPeerInfo', () => { | ||
expect(PeerInfo.isPeerInfo(pi)).to.equal(true) | ||
expect(PeerInfo.isPeerInfo(pi.id)).to.equal(false) | ||
expect(PeerInfo.isPeerInfo('bananas')).to.equal(false) | ||
expect(Info.isPeerInfo(pi)).to.equal(true) | ||
expect(Info.isPeerInfo(pi.id)).to.equal(false) | ||
expect(Info.isPeerInfo('bananas')).to.equal(false) | ||
}) | ||
|
||
it('PeerInfo.create', (done) => { | ||
PeerInfo.create({bits: 512}, (err, pi) => { | ||
it('.create', function (done) { | ||
this.timeout(20 * 1000) | ||
Info.create((err, pi) => { | ||
expect(err).to.not.exist() | ||
expect(pi.id).to.exist() | ||
done() | ||
}) | ||
}) | ||
|
||
it('PeerInfo.create with existing id', (done) => { | ||
PeerId.create({bits: 512}, (err, id) => { | ||
it('create with Id as JSON', (done) => { | ||
Info.create(peerIdJSON, (err, pi) => { | ||
expect(err).to.not.exist() | ||
PeerInfo.create(id, (err, pi) => { | ||
expect(pi.id).to.exist() | ||
expect(pi.id.toJSON()).to.eql(peerIdJSON) | ||
done() | ||
}) | ||
}) | ||
|
||
it('.create with existing id', (done) => { | ||
Id.create({bits: 512}, (err, id) => { | ||
expect(err).to.not.exist() | ||
Info.create(id, (err, pi) => { | ||
expect(err).to.not.exist() | ||
expect(pi.id).to.exist() | ||
expect(pi.id.isEqual(id)).to.equal(true) | ||
|
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,5 @@ | ||
{ | ||
"id": "QmVmZNvjFdRoPqg27UqK56KVZabrN4VRinHF2Jp1FNmHMo", | ||
"privKey": "CAASpgkwggSiAgEAAoIBAQCNSaB/V5Q0FNJ0KrCJNeeZtn/dAua3dXtbDePYl4SA2nQkrn/TNxbkDzmo2CeKB0/40D1tiinv+0PWpln1F3fHAWJcGHhOdsEzueH0AhUhFzz8sInFNAa7kcRDCMmWeR6Sd17Gu0Soettd9U9ldEGcpG0ZrLRyUSjb9K+L/9JbRu157IJw0lVBDm42AtmLIGivbPMXGgYCcKly0ZsNuLEgOdlvN8FNU1NGcjifcbCv9IwcX2TnfbGsv0JGbR7wwvFy18TmVX0Woo2kbFPXa23W0o1anWhpkTaThp6f3rjqUgUXxkCj+3bYSknURfUq0IK//sC5Q7TSYz9PDHxPlro/AgMBAAECggEAL1lMU0C7ZxTPTqT70o/hFM9nXF7biQHzHBm0kOJ+QlxzbdOY/OTKZBWCIkaGQaifsWfAHlSeJ1GSc33+SbfaqTOajfiZYNpFdxtFUOvdvuA1zQ0wroj39KYuGrT4MdhXWYhtl7YslTXPDFboi7yBPIiSE3egZWszgTsoFYffLD1AtEe2jgFGNRQGxHtUxQLQoTmxJYQHC6djsGpM6Iz75VYiSZmngD69BbfO+RM9oqMqNDeqhyIEx+CTuhKfR+A8KKGxJfdanCBIhWuYRsvNnyaE/lMXVbw2NMjYziMAmkHpcgo/nGC+a80oKNRzq+4vUuKo/nICw9lWIBcUvqcCcQKBgQDfpOWV0Si24sQD10pjxCcx5QYSOx6L9cuUDonHwvi4DhRRDIxhzU8RZltBq4MsPZDwbqtf103F1WjwYYEr7a93MqFxexvAyrdiKEVdCLH0V6wv27Ona1sokxQ1UI1tRZhXCddzxKIf8jo4bMEQHTXAJzVa7AqJ85zePuc05cT/eQKBgQChun5CkQBZI7GDq0+NrfzpxH0RJcYz026rZQbT8ktEp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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.
Correction: Creates a new PeerInfo instance from an existing PeerId or creates a new
PeerId
for you.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.
new PeerId doesn't do that. Users have always to resort to PeerInfo.create because creating a PeerId requires async calls (WebCrypto)