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

lightningnetwork / lnd / 13980275562

20 Mar 2025 10:06PM UTC coverage: 58.6% (-10.2%) from 68.789%
13980275562

Pull #9623

github

web-flow
Merge b9b960345 into 09b674508
Pull Request #9623: Size msg test msg

0 of 1518 new or added lines in 42 files covered. (0.0%)

26603 existing lines in 443 files now uncovered.

96807 of 165200 relevant lines covered (58.6%)

1.82 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/v2"
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
func (m *MockInput) Preimage() fn.Option[lntypes.Preimage] {
×
144
        args := m.Called()
×
145

×
146
        info := args.Get(0)
×
147
        if info == nil {
×
148
                return fn.None[lntypes.Preimage]()
×
149
        }
×
150

151
        return info.(fn.Option[lntypes.Preimage])
×
152
}
153

154
// MockWitnessType implements the `WitnessType` interface and is used by other
155
// packages for mock testing.
156
type MockWitnessType struct {
157
        mock.Mock
158
}
159

160
// Compile time assertion that MockWitnessType implements WitnessType.
161
var _ WitnessType = (*MockWitnessType)(nil)
162

163
// String returns a human readable version of the WitnessType.
UNCOV
164
func (m *MockWitnessType) String() string {
×
UNCOV
165
        args := m.Called()
×
UNCOV
166

×
UNCOV
167
        return args.String(0)
×
UNCOV
168
}
×
169

170
// WitnessGenerator will return a WitnessGenerator function that an output uses
171
// to generate the witness and optionally the sigScript for a sweep
172
// transaction.
173
func (m *MockWitnessType) WitnessGenerator(signer Signer,
174
        descriptor *SignDescriptor) WitnessGenerator {
×
175

×
176
        args := m.Called()
×
177

×
178
        return args.Get(0).(WitnessGenerator)
×
179
}
×
180

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

×
UNCOV
188
        return args.Get(0).(lntypes.WeightUnit), args.Bool(1), args.Error(2)
×
UNCOV
189
}
×
190

191
// AddWeightEstimation adds the estimated size of the witness in bytes to the
192
// given weight estimator.
193
func (m *MockWitnessType) AddWeightEstimation(e *TxWeightEstimator) error {
×
194
        args := m.Called()
×
195

×
196
        return args.Error(0)
×
197
}
×
198

199
// MockInputSigner is a mock implementation of the Signer interface.
200
type MockInputSigner struct {
201
        mock.Mock
202
}
203

204
// Compile-time constraint to ensure MockInputSigner implements Signer.
205
var _ Signer = (*MockInputSigner)(nil)
206

207
// SignOutputRaw generates a signature for the passed transaction according to
208
// the data within the passed SignDescriptor.
209
func (m *MockInputSigner) SignOutputRaw(tx *wire.MsgTx,
210
        signDesc *SignDescriptor) (Signature, error) {
×
211

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

217
        return args.Get(0).(Signature), args.Error(1)
×
218
}
219

220
// ComputeInputScript generates a complete InputIndex for the passed
221
// transaction with the signature as defined within the passed SignDescriptor.
222
func (m *MockInputSigner) ComputeInputScript(tx *wire.MsgTx,
UNCOV
223
        signDesc *SignDescriptor) (*Script, error) {
×
UNCOV
224

×
UNCOV
225
        args := m.Called(tx, signDesc)
×
UNCOV
226
        if args.Get(0) == nil {
×
227
                return nil, args.Error(1)
×
228
        }
×
229

UNCOV
230
        return args.Get(0).(*Script), args.Error(1)
×
231
}
232

233
// MuSig2CreateSession creates a new MuSig2 signing session using the local key
234
// identified by the key locator.
235
func (m *MockInputSigner) MuSig2CreateSession(version MuSig2Version,
236
        locator keychain.KeyLocator, pubkey []*btcec.PublicKey,
237
        tweak *MuSig2Tweaks, pubNonces [][musig2.PubNonceSize]byte,
238
        nonces *musig2.Nonces) (*MuSig2SessionInfo, error) {
×
239

×
240
        args := m.Called(version, locator, pubkey, tweak, pubNonces, nonces)
×
241
        if args.Get(0) == nil {
×
242
                return nil, args.Error(1)
×
243
        }
×
244

245
        return args.Get(0).(*MuSig2SessionInfo), args.Error(1)
×
246
}
247

248
// MuSig2RegisterNonces registers one or more public nonces of other signing
249
// participants for a session identified by its ID.
250
func (m *MockInputSigner) MuSig2RegisterNonces(versio MuSig2SessionID,
251
        pubNonces [][musig2.PubNonceSize]byte) (bool, error) {
×
252

×
253
        args := m.Called(versio, pubNonces)
×
254
        if args.Get(0) == nil {
×
255
                return false, args.Error(1)
×
256
        }
×
257

258
        return args.Bool(0), args.Error(1)
×
259
}
260

261
// MuSig2Sign creates a partial signature using the local signing key that was
262
// specified when the session was created.
263
func (m *MockInputSigner) MuSig2Sign(sessionID MuSig2SessionID,
264
        msg [sha256.Size]byte, withSortedKeys bool) (
265
        *musig2.PartialSignature, error) {
×
266

×
267
        args := m.Called(sessionID, msg, withSortedKeys)
×
268
        if args.Get(0) == nil {
×
269
                return nil, args.Error(1)
×
270
        }
×
271

272
        return args.Get(0).(*musig2.PartialSignature), args.Error(1)
×
273
}
274

275
// MuSig2CombineSig combines the given partial signature(s) with the local one,
276
// if it already exists.
277
func (m *MockInputSigner) MuSig2CombineSig(sessionID MuSig2SessionID,
278
        partialSig []*musig2.PartialSignature) (
279
        *schnorr.Signature, bool, error) {
×
280

×
281
        args := m.Called(sessionID, partialSig)
×
282
        if args.Get(0) == nil {
×
283
                return nil, false, args.Error(2)
×
284
        }
×
285

286
        return args.Get(0).(*schnorr.Signature), args.Bool(1), args.Error(2)
×
287
}
288

289
// MuSig2Cleanup removes a session from memory to free up resources.
290
func (m *MockInputSigner) MuSig2Cleanup(sessionID MuSig2SessionID) error {
×
291
        args := m.Called(sessionID)
×
292

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