From 1b0a0b65385445bd67ec50b4279b858d45dfeb0e Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 24 Dec 2016 14:49:52 -0600 Subject: [PATCH] lnwire: add tests to check payload estimates for channel announcements --- lnwire/channel_announcement_test.go | 7 +++++++ lnwire/channel_update_announcement_test.go | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lnwire/channel_announcement_test.go b/lnwire/channel_announcement_test.go index abcb22a7..48990436 100644 --- a/lnwire/channel_announcement_test.go +++ b/lnwire/channel_announcement_test.go @@ -28,6 +28,13 @@ func TestChannelAnnoucementEncodeDecode(t *testing.T) { t.Fatalf("unable to encode ChannelAnnouncement: %v", err) } + // Ensure the max payload estimate is correct. + serializedLength := uint32(b.Len()) + if serializedLength != ca.MaxPayloadLength(0) { + t.Fatalf("payload length estimate is incorrect: expected %v "+ + "got %v", serializedLength, ca.MaxPayloadLength(0)) + } + // Deserialize the encoded CA message into a new empty struct. ca2 := &ChannelAnnouncement{} if err := ca2.Decode(&b, 0); err != nil { diff --git a/lnwire/channel_update_announcement_test.go b/lnwire/channel_update_announcement_test.go index 4d578add..4d95b823 100644 --- a/lnwire/channel_update_announcement_test.go +++ b/lnwire/channel_update_announcement_test.go @@ -24,6 +24,13 @@ func TestChannelUpdateAnnouncementEncodeDecode(t *testing.T) { t.Fatalf("unable to encode ChannelUpdateAnnouncement: %v", err) } + // Ensure the max payload estimate is correct. + serializedLength := uint32(b.Len()) + if serializedLength != cua.MaxPayloadLength(0) { + t.Fatalf("payload length estimate is incorrect: expected %v "+ + "got %v", serializedLength, cua.MaxPayloadLength(0)) + } + // Deserialize the encoded CUA message into a new empty struct. cua2 := &ChannelUpdateAnnouncement{} if err := cua2.Decode(&b, 0); err != nil {