@@ -82,6 +82,33 @@ describe('dial queue', () => {
82
82
await expect ( deferredConn . promise ) . to . eventually . be . undefined ( )
83
83
} )
84
84
85
+ it ( 'should load addresses from the peer store when dialing a multiaddr that only contains a peer id' , async ( ) => {
86
+ const peerId = peerIdFromPrivateKey ( await generateKeyPair ( 'Ed25519' ) )
87
+ const connection = stubInterface < Connection > ( )
88
+ const foundAddress = multiaddr ( '/ip4/127.0.0.1/tcp/4001' )
89
+ const ma = multiaddr ( `/p2p/${ peerId } ` )
90
+
91
+ components . peerStore . get . withArgs ( peerId ) . resolves ( {
92
+ id : peerId ,
93
+ addresses : [ {
94
+ multiaddr : foundAddress ,
95
+ isCertified : false
96
+ } ] ,
97
+ protocols : [ ] ,
98
+ metadata : new Map ( ) ,
99
+ tags : new Map ( )
100
+ } )
101
+
102
+ components . transportManager . dialTransportForMultiaddr . returns ( stubInterface < Transport > ( ) )
103
+ components . transportManager . dial . withArgs ( foundAddress . encapsulate ( `/p2p/${ peerId } ` ) ) . resolves ( connection )
104
+
105
+ dialer = new DialQueue ( components )
106
+
107
+ await expect ( dialer . dial ( ma ) ) . to . eventually . equal ( connection )
108
+
109
+ expect ( components . peerRouting . findPeer ) . to . have . property ( 'called' , false )
110
+ } )
111
+
85
112
it ( 'should load addresses from the peer routing when peer id is not in the peer store' , async ( ) => {
86
113
const peerId = peerIdFromPrivateKey ( await generateKeyPair ( 'Ed25519' ) )
87
114
const connection = stubInterface < Connection > ( )
@@ -103,6 +130,28 @@ describe('dial queue', () => {
103
130
await expect ( dialer . dial ( peerId ) ) . to . eventually . equal ( connection )
104
131
} )
105
132
133
+ it ( 'should load addresses from the peer routing when dialing a multiaddr that only contains a peer id' , async ( ) => {
134
+ const peerId = peerIdFromPrivateKey ( await generateKeyPair ( 'Ed25519' ) )
135
+ const connection = stubInterface < Connection > ( )
136
+ const foundAddress = multiaddr ( '/ip4/127.0.0.1/tcp/4001' )
137
+ const ma = multiaddr ( `/p2p/${ peerId } ` )
138
+
139
+ components . peerStore . get . withArgs ( peerId ) . rejects ( new NotFoundError ( 'Not found' ) )
140
+ components . peerRouting . findPeer . withArgs ( peerId ) . resolves ( {
141
+ id : peerId ,
142
+ multiaddrs : [
143
+ foundAddress
144
+ ]
145
+ } )
146
+
147
+ components . transportManager . dialTransportForMultiaddr . returns ( stubInterface < Transport > ( ) )
148
+ components . transportManager . dial . withArgs ( foundAddress . encapsulate ( `/p2p/${ peerId } ` ) ) . resolves ( connection )
149
+
150
+ dialer = new DialQueue ( components )
151
+
152
+ await expect ( dialer . dial ( ma ) ) . to . eventually . equal ( connection )
153
+ } )
154
+
106
155
it ( 'should load addresses from the peer routing when none are present in the peer store' , async ( ) => {
107
156
const peerId = peerIdFromPrivateKey ( await generateKeyPair ( 'Ed25519' ) )
108
157
const connection = stubInterface < Connection > ( )
0 commit comments