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

lightningnetwork / lnd / 13211764208

08 Feb 2025 03:08AM UTC coverage: 49.288% (-9.5%) from 58.815%
13211764208

Pull #9489

github

calvinrzachman
itest: verify switchrpc server enforces send then track

We prevent the rpc server from allowing onion dispatches for
attempt IDs which have already been tracked by rpc clients.

This helps protect the client from leaking a duplicate onion
attempt. NOTE: This is not the only method for solving this
issue! The issue could be addressed via careful client side
programming which accounts for the uncertainty and async
nature of dispatching onions to a remote process via RPC.
This would require some lnd ChannelRouter changes for how
we intend to use these RPCs though.
Pull Request #9489: multi: add BuildOnion, SendOnion, and TrackOnion RPCs

474 of 990 new or added lines in 11 files covered. (47.88%)

27321 existing lines in 435 files now uncovered.

101192 of 205306 relevant lines covered (49.29%)

1.54 hits per line

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

0.0
/invoices/mock.go
1
package invoices
2

3
import (
4
        "context"
5

6
        "github.com/lightningnetwork/lnd/lntypes"
7
        "github.com/stretchr/testify/mock"
8
)
9

10
type MockInvoiceDB struct {
11
        mock.Mock
12
}
13

14
func NewInvoicesDBMock() *MockInvoiceDB {
×
15
        return &MockInvoiceDB{}
×
16
}
×
17

18
func (m *MockInvoiceDB) AddInvoice(invoice *Invoice,
19
        paymentHash lntypes.Hash) (uint64, error) {
×
20

×
21
        args := m.Called(invoice, paymentHash)
×
22

×
23
        addIndex, _ := args.Get(0).(uint64)
×
24

×
25
        // NOTE: this is a side effect of the AddInvoice method.
×
26
        invoice.AddIndex = addIndex
×
27

×
28
        return addIndex, args.Error(1)
×
29
}
×
30

31
func (m *MockInvoiceDB) InvoicesAddedSince(idx uint64) ([]Invoice, error) {
×
32
        args := m.Called(idx)
×
33
        invoices, _ := args.Get(0).([]Invoice)
×
34

×
35
        return invoices, args.Error(1)
×
36
}
×
37

38
func (m *MockInvoiceDB) InvoicesSettledSince(idx uint64) ([]Invoice, error) {
×
39
        args := m.Called(idx)
×
40
        invoices, _ := args.Get(0).([]Invoice)
×
41

×
42
        return invoices, args.Error(1)
×
43
}
×
44

45
func (m *MockInvoiceDB) LookupInvoice(ref InvoiceRef) (Invoice, error) {
×
46
        args := m.Called(ref)
×
47
        invoice, _ := args.Get(0).(Invoice)
×
48

×
49
        return invoice, args.Error(1)
×
50
}
×
51

52
func (m *MockInvoiceDB) FetchPendingInvoices(ctx context.Context) (
53
        map[lntypes.Hash]Invoice, error) {
×
54

×
55
        args := m.Called(ctx)
×
56
        return args.Get(0).(map[lntypes.Hash]Invoice), args.Error(1)
×
57
}
×
58

59
func (m *MockInvoiceDB) QueryInvoices(q InvoiceQuery) (InvoiceSlice, error) {
×
60
        args := m.Called(q)
×
61
        invoiceSlice, _ := args.Get(0).(InvoiceSlice)
×
62

×
63
        return invoiceSlice, args.Error(1)
×
64
}
×
65

66
func (m *MockInvoiceDB) UpdateInvoice(ref InvoiceRef, setIDHint *SetID,
67
        callback InvoiceUpdateCallback) (*Invoice, error) {
×
68

×
69
        args := m.Called(ref, setIDHint, callback)
×
70
        invoice, _ := args.Get(0).(*Invoice)
×
71

×
72
        return invoice, args.Error(1)
×
73
}
×
74

75
func (m *MockInvoiceDB) DeleteInvoice(invoices []InvoiceDeleteRef) error {
×
76
        args := m.Called(invoices)
×
77

×
78
        return args.Error(0)
×
79
}
×
80

81
func (m *MockInvoiceDB) DeleteCanceledInvoices(ctx context.Context) error {
×
82
        args := m.Called(ctx)
×
83

×
84
        return args.Error(0)
×
85
}
×
86

87
// MockHtlcModifier is a mock implementation of the HtlcModifier interface.
88
type MockHtlcModifier struct {
89
        mock.Mock
90
}
91

92
// Intercept generates a new intercept session for the given invoice.
93
// The call blocks until the client has responded to the request or an
94
// error occurs. The response callback is only called if a session was
95
// created in the first place, which is only the case if a client is
96
// registered.
97
func (m *MockHtlcModifier) Intercept(
UNCOV
98
        req HtlcModifyRequest, callback func(HtlcModifyResponse)) error {
×
UNCOV
99

×
UNCOV
100
        // If no expectations are set, return nil by default.
×
UNCOV
101
        if len(m.ExpectedCalls) == 0 {
×
UNCOV
102
                return nil
×
UNCOV
103
        }
×
104

UNCOV
105
        args := m.Called(req, callback)
×
UNCOV
106

×
UNCOV
107
        // If a response was provided to the mock, execute the callback with it.
×
UNCOV
108
        if response, ok := args.Get(1).(HtlcModifyResponse); ok &&
×
UNCOV
109
                callback != nil {
×
UNCOV
110

×
UNCOV
111
                callback(response)
×
UNCOV
112
        }
×
113

UNCOV
114
        return args.Error(0)
×
115
}
116

117
// RegisterInterceptor sets the client callback function that will be
118
// called when an invoice is intercepted. If a callback is already set,
119
// an error is returned. The returned function must be used to reset the
120
// callback to nil once the client is done or disconnects. The read-only channel
121
// closes when the server stops.
122
func (m *MockHtlcModifier) RegisterInterceptor(HtlcModifyCallback) (func(),
123
        <-chan struct{}, error) {
×
124

×
125
        return func() {}, make(chan struct{}), nil
×
126
}
127

128
// Ensure that MockHtlcModifier implements the HtlcInterceptor and HtlcModifier
129
// interfaces.
130
var _ HtlcInterceptor = (*MockHtlcModifier)(nil)
131
var _ HtlcModifier = (*MockHtlcModifier)(nil)
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