@@ -430,6 +430,39 @@ describe('Identify', () => {
430
430
await connection . close ( )
431
431
} )
432
432
433
+ it ( 'should store remote agent and protocol versions in metadataBook after connecting' , async ( ) => {
434
+ libp2p = new Libp2p ( {
435
+ ...baseOptions ,
436
+ peerId
437
+ } )
438
+
439
+ await libp2p . start ( )
440
+
441
+ sinon . spy ( libp2p . identifyService , 'identify' )
442
+ const peerStoreSpyConsumeRecord = sinon . spy ( libp2p . peerStore . addressBook , 'consumePeerRecord' )
443
+ const peerStoreSpyAdd = sinon . spy ( libp2p . peerStore . addressBook , 'add' )
444
+
445
+ const connection = await libp2p . dialer . connectToPeer ( remoteAddr )
446
+ expect ( connection ) . to . exist ( )
447
+
448
+ // Wait for peer store to be updated
449
+ // Dialer._createDialTarget (add), Identify (consume)
450
+ await pWaitFor ( ( ) => peerStoreSpyConsumeRecord . callCount === 1 && peerStoreSpyAdd . callCount === 1 )
451
+ expect ( libp2p . identifyService . identify . callCount ) . to . equal ( 1 )
452
+
453
+ // The connection should have no open streams
454
+ await pWaitFor ( ( ) => connection . streams . length === 0 )
455
+ await connection . close ( )
456
+
457
+ const remotePeer = PeerId . createFromB58String ( remoteAddr . getPeerId ( ) )
458
+
459
+ const storedAgentVersion = libp2p . peerStore . metadataBook . getValue ( remotePeer , 'AgentVersion' )
460
+ const storedProtocolVersion = libp2p . peerStore . metadataBook . getValue ( remotePeer , 'ProtocolVersion' )
461
+
462
+ expect ( storedAgentVersion ) . to . exist ( )
463
+ expect ( storedProtocolVersion ) . to . exist ( )
464
+ } )
465
+
433
466
it ( 'should push protocol updates to an already connected peer' , async ( ) => {
434
467
libp2p = new Libp2p ( {
435
468
...baseOptions ,
0 commit comments