zpay32: test case for empty routing hints on r fields

This commit is contained in:
MPins
2025-06-24 17:53:11 -03:00
committed by MPins
parent 16187f047a
commit e61d971ce4

View File

@@ -697,18 +697,22 @@ func TestParseRouteHint(t *testing.T) {
testDoubleHopData, _ = bech32.ConvertBits(testDoubleHopData, 8, 5, true) testDoubleHopData, _ = bech32.ConvertBits(testDoubleHopData, 8, 5, true)
tests := []struct { tests := []struct {
data []byte data []byte
valid bool valid bool
result []HopHint result []HopHint
expectedErr error
}{ }{
{ {
data: []byte{0x0, 0x0, 0x0, 0x0}, data: []byte{0x0, 0x0, 0x0, 0x0},
valid: false, // data too short, not multiple of 51 bytes // data too short, not multiple of 51 bytes
valid: false,
expectedErr: ErrLengthNotMultipleOfHopHint,
}, },
{ {
data: []byte{}, data: []byte{},
valid: true, valid: false,
result: []HopHint{}, result: []HopHint{},
expectedErr: ErrEmptyRouteHint,
}, },
{ {
data: testSingleHopData, data: testSingleHopData,
@@ -716,8 +720,11 @@ func TestParseRouteHint(t *testing.T) {
result: testSingleHop, result: testSingleHop,
}, },
{ {
data: append(testSingleHopData, 0x0), data: append(testSingleHopData,
valid: false, // data too long, not multiple of 51 bytes []byte{0x0, 0x0}...),
// data too long, not multiple of 51 bytes
valid: false,
expectedErr: ErrLengthNotMultipleOfHopHint,
}, },
{ {
data: testDoubleHopData, data: testDoubleHopData,
@@ -732,6 +739,7 @@ func TestParseRouteHint(t *testing.T) {
t.Errorf("routing info decoding test %d failed: %v", i, err) t.Errorf("routing info decoding test %d failed: %v", i, err)
return return
} }
require.ErrorIs(t, err, test.expectedErr)
if test.valid { if test.valid {
if err := compareRouteHints(test.result, routeHint); err != nil { if err := compareRouteHints(test.result, routeHint); err != nil {
t.Fatalf("test %d failed decoding routing info: %v", i, err) t.Fatalf("test %d failed decoding routing info: %v", i, err)