Skip to content

Commit 33e0cea

Browse files
committed
lnwallet: add initial unit tests for musig2+tapscript root chans
1 parent 612e93e commit 33e0cea

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
@@ -385,6 +385,12 @@ func TestSimpleAddSettleWorkflow(t *testing.T) {
385385
)
386386
})
387387

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

832848
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)