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

lightningnetwork / lnd / 11166428937

03 Oct 2024 05:07PM UTC coverage: 58.738% (-0.08%) from 58.817%
11166428937

push

github

web-flow
Merge pull request #8960 from lightningnetwork/0-19-staging-rebased

[custom channels 5/5]: merge custom channel staging branch into master

657 of 875 new or added lines in 29 files covered. (75.09%)

260 existing lines in 20 files now uncovered.

130540 of 222243 relevant lines covered (58.74%)

28084.43 hits per line

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

40.58
/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.
29
func (m *MockInput) OutPoint() wire.OutPoint {
93✔
30
        args := m.Called()
93✔
31
        op := args.Get(0)
93✔
32

93✔
33
        return op.(wire.OutPoint)
93✔
34
}
93✔
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.
39
func (m *MockInput) RequiredTxOut() *wire.TxOut {
21✔
40
        args := m.Called()
21✔
41
        txOut := args.Get(0)
21✔
42

21✔
43
        if txOut == nil {
35✔
44
                return nil
14✔
45
        }
14✔
46

47
        return txOut.(*wire.TxOut)
7✔
48
}
49

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

18✔
55
        return args.Get(0).(uint32), args.Bool(1)
18✔
56
}
18✔
57

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

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

68
        return wt.(WitnessType)
33✔
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.
73
func (m *MockInput) SignDesc() *SignDescriptor {
5✔
74
        args := m.Called()
5✔
75

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

81
        return sd.(*SignDescriptor)
5✔
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.
106
func (m *MockInput) BlocksToMaturity() uint32 {
3✔
107
        args := m.Called()
3✔
108

3✔
109
        return args.Get(0).(uint32)
3✔
110
}
3✔
111

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

3✔
117
        return args.Get(0).(uint32)
3✔
118
}
3✔
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

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

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

NEW
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.
153
func (m *MockWitnessType) String() string {
7✔
154
        args := m.Called()
7✔
155

7✔
156
        return args.String(0)
7✔
157
}
7✔
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.
174
func (m *MockWitnessType) SizeUpperBound() (lntypes.WeightUnit, bool, error) {
15✔
175
        args := m.Called()
15✔
176

15✔
177
        return args.Get(0).(lntypes.WeightUnit), args.Bool(1), args.Error(2)
15✔
178
}
15✔
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,
212
        signDesc *SignDescriptor) (*Script, error) {
22✔
213

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

219
        return args.Get(0).(*Script), args.Error(1)
22✔
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