lnwire_test: add onion message to makeAllMessages
What changed, and why it matters
This commit only adds a test helper that creates a random sample 'onion message' for benchmark testing of LND's wire protocol encoding/decoding. It does not change any production code, network handling, or security behavior.
No action required. This is a benign test-only change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies lnwire/message_test.go, appending a new newMsgOnionMessage helper to makeAllMessages. The helper builds a randomized lnwire.OnionMessage with a random public key and an onion blob of 1-1366 random bytes. It is purely test infrastructure for fuzzing/benchmark coverage of message serialization.
Changed components
lnwire/message_test.goInspect captured patch +14 / −0
diff --git a/lnwire/message_test.go b/lnwire/message_test.go
index f1232e8..7b03373 100644
--- a/lnwire/message_test.go
+++ b/lnwire/message_test.go
@@ -290,6 +290,7 @@ func makeAllMessages(t testing.TB, r *rand.Rand) []lnwire.Message {
msgAll = append(msgAll, newMsgGossipTimestampRange(t, r))
msgAll = append(msgAll, newMsgQueryShortChanIDsZlib(t, r))
msgAll = append(msgAll, newMsgReplyChannelRangeZlib(t, r))
+ msgAll = append(msgAll, newMsgOnionMessage(t, r))
return msgAll
}
@@ -883,6 +884,19 @@ func newMsgGossipTimestampRange(t testing.TB,
return msg
}
+// newMsgOnionMessage creates a testing OnionMessage message.
+func newMsgOnionMessage(t testing.TB, r *rand.Rand) *lnwire.OnionMessage {
+ t.Helper()
+
+ // Generate a random onion blob (typical size ~1366 bytes).
+ onionBlobSize := r.Intn(1366) + 1
+ onionBlob := make([]byte, onionBlobSize)
+ _, err := r.Read(onionBlob)
+ require.NoError(t, err, "unable to read onion blob")
+
+ return lnwire.NewOnionMessage(randPubKey(t), onionBlob)
+}
+
func randRawKey(t testing.TB) [33]byte {
t.Helper()
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.