mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-23 14:01:35 +00:00
chore: apply suggestions from code review
Co-authored-by: Jacob Heun <jacobheun@gmail.com>
This commit is contained in:
@ -7,7 +7,6 @@ chai.use(require('chai-bytes'))
|
||||
const { expect } = chai
|
||||
const sinon = require('sinon')
|
||||
|
||||
const PeerId = require('peer-id')
|
||||
const PeerStore = require('../../src/peer-store')
|
||||
|
||||
const peerUtils = require('../utils/creators/peer')
|
||||
@ -24,7 +23,7 @@ describe('keyBook', () => {
|
||||
kb = peerStore.keyBook
|
||||
})
|
||||
|
||||
it('throwns invalid parameters error if invalid PeerId is provided', () => {
|
||||
it('throwns invalid parameters error if invalid PeerId is provided in set', () => {
|
||||
try {
|
||||
kb.set('invalid peerId')
|
||||
} catch (err) {
|
||||
@ -34,9 +33,19 @@ describe('keyBook', () => {
|
||||
throw new Error('invalid peerId should throw error')
|
||||
})
|
||||
|
||||
it('throwns invalid parameters error if invalid PeerId is provided in get', () => {
|
||||
try {
|
||||
kb.get('invalid peerId')
|
||||
} catch (err) {
|
||||
expect(err.code).to.equal(ERR_INVALID_PARAMETERS)
|
||||
return
|
||||
}
|
||||
throw new Error('invalid peerId should throw error')
|
||||
})
|
||||
|
||||
it('stores the peerId in the book and returns the public key', () => {
|
||||
// Set PeerId
|
||||
kb.set(peerId)
|
||||
kb.set(peerId, peerId.pubKey)
|
||||
|
||||
// Get public key
|
||||
const pubKey = kb.get(peerId)
|
||||
@ -47,22 +56,9 @@ describe('keyBook', () => {
|
||||
const spy = sinon.spy(kb, '_setData')
|
||||
|
||||
// Set PeerId
|
||||
kb.set(peerId)
|
||||
kb.set(peerId)
|
||||
kb.set(peerId, peerId.pubKey)
|
||||
kb.set(peerId, peerId.pubKey)
|
||||
|
||||
expect(spy).to.have.property('callCount', 1)
|
||||
})
|
||||
|
||||
it('stores if already stored but there was no public key stored', () => {
|
||||
const spy = sinon.spy(kb, '_setData')
|
||||
|
||||
// Set PeerId without public key
|
||||
const p = PeerId.createFromB58String(peerId.toB58String())
|
||||
kb.set(p)
|
||||
|
||||
// Set complete peerId
|
||||
kb.set(peerId)
|
||||
|
||||
expect(spy).to.have.property('callCount', 2)
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user