Skip to content

Commit 78cbed9

Browse files
committed
contractcourt: add rapid derived fuzz test for HtlcAuxBlob
In this commit, we add a rapid derived fuzz test for the HtlcAuxBlob test. This uses the rapid (randomized property testing) into Go's built in fuzzer. This wrapper will use the fuzz stream, and pass that into rapid where the stream is used to make structured test inputs which are tested against the existing properties. This can be done more widely in the codebase, we pick a simple example to port first before tackling others.
1 parent d6eeaec commit 78cbed9

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

contractcourt/taproot_briefcase_test.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,30 @@ func TestTaprootBriefcase(t *testing.T) {
127127
require.Equal(t, testCase, &decodedCase)
128128
}
129129

130+
// testHtlcAuxBlobProperties is a rapid property that verifies the encoding and
131+
// decoding of the HTLC aux blobs.
132+
func testHtlcAuxBlobProperties(t *rapid.T) {
133+
htlcBlobs := rapid.Make[htlcAuxBlobs]().Draw(t, "htlcAuxBlobs")
134+
135+
var b bytes.Buffer
136+
require.NoError(t, htlcBlobs.Encode(&b))
137+
138+
decodedBlobs := newAuxHtlcBlobs()
139+
require.NoError(t, decodedBlobs.Decode(&b))
140+
141+
require.Equal(t, htlcBlobs, decodedBlobs)
142+
}
143+
130144
// TestHtlcAuxBlobEncodeDecode tests the encode/decode methods of the HTLC aux
131145
// blobs.
132146
func TestHtlcAuxBlobEncodeDecode(t *testing.T) {
133147
t.Parallel()
134148

135-
rapid.Check(t, func(t *rapid.T) {
136-
htlcBlobs := rapid.Make[htlcAuxBlobs]().Draw(t, "htlcAuxBlobs")
137-
138-
var b bytes.Buffer
139-
require.NoError(t, htlcBlobs.Encode(&b))
140-
141-
decodedBlobs := newAuxHtlcBlobs()
142-
require.NoError(t, decodedBlobs.Decode(&b))
149+
rapid.Check(t, testHtlcAuxBlobProperties)
150+
}
143151

144-
require.Equal(t, htlcBlobs, decodedBlobs)
145-
})
152+
// FuzzHtlcAuxBlobEncodeDecodeFuzz tests the encode/decode methods of the HTLC
153+
// aux blobs using the rapid derived fuzzer.
154+
func FuzzHtlcAuxBlobEncodeDecode(f *testing.F) {
155+
f.Fuzz(rapid.MakeFuzz(testHtlcAuxBlobProperties))
146156
}

0 commit comments

Comments
 (0)