• 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
/lntest/mock/walletcontroller.go
1
package mock
2

3
import (
4
        "encoding/hex"
5
        "sync/atomic"
6
        "time"
7

8
        "github.com/btcsuite/btcd/btcec/v2"
9
        "github.com/btcsuite/btcd/btcutil"
10
        "github.com/btcsuite/btcd/btcutil/hdkeychain"
11
        "github.com/btcsuite/btcd/btcutil/psbt"
12
        "github.com/btcsuite/btcd/chaincfg"
13
        "github.com/btcsuite/btcd/chaincfg/chainhash"
14
        "github.com/btcsuite/btcd/wire"
15
        "github.com/btcsuite/btcwallet/waddrmgr"
16
        base "github.com/btcsuite/btcwallet/wallet"
17
        "github.com/btcsuite/btcwallet/wallet/txauthor"
18
        "github.com/btcsuite/btcwallet/wtxmgr"
19
        "github.com/lightningnetwork/lnd/fn/v2"
20
        "github.com/lightningnetwork/lnd/lnwallet"
21
        "github.com/lightningnetwork/lnd/lnwallet/chainfee"
22
)
23

24
var (
25
        CoinPkScript, _ = hex.DecodeString("001431df1bde03c074d0cf21ea2529427e1499b8f1de")
26
)
27

28
// WalletController is a mock implementation of the WalletController
29
// interface. It let's us mock the interaction with the bitcoin network.
30
type WalletController struct {
31
        RootKey               *btcec.PrivateKey
32
        PublishedTransactions chan *wire.MsgTx
33
        index                 uint32
34
        Utxos                 []*lnwallet.Utxo
35
}
36

37
// A compile time check to ensure this mocked WalletController implements the
38
// WalletController.
39
var _ lnwallet.WalletController = (*WalletController)(nil)
40

41
// BackEnd returns "mock" to signify a mock wallet controller.
42
func (w *WalletController) BackEnd() string {
×
43
        return "mock"
×
44
}
×
45

46
// FetchOutpointInfo will be called to get info about the inputs to the funding
47
// transaction.
48
func (w *WalletController) FetchOutpointInfo(
UNCOV
49
        prevOut *wire.OutPoint) (*lnwallet.Utxo, error) {
×
UNCOV
50

×
UNCOV
51
        utxo := &lnwallet.Utxo{
×
UNCOV
52
                AddressType:   lnwallet.WitnessPubKey,
×
UNCOV
53
                Value:         10 * btcutil.SatoshiPerBitcoin,
×
UNCOV
54
                PkScript:      []byte("dummy"),
×
UNCOV
55
                Confirmations: 1,
×
UNCOV
56
                OutPoint:      *prevOut,
×
UNCOV
57
        }
×
UNCOV
58
        return utxo, nil
×
UNCOV
59
}
×
60

61
// ScriptForOutput returns the address, witness program and redeem script for a
62
// given UTXO. An error is returned if the UTXO does not belong to our wallet or
63
// it is not a managed pubKey address.
64
func (w *WalletController) ScriptForOutput(*wire.TxOut) (
65
        waddrmgr.ManagedPubKeyAddress, []byte, []byte, error) {
×
66

×
67
        return nil, nil, nil, nil
×
68
}
×
69

70
// ConfirmedBalance currently returns dummy values.
71
func (w *WalletController) ConfirmedBalance(int32, string) (btcutil.Amount,
72
        error) {
×
73

×
74
        return 0, nil
×
75
}
×
76

77
// NewAddress is called to get new addresses for delivery, change etc.
78
func (w *WalletController) NewAddress(lnwallet.AddressType, bool,
UNCOV
79
        string) (btcutil.Address, error) {
×
UNCOV
80

×
UNCOV
81
        pkh := btcutil.Hash160(w.RootKey.PubKey().SerializeCompressed())
×
UNCOV
82
        addr, _ := btcutil.NewAddressPubKeyHash(pkh, &chaincfg.MainNetParams)
×
UNCOV
83
        return addr, nil
×
UNCOV
84
}
×
85

86
// LastUnusedAddress currently returns dummy values.
87
func (w *WalletController) LastUnusedAddress(lnwallet.AddressType,
88
        string) (btcutil.Address, error) {
×
89

×
90
        return nil, nil
×
91
}
×
92

93
// IsOurAddress currently returns a dummy value.
UNCOV
94
func (w *WalletController) IsOurAddress(btcutil.Address) bool {
×
UNCOV
95
        return false
×
UNCOV
96
}
×
97

98
// AddressInfo currently returns a dummy value.
99
func (w *WalletController) AddressInfo(
100
        btcutil.Address) (waddrmgr.ManagedAddress, error) {
×
101

×
102
        return nil, nil
×
103
}
×
104

105
// ListAccounts currently returns a dummy value.
106
func (w *WalletController) ListAccounts(string,
107
        *waddrmgr.KeyScope) ([]*waddrmgr.AccountProperties, error) {
×
108

×
109
        return nil, nil
×
110
}
×
111

112
// RequiredReserve currently returns a dummy value.
UNCOV
113
func (w *WalletController) RequiredReserve(uint32) btcutil.Amount {
×
UNCOV
114
        return 0
×
UNCOV
115
}
×
116

117
// ListAddresses currently returns a dummy value.
118
func (w *WalletController) ListAddresses(string,
119
        bool) (lnwallet.AccountAddressMap, error) {
×
120

×
121
        return nil, nil
×
122
}
×
123

124
// ImportAccount currently returns a dummy value.
125
func (w *WalletController) ImportAccount(string, *hdkeychain.ExtendedKey,
126
        uint32, *waddrmgr.AddressType, bool) (*waddrmgr.AccountProperties,
127
        []btcutil.Address, []btcutil.Address, error) {
×
128

×
129
        return nil, nil, nil, nil
×
130
}
×
131

132
// ImportPublicKey currently returns a dummy value.
133
func (w *WalletController) ImportPublicKey(*btcec.PublicKey,
134
        waddrmgr.AddressType) error {
×
135

×
136
        return nil
×
137
}
×
138

139
// ImportTaprootScript currently returns a dummy value.
140
func (w *WalletController) ImportTaprootScript(waddrmgr.KeyScope,
141
        *waddrmgr.Tapscript) (waddrmgr.ManagedAddress, error) {
×
142

×
143
        return nil, nil
×
144
}
×
145

146
// SendOutputs currently returns dummy values.
147
func (w *WalletController) SendOutputs(fn.Set[wire.OutPoint], []*wire.TxOut,
148
        chainfee.SatPerKWeight, int32, string, base.CoinSelectionStrategy) (
149
        *wire.MsgTx, error) {
×
150

×
151
        return nil, nil
×
152
}
×
153

154
// CreateSimpleTx currently returns dummy values.
155
func (w *WalletController) CreateSimpleTx(fn.Set[wire.OutPoint], []*wire.TxOut,
156
        chainfee.SatPerKWeight, int32, base.CoinSelectionStrategy,
157
        bool) (*txauthor.AuthoredTx, error) {
×
158

×
159
        return nil, nil
×
160
}
×
161

162
// ListUnspentWitness is called by the wallet when doing coin selection. We just
163
// need one unspent for the funding transaction.
164
func (w *WalletController) ListUnspentWitness(int32, int32,
UNCOV
165
        string) ([]*lnwallet.Utxo, error) {
×
UNCOV
166

×
UNCOV
167
        // If the mock already has a list of utxos, return it.
×
UNCOV
168
        if w.Utxos != nil {
×
UNCOV
169
                return w.Utxos, nil
×
UNCOV
170
        }
×
171

172
        // Otherwise create one to return.
UNCOV
173
        utxo := &lnwallet.Utxo{
×
UNCOV
174
                AddressType: lnwallet.WitnessPubKey,
×
UNCOV
175
                Value:       btcutil.Amount(10 * btcutil.SatoshiPerBitcoin),
×
UNCOV
176
                PkScript:    CoinPkScript,
×
UNCOV
177
                OutPoint: wire.OutPoint{
×
UNCOV
178
                        Hash:  chainhash.Hash{},
×
UNCOV
179
                        Index: w.index,
×
UNCOV
180
                },
×
UNCOV
181
        }
×
UNCOV
182
        atomic.AddUint32(&w.index, 1)
×
UNCOV
183
        var ret []*lnwallet.Utxo
×
UNCOV
184
        ret = append(ret, utxo)
×
UNCOV
185
        return ret, nil
×
186
}
187

188
// ListTransactionDetails currently returns dummy values.
189
func (w *WalletController) ListTransactionDetails(int32, int32,
190
        string, uint32, uint32) ([]*lnwallet.TransactionDetail,
191
        uint64, uint64, error) {
×
192

×
193
        return nil, 0, 0, nil
×
194
}
×
195

196
// LeaseOutput returns the current time and a nil error.
197
func (w *WalletController) LeaseOutput(wtxmgr.LockID, wire.OutPoint,
UNCOV
198
        time.Duration) (time.Time, error) {
×
UNCOV
199

×
UNCOV
200
        return time.Now(), nil
×
UNCOV
201
}
×
202

203
// ReleaseOutput currently does nothing.
UNCOV
204
func (w *WalletController) ReleaseOutput(wtxmgr.LockID, wire.OutPoint) error {
×
UNCOV
205
        return nil
×
UNCOV
206
}
×
207

208
func (w *WalletController) ListLeasedOutputs() ([]*base.ListLeasedOutputResult,
209
        error) {
×
210

×
211
        return nil, nil
×
212
}
×
213

214
// FundPsbt currently does nothing.
215
func (w *WalletController) FundPsbt(*psbt.Packet, int32, chainfee.SatPerKWeight,
216
        string, *waddrmgr.KeyScope, base.CoinSelectionStrategy,
217
        func(utxo wtxmgr.Credit) bool) (int32, error) {
×
218

×
219
        return 0, nil
×
220
}
×
221

222
// SignPsbt currently does nothing.
223
func (w *WalletController) SignPsbt(*psbt.Packet) ([]uint32, error) {
×
224
        return nil, nil
×
225
}
×
226

227
// FinalizePsbt currently does nothing.
228
func (w *WalletController) FinalizePsbt(_ *psbt.Packet, _ string) error {
×
229
        return nil
×
230
}
×
231

232
// DecorateInputs currently does nothing.
233
func (w *WalletController) DecorateInputs(*psbt.Packet, bool) error {
×
234
        return nil
×
235
}
×
236

237
// PublishTransaction sends a transaction to the PublishedTransactions chan.
UNCOV
238
func (w *WalletController) PublishTransaction(tx *wire.MsgTx, _ string) error {
×
UNCOV
239
        w.PublishedTransactions <- tx
×
UNCOV
240
        return nil
×
UNCOV
241
}
×
242

243
// GetTransactionDetails currently does nothing.
244
func (w *WalletController) GetTransactionDetails(
245
        txHash *chainhash.Hash) (*lnwallet.TransactionDetail, error) {
×
246

×
247
        return nil, nil
×
248
}
×
249

250
// LabelTransaction currently does nothing.
251
func (w *WalletController) LabelTransaction(chainhash.Hash, string,
252
        bool) error {
×
253

×
254
        return nil
×
255
}
×
256

257
// SubscribeTransactions currently does nothing.
258
func (w *WalletController) SubscribeTransactions() (lnwallet.TransactionSubscription,
259
        error) {
×
260

×
261
        return nil, nil
×
262
}
×
263

264
// IsSynced currently returns dummy values.
UNCOV
265
func (w *WalletController) IsSynced() (bool, int64, error) {
×
UNCOV
266
        return true, int64(0), nil
×
UNCOV
267
}
×
268

269
// GetRecoveryInfo currently returns dummy values.
270
func (w *WalletController) GetRecoveryInfo() (bool, float64, error) {
×
271
        return true, float64(1), nil
×
272
}
×
273

274
// Start currently does nothing.
UNCOV
275
func (w *WalletController) Start() error {
×
UNCOV
276
        return nil
×
UNCOV
277
}
×
278

279
// Stop currently does nothing.
280
func (w *WalletController) Stop() error {
×
281
        return nil
×
282
}
×
283

284
func (w *WalletController) FetchTx(chainhash.Hash) (*wire.MsgTx, error) {
×
285
        return nil, nil
×
286
}
×
287

288
func (w *WalletController) RemoveDescendants(*wire.MsgTx) error {
×
289
        return nil
×
290
}
×
291

292
func (w *WalletController) CheckMempoolAcceptance(tx *wire.MsgTx) error {
×
293
        return nil
×
294
}
×
295

296
// FetchDerivationInfo queries for the wallet's knowledge of the passed
297
// pkScript and constructs the derivation info and returns it.
298
func (w *WalletController) FetchDerivationInfo(
299
        pkScript []byte) (*psbt.Bip32Derivation, error) {
×
300

×
301
        return nil, nil
×
302
}
×
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