@@ -47,7 +47,7 @@ describe('Identify', () => {
47
47
protocols,
48
48
registrar : {
49
49
peerStore : {
50
- update : ( ) => { }
50
+ replace : ( ) => { }
51
51
}
52
52
}
53
53
} )
@@ -57,27 +57,27 @@ describe('Identify', () => {
57
57
} )
58
58
59
59
const observedAddr = multiaddr ( '/ip4/127.0.0.1/tcp/1234' )
60
- const localConnectionMock = { newStream : ( ) => { } }
60
+ const localConnectionMock = { newStream : ( ) => { } , remotePeer : remotePeer . id }
61
61
const remoteConnectionMock = { remoteAddr : observedAddr }
62
62
63
63
const [ local , remote ] = duplexPair ( )
64
64
sinon . stub ( localConnectionMock , 'newStream' ) . returns ( { stream : local , protocol : multicodecs . IDENTIFY } )
65
65
66
- sinon . spy ( localIdentify . registrar . peerStore , 'update ' )
66
+ sinon . spy ( localIdentify . registrar . peerStore , 'replace ' )
67
67
68
68
// Run identify
69
69
await Promise . all ( [
70
- localIdentify . identify ( localConnectionMock , remotePeer . id ) ,
70
+ localIdentify . identify ( localConnectionMock ) ,
71
71
remoteIdentify . handleMessage ( {
72
72
connection : remoteConnectionMock ,
73
73
stream : remote ,
74
74
protocol : multicodecs . IDENTIFY
75
75
} )
76
76
] )
77
77
78
- expect ( localIdentify . registrar . peerStore . update . callCount ) . to . equal ( 1 )
78
+ expect ( localIdentify . registrar . peerStore . replace . callCount ) . to . equal ( 1 )
79
79
// Validate the remote peer gets updated in the peer store
80
- const call = localIdentify . registrar . peerStore . update . firstCall
80
+ const call = localIdentify . registrar . peerStore . replace . firstCall
81
81
expect ( call . args [ 0 ] . id . bytes ) . to . equal ( remotePeer . id . bytes )
82
82
} )
83
83
@@ -92,7 +92,7 @@ describe('Identify', () => {
92
92
} )
93
93
94
94
const observedAddr = multiaddr ( '/ip4/127.0.0.1/tcp/1234' )
95
- const localConnectionMock = { newStream : ( ) => { } }
95
+ const localConnectionMock = { newStream : ( ) => { } , remotePeer }
96
96
const remoteConnectionMock = { remoteAddr : observedAddr }
97
97
98
98
const [ local , remote ] = duplexPair ( )
@@ -128,7 +128,7 @@ describe('Identify', () => {
128
128
peerInfo : remotePeer ,
129
129
registrar : {
130
130
peerStore : {
131
- update : ( ) => { }
131
+ replace : ( ) => { }
132
132
}
133
133
}
134
134
} )
@@ -148,7 +148,7 @@ describe('Identify', () => {
148
148
149
149
sinon . spy ( IdentifyService , 'updatePeerAddresses' )
150
150
sinon . spy ( IdentifyService , 'updatePeerProtocols' )
151
- sinon . spy ( remoteIdentify . registrar . peerStore , 'update ' )
151
+ sinon . spy ( remoteIdentify . registrar . peerStore , 'replace ' )
152
152
153
153
// Run identify
154
154
await Promise . all ( [
@@ -163,8 +163,8 @@ describe('Identify', () => {
163
163
expect ( IdentifyService . updatePeerAddresses . callCount ) . to . equal ( 1 )
164
164
expect ( IdentifyService . updatePeerProtocols . callCount ) . to . equal ( 1 )
165
165
166
- expect ( remoteIdentify . registrar . peerStore . update . callCount ) . to . equal ( 1 )
167
- const [ peerInfo ] = remoteIdentify . registrar . peerStore . update . firstCall . args
166
+ expect ( remoteIdentify . registrar . peerStore . replace . callCount ) . to . equal ( 1 )
167
+ const [ peerInfo ] = remoteIdentify . registrar . peerStore . replace . firstCall . args
168
168
expect ( peerInfo . id . bytes ) . to . eql ( localPeer . id . bytes )
169
169
expect ( peerInfo . multiaddrs . toArray ( ) ) . to . eql ( [ listeningAddr ] )
170
170
expect ( peerInfo . protocols ) . to . eql ( localProtocols )
@@ -198,7 +198,7 @@ describe('Identify', () => {
198
198
} )
199
199
200
200
sinon . spy ( libp2p . dialer . identifyService , 'identify' )
201
- sinon . spy ( libp2p . peerStore , 'update ' )
201
+ sinon . spy ( libp2p . peerStore , 'replace ' )
202
202
203
203
const connection = await libp2p . dialer . connectToMultiaddr ( remoteAddr )
204
204
expect ( connection ) . to . exist ( )
@@ -207,7 +207,7 @@ describe('Identify', () => {
207
207
expect ( libp2p . dialer . identifyService . identify . callCount ) . to . equal ( 1 )
208
208
await libp2p . dialer . identifyService . identify . firstCall . returnValue
209
209
210
- expect ( libp2p . peerStore . update . callCount ) . to . equal ( 1 )
210
+ expect ( libp2p . peerStore . replace . callCount ) . to . equal ( 1 )
211
211
await connection . close ( )
212
212
} )
213
213
0 commit comments