Skip to content

Commit 08a6c9c

Browse files
Roasbeefguggero
authored andcommitted
lnwallet: add initial unit tests for musig2+tapscript root chans
1 parent 64aed86 commit 08a6c9c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lnwallet/channel_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,12 @@ func TestSimpleAddSettleWorkflow(t *testing.T) {
386386
)
387387
})
388388

389+
t.Run("taproot with tapscript root", func(t *testing.T) {
390+
flags := channeldb.SimpleTaprootFeatureBit |
391+
channeldb.TapscriptRootBit
392+
testAddSettleWorkflow(t, true, flags, false)
393+
})
394+
389395
t.Run("storeFinalHtlcResolutions=true", func(t *testing.T) {
390396
testAddSettleWorkflow(t, false, 0, true)
391397
})
@@ -828,6 +834,16 @@ func TestForceClose(t *testing.T) {
828834
anchorAmt: anchorSize * 2,
829835
})
830836
})
837+
t.Run("taproot with tapscript root", func(t *testing.T) {
838+
testForceClose(t, &forceCloseTestCase{
839+
chanType: channeldb.SingleFunderTweaklessBit |
840+
channeldb.AnchorOutputsBit |
841+
channeldb.SimpleTaprootFeatureBit |
842+
channeldb.TapscriptRootBit,
843+
expectedCommitWeight: input.TaprootCommitWeight,
844+
anchorAmt: anchorSize * 2,
845+
})
846+
})
831847
}
832848

833849
type forceCloseTestCase struct {

lnwallet/test_utils.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/btcsuite/btcd/chaincfg/chainhash"
1515
"github.com/btcsuite/btcd/wire"
1616
"github.com/lightningnetwork/lnd/channeldb"
17+
"github.com/lightningnetwork/lnd/fn"
1718
"github.com/lightningnetwork/lnd/input"
1819
"github.com/lightningnetwork/lnd/keychain"
1920
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
@@ -343,6 +344,21 @@ func CreateTestChannels(t *testing.T, chanType channeldb.ChannelType,
343344
Packager: channeldb.NewChannelPackager(shortChanID),
344345
}
345346

347+
// If the channel type has a tapscript root, then we'll also specify
348+
// one here to apply to both the channels.
349+
if chanType.HasTapscriptRoot() {
350+
var tapscriptRoot chainhash.Hash
351+
_, err := io.ReadFull(rand.Reader, tapscriptRoot[:])
352+
if err != nil {
353+
return nil, nil, err
354+
}
355+
356+
someRoot := fn.Some(tapscriptRoot)
357+
358+
aliceChannelState.TapscriptRoot = someRoot
359+
bobChannelState.TapscriptRoot = someRoot
360+
}
361+
346362
aliceSigner := input.NewMockSigner(aliceKeys, nil)
347363
bobSigner := input.NewMockSigner(bobKeys, nil)
348364

0 commit comments

Comments
 (0)