Skip to content

Commit

Permalink
Merge pull request #9355 from Roasbeef/rapid-fuzz-htlc-blobs
Browse files Browse the repository at this point in the history
contractcourt: add rapid derived fuzz test for HtlcAuxBlob
  • Loading branch information
guggero authored Jan 13, 2025
2 parents 1b0f41d + 78cbed9 commit b958667
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions contractcourt/taproot_briefcase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,30 @@ func TestTaprootBriefcase(t *testing.T) {
require.Equal(t, testCase, &decodedCase)
}

// testHtlcAuxBlobProperties is a rapid property that verifies the encoding and
// decoding of the HTLC aux blobs.
func testHtlcAuxBlobProperties(t *rapid.T) {
htlcBlobs := rapid.Make[htlcAuxBlobs]().Draw(t, "htlcAuxBlobs")

var b bytes.Buffer
require.NoError(t, htlcBlobs.Encode(&b))

decodedBlobs := newAuxHtlcBlobs()
require.NoError(t, decodedBlobs.Decode(&b))

require.Equal(t, htlcBlobs, decodedBlobs)
}

// TestHtlcAuxBlobEncodeDecode tests the encode/decode methods of the HTLC aux
// blobs.
func TestHtlcAuxBlobEncodeDecode(t *testing.T) {
t.Parallel()

rapid.Check(t, func(t *rapid.T) {
htlcBlobs := rapid.Make[htlcAuxBlobs]().Draw(t, "htlcAuxBlobs")

var b bytes.Buffer
require.NoError(t, htlcBlobs.Encode(&b))

decodedBlobs := newAuxHtlcBlobs()
require.NoError(t, decodedBlobs.Decode(&b))
rapid.Check(t, testHtlcAuxBlobProperties)
}

require.Equal(t, htlcBlobs, decodedBlobs)
})
// FuzzHtlcAuxBlobEncodeDecodeFuzz tests the encode/decode methods of the HTLC
// aux blobs using the rapid derived fuzzer.
func FuzzHtlcAuxBlobEncodeDecode(f *testing.F) {
f.Fuzz(rapid.MakeFuzz(testHtlcAuxBlobProperties))
}

0 comments on commit b958667

Please sign in to comment.