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,14 +369,25 @@ func TestParse32Bytes(t *testing.T) {
|
|||||||
func TestParseDescription(t *testing.T) {
|
func TestParseDescription(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
testNonUTF8StrData, _ := bech32.ConvertBits(
|
||||||
|
[]byte(testNonUTF8Str), 8, 5, true,
|
||||||
|
)
|
||||||
|
|
||||||
testCupOfCoffeeData, _ := bech32.ConvertBits([]byte(testCupOfCoffee), 8, 5, true)
|
testCupOfCoffeeData, _ := bech32.ConvertBits([]byte(testCupOfCoffee), 8, 5, true)
|
||||||
testPleaseConsiderData, _ := bech32.ConvertBits([]byte(testPleaseConsider), 8, 5, true)
|
testPleaseConsiderData, _ := bech32.ConvertBits([]byte(testPleaseConsider), 8, 5, true)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
data []byte
|
data []byte
|
||||||
valid bool
|
valid bool
|
||||||
result *string
|
result *string
|
||||||
|
expectedErr error
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
data: testNonUTF8StrData,
|
||||||
|
valid: false,
|
||||||
|
expectedErr: ErrInvalidUTF8Description,
|
||||||
|
result: nil,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
data: []byte{},
|
data: []byte{},
|
||||||
valid: true,
|
valid: true,
|
||||||
@@ -400,6 +411,7 @@ func TestParseDescription(t *testing.T) {
|
|||||||
t.Errorf("description decoding test %d failed: %v", i, err)
|
t.Errorf("description decoding test %d failed: %v", i, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
require.ErrorIs(t, err, test.expectedErr)
|
||||||
if test.valid && !reflect.DeepEqual(description, test.result) {
|
if test.valid && !reflect.DeepEqual(description, test.result) {
|
||||||
t.Fatalf("test %d failed decoding description: "+
|
t.Fatalf("test %d failed decoding description: "+
|
||||||
"expected \"%s\", got \"%s\"",
|
"expected \"%s\", got \"%s\"",
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ var (
|
|||||||
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
|
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testNonUTF8Str = "1 cup coffee\xff\xfe\xfd"
|
||||||
testEmptyString = ""
|
testEmptyString = ""
|
||||||
testCupOfCoffee = "1 cup coffee"
|
testCupOfCoffee = "1 cup coffee"
|
||||||
testCoffeeBeans = "coffee beans"
|
testCoffeeBeans = "coffee beans"
|
||||||
|
|||||||
Reference in New Issue
Block a user