feat: keybook

This commit is contained in:
Vasco Santos
2020-04-28 15:03:16 +02:00
committed by Jacob Heun
parent 3f2b06dc26
commit ce38033c10
12 changed files with 364 additions and 73 deletions

View File

@ -4,6 +4,7 @@
const chai = require('chai')
chai.use(require('dirty-chai'))
const { expect } = chai
const sinon = require('sinon')
const PeerStore = require('../../src/peer-store')
const multiaddr = require('multiaddr')
@ -48,6 +49,27 @@ describe('peer-store', () => {
const peer = peerStore.get(peerIds[0])
expect(peer).to.not.exist()
})
it('sets the peer to the KeyBook when added to the AddressBook', () => {
const spyPeerStore = sinon.spy(peerStore.keyBook, 'set')
peerStore.addressBook.set(peerIds[0], [addr1, addr2])
expect(spyPeerStore).to.have.property('callCount', 1)
})
it('sets the peer to the KeyBook when added to the ProtoBook', () => {
const spyPeerStore = sinon.spy(peerStore.keyBook, 'set')
peerStore.protoBook.set(peerIds[0], [proto1])
expect(spyPeerStore).to.have.property('callCount', 1)
})
it('does not re-set the to the KeyBook when directly added to it', () => {
const spyPeerStore = sinon.spy(peerStore.keyBook, 'set')
peerStore.keyBook.set(peerIds[0])
expect(spyPeerStore).to.have.property('callCount', 1)
})
})
describe('previously populated books', () => {
@ -108,6 +130,8 @@ describe('peer-store', () => {
const peerMultiaddrs = peer.addresses.map((mi) => mi.multiaddr)
expect(peerMultiaddrs).to.have.members([addr1, addr2])
expect(peer.id).to.exist()
})
it('gets the stored information of a peer that is not present in all its books', () => {