-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy patheasy_autoloop_exclusions_test.go
More file actions
118 lines (106 loc) · 3.58 KB
/
Copy patheasy_autoloop_exclusions_test.go
File metadata and controls
118 lines (106 loc) · 3.58 KB
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
package liquidity
import (
"testing"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightninglabs/lndclient"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/stretchr/testify/require"
)
// TestEasyAutoloopExcludedPeers ensures that peers listed in
// Parameters.EasyAutoloopExcludedPeers are not selected by
// pickEasyAutoloopChannel even if they would otherwise be preferred.
func TestEasyAutoloopExcludedPeers(t *testing.T) {
// Two channels, peer1 has the higher local balance and would be picked
// if not excluded.
ch1 := lndclient.ChannelInfo{
Active: true,
ChannelID: lnwire.NewShortChanIDFromInt(11).ToUint64(),
PubKeyBytes: peer1,
LocalBalance: 90000,
RemoteBalance: 0,
Capacity: 100000,
}
ch2 := lndclient.ChannelInfo{
Active: true,
ChannelID: lnwire.NewShortChanIDFromInt(22).ToUint64(),
PubKeyBytes: peer2,
LocalBalance: 80000,
RemoteBalance: 0,
Capacity: 100000,
}
params := defaultParameters
params.Autoloop = true
params.EasyAutoloop = true
params.EasyAutoloopTarget = 80000
params.ClientRestrictions.Minimum = btcutil.Amount(1)
params.ClientRestrictions.Maximum = btcutil.Amount(10000)
// Exclude peer1, even though its channel has more local balance.
params.EasyAutoloopExcludedPeers = []route.Vertex{peer1}
c := newAutoloopTestCtx(
t, params, []lndclient.ChannelInfo{ch1, ch2}, testRestrictions,
)
// Picking a channel should not pick the excluded peer's channel.
picked, err := c.manager.pickEasyAutoloopChannel(
t.Context(), []lndclient.ChannelInfo{ch1, ch2},
¶ms.ClientRestrictions, nil, nil, 1,
)
require.NoError(t, err)
require.NotNil(t, picked)
require.Equal(
t, ch2.ChannelID, picked.ChannelID,
"should pick non-excluded peer's channel",
)
}
// TestEasyAutoloopIncludeAllPeers simulates the --includealleasypeers flag by
// clearing the exclusion list and ensuring a previously excluded peer can be
// selected again.
func TestEasyAutoloopIncludeAllPeers(t *testing.T) {
ch1 := lndclient.ChannelInfo{
Active: true,
ChannelID: lnwire.NewShortChanIDFromInt(33).ToUint64(),
PubKeyBytes: peer1,
LocalBalance: 90000,
RemoteBalance: 0,
Capacity: 100000,
}
ch2 := lndclient.ChannelInfo{
Active: true,
ChannelID: lnwire.NewShortChanIDFromInt(44).ToUint64(),
PubKeyBytes: peer2,
LocalBalance: 80000,
RemoteBalance: 0,
Capacity: 100000,
}
params := defaultParameters
params.Autoloop = true
params.EasyAutoloop = true
params.EasyAutoloopTarget = 80000
params.ClientRestrictions.Minimum = btcutil.Amount(1)
params.ClientRestrictions.Maximum = btcutil.Amount(10000)
params.EasyAutoloopExcludedPeers = []route.Vertex{peer1}
c := newAutoloopTestCtx(
t, params, []lndclient.ChannelInfo{ch1, ch2}, testRestrictions,
)
// With exclusion active, peer1 should not be picked.
picked, err := c.manager.pickEasyAutoloopChannel(
t.Context(), []lndclient.ChannelInfo{ch1, ch2},
¶ms.ClientRestrictions, nil, nil, 1,
)
require.NoError(t, err)
require.NotNil(t, picked)
require.Equal(t, ch2.ChannelID, picked.ChannelID)
// Simulate --includealleasypeers by clearing the exclusion list as the
// CLI does before sending to the server.
c.manager.params.EasyAutoloopExcludedPeers = nil
picked, err = c.manager.pickEasyAutoloopChannel(
t.Context(), []lndclient.ChannelInfo{ch1, ch2},
¶ms.ClientRestrictions, nil, nil, 1,
)
require.NoError(t, err)
require.NotNil(t, picked)
require.Equal(
t, ch1.ChannelID, picked.ChannelID,
"after include-all, highest local balance should win again",
)
}