diff options
Diffstat (limited to 'dht/krpc_test.go')
| -rw-r--r-- | dht/krpc_test.go | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/dht/krpc_test.go b/dht/krpc_test.go index d710678..5bc8373 100644 --- a/dht/krpc_test.go +++ b/dht/krpc_test.go @@ -1,25 +1,30 @@ package dht import ( + "encoding/hex" "testing" ) -func TestStringToCompactNodeInfo(t *testing.T) { +func TestCompactNodeAddr(t *testing.T) { tests := []struct { in string - out []byte + out string }{ - {in: "192.168.1.1:6881", out: []byte("asdfasdf")}, + {in: "192.168.1.1:6881", out: "c0a801011ae1"}, + {in: "[2001:9372:434a:800::2]:6881", out: "20019372434a080000000000000000021ae1"}, } for _, tt := range tests { - r, err := stringToCompactNodeInfo(tt.in) - if err != nil { - t.Errorf("stringToCompactNodeInfo failed with %s", err) + r := encodeCompactNodeAddr(tt.in) + out, _ := hex.DecodeString(tt.out) + if r != string(out) { + t.Errorf("encodeCompactNodeAddr(%s) => %x, expected %s", tt.in, r, tt.out) } - if r != tt.out { - t.Errorf("stringToCompactNodeInfo(%s) => %s, expected %s", tt.in, r, tt.out) + + s := decodeCompactNodeAddr(r) + if s != tt.in { + t.Errorf("decodeCompactNodeAddr(%x) => %s, expected %s", r, s, tt.in) } } } |
