Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/es-node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ func EsNodeInit(ctx *cli.Context) error {
}
shardIndexes := ctx.Int64Slice(shardIndexFlagName)
lg.Info("Read flag", "name", shardIndexFlagName, "value", shardIndexes)
for _, shardIndex := range shardIndexes {
if shardIndex < 0 {
return fmt.Errorf("%s must be non-negative: %d", shardIndexFlagName, shardIndex)
}
}
shardLen := 0
if len(shardIndexes) == 0 {
shards := ctx.Int(shardLenFlagName)
Expand Down
40 changes: 40 additions & 0 deletions cmd/es-node/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2022-2023, EthStorage.
// For license information, see https://github.com/ethstorage/es-node/blob/main/LICENSE

package main

import (
"testing"

"github.com/ethstorage/go-ethstorage/ethstorage/flags"
"github.com/urfave/cli"
)

func TestEsNodeInitRejectsNegativeShardIndex(t *testing.T) {
app := cli.NewApp()
app.Commands = []cli.Command{
{
Name: "init",
Flags: []cli.Flag{
cli.IntFlag{Name: encodingTypeFlagName},
cli.Int64SliceFlag{Name: shardIndexFlagName},
flags.DataDir,
flags.L1NodeAddr,
flags.StorageL1Contract,
},
Action: EsNodeInit,
},
}

err := app.Run([]string{
"es-node", "init",
"--encoding_type", "0",
"--shard_index=-1",
"--datadir", t.TempDir(),
"--l1.rpc", "invalid://rpc",
"--storage.l1contract", "0x0000000000000000000000000000000000000001",
})
if err == nil || err.Error() != "shard_index must be non-negative: -1" {
t.Fatalf("expected negative shard index error, got %v", err)
}
}