go-ethereum/internal/cli/server/command_test.go
Pratik Patil e62beee1b2 internal/cli: use config file for flags in new-cli, builder/files: update defaults (#457)
* updated simple.json and simple.hcl

* added annotations for developer and grpc block

* added toml tags and simple.toml file

* added support for toml config files

* updated simple files toml, hcl, json

* added config.toml in builder/files and updated bor.service

* add dumpconfig command in cli for exporting configs

* update docs

* updated .goreleaser.yml (POS-651)

* changed --config to -config

* added test config for tests and fixed lint errors

* made fields of type big.int and time.Duration private, removed merge from dumpconfig, setting up default values to the Raw fields in dumpconfig, and fixed one lint error

* fixed lint errors (strange)

* lint fix

* private no-more, using '-' in name tags to ignore

* updated name tags, made c.configFile as a stringFlag (only one config file supported) and updated the merge logic in command.go -> Run()

* fix: set method for big.Int flags, added a TODO

* handeled bigInt and timeDuration type, bug fix in config_legacy, lint fix

* updated flags, consistent across flags.go and config.go

* fixed config test and updated test hcl, json config files

* updated config legacy test

* added test to check values of cmd flags, restructured Run in command.go, linter fix

* fix linters

* lint again

* changed 2 flags and assert -> require

* changed the 2 flags back

* updated correct congig.toml path and made mainnet default

* updated config.toml with new flags

* added sample config (toml) file

* removed sample-config.toml and added it in docs/config.md

Co-authored-by: Manav Darji <manavdarji.india@gmail.com>
2022-07-29 17:12:30 -07:00

50 lines
1.4 KiB
Go

package server
import (
"math/big"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestFlags(t *testing.T) {
t.Parallel()
var c Command
args := []string{
"--txpool.rejournal", "30m0s",
"--txpool.lifetime", "30m0s",
"--miner.gasprice", "20000000000",
"--gpo.maxprice", "70000000000",
"--gpo.ignoreprice", "1",
"--cache.trie.rejournal", "40m0s",
"--dev",
"--dev.period", "2",
"--datadir", "./data",
"--maxpeers", "30",
"--requiredblocks", "a=b",
"--http.api", "eth,web3,bor",
}
err := c.extractFlags(args)
require.NoError(t, err)
txRe, _ := time.ParseDuration("30m0s")
txLt, _ := time.ParseDuration("30m0s")
caRe, _ := time.ParseDuration("40m0s")
require.Equal(t, c.config.DataDir, "./data")
require.Equal(t, c.config.Developer.Enabled, true)
require.Equal(t, c.config.Developer.Period, uint64(2))
require.Equal(t, c.config.TxPool.Rejournal, txRe)
require.Equal(t, c.config.TxPool.LifeTime, txLt)
require.Equal(t, c.config.Sealer.GasPrice, big.NewInt(20000000000))
require.Equal(t, c.config.Gpo.MaxPrice, big.NewInt(70000000000))
require.Equal(t, c.config.Gpo.IgnorePrice, big.NewInt(1))
require.Equal(t, c.config.Cache.Rejournal, caRe)
require.Equal(t, c.config.P2P.MaxPeers, uint64(30))
require.Equal(t, c.config.RequiredBlocks, map[string]string{"a": "b"})
require.Equal(t, c.config.JsonRPC.Http.API, []string{"eth", "web3", "bor"})
}