From ed17574196e01ba1d024d13efeb53591e6a12b71 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Mon, 14 Jul 2025 09:47:11 +0200 Subject: [PATCH] lnwire: fix RandNodeAlias to produce valid UTF-8 To ensure that the RandNodeAlias helper can be used elsewhere to generate random aliases, we adjust it in this test to only produce valid UTF-8 strings as required by the spec. --- lnwire/test_utils.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lnwire/test_utils.go b/lnwire/test_utils.go index 1065cbacf..07c9d795b 100644 --- a/lnwire/test_utils.go +++ b/lnwire/test_utils.go @@ -14,7 +14,11 @@ import ( "pgregory.net/rapid" ) -// RandChannelUpdate generates a random ChannelUpdate message using rapid's +// charset contains valid UTF-8 characters that can be used to generate random +// strings for testing purposes. +const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + +// RandPartialSig generates a random ParialSig message using rapid's // generators. func RandPartialSig(t *rapid.T) *PartialSig { // Generate random private key bytes @@ -139,11 +143,11 @@ func RandNodeAlias(t *rapid.T) NodeAlias { var alias NodeAlias aliasLength := rapid.IntRange(0, 32).Draw(t, "aliasLength") - aliasBytes := rapid.StringN( - 0, aliasLength, aliasLength, + aliasBytes := rapid.SliceOfN( + rapid.SampledFrom([]rune(charset)), aliasLength, aliasLength, ).Draw(t, "alias") - copy(alias[:], aliasBytes) + copy(alias[:], string(aliasBytes)) return alias }