-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathconfig_max_operator_fee_test.go
More file actions
117 lines (96 loc) · 3.07 KB
/
Copy pathconfig_max_operator_fee_test.go
File metadata and controls
117 lines (96 loc) · 3.07 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
package waved
import (
"testing"
"github.com/stretchr/testify/require"
)
// TestConfigValidateRejectsZeroMaxOperatorFee asserts that a
// non-positive MaxOperatorFeeSat fails validation. This closes the
// lazy-integrator fail-open where an unset cap would silently
// accept any server-quoted operator fee under the #270 seal-time
// handshake.
func TestConfigValidateRejectsZeroMaxOperatorFee(t *testing.T) {
t.Parallel()
cases := []struct {
name string
value int64
}{
{
name: "zero",
value: 0,
},
{
name: "negative",
value: -1,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
cfg := DefaultConfig()
cfg.Network = "regtest"
cfg.Server.Host = "127.0.0.1:10010"
cfg.Wallet.EsploraURL = "http://127.0.0.1:3000"
cfg.MaxOperatorFeeSat = tc.value
err := cfg.Validate()
require.Error(t, err)
require.Contains(t, err.Error(),
"maxoperatorfeesat")
})
}
}
// TestConfigValidateAcceptsPositiveMaxOperatorFee asserts a
// positive cap is accepted.
func TestConfigValidateAcceptsPositiveMaxOperatorFee(t *testing.T) {
t.Parallel()
cfg := DefaultConfig()
cfg.Network = "regtest"
cfg.Server.Host = "127.0.0.1:10010"
cfg.Wallet.EsploraURL = "http://127.0.0.1:3000"
cfg.MaxOperatorFeeSat = 500_000
require.NoError(t, cfg.Validate())
}
// TestDefaultConfigHasPositiveMaxOperatorFee locks in the default:
// DefaultConfig must produce a cap >0 so a user who builds from
// defaults never runs with fee rejection fail-closed by accident.
func TestDefaultConfigHasPositiveMaxOperatorFee(t *testing.T) {
t.Parallel()
cfg := DefaultConfig()
require.Positive(t, cfg.MaxOperatorFeeSat)
require.Equal(t, DefaultMaxOperatorFeeSat, cfg.MaxOperatorFeeSat)
}
// TestDefaultConfigDisablesAutomaticRefreshBudgets verifies the optional
// maintenance-specific caps preserve existing behavior unless configured.
func TestDefaultConfigDisablesAutomaticRefreshBudgets(t *testing.T) {
t.Parallel()
cfg := DefaultConfig()
require.Zero(t, cfg.AutoRefreshFeeFloorSat)
require.Zero(t, cfg.AutoRefreshFeeRatePPM)
}
// TestConfigValidateAutomaticRefreshBudgets checks both public policy bounds.
func TestConfigValidateAutomaticRefreshBudgets(t *testing.T) {
t.Parallel()
newConfig := func() *Config {
cfg := DefaultConfig()
cfg.Network = "regtest"
cfg.Server.Host = "127.0.0.1:10010"
cfg.Wallet.EsploraURL = "http://127.0.0.1:3000"
return cfg
}
negativeFloor := newConfig()
negativeFloor.AutoRefreshFeeFloorSat = -1
err := negativeFloor.Validate()
require.ErrorContains(t, err, "autorefreshfeefloorsat")
invalidRate := newConfig()
invalidRate.AutoRefreshFeeRatePPM = 1_000_001
err = invalidRate.Validate()
require.ErrorContains(t, err, "autorefreshfeerateppm")
floorAboveGlobal := newConfig()
floorAboveGlobal.AutoRefreshFeeFloorSat =
floorAboveGlobal.MaxOperatorFeeSat + 1
err = floorAboveGlobal.Validate()
require.ErrorContains(t, err, "must not exceed maxoperatorfeesat")
valid := newConfig()
valid.AutoRefreshFeeFloorSat = 10_000
valid.AutoRefreshFeeRatePPM = 25_000
require.NoError(t, valid.Validate())
}