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

lightningnetwork / lnd / 11954082915

21 Nov 2024 01:20PM UTC coverage: 59.327% (+0.6%) from 58.776%
11954082915

Pull #8754

github

ViktorTigerstrom
itest: wrap deriveCustomScopeAccounts at 80 chars

This commit fixes that word wrapping for the deriveCustomScopeAccounts
function docs, and ensures that it wraps at 80 characters or less.
Pull Request #8754: Add `Outbound` Remote Signer implementation

1940 of 2984 new or added lines in 44 files covered. (65.01%)

226 existing lines in 37 files now uncovered.

135234 of 227947 relevant lines covered (59.33%)

19316.75 hits per line

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

35.98
/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(
49
        prevOut *wire.OutPoint) (*lnwallet.Utxo, error) {
96✔
50

96✔
51
        utxo := &lnwallet.Utxo{
96✔
52
                AddressType:   lnwallet.WitnessPubKey,
96✔
53
                Value:         10 * btcutil.SatoshiPerBitcoin,
96✔
54
                PkScript:      []byte("dummy"),
96✔
55
                Confirmations: 1,
96✔
56
                OutPoint:      *prevOut,
96✔
57
        }
96✔
58
        return utxo, nil
96✔
59
}
96✔
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,
79
        string) (btcutil.Address, error) {
56✔
80

56✔
81
        pkh := btcutil.Hash160(w.RootKey.PubKey().SerializeCompressed())
56✔
82
        addr, _ := btcutil.NewAddressPubKeyHash(pkh, &chaincfg.MainNetParams)
56✔
83
        return addr, nil
56✔
84
}
56✔
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.
94
func (w *WalletController) IsOurAddress(btcutil.Address) bool {
48✔
95
        return false
48✔
96
}
48✔
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.
113
func (w *WalletController) RequiredReserve(uint32) btcutil.Amount {
150✔
114
        return 0
150✔
115
}
150✔
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,
165
        string) ([]*lnwallet.Utxo, error) {
149✔
166

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

172
        // Otherwise create one to return.
173
        utxo := &lnwallet.Utxo{
127✔
174
                AddressType: lnwallet.WitnessPubKey,
127✔
175
                Value:       btcutil.Amount(10 * btcutil.SatoshiPerBitcoin),
127✔
176
                PkScript:    CoinPkScript,
127✔
177
                OutPoint: wire.OutPoint{
127✔
178
                        Hash:  chainhash.Hash{},
127✔
179
                        Index: w.index,
127✔
180
                },
127✔
181
        }
127✔
182
        atomic.AddUint32(&w.index, 1)
127✔
183
        var ret []*lnwallet.Utxo
127✔
184
        ret = append(ret, utxo)
127✔
185
        return ret, nil
127✔
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,
197
        time.Duration) (time.Time, error) {
57✔
198

57✔
199
        return time.Now(), nil
57✔
200
}
57✔
201

202
// ReleaseOutput currently does nothing.
203
func (w *WalletController) ReleaseOutput(wtxmgr.LockID, wire.OutPoint) error {
14✔
204
        return nil
14✔
205
}
14✔
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.
237
func (w *WalletController) PublishTransaction(tx *wire.MsgTx, _ string) error {
4✔
238
        w.PublishedTransactions <- tx
4✔
239
        return nil
4✔
240
}
4✔
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.
264
func (w *WalletController) IsSynced() (bool, int64, error) {
50✔
265
        return true, int64(0), nil
50✔
266
}
50✔
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.
274
func (w *WalletController) Start() error {
98✔
275
        return nil
98✔
276
}
98✔
277

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

283
// ReadySignal currently signals that the wallet is ready instantly.
NEW
284
func (w *WalletController) ReadySignal() chan error {
×
NEW
285
        readyChan := make(chan error, 1)
×
NEW
286
        readyChan <- nil
×
NEW
287

×
NEW
288
        return readyChan
×
NEW
289
}
×
290

291
func (w *WalletController) FetchTx(chainhash.Hash) (*wire.MsgTx, error) {
×
292
        return nil, nil
×
293
}
×
294

295
func (w *WalletController) RemoveDescendants(*wire.MsgTx) error {
×
296
        return nil
×
297
}
×
298

299
func (w *WalletController) CheckMempoolAcceptance(tx *wire.MsgTx) error {
×
300
        return nil
×
301
}
×
302

303
// FetchDerivationInfo queries for the wallet's knowledge of the passed
304
// pkScript and constructs the derivation info and returns it.
305
func (w *WalletController) FetchDerivationInfo(
306
        pkScript []byte) (*psbt.Bip32Derivation, error) {
×
307

×
308
        return nil, nil
×
309
}
×
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