mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-10 14:17:56 +01:00
zpay32: test case for parsing non UTF-8 description
This commit is contained in:
@@ -369,6 +369,10 @@ func TestParse32Bytes(t *testing.T) {
|
||||
func TestParseDescription(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testNonUTF8StrData, _ := bech32.ConvertBits(
|
||||
[]byte(testNonUTF8Str), 8, 5, true,
|
||||
)
|
||||
|
||||
testCupOfCoffeeData, _ := bech32.ConvertBits([]byte(testCupOfCoffee), 8, 5, true)
|
||||
testPleaseConsiderData, _ := bech32.ConvertBits([]byte(testPleaseConsider), 8, 5, true)
|
||||
|
||||
@@ -376,7 +380,14 @@ func TestParseDescription(t *testing.T) {
|
||||
data []byte
|
||||
valid bool
|
||||
result *string
|
||||
expectedErr error
|
||||
}{
|
||||
{
|
||||
data: testNonUTF8StrData,
|
||||
valid: false,
|
||||
expectedErr: ErrInvalidUTF8Description,
|
||||
result: nil,
|
||||
},
|
||||
{
|
||||
data: []byte{},
|
||||
valid: true,
|
||||
@@ -400,6 +411,7 @@ func TestParseDescription(t *testing.T) {
|
||||
t.Errorf("description decoding test %d failed: %v", i, err)
|
||||
return
|
||||
}
|
||||
require.ErrorIs(t, err, test.expectedErr)
|
||||
if test.valid && !reflect.DeepEqual(description, test.result) {
|
||||
t.Fatalf("test %d failed decoding description: "+
|
||||
"expected \"%s\", got \"%s\"",
|
||||
|
||||
@@ -50,6 +50,7 @@ var (
|
||||
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
|
||||
}
|
||||
|
||||
testNonUTF8Str = "1 cup coffee\xff\xfe\xfd"
|
||||
testEmptyString = ""
|
||||
testCupOfCoffee = "1 cup coffee"
|
||||
testCoffeeBeans = "coffee beans"
|
||||
|
||||
Reference in New Issue
Block a user