lnwire: add a basic test for NetAddress
This commit is contained in:
parent
e3686cbc69
commit
89f4b1185e
@ -8,10 +8,6 @@ import (
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
)
|
||||
|
||||
// ServiceFlag identifies the services supported by a particular Lightning
|
||||
// Network peer.
|
||||
type ServiceFlag uint64
|
||||
|
||||
// NetAddress represents information pertaining to the identity and network
|
||||
// reachability of a peer. Information stored includes the node's identity
|
||||
// public key for establishing a confidential+authenticated connection, the
|
||||
@ -26,10 +22,6 @@ type NetAddress struct {
|
||||
// the node.
|
||||
IdentityKey *btcec.PublicKey
|
||||
|
||||
// Services defines the set of services supported by the node reachable at
|
||||
// the address and identity key defined in the struct.
|
||||
Services ServiceFlag
|
||||
|
||||
// Address is is the IP address and port of the node.
|
||||
Address *net.TCPAddr
|
||||
|
||||
|
38
lnwire/netaddress_test.go
Normal file
38
lnwire/netaddress_test.go
Normal file
@ -0,0 +1,38 @@
|
||||
package lnwire
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/roasbeef/btcd/btcec"
|
||||
)
|
||||
|
||||
func TestNetAddressDisplay(t *testing.T) {
|
||||
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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user