Skip to content

Commit 5058432

Browse files
committed
lnwallet: add new TestChanSyncOweCommitmentAuxSigner test
This test ensures that when we go to retransmit a signature, we also include the set of CustomRecords.
1 parent f41dd86 commit 5058432

File tree

2 files changed

+67
-6
lines changed

2 files changed

+67
-6
lines changed

lnwallet/channel_test.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
2929
"github.com/lightningnetwork/lnd/lnwire"
3030
"github.com/lightningnetwork/lnd/tlv"
31+
"github.com/stretchr/testify/mock"
3132
"github.com/stretchr/testify/require"
3233
)
3334

@@ -3368,6 +3369,10 @@ func TestChanSyncOweCommitment(t *testing.T) {
33683369
}
33693370
}
33703371

3372+
type testSigBlob struct {
3373+
BlobInt tlv.RecordT[tlv.TlvType65634, uint16]
3374+
}
3375+
33713376
// TestChanSyncOweCommitmentAuxSigner tests that when one party owes a
33723377
// signature after a channel reest, if an aux signer is present, then the
33733378
// signature message sent includes the additional aux sigs as extra data.
@@ -3411,12 +3416,23 @@ func TestChanSyncOweCommitmentAuxSigner(t *testing.T) {
34113416

34123417
// We'll set up the mock to expect calls to PackSigs and also
34133418
// SubmitSubmitSecondLevelSigBatch.
3414-
sigBlobs := bytes.Repeat([]byte{0x01}, 64)
3419+
var sigBlobBuf bytes.Buffer
3420+
sigBlob := testSigBlob{
3421+
BlobInt: tlv.NewPrimitiveRecord[tlv.TlvType65634, uint16](5),
3422+
}
3423+
tlvStream, err := tlv.NewStream(sigBlob.BlobInt.Record())
3424+
require.NoError(t, err, "unable to create tlv stream")
3425+
require.NoError(t, tlvStream.Encode(&sigBlobBuf))
3426+
34153427
auxSigner.On(
34163428
"SubmitSecondLevelSigBatch", mock.Anything, mock.Anything,
34173429
mock.Anything,
34183430
).Return(nil).Twice()
3419-
auxSigner.On("PackSigs", mock.Anything).Return(fn.Some(sigBlobs), nil)
3431+
auxSigner.On(
3432+
"PackSigs", mock.Anything,
3433+
).Return(
3434+
fn.Some(sigBlobBuf.Bytes()), nil,
3435+
)
34203436

34213437
_, err = aliceChannel.SignNextCommitment()
34223438
require.NoError(t, err, "unable to sign commitment")
@@ -3443,10 +3459,8 @@ func TestChanSyncOweCommitmentAuxSigner(t *testing.T) {
34433459
require.True(t, ok)
34443460
require.True(t, sigMsg.PartialSig.IsSome())
34453461

3446-
// The signature should have the ExtraData field set.
3447-
require.NotNil(t, sigMsg.ExtraData)
3448-
3449-
// TODO(roasbeef): also make one for owe revocation
3462+
// The signature should have the CustomRecords field set.
3463+
require.NotEmpty(t, sigMsg.CustomRecords)
34503464
}
34513465

34523466
func testChanSyncOweCommitmentPendingRemote(t *testing.T,

lnwallet/mock.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ import (
1717
"github.com/btcsuite/btcwallet/wallet/txauthor"
1818
"github.com/btcsuite/btcwallet/wtxmgr"
1919
"github.com/lightningnetwork/lnd/chainntnfs"
20+
"github.com/lightningnetwork/lnd/channeldb"
21+
"github.com/lightningnetwork/lnd/fn"
2022
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
23+
"github.com/lightningnetwork/lnd/tlv"
24+
"github.com/stretchr/testify/mock"
2125
)
2226

2327
var (
@@ -384,3 +388,46 @@ func (*mockChainIO) GetBlockHeader(
384388

385389
return nil, nil
386390
}
391+
392+
type auxSignerMock struct {
393+
mock.Mock
394+
}
395+
396+
func (a *auxSignerMock) SubmitSecondLevelSigBatch(
397+
chanState *channeldb.OpenChannel,
398+
commitTx *wire.MsgTx, sigJobs []AuxSigJob) error {
399+
400+
args := a.Called(chanState, commitTx, sigJobs)
401+
402+
// While we return, we'll also send back an instant response for the
403+
// set of jobs.
404+
for _, sigJob := range sigJobs {
405+
sigJob.Resp <- AuxSigJobResp{}
406+
}
407+
408+
return args.Error(0)
409+
}
410+
411+
func (a *auxSignerMock) PackSigs(sigs []fn.Option[tlv.Blob],
412+
) (fn.Option[tlv.Blob], error) {
413+
414+
args := a.Called(sigs)
415+
416+
return args.Get(0).(fn.Option[tlv.Blob]), args.Error(1)
417+
}
418+
419+
func (a *auxSignerMock) UnpackSigs(sigs fn.Option[tlv.Blob]) (
420+
[]fn.Option[tlv.Blob], error) {
421+
422+
args := a.Called(sigs)
423+
424+
return args.Get(0).([]fn.Option[tlv.Blob]), args.Error(1)
425+
}
426+
427+
func (a *auxSignerMock) VerifySecondLevelSigs(chanState *channeldb.OpenChannel,
428+
commitTx *wire.MsgTx, verifyJob []AuxVerifyJob) error {
429+
430+
args := a.Called(chanState, commitTx, verifyJob)
431+
432+
return args.Error(0)
433+
}

0 commit comments

Comments
 (0)