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

lightningnetwork / lnd / 9915780197

13 Jul 2024 12:30AM UTC coverage: 49.268% (-9.1%) from 58.413%
9915780197

push

github

web-flow
Merge pull request #8653 from ProofOfKeags/fn-prim

DynComms [0/n]: `fn` package additions

92837 of 188433 relevant lines covered (49.27%)

1.55 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/keychain"
12
        "github.com/lightningnetwork/lnd/lntypes"
13
        "github.com/stretchr/testify/mock"
14
)
15

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

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

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

×
31
        return op.(wire.OutPoint)
×
32
}
×
33

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

×
41
        if txOut == nil {
×
42
                return nil
×
43
        }
×
44

45
        return txOut.(*wire.TxOut)
×
46
}
47

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

×
53
        return args.Get(0).(uint32), args.Bool(1)
×
54
}
×
55

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

×
61
        wt := args.Get(0)
×
62
        if wt == nil {
×
63
                return nil
×
64
        }
×
65

66
        return wt.(WitnessType)
×
67
}
68

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

×
74
        sd := args.Get(0)
×
75
        if sd == nil {
×
76
                return nil
×
77
        }
×
78

79
        return sd.(*SignDescriptor)
×
80
}
81

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

×
91
        args := m.Called(signer, txn, hashCache, prevOutputFetcher, txinIdx)
×
92

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

98
        return s.(*Script), args.Error(1)
×
99
}
100

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

×
107
        return args.Get(0).(uint32)
×
108
}
×
109

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

×
115
        return args.Get(0).(uint32)
×
116
}
×
117

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

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

127
        return info.(*TxInfo)
×
128
}
129

130
// MockWitnessType implements the `WitnessType` interface and is used by other
131
// packages for mock testing.
132
type MockWitnessType struct {
133
        mock.Mock
134
}
135

136
// Compile time assertion that MockWitnessType implements WitnessType.
137
var _ WitnessType = (*MockWitnessType)(nil)
138

139
// String returns a human readable version of the WitnessType.
140
func (m *MockWitnessType) String() string {
×
141
        args := m.Called()
×
142

×
143
        return args.String(0)
×
144
}
×
145

146
// WitnessGenerator will return a WitnessGenerator function that an output uses
147
// to generate the witness and optionally the sigScript for a sweep
148
// transaction.
149
func (m *MockWitnessType) WitnessGenerator(signer Signer,
150
        descriptor *SignDescriptor) WitnessGenerator {
×
151

×
152
        args := m.Called()
×
153

×
154
        return args.Get(0).(WitnessGenerator)
×
155
}
×
156

157
// SizeUpperBound returns the maximum length of the witness of this WitnessType
158
// if it would be included in a tx. It also returns if the output itself is a
159
// nested p2sh output, if so then we need to take into account the extra
160
// sigScript data size.
161
func (m *MockWitnessType) SizeUpperBound() (lntypes.WeightUnit, bool, error) {
×
162
        args := m.Called()
×
163

×
164
        return args.Get(0).(lntypes.WeightUnit), args.Bool(1), args.Error(2)
×
165
}
×
166

167
// AddWeightEstimation adds the estimated size of the witness in bytes to the
168
// given weight estimator.
169
func (m *MockWitnessType) AddWeightEstimation(e *TxWeightEstimator) error {
×
170
        args := m.Called()
×
171

×
172
        return args.Error(0)
×
173
}
×
174

175
// MockInputSigner is a mock implementation of the Signer interface.
176
type MockInputSigner struct {
177
        mock.Mock
178
}
179

180
// Compile-time constraint to ensure MockInputSigner implements Signer.
181
var _ Signer = (*MockInputSigner)(nil)
182

183
// SignOutputRaw generates a signature for the passed transaction according to
184
// the data within the passed SignDescriptor.
185
func (m *MockInputSigner) SignOutputRaw(tx *wire.MsgTx,
186
        signDesc *SignDescriptor) (Signature, error) {
×
187

×
188
        args := m.Called(tx, signDesc)
×
189
        if args.Get(0) == nil {
×
190
                return nil, args.Error(1)
×
191
        }
×
192

193
        return args.Get(0).(Signature), args.Error(1)
×
194
}
195

196
// ComputeInputScript generates a complete InputIndex for the passed
197
// transaction with the signature as defined within the passed SignDescriptor.
198
func (m *MockInputSigner) ComputeInputScript(tx *wire.MsgTx,
199
        signDesc *SignDescriptor) (*Script, 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).(*Script), args.Error(1)
×
207
}
208

209
// MuSig2CreateSession creates a new MuSig2 signing session using the local key
210
// identified by the key locator.
211
func (m *MockInputSigner) MuSig2CreateSession(version MuSig2Version,
212
        locator keychain.KeyLocator, pubkey []*btcec.PublicKey,
213
        tweak *MuSig2Tweaks, pubNonces [][musig2.PubNonceSize]byte,
214
        nonces *musig2.Nonces) (*MuSig2SessionInfo, error) {
×
215

×
216
        args := m.Called(version, locator, pubkey, tweak, pubNonces, nonces)
×
217
        if args.Get(0) == nil {
×
218
                return nil, args.Error(1)
×
219
        }
×
220

221
        return args.Get(0).(*MuSig2SessionInfo), args.Error(1)
×
222
}
223

224
// MuSig2RegisterNonces registers one or more public nonces of other signing
225
// participants for a session identified by its ID.
226
func (m *MockInputSigner) MuSig2RegisterNonces(versio MuSig2SessionID,
227
        pubNonces [][musig2.PubNonceSize]byte) (bool, error) {
×
228

×
229
        args := m.Called(versio, pubNonces)
×
230
        if args.Get(0) == nil {
×
231
                return false, args.Error(1)
×
232
        }
×
233

234
        return args.Bool(0), args.Error(1)
×
235
}
236

237
// MuSig2Sign creates a partial signature using the local signing key that was
238
// specified when the session was created.
239
func (m *MockInputSigner) MuSig2Sign(sessionID MuSig2SessionID,
240
        msg [sha256.Size]byte, withSortedKeys bool) (
241
        *musig2.PartialSignature, error) {
×
242

×
243
        args := m.Called(sessionID, msg, withSortedKeys)
×
244
        if args.Get(0) == nil {
×
245
                return nil, args.Error(1)
×
246
        }
×
247

248
        return args.Get(0).(*musig2.PartialSignature), args.Error(1)
×
249
}
250

251
// MuSig2CombineSig combines the given partial signature(s) with the local one,
252
// if it already exists.
253
func (m *MockInputSigner) MuSig2CombineSig(sessionID MuSig2SessionID,
254
        partialSig []*musig2.PartialSignature) (
255
        *schnorr.Signature, bool, error) {
×
256

×
257
        args := m.Called(sessionID, partialSig)
×
258
        if args.Get(0) == nil {
×
259
                return nil, false, args.Error(2)
×
260
        }
×
261

262
        return args.Get(0).(*schnorr.Signature), args.Bool(1), args.Error(2)
×
263
}
264

265
// MuSig2Cleanup removes a session from memory to free up resources.
266
func (m *MockInputSigner) MuSig2Cleanup(sessionID MuSig2SessionID) error {
×
267
        args := m.Called(sessionID)
×
268

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