mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-28 22:50:58 +02:00
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:
@@ -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)
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user