Skip to content

Commit fdbe171

Browse files
committed
lnwallet: update testAddSettleWorkflow to test the new taproot flow
1 parent bd94f6c commit fdbe171

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

lnwallet/channel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5229,7 +5229,7 @@ func (lc *LightningChannel) RevokeCurrentCommitment() (*lnwire.RevokeAndAck,
52295229
)
52305230
}
52315231

5232-
return revocationMsg, newCommitment.Htlcs, nil
5232+
return revocationMsg, newCommitment.Htlcs, finalHtlcs, nil
52335233
}
52345234

52355235
// ReceiveRevocation processes a revocation sent by the remote party for the

lnwallet/channel_test.go

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ func assertOutputExistsByValue(t *testing.T, commitTx *wire.MsgTx,
5959

6060
// testAddSettleWorkflow tests a simple channel scenario where Alice and Bob
6161
// add, the settle an HTLC between themselves.
62-
func testAddSettleWorkflow(t *testing.T, tweakless,
63-
storeFinalHtlcResolutions bool) {
62+
func testAddSettleWorkflow(t *testing.T, tweakless bool,
63+
chanTypeModifier channeldb.ChannelType, storeFinalHtlcResolutions bool) {
6464

6565
// Create a test channel which will be used for the duration of this
6666
// unittest. The channel will be funded evenly with Alice having 5 BTC,
@@ -70,6 +70,10 @@ func testAddSettleWorkflow(t *testing.T, tweakless,
7070
chanType = channeldb.SingleFunderBit
7171
}
7272

73+
if chanTypeModifier != 0 {
74+
chanType |= chanTypeModifier
75+
}
76+
7377
aliceChannel, bobChannel, err := CreateTestChannels(
7478
t, chanType,
7579
channeldb.OptionStoreFinalHtlcResolutions(
@@ -193,12 +197,18 @@ func testAddSettleWorkflow(t *testing.T, tweakless,
193197

194198
// Both commitment transactions should have three outputs, and one of
195199
// them should be exactly the amount of the HTLC.
196-
if len(aliceChannel.channelState.LocalCommitment.CommitTx.TxOut) != 3 {
200+
numOutputs := 3
201+
if chanTypeModifier.HasAnchors() {
202+
// In this case we expect two extra outputs as both sides need an
203+
// anchor output.
204+
numOutputs = 5
205+
}
206+
if len(aliceChannel.channelState.LocalCommitment.CommitTx.TxOut) != numOutputs {
197207
t.Fatalf("alice should have three commitment outputs, instead "+
198208
"have %v",
199209
len(aliceChannel.channelState.LocalCommitment.CommitTx.TxOut))
200210
}
201-
if len(bobChannel.channelState.LocalCommitment.CommitTx.TxOut) != 3 {
211+
if len(bobChannel.channelState.LocalCommitment.CommitTx.TxOut) != numOutputs {
202212
t.Fatalf("bob should have three commitment outputs, instead "+
203213
"have %v",
204214
len(bobChannel.channelState.LocalCommitment.CommitTx.TxOut))
@@ -350,13 +360,28 @@ func TestSimpleAddSettleWorkflow(t *testing.T) {
350360

351361
for _, tweakless := range []bool{true, false} {
352362
tweakless := tweakless
363+
353364
t.Run(fmt.Sprintf("tweakless=%v", tweakless), func(t *testing.T) {
354-
testAddSettleWorkflow(t, tweakless, false)
365+
testAddSettleWorkflow(t, tweakless, 0, false)
355366
})
356367
}
357368

369+
t.Run("anchors", func(t *testing.T) {
370+
testAddSettleWorkflow(
371+
t, true,
372+
channeldb.AnchorOutputsBit|channeldb.ZeroHtlcTxFeeBit,
373+
false,
374+
)
375+
})
376+
377+
t.Run("taproot", func(t *testing.T) {
378+
testAddSettleWorkflow(
379+
t, true, channeldb.SimpleTaprootFeatureBit, false,
380+
)
381+
})
382+
358383
t.Run("storeFinalHtlcResolutions=true", func(t *testing.T) {
359-
testAddSettleWorkflow(t, false, true)
384+
testAddSettleWorkflow(t, false, 0, true)
360385
})
361386
}
362387

lnwallet/test_utils.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,27 @@ func CreateTestChannels(t *testing.T, chanType channeldb.ChannelType,
418418
// network by populating the initial revocation windows of the passed
419419
// commitment state machines.
420420
func initRevocationWindows(chanA, chanB *LightningChannel) error {
421+
// If these are taproot chanenls, then we need to also simulate sending
422+
// either FundingLocked or ChannelReestablish by calling
423+
// InitRemoteMusigNonces for both sides.
424+
if chanA.channelState.ChanType.IsTaproot() {
425+
chanANonces, err := chanA.GenMusigNonces()
426+
if err != nil {
427+
return err
428+
}
429+
chanBNonces, err := chanB.GenMusigNonces()
430+
if err != nil {
431+
return err
432+
}
433+
434+
if err := chanA.InitRemoteMusigNonces(chanBNonces); err != nil {
435+
return err
436+
}
437+
if err := chanB.InitRemoteMusigNonces(chanANonces); err != nil {
438+
return err
439+
}
440+
}
441+
421442
aliceNextRevoke, err := chanA.NextRevocationKey()
422443
if err != nil {
423444
return err

0 commit comments

Comments
 (0)