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
package config
import (
"testing"
"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/stretchr/testify/require"
)
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 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 {
// Should be valid using only the required arguments passed in via the constructor.
return NewConfig([]string{"http://localhost:8545"}, "./supervisor_config_testdir")
}