3
3
4
4
const chai = require ( 'chai' )
5
5
chai . use ( require ( 'dirty-chai' ) )
6
- chai . use ( require ( 'chai-as-promised ' ) )
6
+ chai . use ( require ( 'chai-bytes ' ) )
7
7
const { expect } = chai
8
8
const sinon = require ( 'sinon' )
9
9
@@ -23,12 +23,29 @@ describe('libp2p.peerStore', () => {
23
23
} )
24
24
} )
25
25
26
- it ( 'adds peer address to AddressBook when establishing connection' , async ( ) => {
26
+ it ( 'adds peer address to AddressBook and keys to the keybook when establishing connection' , async ( ) => {
27
+ const idStr = libp2p . peerId . toB58String ( )
28
+ const remoteIdStr = remoteLibp2p . peerId . toB58String ( )
29
+
27
30
const spyAddressBook = sinon . spy ( libp2p . peerStore . addressBook , 'add' )
28
- const remoteMultiaddr = `${ remoteLibp2p . multiaddrs [ 0 ] } /p2p/${ remoteLibp2p . peerId . toB58String ( ) } `
31
+ const spyKeyBook = sinon . spy ( libp2p . peerStore . keyBook , 'set' )
32
+
33
+ const remoteMultiaddr = `${ remoteLibp2p . multiaddrs [ 0 ] } /p2p/${ remoteIdStr } `
29
34
const conn = await libp2p . dial ( remoteMultiaddr )
30
35
31
36
expect ( conn ) . to . exist ( )
32
- expect ( spyAddressBook ) . to . have . property ( 'callCount' , 1 )
37
+ expect ( spyAddressBook ) . to . have . property ( 'called' , true )
38
+ expect ( spyKeyBook ) . to . have . property ( 'called' , true )
39
+
40
+ const localPeers = libp2p . peerStore . peers
41
+ expect ( localPeers . size ) . to . equal ( 1 )
42
+ // const publicKeyInLocalPeer = localPeers.get(remoteIdStr).id.pubKey
43
+ // expect(publicKeyInLocalPeer.bytes).to.equalBytes(remoteLibp2p.peerId.pubKey.bytes)
44
+
45
+ const remotePeers = remoteLibp2p . peerStore . peers
46
+ expect ( remotePeers . size ) . to . equal ( 1 )
47
+ const publicKeyInRemotePeer = remotePeers . get ( idStr ) . id . pubKey
48
+ expect ( publicKeyInRemotePeer ) . to . exist ( )
49
+ expect ( publicKeyInRemotePeer . bytes ) . to . equalBytes ( libp2p . peerId . pubKey . bytes )
33
50
} )
34
51
} )
0 commit comments