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

lightningnetwork / lnd / 15951470896

29 Jun 2025 04:23AM UTC coverage: 67.594% (-0.01%) from 67.606%
15951470896

Pull #9751

github

web-flow
Merge 599d9b051 into 6290edf14
Pull Request #9751: multi: update Go to 1.23.10 and update some packages

135088 of 199851 relevant lines covered (67.59%)

21909.44 hits per line

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

85.59
/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

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

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

15✔
40
        defer d.msgSent.Store(true)
15✔
41

15✔
42
        args := d.Called(pub, msgs)
15✔
43

15✔
44
        return args.Error(0)
15✔
45
}
15✔
46

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

9✔
50
        args := d.Called(tx, label)
9✔
51

9✔
52
        return args.Error(0)
9✔
53
}
9✔
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,
76
        pkScript []byte, heightHint uint32) (*chainntnfs.SpendEvent, error) {
42✔
77

42✔
78
        args := d.Called(outpoint, pkScript, heightHint)
42✔
79

42✔
80
        err := args.Error(0)
42✔
81

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

14✔
160
        // Non-blockingly send the error to the channel.
14✔
161
        select {
14✔
162
        case m.errorReported <- err:
14✔
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) (
179
        input.Signature, *wire.MsgTx, btcutil.Amount, error) {
14✔
180

14✔
181
        args := m.Called(fee, localScript, remoteScript, closeOpt)
14✔
182

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

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

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

9✔
197
        return args.Get(0).(*wire.MsgTx), args.Get(1).(btcutil.Amount),
9✔
198
                args.Error(2)
9✔
199
}
9✔
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