zpay32: test case for parsing non UTF-8 description

This commit is contained in:
MPins
2025-06-24 16:29:21 -03:00
committed by MPins
parent 2b1a89fbaf
commit b8acca2c89
2 changed files with 16 additions and 3 deletions

View File

@@ -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\"",

View File

@@ -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"