forked from dymensionxyz/dymint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
239 lines (227 loc) · 6.12 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package config
import (
"fmt"
"testing"
"time"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/dymensionxyz/dymint/da/grpc"
"github.com/dymensionxyz/dymint/settlement"
)
func TestViperAndCobra(t *testing.T) {
t.Parallel()
assert := assert.New(t)
cmd := &cobra.Command{}
AddNodeFlags(cmd)
dir := t.TempDir()
nc := DefaultConfig("", "")
EnsureRoot(dir, nc)
assert.NoError(cmd.Flags().Set(flagAggregator, "true"))
assert.NoError(cmd.Flags().Set(flagDALayer, "foobar"))
assert.NoError(cmd.Flags().Set(flagDAConfig, `{"json":true}`))
assert.NoError(cmd.Flags().Set(flagBlockTime, "1234s"))
assert.NoError(cmd.Flags().Set(flagEmptyBlocksMaxTime, "2000s"))
assert.NoError(cmd.Flags().Set(flagBatchSubmitMaxTime, "3000s"))
assert.NoError(cmd.Flags().Set(flagNamespaceID, "0102030405060708"))
assert.NoError(cmd.Flags().Set(flagBlockBatchSize, "10"))
assert.NoError(nc.GetViperConfig(cmd, dir))
assert.Equal(true, nc.Aggregator)
assert.Equal("foobar", nc.DALayer)
assert.Equal(`{"json":true}`, nc.DAConfig)
assert.Equal(1234*time.Second, nc.BlockTime)
assert.Equal("0102030405060708", nc.NamespaceID)
assert.Equal(uint64(10), nc.BlockBatchSize)
}
func TestNodeConfig_Validate(t *testing.T) {
tests := []struct {
name string
malleate func(*NodeConfig)
wantErr assert.ErrorAssertionFunc
}{
{
name: "full config",
wantErr: assert.NoError,
}, {
name: "missing block time",
malleate: func(nc *NodeConfig) {
nc.BlockTime = 0
},
wantErr: assert.Error,
}, {
name: "missing empty blocks max time",
malleate: func(nc *NodeConfig) {
nc.EmptyBlocksMaxTime = -1
},
wantErr: assert.Error,
}, {
name: "missing batch submit max time",
malleate: func(nc *NodeConfig) {
nc.BlockManagerConfig.BatchSubmitMaxTime = 0
},
wantErr: assert.Error,
}, {
name: "empty_blocks_max_time not greater than block_time",
malleate: func(nc *NodeConfig) {
nc.BlockManagerConfig.EmptyBlocksMaxTime = 1
nc.BlockManagerConfig.BlockTime = 2
},
wantErr: assert.Error,
}, {
name: "batch_submit_max_time not greater than block_time",
malleate: func(nc *NodeConfig) {
nc.BlockManagerConfig.BatchSubmitMaxTime = 1
nc.BlockManagerConfig.BlockTime = 2
},
wantErr: assert.Error,
}, {
name: "missing block batch size",
malleate: func(nc *NodeConfig) {
nc.BlockManagerConfig.BlockBatchSize = 0
},
wantErr: assert.Error,
}, {
name: "missing block batch max size bytes",
malleate: func(nc *NodeConfig) {
nc.BlockManagerConfig.BlockBatchMaxSizeBytes = 0
},
wantErr: assert.Error,
}, {
name: "missing gossiped blocks cache size",
malleate: func(nc *NodeConfig) {
nc.BlockManagerConfig.GossipedBlocksCacheSize = 0
},
wantErr: assert.Error,
}, {
name: "empty settlement layer",
malleate: func(nc *NodeConfig) {
nc.SettlementLayer = ""
},
wantErr: assert.Error,
}, {
name: "settlement: provide both fees and gas prices",
malleate: func(nc *NodeConfig) {
nc.SettlementConfig.GasPrices = "1"
nc.SettlementConfig.GasFees = "1"
},
wantErr: assert.Error,
}, {
name: "settlement: provide neither fees nor gas prices",
malleate: func(nc *NodeConfig) {
nc.SettlementConfig.GasPrices = ""
nc.SettlementConfig.GasFees = ""
},
wantErr: assert.Error,
}, {
name: "settlement: missing rollapp id",
malleate: func(nc *NodeConfig) {
nc.SettlementConfig.RollappID = ""
},
wantErr: assert.Error,
}, {
name: "settlement: mock",
malleate: func(nc *NodeConfig) {
nc.SettlementLayer = "mock"
},
wantErr: assert.NoError,
}, {
name: "DALayer: empty",
malleate: func(nc *NodeConfig) {
nc.DALayer = ""
},
wantErr: assert.Error,
}, {
name: "DALayer: mock",
malleate: func(nc *NodeConfig) {
nc.DALayer = "mock"
},
wantErr: assert.NoError,
}, {
name: "DAConfig: empty",
malleate: func(nc *NodeConfig) {
nc.DAConfig = ""
},
wantErr: assert.Error,
}, {
name: "DAGrpc.Host empty",
malleate: func(nc *NodeConfig) {
nc.DAGrpc.Host = ""
},
wantErr: assert.Error,
}, {
name: "DAGrpc.Port 0",
malleate: func(nc *NodeConfig) {
nc.DAGrpc.Port = 0
},
wantErr: assert.Error,
}, {
name: "instrumentation: missing prometheus listen addr",
malleate: func(nc *NodeConfig) {
nc.Instrumentation.PrometheusListenAddr = ""
},
wantErr: assert.Error,
}, {
name: "instrumentation: prometheus enabled, but listen addr empty",
malleate: func(nc *NodeConfig) {
nc.Instrumentation.Prometheus = true
nc.Instrumentation.PrometheusListenAddr = ""
},
wantErr: assert.Error,
}, {
name: "instrumentation: prometheus disabled, listen addr empty",
malleate: func(nc *NodeConfig) {
nc.Instrumentation.Prometheus = false
nc.Instrumentation.PrometheusListenAddr = ""
},
wantErr: assert.NoError,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
nc := fullNodeConfig()
if tt.malleate != nil {
tt.malleate(&nc)
}
tt.wantErr(t, nc.Validate(), fmt.Sprintf("Validate()"))
})
}
}
func fullNodeConfig() NodeConfig {
return NodeConfig{
BlockManagerConfig: BlockManagerConfig{
BlockTime: 1 * time.Second,
EmptyBlocksMaxTime: 2 * time.Second,
BatchSubmitMaxTime: 1 * time.Second,
NamespaceID: "test",
BlockBatchSize: 1,
BlockBatchMaxSizeBytes: 1,
GossipedBlocksCacheSize: 1,
},
DALayer: "celestia",
DAConfig: "da-config",
SettlementLayer: "dymension",
SettlementConfig: settlement.Config{
KeyringBackend: "test",
NodeAddress: "http://localhost:26657",
KeyringHomeDir: "/tmp/keyring-test",
DymAccountName: "test",
RollappID: "test_123-1",
GasLimit: 120,
GasPrices: "0.025stake",
GasFees: "",
ProposerPubKey: "test",
SLGrpc: settlement.GrpcConfig{
Host: "localhost",
Port: 9090,
RefreshTime: 1,
},
},
Instrumentation: &InstrumentationConfig{
Prometheus: true,
PrometheusListenAddr: "localhost:9090",
},
DAGrpc: grpc.Config{
Host: "localhost",
Port: 9090,
},
}
}