Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contractcourt: add rapid derived fuzz test for HtlcAuxBlob #9355

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
Loading