contractcourt: add HtlcBlobs to taprootBriefcase

In this commit, we add the set of HtlcBlobs to the taprootBriefcase
struct. This new field will store all the resolution blobs for a given
HTLC. We also add some new property based tests along the way for
adequate test coverage.
This commit is contained in:
Olaoluwa Osuntokun
2024-10-15 19:18:23 -07:00
parent 1e7c5415ae
commit 9b8adf5f5c
5 changed files with 242 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/lightningnetwork/lnd/tlv"
"github.com/stretchr/testify/require"
"pgregory.net/rapid"
)
func randResolverCtrlBlocks(t *testing.T) resolverCtrlBlocks {
@@ -53,6 +54,25 @@ func randHtlcTweaks(t *testing.T) htlcTapTweaks {
return tweaks
}
func randHtlcAuxBlobs(t *testing.T) htlcAuxBlobs {
numBlobs := rand.Int() % 256
blobs := make(htlcAuxBlobs, numBlobs)
for i := 0; i < numBlobs; i++ {
var id resolverID
_, err := rand.Read(id[:])
require.NoError(t, err)
var blob [100]byte
_, err = rand.Read(blob[:])
require.NoError(t, err)
blobs[id] = blob[:]
}
return blobs
}
// TestTaprootBriefcase tests the encode/decode methods of the taproot
// briefcase extension.
func TestTaprootBriefcase(t *testing.T) {
@@ -93,6 +113,9 @@ func TestTaprootBriefcase(t *testing.T) {
BreachedCommitBlob: tlv.SomeRecordT(
tlv.NewPrimitiveRecord[tlv.TlvType3](commitBlob[:]),
),
HtlcBlobs: tlv.SomeRecordT(
tlv.NewRecordT[tlv.TlvType4](randHtlcAuxBlobs(t)),
),
}
var b bytes.Buffer
@@ -103,3 +126,21 @@ func TestTaprootBriefcase(t *testing.T) {
require.Equal(t, testCase, &decodedCase)
}
// 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))
require.Equal(t, htlcBlobs, decodedBlobs)
})
}