lnwire: correct max payload estimate for NodeAnnouncement, add test
This commit is contained in:
parent
4790ce96a8
commit
3dc8cd5659
@ -178,11 +178,11 @@ func (c *NodeAnnouncement) MaxPayloadLength(pver uint32) uint32 {
|
|||||||
// Ipv6 - 16 bytes
|
// Ipv6 - 16 bytes
|
||||||
length += 16
|
length += 16
|
||||||
|
|
||||||
// Port - 2 bytes
|
// Port - 4 bytes
|
||||||
length += 2
|
length += 4
|
||||||
|
|
||||||
// NodeID - 32 bytes
|
// NodeID - 33 bytes
|
||||||
length += 32
|
length += 33
|
||||||
|
|
||||||
// RGBColor - 3 bytes
|
// RGBColor - 3 bytes
|
||||||
length += 3
|
length += 3
|
||||||
@ -193,6 +193,7 @@ func (c *NodeAnnouncement) MaxPayloadLength(pver uint32) uint32 {
|
|||||||
// Alias - 32 bytes
|
// Alias - 32 bytes
|
||||||
length += 32
|
length += 32
|
||||||
|
|
||||||
|
// 158
|
||||||
return length
|
return length
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,10 +2,11 @@ package lnwire
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/roasbeef/btcd/btcec"
|
|
||||||
"github.com/roasbeef/btcd/wire"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/roasbeef/btcd/btcec"
|
||||||
|
"github.com/roasbeef/btcd/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNodeAnnouncementEncodeDecode(t *testing.T) {
|
func TestNodeAnnouncementEncodeDecode(t *testing.T) {
|
||||||
@ -92,3 +93,26 @@ func TestNodeAnnoucementBadValidation(t *testing.T) {
|
|||||||
t.Fatal("error wasn't raised")
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user