lnd.xprv/lnwire/node_announcement_test.go
Olaoluwa Osuntokun 78ce39692e
lnwire: remove channel graph announcement validation tests
This commit removes the previous test cases which excised the proper
validation of graph announcements on the network. As full generation of
the authenticated messages has not yet been implemented, these tests
aren’t currently applicable.

In a future commit, these tests will be replicated on the new discovery
package which will handle producing the channel proofs and also fully
validating them.
2016-12-27 16:43:48 -08:00

93 lines
2.1 KiB
Go

package lnwire
import (
"bytes"
"reflect"
"testing"
"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/wire"
)
func TestNodeAnnouncementEncodeDecode(t *testing.T) {
cua := &NodeAnnouncement{
Signature: someSig,
Timestamp: maxUint32,
Address: someAddress,
NodeID: pubKey,
RGBColor: someRGB,
pad: maxUint16,
Alias: someAlias,
}
// Next encode the NA message into an empty bytes buffer.
var b bytes.Buffer
if err := cua.Encode(&b, 0); err != nil {
t.Fatalf("unable to encode NodeAnnouncement: %v", err)
}
// Deserialize the encoded NA message into a new empty struct.
cua2 := &NodeAnnouncement{}
if err := cua2.Decode(&b, 0); err != nil {
t.Fatalf("unable to decode NodeAnnouncement: %v", err)
}
// Assert equality of the two instances.
if !reflect.DeepEqual(cua, cua2) {
t.Fatalf("encode/decode error messages don't match %#v vs %#v",
cua, cua2)
}
}
func TestNodeAnnoucementValidation(t *testing.T) {
getKeys := func(s string) (*btcec.PrivateKey, *btcec.PublicKey) {
return btcec.PrivKeyFromBytes(btcec.S256(), []byte(s))
}
nodePrivKey, nodePubKey := getKeys("node-id-1")
var hash []byte
na := &NodeAnnouncement{
Timestamp: maxUint32,
Address: someAddress,
NodeID: nodePubKey,
RGBColor: someRGB,
pad: maxUint16,
Alias: someAlias,
}
dataToSign, _ := na.DataToSign()
hash = wire.DoubleSha256(dataToSign)
signature, _ := nodePrivKey.Sign(hash)
na.Signature = signature
if err := na.Validate(); err != nil {
t.Fatal(err)
}
}
func TestNodeAnnoucementPayloadLength(t *testing.T) {
na := &NodeAnnouncement{
Signature: someSig,
Timestamp: maxUint32,
Address: someAddress,
NodeID: pubKey,
RGBColor: someRGB,
pad: maxUint16,
Alias: someAlias,
}
var b bytes.Buffer
if err := na.Encode(&b, 0); err != nil {
t.Fatalf("unable to encode node: %v", err)
}
serializedLength := uint32(b.Len())
if serializedLength != na.MaxPayloadLength(0) {
t.Fatalf("payload length estimate is incorrect: expected %v "+
"got %v", serializedLength, na.MaxPayloadLength(0))
}
}