• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 15736109134

18 Jun 2025 02:46PM UTC coverage: 58.197% (-10.1%) from 68.248%
15736109134

Pull #9752

github

web-flow
Merge d2634a68c into 31c74f20f
Pull Request #9752: routerrpc: reject payment to invoice that don't have payment secret or blinded paths

6 of 13 new or added lines in 2 files covered. (46.15%)

28331 existing lines in 455 files now uncovered.

97860 of 168153 relevant lines covered (58.2%)

1.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lnwallet/chancloser/mock.go
1
package chancloser
2

3
import (
4
        "sync/atomic"
5
        "testing"
6

7
        "github.com/btcsuite/btcd/btcec/v2"
8
        "github.com/btcsuite/btcd/btcutil"
9
        "github.com/btcsuite/btcd/chaincfg/chainhash"
10
        "github.com/btcsuite/btcd/wire"
11
        "github.com/lightningnetwork/lnd/chainntnfs"
12
        "github.com/lightningnetwork/lnd/channeldb"
13
        "github.com/lightningnetwork/lnd/fn/v2"
14
        "github.com/lightningnetwork/lnd/input"
15
        "github.com/lightningnetwork/lnd/lnwallet"
16
        "github.com/lightningnetwork/lnd/lnwallet/chainfee"
17
        "github.com/lightningnetwork/lnd/lnwire"
18
        "github.com/stretchr/testify/mock"
19
)
20

21
type dummyAdapters struct {
22
        mock.Mock
23

24
        msgSent atomic.Bool
25

26
        confChan  chan *chainntnfs.TxConfirmation
27
        spendChan chan *chainntnfs.SpendDetail
28
}
29

UNCOV
30
func newDaemonAdapters() *dummyAdapters {
×
UNCOV
31
        return &dummyAdapters{
×
UNCOV
32
                confChan:  make(chan *chainntnfs.TxConfirmation, 1),
×
UNCOV
33
                spendChan: make(chan *chainntnfs.SpendDetail, 1),
×
UNCOV
34
        }
×
UNCOV
35
}
×
36

37
func (d *dummyAdapters) SendMessages(pub btcec.PublicKey,
UNCOV
38
        msgs []lnwire.Message) error {
×
UNCOV
39

×
UNCOV
40
        defer d.msgSent.Store(true)
×
UNCOV
41

×
UNCOV
42
        args := d.Called(pub, msgs)
×
UNCOV
43

×
UNCOV
44
        return args.Error(0)
×
UNCOV
45
}
×
46

47
func (d *dummyAdapters) BroadcastTransaction(tx *wire.MsgTx,
UNCOV
48
        label string) error {
×
UNCOV
49

×
UNCOV
50
        args := d.Called(tx, label)
×
UNCOV
51

×
UNCOV
52
        return args.Error(0)
×
UNCOV
53
}
×
54

55
func (d *dummyAdapters) DisableChannel(op wire.OutPoint) error {
×
56
        args := d.Called(op)
×
57

×
58
        return args.Error(0)
×
59
}
×
60

61
func (d *dummyAdapters) RegisterConfirmationsNtfn(txid *chainhash.Hash,
62
        pkScript []byte, numConfs, heightHint uint32,
63
        opts ...chainntnfs.NotifierOption,
64
) (*chainntnfs.ConfirmationEvent, error) {
×
65

×
66
        args := d.Called(txid, pkScript, numConfs)
×
67

×
68
        err := args.Error(0)
×
69

×
70
        return &chainntnfs.ConfirmationEvent{
×
71
                Confirmed: d.confChan,
×
72
        }, err
×
73
}
×
74

75
func (d *dummyAdapters) RegisterSpendNtfn(outpoint *wire.OutPoint,
UNCOV
76
        pkScript []byte, heightHint uint32) (*chainntnfs.SpendEvent, error) {
×
UNCOV
77

×
UNCOV
78
        args := d.Called(outpoint, pkScript, heightHint)
×
UNCOV
79

×
UNCOV
80
        err := args.Error(0)
×
UNCOV
81

×
UNCOV
82
        return &chainntnfs.SpendEvent{
×
UNCOV
83
                Spend: d.spendChan,
×
UNCOV
84
        }, err
×
UNCOV
85
}
×
86

87
type mockFeeEstimator struct {
88
        mock.Mock
89
}
90

91
func (m *mockFeeEstimator) EstimateFee(chanType channeldb.ChannelType,
92
        localTxOut, remoteTxOut *wire.TxOut,
UNCOV
93
        idealFeeRate chainfee.SatPerKWeight) btcutil.Amount {
×
UNCOV
94

×
UNCOV
95
        args := m.Called(chanType, localTxOut, remoteTxOut, idealFeeRate)
×
UNCOV
96
        return args.Get(0).(btcutil.Amount)
×
UNCOV
97
}
×
98

99
type mockChanObserver struct {
100
        mock.Mock
101
}
102

UNCOV
103
func (m *mockChanObserver) NoDanglingUpdates() bool {
×
UNCOV
104
        args := m.Called()
×
UNCOV
105
        return args.Bool(0)
×
UNCOV
106
}
×
107

UNCOV
108
func (m *mockChanObserver) DisableIncomingAdds() error {
×
UNCOV
109
        args := m.Called()
×
UNCOV
110
        return args.Error(0)
×
UNCOV
111
}
×
112

UNCOV
113
func (m *mockChanObserver) DisableOutgoingAdds() error {
×
UNCOV
114
        args := m.Called()
×
UNCOV
115
        return args.Error(0)
×
UNCOV
116
}
×
117

118
func (m *mockChanObserver) MarkCoopBroadcasted(txn *wire.MsgTx,
UNCOV
119
        local bool) error {
×
UNCOV
120

×
UNCOV
121
        args := m.Called(txn, local)
×
UNCOV
122
        return args.Error(0)
×
UNCOV
123
}
×
124

125
func (m *mockChanObserver) MarkShutdownSent(deliveryAddr []byte,
UNCOV
126
        isInitiator bool) error {
×
UNCOV
127

×
UNCOV
128
        args := m.Called(deliveryAddr, isInitiator)
×
UNCOV
129
        return args.Error(0)
×
UNCOV
130
}
×
131

UNCOV
132
func (m *mockChanObserver) FinalBalances() fn.Option[ShutdownBalances] {
×
UNCOV
133
        args := m.Called()
×
UNCOV
134
        return args.Get(0).(fn.Option[ShutdownBalances])
×
UNCOV
135
}
×
136

UNCOV
137
func (m *mockChanObserver) DisableChannel() error {
×
UNCOV
138
        args := m.Called()
×
UNCOV
139
        return args.Error(0)
×
UNCOV
140
}
×
141

142
type mockErrorReporter struct {
143
        mock.Mock
144
        errorReported chan error
145
}
146

147
// newMockErrorReporter creates a new mockErrorReporter.
UNCOV
148
func newMockErrorReporter(t *testing.T) *mockErrorReporter {
×
UNCOV
149
        return &mockErrorReporter{
×
UNCOV
150
                // Buffer of 1 allows ReportError to send without blocking
×
UNCOV
151
                // if the test isn't immediately ready to receive.
×
UNCOV
152
                errorReported: make(chan error, 1),
×
UNCOV
153
        }
×
UNCOV
154
}
×
155

UNCOV
156
func (m *mockErrorReporter) ReportError(err error) {
×
UNCOV
157
        // Keep existing behavior of forwarding to mock.Mock
×
UNCOV
158
        m.Called(err)
×
UNCOV
159

×
UNCOV
160
        // Non-blockingly send the error to the channel.
×
UNCOV
161
        select {
×
UNCOV
162
        case m.errorReported <- err:
×
163

164
        // If the channel is full or no one is listening, this prevents
165
        // ReportError from blocking. This might happen if ReportError is called
166
        // multiple times and the test only waits for the first, or if the test
167
        // times out waiting.
168
        default:
×
169
        }
170
}
171

172
type mockCloseSigner struct {
173
        mock.Mock
174
}
175

176
func (m *mockCloseSigner) CreateCloseProposal(fee btcutil.Amount,
177
        localScript []byte, remoteScript []byte,
178
        closeOpt ...lnwallet.ChanCloseOpt) (
UNCOV
179
        input.Signature, *wire.MsgTx, btcutil.Amount, error) {
×
UNCOV
180

×
UNCOV
181
        args := m.Called(fee, localScript, remoteScript, closeOpt)
×
UNCOV
182

×
UNCOV
183
        return args.Get(0).(input.Signature), args.Get(1).(*wire.MsgTx),
×
UNCOV
184
                args.Get(2).(btcutil.Amount), args.Error(3)
×
UNCOV
185
}
×
186

187
func (m *mockCloseSigner) CompleteCooperativeClose(localSig,
188
        remoteSig input.Signature,
189
        localScript, remoteScript []byte,
190
        fee btcutil.Amount, closeOpt ...lnwallet.ChanCloseOpt,
UNCOV
191
) (*wire.MsgTx, btcutil.Amount, error) {
×
UNCOV
192

×
UNCOV
193
        args := m.Called(
×
UNCOV
194
                localSig, remoteSig, localScript, remoteScript, fee, closeOpt,
×
UNCOV
195
        )
×
UNCOV
196

×
UNCOV
197
        return args.Get(0).(*wire.MsgTx), args.Get(1).(btcutil.Amount),
×
UNCOV
198
                args.Error(2)
×
UNCOV
199
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc