Skip to content

Commit

Permalink
lnwallet: add initial unit tests for musig2+tapscript root chans
Browse files Browse the repository at this point in the history
  • Loading branch information
Roasbeef authored and guggero committed Apr 30, 2024
1 parent 66fa0a2 commit 26ce8ee
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lnwallet/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,12 @@ func TestSimpleAddSettleWorkflow(t *testing.T) {
)
})

t.Run("taproot with tapscript root", func(t *testing.T) {
flags := channeldb.SimpleTaprootFeatureBit |
channeldb.TapscriptRootBit
testAddSettleWorkflow(t, true, flags, false)
})

t.Run("storeFinalHtlcResolutions=true", func(t *testing.T) {
testAddSettleWorkflow(t, false, 0, true)
})
Expand Down Expand Up @@ -828,6 +834,16 @@ func TestForceClose(t *testing.T) {
anchorAmt: anchorSize * 2,
})
})
t.Run("taproot with tapscript root", func(t *testing.T) {
testForceClose(t, &forceCloseTestCase{
chanType: channeldb.SingleFunderTweaklessBit |
channeldb.AnchorOutputsBit |
channeldb.SimpleTaprootFeatureBit |
channeldb.TapscriptRootBit,
expectedCommitWeight: input.TaprootCommitWeight,
anchorAmt: anchorSize * 2,
})
})
}

type forceCloseTestCase struct {
Expand Down
16 changes: 16 additions & 0 deletions lnwallet/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
Expand Down Expand Up @@ -343,6 +344,21 @@ func CreateTestChannels(t *testing.T, chanType channeldb.ChannelType,
Packager: channeldb.NewChannelPackager(shortChanID),
}

// If the channel type has a tapscript root, then we'll also specify
// one here to apply to both the channels.
if chanType.HasTapscriptRoot() {
var tapscriptRoot chainhash.Hash
_, err := io.ReadFull(rand.Reader, tapscriptRoot[:])
if err != nil {
return nil, nil, err
}

someRoot := fn.Some(tapscriptRoot)

aliceChannelState.TapscriptRoot = someRoot
bobChannelState.TapscriptRoot = someRoot
}

aliceSigner := input.NewMockSigner(aliceKeys, nil)
bobSigner := input.NewMockSigner(bobKeys, nil)

Expand Down

0 comments on commit 26ce8ee

Please sign in to comment.