forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig_test.go
71 lines (60 loc) · 1.92 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
package config
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/ethereum-optimism/optimism/op-service/metrics"
"github.com/ethereum-optimism/optimism/op-service/oppprof"
"github.com/ethereum-optimism/optimism/op-service/rpc"
"github.com/ethereum-optimism/optimism/op-supervisor/supervisor/backend/depset"
"github.com/ethereum-optimism/optimism/op-supervisor/supervisor/types"
)
func TestDefaultConfigIsValid(t *testing.T) {
cfg := validConfig()
require.NoError(t, cfg.Check())
}
func TestRequireL2RPC(t *testing.T) {
cfg := validConfig()
cfg.L2RPCs = []string{}
require.ErrorIs(t, cfg.Check(), ErrMissingL2RPC)
}
func TestRequireDependencySet(t *testing.T) {
cfg := validConfig()
cfg.DependencySetSource = nil
require.ErrorIs(t, cfg.Check(), ErrMissingDependencySet)
}
func TestRequireDatadir(t *testing.T) {
cfg := validConfig()
cfg.Datadir = ""
require.ErrorIs(t, cfg.Check(), ErrMissingDatadir)
}
func TestValidateMetricsConfig(t *testing.T) {
cfg := validConfig()
cfg.MetricsConfig.Enabled = true
cfg.MetricsConfig.ListenPort = -1
require.ErrorIs(t, cfg.Check(), metrics.ErrInvalidPort)
}
func TestValidatePprofConfig(t *testing.T) {
cfg := validConfig()
cfg.PprofConfig.ListenEnabled = true
cfg.PprofConfig.ListenPort = -1
require.ErrorIs(t, cfg.Check(), oppprof.ErrInvalidPort)
}
func TestValidateRPCConfig(t *testing.T) {
cfg := validConfig()
cfg.RPC.ListenPort = -1
require.ErrorIs(t, cfg.Check(), rpc.ErrInvalidPort)
}
func validConfig() *Config {
depSet, err := depset.NewStaticConfigDependencySet(map[types.ChainID]*depset.StaticConfigDependency{
types.ChainIDFromUInt64(900): &depset.StaticConfigDependency{
ChainIndex: 900,
ActivationTime: 0,
HistoryMinTime: 0,
},
})
if err != nil {
panic(err)
}
// Should be valid using only the required arguments passed in via the constructor.
return NewConfig([]string{"http://localhost:8545"}, depSet, "./supervisor_testdir")
}