2018-06-25 19:00:55 +02:00
|
|
|
package dht
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
2019-10-10 05:07:33 +02:00
|
|
|
"github.com/lbryio/lbry.go/v2/dht/bits"
|
2018-06-25 19:00:55 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|