chore: update aegir and fix lint

This commit is contained in:
David Dias 2017-03-16 17:06:13 +00:00
parent 0642070fdd
commit 961b218a53
2 changed files with 36 additions and 44 deletions

View File

@ -34,14 +34,15 @@
}, },
"homepage": "https://github.com/libp2p/js-peer-id", "homepage": "https://github.com/libp2p/js-peer-id",
"devDependencies": { "devDependencies": {
"aegir": "^10.0.0", "aegir": "^11.0.0",
"chai": "^3.5.0", "chai": "^3.5.0",
"dirty-chai": "^1.2.2",
"pre-commit": "^1.2.2" "pre-commit": "^1.2.2"
}, },
"dependencies": { "dependencies": {
"libp2p-crypto": "~0.8.0", "libp2p-crypto": "~0.8.6",
"multihashes": "~0.3.3", "multihashes": "~0.4.4",
"async": "^2.1.4" "async": "^2.1.5"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -2,7 +2,10 @@
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'
const expect = require('chai').expect const chai = require('chai')
const dirtyChai = require('dirty-chai')
chai.use(dirtyChai)
const expect = chai.expect
const crypto = require('libp2p-crypto') const crypto = require('libp2p-crypto')
const mh = require('multihashes') const mh = require('multihashes')
const parallel = require('async/parallel') const parallel = require('async/parallel')
@ -23,7 +26,7 @@ describe('PeerId', () => {
it('create a new id', (done) => { it('create a new id', (done) => {
PeerId.create((err, id) => { PeerId.create((err, id) => {
expect(err).to.not.exist expect(err).to.not.exist()
expect(id.toB58String().length).to.equal(46) expect(id.toB58String().length).to.equal(46)
done() done()
}) })
@ -31,7 +34,7 @@ describe('PeerId', () => {
it('throws on changing the id', (done) => { it('throws on changing the id', (done) => {
PeerId.create((err, id) => { PeerId.create((err, id) => {
expect(err).to.not.exist expect(err).to.not.exist()
expect(id.toB58String().length).to.equal(46) expect(id.toB58String().length).to.equal(46)
expect(() => { expect(() => {
id.id = new Buffer('hello') id.id = new Buffer('hello')
@ -57,7 +60,7 @@ describe('PeerId', () => {
it('Recreate from a Public Key', (done) => { it('Recreate from a Public Key', (done) => {
PeerId.createFromPubKey(testId.pubKey, (err, id) => { PeerId.createFromPubKey(testId.pubKey, (err, id) => {
expect(err).to.not.exist expect(err).to.not.exist()
expect(testIdB58String).to.equal(id.toB58String()) expect(testIdB58String).to.equal(id.toB58String())
done() done()
}) })
@ -65,12 +68,12 @@ describe('PeerId', () => {
it('Recreate from a Private Key', (done) => { it('Recreate from a Private Key', (done) => {
PeerId.createFromPrivKey(testId.privKey, (err, id) => { PeerId.createFromPrivKey(testId.privKey, (err, id) => {
expect(err).to.not.exist expect(err).to.not.exist()
expect(testIdB58String).to.equal(id.toB58String()) expect(testIdB58String).to.equal(id.toB58String())
const encoded = new Buffer(testId.privKey, 'base64') const encoded = new Buffer(testId.privKey, 'base64')
PeerId.createFromPrivKey(encoded, (err, id2) => { PeerId.createFromPrivKey(encoded, (err, id2) => {
expect(err).to.not.exist expect(err).to.not.exist()
expect(testIdB58String).to.equal(id2.toB58String()) expect(testIdB58String).to.equal(id2.toB58String())
done() done()
}) })
@ -79,10 +82,10 @@ describe('PeerId', () => {
it('Compare generated ID with one created from PubKey', (done) => { it('Compare generated ID with one created from PubKey', (done) => {
PeerId.create((err, id1) => { PeerId.create((err, id1) => {
expect(err).to.not.exist expect(err).to.not.exist()
PeerId.createFromPubKey(id1.marshalPubKey(), (err, id2) => { PeerId.createFromPubKey(id1.marshalPubKey(), (err, id2) => {
expect(err).to.not.exist expect(err).to.not.exist()
expect(id1.id).to.be.eql(id2.id) expect(id1.id).to.be.eql(id2.id)
done() done()
}) })
@ -91,9 +94,9 @@ describe('PeerId', () => {
it('Non-default # of bits', (done) => { it('Non-default # of bits', (done) => {
PeerId.create({ bits: 1024 }, (err, shortId) => { PeerId.create({ bits: 1024 }, (err, shortId) => {
expect(err).to.not.exist expect(err).to.not.exist()
PeerId.create({ bits: 4096 }, (err, longId) => { PeerId.create({ bits: 4096 }, (err, longId) => {
expect(err).to.not.exist expect(err).to.not.exist()
expect(shortId.privKey.bytes.length).is.below(longId.privKey.bytes.length) expect(shortId.privKey.bytes.length).is.below(longId.privKey.bytes.length)
done() done()
}) })
@ -102,9 +105,9 @@ describe('PeerId', () => {
it('Pretty printing', (done) => { it('Pretty printing', (done) => {
PeerId.create((err, id1) => { PeerId.create((err, id1) => {
expect(err).to.not.exist expect(err).to.not.exist()
PeerId.createFromPrivKey(id1.toPrint().privKey, (err, id2) => { PeerId.createFromPrivKey(id1.toPrint().privKey, (err, id2) => {
expect(err).to.not.exist expect(err).to.not.exist()
expect(id1.toPrint()).to.be.eql(id2.toPrint()) expect(id1.toPrint()).to.be.eql(id2.toPrint())
done() done()
}) })
@ -118,26 +121,14 @@ describe('PeerId', () => {
describe('fromJSON', () => { describe('fromJSON', () => {
it('full node', (done) => { it('full node', (done) => {
PeerId.create({bits: 1024}, (err, id) => { PeerId.create({ bits: 1024 }, (err, id) => {
expect(err).to.not.exist expect(err).to.not.exist()
PeerId.createFromJSON(id.toJSON(), (err, other) => { PeerId.createFromJSON(id.toJSON(), (err, other) => {
expect(err).to.not.exist expect(err).to.not.exist()
expect( expect(id.toB58String()).to.equal(other.toB58String())
id.toB58String() expect(id.privKey.bytes).to.eql(other.privKey.bytes)
).to.equal( expect(id.pubKey.bytes).to.eql(other.pubKey.bytes)
other.toB58String()
)
expect(
id.privKey.bytes
).to.deep.equal(
other.privKey.bytes
)
expect(
id.pubKey.bytes
).to.deep.equal(
other.pubKey.bytes
)
done() done()
}) })
}) })
@ -145,16 +136,16 @@ describe('PeerId', () => {
it('only id', (done) => { it('only id', (done) => {
crypto.generateKeyPair('RSA', 1024, (err, key) => { crypto.generateKeyPair('RSA', 1024, (err, key) => {
expect(err).to.not.exist expect(err).to.not.exist()
key.public.hash((err, digest) => { key.public.hash((err, digest) => {
expect(err).to.not.exist expect(err).to.not.exist()
const id = PeerId.createFromBytes(digest) const id = PeerId.createFromBytes(digest)
expect(id.privKey).to.not.exist expect(id.privKey).to.not.exist()
expect(id.pubKey).to.not.exist expect(id.pubKey).to.not.exist()
PeerId.createFromJSON(id.toJSON(), (err, other) => { PeerId.createFromJSON(id.toJSON(), (err, other) => {
expect(err).to.not.exist expect(err).to.not.exist()
expect( expect(
id.toB58String() id.toB58String()
).to.equal( ).to.equal(
@ -168,9 +159,9 @@ describe('PeerId', () => {
it('go interop', (done) => { it('go interop', (done) => {
PeerId.createFromJSON(goId, (err, id) => { PeerId.createFromJSON(goId, (err, id) => {
expect(err).to.not.exist expect(err).to.not.exist()
id.privKey.public.hash((err, digest) => { id.privKey.public.hash((err, digest) => {
expect(err).to.not.exist expect(err).to.not.exist()
expect( expect(
mh.toB58String(digest) mh.toB58String(digest)
).to.be.eql( ).to.be.eql(
@ -203,7 +194,7 @@ describe('PeerId', () => {
it('missmatch private - public key', (done) => { it('missmatch private - public key', (done) => {
k1.public.hash((err, digest) => { k1.public.hash((err, digest) => {
expect(err).to.not.exist expect(err).to.not.exist()
expect( expect(
() => new PeerId(digest, k1, k2.public) () => new PeerId(digest, k1, k2.public)
).to.throw( ).to.throw(
@ -215,7 +206,7 @@ describe('PeerId', () => {
it('missmatch id - private - public key', (done) => { it('missmatch id - private - public key', (done) => {
k1.public.hash((err, digest) => { k1.public.hash((err, digest) => {
expect(err).to.not.exist expect(err).to.not.exist()
expect( expect(
() => new PeerId(digest, k1, k3.public) () => new PeerId(digest, k1, k3.public)
).to.throw( ).to.throw(