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.
This commit is contained in:
1 file changed
+8
-4
@@ -14,7 +14,11 @@ import (
|
|||||||
"pgregory.net/rapid"
|
"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.
|
// generators.
|
||||||
func RandPartialSig(t *rapid.T) *PartialSig {
|
func RandPartialSig(t *rapid.T) *PartialSig {
|
||||||
// Generate random private key bytes
|
// Generate random private key bytes
|
||||||
@@ -139,11 +143,11 @@ func RandNodeAlias(t *rapid.T) NodeAlias {
|
|||||||
var alias NodeAlias
|
var alias NodeAlias
|
||||||
aliasLength := rapid.IntRange(0, 32).Draw(t, "aliasLength")
|
aliasLength := rapid.IntRange(0, 32).Draw(t, "aliasLength")
|
||||||
|
|
||||||
aliasBytes := rapid.StringN(
|
aliasBytes := rapid.SliceOfN(
|
||||||
0, aliasLength, aliasLength,
|
rapid.SampledFrom([]rune(charset)), aliasLength, aliasLength,
|
||||||
).Draw(t, "alias")
|
).Draw(t, "alias")
|
||||||
|
|
||||||
copy(alias[:], aliasBytes)
|
copy(alias[:], string(aliasBytes))
|
||||||
|
|
||||||
return alias
|
return alias
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user