forked from lightningnetwork/lnd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
netaddress_test.go
40 lines (32 loc) · 867 Bytes
/
netaddress_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package lnwire
import (
"encoding/hex"
"net"
"testing"
"github.com/btcsuite/btcd/btcec"
)
func TestNetAddressDisplay(t *testing.T) {
t.Parallel()
pubKeyStr := "036a0c5ea35df8a528b98edf6f290b28676d51d0fe202b073fe677612a39c0aa09"
pubHex, err := hex.DecodeString(pubKeyStr)
if err != nil {
t.Fatalf("unable to decode str: %v", err)
}
pubKey, err := btcec.ParsePubKey(pubHex, btcec.S256())
if err != nil {
t.Fatalf("unable to parse pubkey: %v", err)
}
addr, _ := net.ResolveTCPAddr("tcp", "10.0.0.2:9000")
netAddr := NetAddress{
IdentityKey: pubKey,
Address: addr,
}
if addr.Network() != netAddr.Network() {
t.Fatalf("network addr mismatch: %v", err)
}
expectedAddr := pubKeyStr + "@" + addr.String()
addrString := netAddr.String()
if expectedAddr != addrString {
t.Fatalf("expected %v, got %v", expectedAddr, addrString)
}
}