2017-04-20 02:17:26 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"net"
|
|
|
|
"testing"
|
|
|
|
|
2018-06-05 04:34:16 +03:00
|
|
|
"github.com/btcsuite/btcd/btcec"
|
2017-04-20 02:17:26 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNetAddressDisplay(t *testing.T) {
|
2017-06-17 01:59:20 +03:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-04-20 02:17:26 +03:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|