forked from lightningnetwork/lnd
-
Notifications
You must be signed in to change notification settings - Fork 2
/
config_test.go
132 lines (121 loc) · 3.01 KB
/
config_test.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
package contractcourt
import (
"testing"
"github.com/btcsuite/btcd/btcutil"
"github.com/stretchr/testify/require"
)
// TestBudgetConfigValidate checks that the budget config validation works as
// expected.
func TestBudgetConfigValidate(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
cfg *BudgetConfig
expectedErrStr string
}{
{
name: "valid config",
cfg: DefaultBudgetConfig(),
},
{
name: "nil config",
cfg: nil,
expectedErrStr: "no budget config set",
},
{
name: "invalid tolocal",
cfg: &BudgetConfig{ToLocal: -1},
expectedErrStr: "tolocal",
},
{
name: "invalid tolocalratio",
cfg: &BudgetConfig{ToLocalRatio: -1},
expectedErrStr: "tolocalratio",
},
{
name: "invalid anchorcpfp",
cfg: &BudgetConfig{AnchorCPFP: -1},
expectedErrStr: "anchorcpfp",
},
{
name: "invalid anchorcpfpratio",
cfg: &BudgetConfig{AnchorCPFPRatio: -1},
expectedErrStr: "anchorcpfpratio",
},
{
name: "invalid deadlinehtlc",
cfg: &BudgetConfig{DeadlineHTLC: -1},
expectedErrStr: "deadlinehtlc",
},
{
name: "invalid deadlinehtlcratio",
cfg: &BudgetConfig{DeadlineHTLCRatio: -1},
expectedErrStr: "deadlinehtlcratio",
},
{
name: "invalid nodeadlinehtlc",
cfg: &BudgetConfig{NoDeadlineHTLC: -1},
expectedErrStr: "nodeadlinehtlc",
},
{
name: "invalid nodeadlinehtlcratio",
cfg: &BudgetConfig{NoDeadlineHTLCRatio: -1},
expectedErrStr: "nodeadlinehtlcratio",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := tc.cfg.Validate()
if tc.expectedErrStr == "" {
require.NoError(t, err)
return
}
require.ErrorContains(t, err, tc.expectedErrStr)
})
}
}
// TestCalculateBudget checks that the budget calculation works as expected.
func TestCalculateBudget(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
value btcutil.Amount
ratio float64
max btcutil.Amount
expected btcutil.Amount
}{
{
// When the ratio is not specified, the default 0.5
// should be used.
name: "use default ratio",
value: btcutil.Amount(1000),
ratio: 0,
max: 0,
expected: btcutil.Amount(500),
},
{
// When the ratio is specified, the default is not
// used.
name: "use specified ratio",
value: btcutil.Amount(1000),
ratio: 0.1,
max: 0,
expected: btcutil.Amount(100),
},
{
// When the max is specified, the budget should be
// capped at that value.
name: "budget capped at max",
value: btcutil.Amount(1000),
ratio: 0.1,
max: btcutil.Amount(1),
expected: btcutil.Amount(1),
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
budget := calculateBudget(tc.value, tc.ratio, tc.max)
require.Equal(t, tc.expected, budget)
})
}
}