@@ -87,6 +87,7 @@ func TestConstructFails(t *testing.T) {
87
87
"/ip4/127.0.0.1/tcp/9090/http/p2p-webcrt-direct" ,
88
88
"/" ,
89
89
"" ,
90
+ "/p2p/QmxoHT6iViN5xAjoz1VZ553cL31U9F94ht3QvWR1FrEbZY" , // sha256 multihash with digest len > 32
90
91
}
91
92
92
93
for _ , a := range cases {
@@ -510,13 +511,14 @@ func FuzzNewMultiaddrBytes(f *testing.F) {
510
511
f .Add (ma .Bytes ())
511
512
}
512
513
513
- f .Fuzz (func (_ * testing.T , b []byte ) {
514
+ f .Fuzz (func (t * testing.T , b []byte ) {
514
515
// just checking that it doesn't panic
515
516
ma , err := NewMultiaddrBytes (b )
516
517
if err == nil {
517
518
// for any valid multiaddrs, make sure these calls don't panic
518
- _ = ma .String ()
519
519
ma .Protocols ()
520
+ roundTripBytes (t , ma )
521
+ roundTripString (t , ma )
520
522
}
521
523
})
522
524
}
@@ -529,18 +531,38 @@ func FuzzNewMultiaddrString(f *testing.F) {
529
531
}
530
532
f .Add (v )
531
533
}
532
-
533
- f .Fuzz (func (_ * testing.T , s string ) {
534
+ f .Fuzz (func (t * testing.T , s string ) {
534
535
// just checking that it doesn't panic
535
536
ma , err := NewMultiaddr (s )
536
537
if err == nil {
537
538
// for any valid multiaddrs, make sure these calls don't panic
538
- _ = ma .String ()
539
539
ma .Protocols ()
540
+ roundTripBytes (t , ma )
541
+ roundTripString (t , ma )
540
542
}
541
543
})
542
544
}
543
545
546
+ func roundTripBytes (t * testing.T , orig Multiaddr ) {
547
+ m2 , err := NewMultiaddrBytes (orig .Bytes ())
548
+ if err != nil {
549
+ t .Fatalf ("failed to parse maddr back from ma.Bytes, %v: %v" , orig , err )
550
+ }
551
+ if ! m2 .Equal (orig ) {
552
+ t .Fatalf ("unequal maddr after roundTripBytes %v %v" , orig , m2 )
553
+ }
554
+ }
555
+
556
+ func roundTripString (t * testing.T , orig Multiaddr ) {
557
+ m2 , err := NewMultiaddr (orig .String ())
558
+ if err != nil {
559
+ t .Fatalf ("failed to parse maddr back from ma.String, %v: %v" , orig , err )
560
+ }
561
+ if ! m2 .Equal (orig ) {
562
+ t .Fatalf ("unequal maddr after roundTripString %v %v\n % 02x\n % 02x\n " , orig , m2 , orig .Bytes (), m2 .Bytes ())
563
+ }
564
+ }
565
+
544
566
func TestBinaryRepresentation (t * testing.T ) {
545
567
expected := []byte {0x4 , 0x7f , 0x0 , 0x0 , 0x1 , 0x91 , 0x2 , 0x4 , 0xd2 }
546
568
ma , err := NewMultiaddr ("/ip4/127.0.0.1/udp/1234" )
@@ -848,3 +870,15 @@ func BenchmarkUniqueAddrs(b *testing.B) {
848
870
})
849
871
}
850
872
}
873
+
874
+ func TestDNS (t * testing.T ) {
875
+ b := []byte ("7*000000000000000000000000000000000000000000" )
876
+ a , err := NewMultiaddrBytes (b )
877
+ if err != nil {
878
+ t .Fatal (err )
879
+ }
880
+ aa := StringCast (a .String ())
881
+ if ! a .Equal (aa ) {
882
+ t .Fatal ("expected equality" )
883
+ }
884
+ }
0 commit comments