Skip to content

Commit a05e466

Browse files
committed
test: assert raw output signing requests
1 parent cecb26c commit a05e466

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

client_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ func testSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
265265
// Publish tick.
266266
ctx.expiryChan <- testTime
267267

268+
// Expect a signing request.
269+
<-ctx.Lnd.SignOutputRawChannel
270+
268271
if !preimageRevealed {
269272
ctx.assertStatus(loopdb.StatePreimageRevealed)
270273
ctx.assertStorePreimageReveal()

loopin_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ func TestLoopInTimeout(t *testing.T) {
175175
// Let htlc expire.
176176
ctx.blockEpochChan <- swap.LoopInContract.CltvExpiry
177177

178+
// Expect a signing request.
179+
<-ctx.lnd.SignOutputRawChannel
180+
178181
// Expect timeout tx to be published.
179182
timeoutTx := <-ctx.lnd.TxPublishChannel
180183

loopout_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ func TestCustomSweepConfTarget(t *testing.T) {
192192

193193
expiryChan <- time.Now()
194194

195+
// Expect a signing request for the HTLC success transaction.
196+
<-ctx.Lnd.SignOutputRawChannel
197+
195198
cfg.store.(*storeMock).assertLoopOutState(loopdb.StatePreimageRevealed)
196199
status := <-statusChan
197200
if status.State != loopdb.StatePreimageRevealed {
@@ -247,6 +250,9 @@ func TestCustomSweepConfTarget(t *testing.T) {
247250
blockEpochChan <- int32(defaultConfTargetHeight)
248251
expiryChan <- time.Now()
249252

253+
// Expect another signing request.
254+
<-ctx.Lnd.SignOutputRawChannel
255+
250256
// We should expect to see another sweep using the higher fee since the
251257
// spend hasn't been confirmed yet.
252258
sweepTx := assertSweepTx(DefaultSweepConfTarget)

test/lnd_services_mock.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/btcsuite/btcd/wire"
1010
"github.com/lightninglabs/loop/lndclient"
1111
"github.com/lightningnetwork/lnd/chainntnfs"
12+
"github.com/lightningnetwork/lnd/input"
1213
"github.com/lightningnetwork/lnd/lntypes"
1314
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
1415
"github.com/lightningnetwork/lnd/zpay32"
@@ -57,6 +58,8 @@ func NewMockLnd() *LndMockServices {
5758
RouterSendPaymentChannel: make(chan RouterPaymentChannelMessage),
5859
TrackPaymentChannel: make(chan TrackPaymentMessage),
5960

61+
SignOutputRawChannel: make(chan SignOutputRawRequest),
62+
6063
FailInvoiceChannel: make(chan lntypes.Hash, 2),
6164
epochChannel: make(chan int32),
6265
Height: testStartingHeight,
@@ -109,6 +112,12 @@ type SingleInvoiceSubscription struct {
109112
Err chan error
110113
}
111114

115+
// SignOutputRawRequest contains input data for a tx signing request.
116+
type SignOutputRawRequest struct {
117+
Tx *wire.MsgTx
118+
SignDescriptors []*input.SignDescriptor
119+
}
120+
112121
// LndMockServices provides a full set of mocked lnd services.
113122
type LndMockServices struct {
114123
lndclient.LndServices
@@ -130,6 +139,8 @@ type LndMockServices struct {
130139
RouterSendPaymentChannel chan RouterPaymentChannelMessage
131140
TrackPaymentChannel chan TrackPaymentMessage
132141

142+
SignOutputRawChannel chan SignOutputRawRequest
143+
133144
Height int32
134145
NodePubkey string
135146
Signature []byte

test/signer_mock.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ type mockSigner struct {
1616
func (s *mockSigner) SignOutputRaw(ctx context.Context, tx *wire.MsgTx,
1717
signDescriptors []*input.SignDescriptor) ([][]byte, error) {
1818

19+
s.lnd.SignOutputRawChannel <- SignOutputRawRequest{
20+
Tx: tx,
21+
SignDescriptors: signDescriptors,
22+
}
23+
1924
rawSigs := [][]byte{{1, 2, 3}}
2025

2126
return rawSigs, nil

0 commit comments

Comments
 (0)