reflector.go/dht/contact_test.go

32 lines
708 B
Go
Raw Normal View History

2018-06-25 19:00:55 +02:00
package dht
import (
"net"
"reflect"
"testing"
"github.com/lbryio/reflector.go/dht/bits"
)
func TestCompactEncoding(t *testing.T) {
c := Contact{
2018-07-13 19:31:54 +02:00
ID: bits.FromHexP("1c8aff71b99462464d9eeac639595ab99664be3482cb91a29d87467515c7d9158fe72aa1f1582dab07d8f8b5db277f41"),
IP: net.ParseIP("1.2.3.4"),
PeerPort: int(55<<8 + 66),
2018-06-25 19:00:55 +02:00
}
var compact []byte
compact, err := c.MarshalCompact()
if err != nil {
t.Fatal(err)
}
if len(compact) != compactNodeInfoLength {
t.Fatalf("got length of %d; expected %d", len(compact), compactNodeInfoLength)
}
if !reflect.DeepEqual(compact, append([]byte{1, 2, 3, 4, 55, 66}, c.ID[:]...)) {
t.Errorf("compact bytes not encoded correctly")
}
}