@@ -23,6 +23,7 @@ import (
23
23
24
24
"github.com/ChainSafe/gossamer/lib/common"
25
25
"github.com/ChainSafe/gossamer/lib/utils"
26
+ "github.com/libp2p/go-libp2p-core/protocol"
26
27
ma "github.com/multiformats/go-multiaddr"
27
28
28
29
"github.com/stretchr/testify/require"
@@ -366,3 +367,71 @@ func TestStreamCloseMetadataCleanup(t *testing.T) {
366
367
_ , ok = info .getHandshakeData (nodeB .host .id (), true )
367
368
require .False (t , ok )
368
369
}
370
+
371
+ func Test_PeerSupportsProtocol (t * testing.T ) {
372
+ basePathA := utils .NewTestBasePath (t , "nodeA" )
373
+ configA := & Config {
374
+ BasePath : basePathA ,
375
+ Port : 7001 ,
376
+ RandSeed : 1 ,
377
+ NoBootstrap : true ,
378
+ NoMDNS : true ,
379
+ }
380
+
381
+ nodeA := createTestService (t , configA )
382
+
383
+ basePathB := utils .NewTestBasePath (t , "nodeB" )
384
+ configB := & Config {
385
+ BasePath : basePathB ,
386
+ Port : 7002 ,
387
+ RandSeed : 2 ,
388
+ NoBootstrap : true ,
389
+ NoMDNS : true ,
390
+ }
391
+
392
+ nodeB := createTestService (t , configB )
393
+ nodeB .noGossip = true
394
+
395
+ addrInfosB , err := nodeB .host .addrInfos ()
396
+ require .NoError (t , err )
397
+
398
+ err = nodeA .host .connect (* addrInfosB [0 ])
399
+ // retry connect if "failed to dial" error
400
+ if failedToDial (err ) {
401
+ time .Sleep (TestBackoffTimeout )
402
+ err = nodeA .host .connect (* addrInfosB [0 ])
403
+ }
404
+ require .NoError (t , err )
405
+
406
+ tests := []struct {
407
+ protocol protocol.ID
408
+ expect bool
409
+ }{
410
+ {
411
+ protocol : protocol .ID ("/gossamer/test/0/sync/2" ),
412
+ expect : true ,
413
+ },
414
+ {
415
+ protocol : protocol .ID ("/gossamer/test/0/light/2" ),
416
+ expect : true ,
417
+ },
418
+ {
419
+ protocol : protocol .ID ("/gossamer/test/0/block-announces/1" ),
420
+ expect : true ,
421
+ },
422
+ {
423
+ protocol : protocol .ID ("/gossamer/test/0/transactions/1" ),
424
+ expect : true ,
425
+ },
426
+ {
427
+ protocol : protocol .ID ("/gossamer/not_supported/protocol" ),
428
+ expect : false ,
429
+ },
430
+ }
431
+
432
+ for _ , test := range tests {
433
+ output , err := nodeA .host .supportsProtocol (nodeB .host .id (), test .protocol )
434
+ require .NoError (t , err )
435
+ require .Equal (t , test .expect , output )
436
+ }
437
+ }
0 commit comments