Skip to content

Commit e61d971

Browse files
committed
zpay32: test case for empty routing hints on r fields
1 parent 16187f0 commit e61d971

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

zpay32/invoice_internal_test.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -697,27 +697,34 @@ func TestParseRouteHint(t *testing.T) {
697697
testDoubleHopData, _ = bech32.ConvertBits(testDoubleHopData, 8, 5, true)
698698

699699
tests := []struct {
700-
data []byte
701-
valid bool
702-
result []HopHint
700+
data []byte
701+
valid bool
702+
result []HopHint
703+
expectedErr error
703704
}{
704705
{
705-
data: []byte{0x0, 0x0, 0x0, 0x0},
706-
valid: false, // data too short, not multiple of 51 bytes
706+
data: []byte{0x0, 0x0, 0x0, 0x0},
707+
// data too short, not multiple of 51 bytes
708+
valid: false,
709+
expectedErr: ErrLengthNotMultipleOfHopHint,
707710
},
708711
{
709-
data: []byte{},
710-
valid: true,
711-
result: []HopHint{},
712+
data: []byte{},
713+
valid: false,
714+
result: []HopHint{},
715+
expectedErr: ErrEmptyRouteHint,
712716
},
713717
{
714718
data: testSingleHopData,
715719
valid: true,
716720
result: testSingleHop,
717721
},
718722
{
719-
data: append(testSingleHopData, 0x0),
720-
valid: false, // data too long, not multiple of 51 bytes
723+
data: append(testSingleHopData,
724+
[]byte{0x0, 0x0}...),
725+
// data too long, not multiple of 51 bytes
726+
valid: false,
727+
expectedErr: ErrLengthNotMultipleOfHopHint,
721728
},
722729
{
723730
data: testDoubleHopData,
@@ -732,6 +739,7 @@ func TestParseRouteHint(t *testing.T) {
732739
t.Errorf("routing info decoding test %d failed: %v", i, err)
733740
return
734741
}
742+
require.ErrorIs(t, err, test.expectedErr)
735743
if test.valid {
736744
if err := compareRouteHints(test.result, routeHint); err != nil {
737745
t.Fatalf("test %d failed decoding routing info: %v", i, err)

0 commit comments

Comments
 (0)