-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_utils.go
111 lines (81 loc) · 2.53 KB
/
test_utils.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
package lrc
import (
"fmt"
"time"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/stretchr/testify/mock"
)
type TestLogger struct{}
func (t *TestLogger) Infof(template string, args ...interface{}) {
fmt.Printf("INFO:"+template+"\n", args...)
}
func (t *TestLogger) Debugf(template string, args ...interface{}) {
fmt.Printf("DBG:"+template+"\n", args...)
}
// MockClock implements the `clock.Clock` interface.
type MockBucket struct {
mock.Mock
}
// Compile time assertion that MockClock implements clock.Clock.
var _ resourceBucketer = (*MockBucket)(nil)
func (m *MockBucket) addHTLC(protected bool, amount lnwire.MilliSatoshi) bool {
args := m.Called(protected, amount)
return args.Get(0).(bool)
}
func (m *MockBucket) removeHTLC(protected bool, amount lnwire.MilliSatoshi) {
m.Called(protected, amount)
}
const mockProposedFee = 1000
// mockProposedHtlc returns a proposed htlc over the channel pair provided.
func mockProposedHtlc(chanIn, chanOut uint64, idx int,
endorsed bool) *ProposedHTLC {
return &ProposedHTLC{
IncomingChannel: lnwire.NewShortChanIDFromInt(chanIn),
OutgoingChannel: lnwire.NewShortChanIDFromInt(chanOut),
IncomingIndex: idx,
IncomingEndorsed: NewEndorsementSignal(endorsed),
IncomingAmount: 10000 + mockProposedFee,
OutgoingAmount: 10000,
CltvExpiryDelta: 80,
}
}
func resolutionForProposed(proposed *ProposedHTLC, success bool,
settleTS time.Time) *ResolvedHTLC {
return &ResolvedHTLC{
IncomingChannel: proposed.IncomingChannel,
IncomingIndex: proposed.IncomingIndex,
OutgoingChannel: proposed.OutgoingChannel,
Success: success,
TimestampSettled: settleTS,
}
}
// MockTarget mocks out revenueMontior.
type MockTarget struct {
mock.Mock
}
func (m *MockTarget) AddInFlight(incomingReputation IncomingReputation,
htlc *ProposedHTLC) ForwardDecision {
args := m.Called(incomingReputation, htlc)
return args.Get(0).(ForwardDecision)
}
func (m *MockTarget) ResolveInFlight(htlc *ResolvedHTLC,
inFlight *InFlightHTLC) error {
return m.Called(htlc, inFlight).Error(0)
}
type MockReputation struct {
mock.Mock
}
func (m *MockReputation) AddInFlight(htlc *ProposedHTLC,
outgoingDecision ForwardOutcome) error {
args := m.Called(htlc, outgoingDecision)
return args.Error(0)
}
func (m *MockReputation) ResolveInFlight(htlc *ResolvedHTLC) (*InFlightHTLC,
error) {
args := m.Called(htlc)
return args.Get(0).(*InFlightHTLC), args.Error(1)
}
func (m *MockReputation) IncomingReputation() IncomingReputation {
args := m.Called()
return args.Get(0).(IncomingReputation)
}