• 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
/input/mocks.go
1
package input
2

3
import (
4
        "crypto/sha256"
5

6
        "github.com/btcsuite/btcd/btcec/v2"
7
        "github.com/btcsuite/btcd/btcec/v2/schnorr"
8
        "github.com/btcsuite/btcd/btcec/v2/schnorr/musig2"
9
        "github.com/btcsuite/btcd/txscript"
10
        "github.com/btcsuite/btcd/wire"
11
        "github.com/lightningnetwork/lnd/fn"
12
        "github.com/lightningnetwork/lnd/keychain"
13
        "github.com/lightningnetwork/lnd/lntypes"
14
        "github.com/lightningnetwork/lnd/tlv"
15
        "github.com/stretchr/testify/mock"
16
)
17

18
// MockInput implements the `Input` interface and is used by other packages for
19
// mock testing.
20
type MockInput struct {
21
        mock.Mock
22
}
23

24
// Compile time assertion that MockInput implements Input.
25
var _ Input = (*MockInput)(nil)
26

27
// Outpoint returns the reference to the output being spent, used to construct
28
// the corresponding transaction input.
UNCOV
29
func (m *MockInput) OutPoint() wire.OutPoint {
×
UNCOV
30
        args := m.Called()
×
UNCOV
31
        op := args.Get(0)
×
UNCOV
32

×
UNCOV
33
        return op.(wire.OutPoint)
×
UNCOV
34
}
×
35

36
// RequiredTxOut returns a non-nil TxOut if input commits to a certain
37
// transaction output. This is used in the SINGLE|ANYONECANPAY case to make
38
// sure any presigned input is still valid by including the output.
UNCOV
39
func (m *MockInput) RequiredTxOut() *wire.TxOut {
×
UNCOV
40
        args := m.Called()
×
UNCOV
41
        txOut := args.Get(0)
×
UNCOV
42

×
UNCOV
43
        if txOut == nil {
×
UNCOV
44
                return nil
×
UNCOV
45
        }
×
46

UNCOV
47
        return txOut.(*wire.TxOut)
×
48
}
49

50
// RequiredLockTime returns whether this input commits to a tx locktime that
51
// must be used in the transaction including it.
UNCOV
52
func (m *MockInput) RequiredLockTime() (uint32, bool) {
×
UNCOV
53
        args := m.Called()
×
UNCOV
54

×
UNCOV
55
        return args.Get(0).(uint32), args.Bool(1)
×
UNCOV
56
}
×
57

58
// WitnessType returns an enum specifying the type of witness that must be
59
// generated in order to spend this output.
UNCOV
60
func (m *MockInput) WitnessType() WitnessType {
×
UNCOV
61
        args := m.Called()
×
UNCOV
62

×
UNCOV
63
        wt := args.Get(0)
×
UNCOV
64
        if wt == nil {
×
65
                return nil
×
66
        }
×
67

UNCOV
68
        return wt.(WitnessType)
×
69
}
70

71
// SignDesc returns a reference to a spendable output's sign descriptor, which
72
// is used during signing to compute a valid witness that spends this output.
UNCOV
73
func (m *MockInput) SignDesc() *SignDescriptor {
×
UNCOV
74
        args := m.Called()
×
UNCOV
75

×
UNCOV
76
        sd := args.Get(0)
×
UNCOV
77
        if sd == nil {
×
78
                return nil
×
79
        }
×
80

UNCOV
81
        return sd.(*SignDescriptor)
×
82
}
83

84
// CraftInputScript returns a valid set of input scripts allowing this output
85
// to be spent. The returns input scripts should target the input at location
86
// txIndex within the passed transaction. The input scripts generated by this
87
// method support spending p2wkh, p2wsh, and also nested p2sh outputs.
88
func (m *MockInput) CraftInputScript(signer Signer, txn *wire.MsgTx,
89
        hashCache *txscript.TxSigHashes,
90
        prevOutputFetcher txscript.PrevOutputFetcher,
91
        txinIdx int) (*Script, error) {
×
92

×
93
        args := m.Called(signer, txn, hashCache, prevOutputFetcher, txinIdx)
×
94

×
95
        s := args.Get(0)
×
96
        if s == nil {
×
97
                return nil, args.Error(1)
×
98
        }
×
99

100
        return s.(*Script), args.Error(1)
×
101
}
102

103
// BlocksToMaturity returns the relative timelock, as a number of blocks, that
104
// must be built on top of the confirmation height before the output can be
105
// spent. For non-CSV locked inputs this is always zero.
UNCOV
106
func (m *MockInput) BlocksToMaturity() uint32 {
×
UNCOV
107
        args := m.Called()
×
UNCOV
108

×
UNCOV
109
        return args.Get(0).(uint32)
×
UNCOV
110
}
×
111

112
// HeightHint returns the minimum height at which a confirmed spending tx can
113
// occur.
UNCOV
114
func (m *MockInput) HeightHint() uint32 {
×
UNCOV
115
        args := m.Called()
×
UNCOV
116

×
UNCOV
117
        return args.Get(0).(uint32)
×
UNCOV
118
}
×
119

120
// UnconfParent returns information about a possibly unconfirmed parent tx.
121
func (m *MockInput) UnconfParent() *TxInfo {
×
122
        args := m.Called()
×
123

×
124
        info := args.Get(0)
×
125
        if info == nil {
×
126
                return nil
×
127
        }
×
128

129
        return info.(*TxInfo)
×
130
}
131

132
func (m *MockInput) ResolutionBlob() fn.Option[tlv.Blob] {
×
133
        args := m.Called()
×
134

×
135
        info := args.Get(0)
×
136
        if info == nil {
×
137
                return fn.None[tlv.Blob]()
×
138
        }
×
139

140
        return info.(fn.Option[tlv.Blob])
×
141
}
142

143
// MockWitnessType implements the `WitnessType` interface and is used by other
144
// packages for mock testing.
145
type MockWitnessType struct {
146
        mock.Mock
147
}
148

149
// Compile time assertion that MockWitnessType implements WitnessType.
150
var _ WitnessType = (*MockWitnessType)(nil)
151

152
// String returns a human readable version of the WitnessType.
UNCOV
153
func (m *MockWitnessType) String() string {
×
UNCOV
154
        args := m.Called()
×
UNCOV
155

×
UNCOV
156
        return args.String(0)
×
UNCOV
157
}
×
158

159
// WitnessGenerator will return a WitnessGenerator function that an output uses
160
// to generate the witness and optionally the sigScript for a sweep
161
// transaction.
162
func (m *MockWitnessType) WitnessGenerator(signer Signer,
163
        descriptor *SignDescriptor) WitnessGenerator {
×
164

×
165
        args := m.Called()
×
166

×
167
        return args.Get(0).(WitnessGenerator)
×
168
}
×
169

170
// SizeUpperBound returns the maximum length of the witness of this WitnessType
171
// if it would be included in a tx. It also returns if the output itself is a
172
// nested p2sh output, if so then we need to take into account the extra
173
// sigScript data size.
UNCOV
174
func (m *MockWitnessType) SizeUpperBound() (lntypes.WeightUnit, bool, error) {
×
UNCOV
175
        args := m.Called()
×
UNCOV
176

×
UNCOV
177
        return args.Get(0).(lntypes.WeightUnit), args.Bool(1), args.Error(2)
×
UNCOV
178
}
×
179

180
// AddWeightEstimation adds the estimated size of the witness in bytes to the
181
// given weight estimator.
182
func (m *MockWitnessType) AddWeightEstimation(e *TxWeightEstimator) error {
×
183
        args := m.Called()
×
184

×
185
        return args.Error(0)
×
186
}
×
187

188
// MockInputSigner is a mock implementation of the Signer interface.
189
type MockInputSigner struct {
190
        mock.Mock
191
}
192

193
// Compile-time constraint to ensure MockInputSigner implements Signer.
194
var _ Signer = (*MockInputSigner)(nil)
195

196
// SignOutputRaw generates a signature for the passed transaction according to
197
// the data within the passed SignDescriptor.
198
func (m *MockInputSigner) SignOutputRaw(tx *wire.MsgTx,
199
        signDesc *SignDescriptor) (Signature, error) {
×
200

×
201
        args := m.Called(tx, signDesc)
×
202
        if args.Get(0) == nil {
×
203
                return nil, args.Error(1)
×
204
        }
×
205

206
        return args.Get(0).(Signature), args.Error(1)
×
207
}
208

209
// ComputeInputScript generates a complete InputIndex for the passed
210
// transaction with the signature as defined within the passed SignDescriptor.
211
func (m *MockInputSigner) ComputeInputScript(tx *wire.MsgTx,
UNCOV
212
        signDesc *SignDescriptor) (*Script, error) {
×
UNCOV
213

×
UNCOV
214
        args := m.Called(tx, signDesc)
×
UNCOV
215
        if args.Get(0) == nil {
×
216
                return nil, args.Error(1)
×
217
        }
×
218

UNCOV
219
        return args.Get(0).(*Script), args.Error(1)
×
220
}
221

222
// MuSig2CreateSession creates a new MuSig2 signing session using the local key
223
// identified by the key locator.
224
func (m *MockInputSigner) MuSig2CreateSession(version MuSig2Version,
225
        locator keychain.KeyLocator, pubkey []*btcec.PublicKey,
226
        tweak *MuSig2Tweaks, pubNonces [][musig2.PubNonceSize]byte,
227
        nonces *musig2.Nonces) (*MuSig2SessionInfo, error) {
×
228

×
229
        args := m.Called(version, locator, pubkey, tweak, pubNonces, nonces)
×
230
        if args.Get(0) == nil {
×
231
                return nil, args.Error(1)
×
232
        }
×
233

234
        return args.Get(0).(*MuSig2SessionInfo), args.Error(1)
×
235
}
236

237
// MuSig2RegisterNonces registers one or more public nonces of other signing
238
// participants for a session identified by its ID.
239
func (m *MockInputSigner) MuSig2RegisterNonces(versio MuSig2SessionID,
240
        pubNonces [][musig2.PubNonceSize]byte) (bool, error) {
×
241

×
242
        args := m.Called(versio, pubNonces)
×
243
        if args.Get(0) == nil {
×
244
                return false, args.Error(1)
×
245
        }
×
246

247
        return args.Bool(0), args.Error(1)
×
248
}
249

250
// MuSig2Sign creates a partial signature using the local signing key that was
251
// specified when the session was created.
252
func (m *MockInputSigner) MuSig2Sign(sessionID MuSig2SessionID,
253
        msg [sha256.Size]byte, withSortedKeys bool) (
254
        *musig2.PartialSignature, error) {
×
255

×
256
        args := m.Called(sessionID, msg, withSortedKeys)
×
257
        if args.Get(0) == nil {
×
258
                return nil, args.Error(1)
×
259
        }
×
260

261
        return args.Get(0).(*musig2.PartialSignature), args.Error(1)
×
262
}
263

264
// MuSig2CombineSig combines the given partial signature(s) with the local one,
265
// if it already exists.
266
func (m *MockInputSigner) MuSig2CombineSig(sessionID MuSig2SessionID,
267
        partialSig []*musig2.PartialSignature) (
268
        *schnorr.Signature, bool, error) {
×
269

×
270
        args := m.Called(sessionID, partialSig)
×
271
        if args.Get(0) == nil {
×
272
                return nil, false, args.Error(2)
×
273
        }
×
274

275
        return args.Get(0).(*schnorr.Signature), args.Bool(1), args.Error(2)
×
276
}
277

278
// MuSig2Cleanup removes a session from memory to free up resources.
279
func (m *MockInputSigner) MuSig2Cleanup(sessionID MuSig2SessionID) error {
×
280
        args := m.Called(sessionID)
×
281

×
282
        return args.Error(0)
×
283
}
×
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