Skip to content

Commit 4f7267e

Browse files
committed
lnwire: add fuzz target for Fee TLV
The new Fee TLV is not included in any other messages within the lnwire package, so it currently has no fuzzing coverage. This fuzz target directly tests the encoding/decoding of the TLV to get some coverage.
1 parent f1b7d52 commit 4f7267e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

lnwire/fuzz_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,3 +1053,30 @@ func FuzzClosingComplete(f *testing.F) {
10531053
harness(t, data)
10541054
})
10551055
}
1056+
1057+
// FuzzFee tests that decoding and re-encoding a Fee TLV does not mutate it.
1058+
func FuzzFee(f *testing.F) {
1059+
f.Fuzz(func(t *testing.T, data []byte) {
1060+
if len(data) > 8 {
1061+
return
1062+
}
1063+
1064+
var fee Fee
1065+
var buf [8]byte
1066+
r := bytes.NewReader(data)
1067+
1068+
if err := feeDecoder(r, &fee, &buf, 8); err != nil {
1069+
return
1070+
}
1071+
1072+
var b bytes.Buffer
1073+
require.NoError(t, feeEncoder(&b, &fee, &buf))
1074+
1075+
// Use bytes.Equal instead of require.Equal so that nil and
1076+
// empty slices are considered equal.
1077+
require.True(
1078+
t, bytes.Equal(data, b.Bytes()), "%v != %v", data,
1079+
b.Bytes(),
1080+
)
1081+
})
1082+
}

0 commit comments

Comments
 (0)