lnd/lnwire/netaddress_test.go
Oliver Gugger 7dfe4018ce
multi: use btcd's btcec/v2 and btcutil modules
This commit was previously split into the following parts to ease
review:
 - 2d746f68: replace imports
 - 4008f0fd: use ecdsa.Signature
 - 849e33d1: remove btcec.S256()
 - b8f6ebbd: use v2 library correctly
 - fa80bca9: bump go modules
2022-03-09 19:02:37 +01:00

41 lines
856 B
Go

package lnwire
import (
"encoding/hex"
"net"
"testing"
"github.com/btcsuite/btcd/btcec/v2"
)
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)
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)
}
}