lnwire: correct max payload estimate for NodeAnnouncement, add test

This commit is contained in:
Olaoluwa Osuntokun 2016-12-24 14:46:42 -06:00
parent 4790ce96a8
commit 3dc8cd5659
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
2 changed files with 31 additions and 6 deletions

@ -178,11 +178,11 @@ func (c *NodeAnnouncement) MaxPayloadLength(pver uint32) uint32 {
// Ipv6 - 16 bytes
length += 16
// Port - 2 bytes
length += 2
// Port - 4 bytes
length += 4
// NodeID - 32 bytes
length += 32
// NodeID - 33 bytes
length += 33
// RGBColor - 3 bytes
length += 3
@ -193,6 +193,7 @@ func (c *NodeAnnouncement) MaxPayloadLength(pver uint32) uint32 {
// Alias - 32 bytes
length += 32
// 158
return length
}

@ -2,10 +2,11 @@ package lnwire
import (
"bytes"
"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/wire"
"reflect"
"testing"
"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/wire"
)
func TestNodeAnnouncementEncodeDecode(t *testing.T) {
@ -92,3 +93,26 @@ func TestNodeAnnoucementBadValidation(t *testing.T) {
t.Fatal("error wasn't raised")
}
}
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))
}
}