Skip to content

Commit bfd8198

Browse files
committed
add validate to config
1 parent 17b3d0d commit bfd8198

File tree

8 files changed

+21
-12
lines changed

8 files changed

+21
-12
lines changed

apps/testapp/cmd/init_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestInitCommand(t *testing.T) {
4343
rollconf.AddGlobalFlags(cmd, "testapp")
4444

4545
// Set home flag to the test directory
46-
cmd.SetArgs([]string{"init", "--home", dir, "--rollkit.node.aggregator", "--rollkit.signer.passphrase", "test"})
46+
cmd.SetArgs([]string{"init", "--home", dir, "--rollkit.node.aggregator", "--rollkit.signer.passphrase", "test", "--chain_id", "ev-1"})
4747

4848
// Execute the command
4949
err = cmd.Execute()

block/namespace_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,15 @@ func TestLegacyNamespaceDetection(t *testing.T) {
225225
if tt.namespace != "" {
226226
assert.Equal(t, tt.namespace, headerNS)
227227
} else {
228-
assert.Equal(t, "rollkit-headers", headerNS) // Default
228+
assert.Equal(t, "", headerNS) // Default
229229
}
230230

231231
if tt.dataNamespace != "" {
232232
assert.Equal(t, tt.dataNamespace, dataNS)
233233
} else if tt.namespace != "" {
234234
assert.Equal(t, tt.namespace, dataNS)
235235
} else {
236-
assert.Equal(t, "rollkit-headers", dataNS) // Falls back to default namespace
236+
assert.Equal(t, "", dataNS) // Falls back to default namespace
237237
}
238238

239239
// Test actual behavior in fetchBlobs

pkg/cmd/p2p_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func TestNetInfoCmd_Success(t *testing.T) {
9696
rootCmd := &cobra.Command{Use: "root"}
9797
rootCmd.PersistentFlags().String(config.FlagRootDir, tempDir, "Root directory for config and data")
9898
rootCmd.PersistentFlags().String(config.FlagRPCAddress, rpcAddr, "RPC listen address")
99+
rootCmd.PersistentFlags().String(config.FlagDANamespace, "ev-namespace", "DA Namespace")
99100

100101
err = v.BindPFlag(config.FlagRootDir, rootCmd.PersistentFlags().Lookup(config.FlagRootDir))
101102
require.NoError(err)
@@ -174,6 +175,7 @@ func TestNetInfoCmd_NoPeers(t *testing.T) {
174175
rootCmd := &cobra.Command{Use: "root"}
175176
rootCmd.PersistentFlags().String(config.FlagRootDir, tempDir, "Root directory for config and data")
176177
rootCmd.PersistentFlags().String(config.FlagRPCAddress, rpcAddr, "RPC listen address")
178+
rootCmd.PersistentFlags().String(config.FlagDANamespace, "ev-namespace", "DA Namespace")
177179

178180
err = v.BindPFlag(config.FlagRootDir, rootCmd.PersistentFlags().Lookup(config.FlagRootDir))
179181
require.NoError(err)

pkg/cmd/run_node.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ func ParseConfig(cmd *cobra.Command) (rollconf.Config, error) {
3636
return rollconf.Config{}, fmt.Errorf("failed to validate node config: %w", err)
3737
}
3838

39+
if nodeConfig.DA.Namespace == "" {
40+
return rollconf.Config{}, errors.New("namespace cannot be empty")
41+
}
42+
3943
return nodeConfig, nil
4044
}
4145

pkg/cmd/run_node_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func TestAggregatorFlagInvariants(t *testing.T) {
159159
validValues := []bool{false, true, true}
160160

161161
for i, flags := range flagVariants {
162-
args := append([]string{"start"}, flags...)
162+
args := append([]string{"start", "--evnode.da.namespace=ev-namespace"}, flags...)
163163

164164
executor, sequencer, dac, keyProvider, p2pClient, ds, stopDAHeightTicker := createTestComponents(context.Background(), t)
165165
defer stopDAHeightTicker()
@@ -209,9 +209,9 @@ func TestDefaultAggregatorValue(t *testing.T) {
209209
// Create a new command without specifying any flags
210210
var args []string
211211
if tc.expected {
212-
args = []string{"start", "--rollkit.node.aggregator"}
212+
args = []string{"start", "--evnode.node.aggregator", "--evnode.da.namespace=ev-namespace"}
213213
} else {
214-
args = []string{"start", "--rollkit.node.aggregator=false"}
214+
args = []string{"start", "--evnode.da.namespace=ev-namespace"}
215215
}
216216

217217
if err := newRunNodeCmd.ParseFlags(args); err != nil {
@@ -277,6 +277,7 @@ func TestCentralizedAddresses(t *testing.T) {
277277
args := []string{
278278
"start",
279279
"--rollkit.da.address=http://central-da:26657",
280+
"--rollkit.da.namespace=ev-namespace",
280281
}
281282

282283
executor, sequencer, dac, keyProvider, p2pClient, ds, stopDAHeightTicker := createTestComponents(context.Background(), t)

pkg/cmd/store_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"path/filepath"
88
"testing"
99

10+
"github.com/evstack/ev-node/pkg/config"
1011
"github.com/spf13/cobra"
1112
"github.com/stretchr/testify/require"
1213
)
@@ -60,7 +61,8 @@ func TestStoreUnsafeCleanCmd(t *testing.T) {
6061

6162
// Create a root command and add the subcommand
6263
rootCmd := &cobra.Command{Use: "root"}
63-
rootCmd.PersistentFlags().String("home", tempDir, "root directory")
64+
rootCmd.PersistentFlags().String(config.FlagRootDir, tempDir, "root directory")
65+
rootCmd.PersistentFlags().String(config.FlagDANamespace, "ev-namespace", "DA Namespace")
6466
rootCmd.AddCommand(StoreUnsafeCleanCmd)
6567

6668
// Capture output

pkg/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (d *DAConfig) GetNamespace() string {
168168
if d.Namespace != "" {
169169
return d.Namespace
170170
}
171-
return "rollkit-headers" // Default value
171+
return "" // Default value is empty string
172172
}
173173

174174
// GetDataNamespace returns the namespace for data submissions, falling back to the header namespace if not set
@@ -227,7 +227,7 @@ type RPCConfig struct {
227227
// It creates the directory if it does not exist.
228228
func (c *Config) Validate() error {
229229
if c.RootDir == "" {
230-
return fmt.Errorf("root directory cannot be empty")
230+
return errors.New("root directory cannot be empty")
231231
}
232232

233233
fullDir := filepath.Dir(c.ConfigPath())

pkg/config/config_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestDefaultConfig(t *testing.T) {
2727
assert.Equal(t, float64(-1), def.DA.GasPrice)
2828
assert.Equal(t, float64(0), def.DA.GasMultiplier)
2929
assert.Equal(t, "", def.DA.SubmitOptions)
30-
assert.Equal(t, "rollkit-headers", def.DA.Namespace)
30+
assert.Equal(t, "", def.DA.Namespace)
3131
assert.Equal(t, 1*time.Second, def.Node.BlockTime.Duration)
3232
assert.Equal(t, 6*time.Second, def.DA.BlockTime.Duration)
3333
assert.Equal(t, uint64(0), def.DA.StartHeight)
@@ -300,10 +300,10 @@ func TestDAConfig_GetDataNamespace(t *testing.T) {
300300
expectedNamespace: "namespace",
301301
},
302302
{
303-
name: "Both empty, use default value from default namespace",
303+
name: "Both empty, return empty string",
304304
dataNamespace: "",
305305
defaultNamespace: "",
306-
expectedNamespace: "rollkit-headers",
306+
expectedNamespace: "",
307307
},
308308
}
309309

0 commit comments

Comments
 (0)