What changed, and why it matters
This commit only adds and updates test code for the Lightning Network wire protocol's Init message. It does not change any production code, so it cannot introduce a security vulnerability or fix one directly.
No security action needed; this is a test-only change. Review the related production code changes that prompted these tests if assessing security relevance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit adds lnwire/init_message_test.go, which tests encoding/decoding of an Init message with GlobalFeatures, Features, unknown odd-type TLV records, and custom TLV records. It also updates lnwire/test_message.go’s RandTestMessage for Init to populate ExtraData with random opaque data. No production logic is modified.
Changed components
lnwire/init_message_test.golnwire/test_message.goInspect captured patch +65 / −0
diff --git a/lnwire/init_message_test.go b/lnwire/init_message_test.go
new file mode 100644
index 0000000..d0a3aca
--- /dev/null
+++ b/lnwire/init_message_test.go
@@ -0,0 +1,61 @@
+package lnwire
+
+import (
+ "bytes"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+// TestInitEncodeDecode checks that we can encode and decode an Init message
+// to and from a byte stream.
+func TestInitEncodeDecode(t *testing.T) {
+ t.Parallel()
+
+ // These are the raw bytes that we expect to be generated from the
+ // sample Init message.
+ rawBytes := []byte{
+ // GlobalFeatures
+ 0x00, 0x01, 0xc0,
+
+ // Features
+ 0x00, 0x01, 0xc0,
+
+ // ExtraData - unknown odd-type TLV record.
+ 0x6f, // type (111)
+ 0x02, // length
+ 0x79, 0x79, // value
+
+ // ExtraData - custom TLV record.
+ // TLV record for type 67676
+ 0xfe, 0x00, 0x01, 0x08, 0x6c, // type (67676)
+ 0x05, // length
+ 0x01, 0x02, 0x03, 0x04, 0x05, // value
+
+ // ExtraData - custom TLV record.
+ // TLV record for type 67777
+ 0xfe, 0x00, 0x01, 0x08, 0xc1, // type (67777)
+ 0x03, // length
+ 0x01, 0x02, 0x03, // value
+ }
+
+ // Create a new empty message and decode the raw bytes into it.
+ msg := &Init{}
+ r := bytes.NewReader(rawBytes)
+ err := msg.Decode(r, 0)
+ require.NoError(t, err)
+
+ require.NotNil(t, msg.GlobalFeatures)
+ require.NotNil(t, msg.Features)
+ require.NotNil(t, msg.CustomRecords)
+ require.NotNil(t, msg.ExtraData)
+
+ // Next, encode the message back into a new byte buffer.
+ var b bytes.Buffer
+ err = msg.Encode(&b, 0)
+ require.NoError(t, err)
+
+ // The re-encoded bytes should be exactly the same as the original raw
+ // bytes.
+ require.Equal(t, rawBytes, b.Bytes())
+}
diff --git a/lnwire/test_message.go b/lnwire/test_message.go
index 8f946f1..0c2fe5e 100644
--- a/lnwire/test_message.go
+++ b/lnwire/test_message.go
@@ -1188,6 +1188,10 @@ func (msg *Init) RandTestMessage(t *rapid.T) Message {
local.Set(bit)
}
+ ignoreRecords := fn.NewSet[uint64]()
+
+ msg.ExtraData = RandExtraOpaqueData(t, ignoreRecords)
+
return NewInitMessage(global, local)
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.