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

lightningnetwork / lnd / 11216766535

07 Oct 2024 01:37PM UTC coverage: 57.817% (-1.0%) from 58.817%
11216766535

Pull #9148

github

ProofOfKeags
lnwire: remove kickoff feerate from propose/commit
Pull Request #9148: DynComms [2/n]: lnwire: add authenticated wire messages for Dyn*

571 of 879 new or added lines in 16 files covered. (64.96%)

23253 existing lines in 251 files now uncovered.

99022 of 171268 relevant lines covered (57.82%)

38420.67 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/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)
93✔
30

93✔
31
        return op.(wire.OutPoint)
93✔
32
}
93✔
33

93✔
34
// RequiredTxOut returns a non-nil TxOut if input commits to a certain
93✔
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)
21✔
40

21✔
41
        if txOut == nil {
21✔
42
                return nil
21✔
43
        }
35✔
44

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

7✔
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

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

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

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

×
UNCOV
66
        return wt.(WitnessType)
×
67
}
68

33✔
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

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

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

5✔
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
        }
×
UNCOV
97

×
98
        return s.(*Script), args.Error(1)
×
99
}
UNCOV
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

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

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

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

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

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

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

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

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

×
139
// String returns a human readable version of the WitnessType.
UNCOV
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

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

7✔
157
// SizeUpperBound returns the maximum length of the witness of this WitnessType
7✔
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()
UNCOV
163

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

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

172
        return args.Error(0)
173
}
174

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

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

×
UNCOV
183
// SignOutputRaw generates a signature for the passed transaction according to
×
UNCOV
184
// the data within the passed SignDescriptor.
×
UNCOV
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,
UNCOV
199
        signDesc *SignDescriptor) (*Script, error) {
×
UNCOV
200

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

UNCOV
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,
22✔
213
        tweak *MuSig2Tweaks, pubNonces [][musig2.PubNonceSize]byte,
22✔
214
        nonces *musig2.Nonces) (*MuSig2SessionInfo, error) {
22✔
215

22✔
216
        args := m.Called(version, locator, pubkey, tweak, pubNonces, nonces)
×
217
        if args.Get(0) == nil {
×
218
                return nil, args.Error(1)
219
        }
22✔
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,
UNCOV
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
        }
UNCOV
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,
UNCOV
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
        }
UNCOV
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