-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmocks.go
184 lines (157 loc) · 5.12 KB
/
mocks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package lsps2
import (
"context"
"errors"
"fmt"
"time"
"github.com/GoWebProd/uuid7"
"github.com/breez/lspd/chain"
"github.com/breez/lspd/common"
"github.com/breez/lspd/history"
"github.com/breez/lspd/lightning"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/wire"
)
var ErrNotImplemented = errors.New("not implemented")
type mockNodesService struct {
node *common.Node
err error
}
func (m *mockNodesService) GetNode(token string) (*common.Node, error) {
return m.node, m.err
}
func (m *mockNodesService) GetNodes() []*common.Node {
return []*common.Node{m.node}
}
type mockOpeningService struct {
menu []*common.OpeningFeeParams
err error
invalid bool
isCurrentChainFeeCheaper bool
}
func (m *mockOpeningService) GetFeeParamsMenu(
token string,
privateKey *btcec.PrivateKey,
) ([]*common.OpeningFeeParams, error) {
return m.menu, m.err
}
func (m *mockOpeningService) ValidateOpeningFeeParams(
params *common.OpeningFeeParams,
publicKey *btcec.PublicKey,
) bool {
return !m.invalid
}
func (m *mockOpeningService) IsCurrentChainFeeCheaper(
token string,
params *common.OpeningFeeParams,
) bool {
return m.isCurrentChainFeeCheaper
}
type mockLsps2Store struct {
err error
req *RegisterBuy
registrations map[uint64]*BuyRegistration
delay time.Duration
}
func (s *mockLsps2Store) RegisterBuy(ctx context.Context, req *RegisterBuy) error {
s.req = req
return s.err
}
func (s *mockLsps2Store) GetBuyRegistration(ctx context.Context, scid lightning.ShortChannelID) (*BuyRegistration, error) {
if s.delay.Nanoseconds() != 0 {
<-time.After(s.delay)
}
reg, ok := s.registrations[uint64(scid)]
if !ok {
return nil, ErrNotFound
}
return reg, nil
}
func (s *mockLsps2Store) SetChannelOpened(ctx context.Context, channelOpened *ChannelOpened) error {
return s.err
}
func (s *mockLsps2Store) SetCompleted(ctx context.Context, registrationId uuid7.UUID) error {
return nil
}
func (s *mockLsps2Store) SavePromises(ctx context.Context, req *SavePromises) error {
return nil
}
func (s *mockLsps2Store) RemoveUnusedExpired(ctx context.Context, before time.Time) error {
return nil
}
type mockHistoryStore struct{}
func (s *mockHistoryStore) UpdateChannels(ctx context.Context, updates []*history.ChannelUpdate) error {
return nil
}
func (s *mockHistoryStore) InsertForwards(ctx context.Context, forwards []*history.Forward, nodeId []byte) error {
return nil
}
func (s *mockHistoryStore) UpdateForwards(ctx context.Context, forwards []*history.Forward, nodeId []byte) error {
return nil
}
func (s *mockHistoryStore) FetchClnForwardOffsets(ctx context.Context, nodeId []byte) (uint64, uint64, error) {
return 0, 0, ErrNotImplemented
}
func (s *mockHistoryStore) SetClnForwardOffsets(ctx context.Context, nodeId []byte, created uint64, updated uint64) error {
return nil
}
func (s *mockHistoryStore) FetchLndForwardOffset(ctx context.Context, nodeId []byte) (*time.Time, error) {
return nil, ErrNotImplemented
}
func (s *mockHistoryStore) AddOpenChannelHtlc(ctx context.Context, htlc *history.OpenChannelHtlc) error {
return nil
}
type mockLightningClient struct {
openResponses []*wire.OutPoint
openRequests []*lightning.OpenChannelRequest
getChanRequests []*wire.OutPoint
getChanResponses []*lightning.GetChannelResult
}
func (c *mockLightningClient) GetInfo() (*lightning.GetInfoResult, error) {
return nil, ErrNotImplemented
}
func (c *mockLightningClient) IsConnected(destination []byte) (bool, error) {
return false, ErrNotImplemented
}
func (c *mockLightningClient) OpenChannel(req *lightning.OpenChannelRequest) (*wire.OutPoint, error) {
c.openRequests = append(c.openRequests, req)
if len(c.openResponses) < len(c.openRequests) {
return nil, fmt.Errorf("no responses available")
}
res := c.openResponses[len(c.openRequests)-1]
if res == nil {
return nil, fmt.Errorf("no response available")
}
return res, nil
}
func (c *mockLightningClient) GetChannel(peerID []byte, channelPoint wire.OutPoint) (*lightning.GetChannelResult, error) {
c.getChanRequests = append(c.getChanRequests, &channelPoint)
if len(c.getChanResponses) < len(c.getChanRequests) {
return nil, fmt.Errorf("no responses available")
}
res := c.getChanResponses[len(c.getChanRequests)-1]
if res == nil {
return nil, fmt.Errorf("no response available")
}
return res, nil
}
func (c *mockLightningClient) GetPeerId(scid *lightning.ShortChannelID) ([]byte, error) {
return nil, ErrNotImplemented
}
func (c *mockLightningClient) GetClosedChannels(nodeID string, channelPoints map[string]uint64) (map[string]uint64, error) {
return nil, ErrNotImplemented
}
func (c *mockLightningClient) WaitOnline(peerID []byte, deadline time.Time) error {
return ErrNotImplemented
}
func (c *mockLightningClient) WaitChannelActive(peerID []byte, deadline time.Time) error {
return ErrNotImplemented
}
func (c *mockLightningClient) ListChannels() ([]*lightning.Channel, error) {
return nil, ErrNotImplemented
}
type mockFeeEstimator struct {
}
func (f *mockFeeEstimator) EstimateFeeRate(context.Context, chain.FeeStrategy) (*chain.FeeEstimation, error) {
return nil, ErrNotImplemented
}