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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from diasdavid/features
new features: add and remove multiaddrs, avoid adding repeating, addSafe mode to avoid multiaddr explosion
- Loading branch information
Showing
4 changed files
with
130 additions
and
24 deletions.
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* eslint-env mocha */ | ||
|
||
const expect = require('chai').expect | ||
const Id = require('peer-id') | ||
const Multiaddr = require('multiaddr') | ||
const PeerInfo = require('../src') | ||
|
||
describe('peer-info', function (done) { | ||
this.timeout(10000) | ||
|
||
it('create with Id', (done) => { | ||
const id = Id.create() | ||
const pi = new PeerInfo(id) | ||
expect(pi).to.exist | ||
expect(pi.id).to.exist | ||
expect(pi.id).to.deep.equal(id) | ||
done() | ||
}) | ||
|
||
it('create without passing an Id', (done) => { | ||
const pi = new PeerInfo() | ||
expect(pi).to.exist | ||
expect(pi.id).to.exist | ||
done() | ||
}) | ||
|
||
it('add multiaddr', (done) => { | ||
const pi = new PeerInfo() | ||
expect(pi).to.exist | ||
const mh = Multiaddr('/ip4/127.0.0.1/tcp/5001') | ||
pi.multiaddr.add(mh) | ||
expect(pi.multiaddrs.length).to.equal(1) | ||
done() | ||
}) | ||
|
||
it('add repeated multiaddr', (done) => { | ||
const pi = new PeerInfo() | ||
expect(pi).to.exist | ||
const mh = Multiaddr('/ip4/127.0.0.1/tcp/5001') | ||
pi.multiaddr.add(mh) | ||
expect(pi.multiaddrs.length).to.equal(1) | ||
pi.multiaddr.add(mh) | ||
expect(pi.multiaddrs.length).to.equal(1) | ||
done() | ||
}) | ||
|
||
it('rm multiaddr', (done) => { | ||
const pi = new PeerInfo() | ||
expect(pi).to.exist | ||
const mh = Multiaddr('/ip4/127.0.0.1/tcp/5001') | ||
pi.multiaddr.add(mh) | ||
expect(pi.multiaddrs.length).to.equal(1) | ||
pi.multiaddr.rm(mh) | ||
expect(pi.multiaddrs.length).to.equal(0) | ||
done() | ||
}) | ||
|
||
it('addSafe - avoid multiaddr explosion', (done) => { | ||
const pi = new PeerInfo() | ||
expect(pi).to.exist | ||
const mh = Multiaddr('/ip4/127.0.0.1/tcp/5001') | ||
pi.multiaddr.addSafe(mh) | ||
expect(pi.multiaddrs.length).to.equal(0) | ||
pi.multiaddr.addSafe(mh) | ||
expect(pi.multiaddrs.length).to.equal(1) | ||
done() | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.