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

lightningnetwork / lnd / 11170835610

03 Oct 2024 10:41PM UTC coverage: 49.188% (-9.6%) from 58.738%
11170835610

push

github

web-flow
Merge pull request #9154 from ziggie1984/master

multi: bump btcd version.

3 of 6 new or added lines in 6 files covered. (50.0%)

26110 existing lines in 428 files now uncovered.

97359 of 197934 relevant lines covered (49.19%)

1.04 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"
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) ([]*lnwallet.TransactionDetail, error) {
×
191

×
192
        return nil, nil
×
193
}
×
194

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

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

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

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

×
210
        return nil, nil
×
211
}
×
212

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

×
218
        return 0, nil
×
219
}
×
220

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

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

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

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

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

×
246
        return nil, nil
×
247
}
×
248

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

×
253
        return nil
×
254
}
×
255

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

×
260
        return nil, nil
×
261
}
×
262

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

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

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

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

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

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

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

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

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