Merge PR #6651: More CLI cleanup
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
flag "github.com/spf13/pflag"
|
||||
"github.com/spf13/viper"
|
||||
cfg "github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
@@ -329,6 +328,7 @@ func CreateValidatorMsgFlagSet(ipDefault string) (fs *flag.FlagSet, defaultsDesc
|
||||
fsCreateValidator := flag.NewFlagSet("", flag.ContinueOnError)
|
||||
fsCreateValidator.String(FlagIP, ipDefault, "The node's public IP")
|
||||
fsCreateValidator.String(FlagNodeID, "", "The node's NodeID")
|
||||
fsCreateValidator.String(FlagMoniker, "", "The validator's (optional) moniker")
|
||||
fsCreateValidator.String(FlagWebsite, "", "The validator's (optional) website")
|
||||
fsCreateValidator.String(FlagSecurityContact, "", "The validator's (optional) security contact email")
|
||||
fsCreateValidator.String(FlagDetails, "", "The validator's (optional) details")
|
||||
@@ -353,7 +353,6 @@ func CreateValidatorMsgFlagSet(ipDefault string) (fs *flag.FlagSet, defaultsDesc
|
||||
|
||||
type TxCreateValidatorConfig struct {
|
||||
ChainID string
|
||||
From string
|
||||
NodeID string
|
||||
Moniker string
|
||||
|
||||
@@ -374,9 +373,7 @@ type TxCreateValidatorConfig struct {
|
||||
Identity string
|
||||
}
|
||||
|
||||
func PrepareConfigForTxCreateValidator(
|
||||
config *cfg.Config, flagSet *flag.FlagSet, nodeID, chainID string, valPubKey crypto.PubKey,
|
||||
) (TxCreateValidatorConfig, error) {
|
||||
func PrepareConfigForTxCreateValidator(flagSet *flag.FlagSet, moniker, nodeID, chainID string, valPubKey crypto.PubKey) (TxCreateValidatorConfig, error) {
|
||||
c := TxCreateValidatorConfig{}
|
||||
|
||||
ip, err := flagSet.GetString(FlagIP)
|
||||
@@ -413,12 +410,6 @@ func PrepareConfigForTxCreateValidator(
|
||||
}
|
||||
c.Identity = identity
|
||||
|
||||
c.ChainID = chainID
|
||||
c.From, err = flagSet.GetString(flags.FlagName)
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
|
||||
c.Amount, err = flagSet.GetString(FlagAmount)
|
||||
if err != nil {
|
||||
return c, err
|
||||
@@ -447,15 +438,12 @@ func PrepareConfigForTxCreateValidator(
|
||||
c.NodeID = nodeID
|
||||
c.TrustNode = true
|
||||
c.PubKey = sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey)
|
||||
c.Moniker = config.Moniker
|
||||
c.Website = website
|
||||
c.SecurityContact = securityContact
|
||||
c.Details = details
|
||||
c.Identity = identity
|
||||
|
||||
if config.Moniker == "" {
|
||||
c.Moniker = c.From
|
||||
}
|
||||
c.ChainID = chainID
|
||||
c.Moniker = moniker
|
||||
|
||||
if c.Amount == "" {
|
||||
c.Amount = defaultAmount
|
||||
|
||||
@@ -4,12 +4,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
cfg "github.com/tendermint/tendermint/config"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
@@ -18,21 +15,15 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {
|
||||
ip := "1.1.1.1"
|
||||
nodeID := "nodeID"
|
||||
valPubKey, _ := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, "cosmosvalconspub1zcjduepq7jsrkl9fgqk0wj3ahmfr8pgxj6vakj2wzn656s8pehh0zhv2w5as5gd80a")
|
||||
moniker := "myMoniker"
|
||||
moniker := "DefaultMoniker"
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
config func() *cfg.Config
|
||||
fsModify func(fs *pflag.FlagSet)
|
||||
expectedCfg TxCreateValidatorConfig
|
||||
}{
|
||||
{
|
||||
name: "all defaults",
|
||||
config: func() *cfg.Config {
|
||||
config := &cfg.Config{BaseConfig: cfg.TestBaseConfig()}
|
||||
config.Moniker = moniker
|
||||
return config
|
||||
},
|
||||
fsModify: func(fs *pflag.FlagSet) {
|
||||
return
|
||||
},
|
||||
@@ -50,48 +41,14 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {
|
||||
MinSelfDelegation: "1",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "If moniker is empty it sets from Flag.",
|
||||
config: func() *cfg.Config {
|
||||
config := &cfg.Config{BaseConfig: cfg.TestBaseConfig()}
|
||||
config.Moniker = ""
|
||||
|
||||
return config
|
||||
},
|
||||
fsModify: func(fs *pflag.FlagSet) {
|
||||
fs.Set(flags.FlagName, "theNameFlag")
|
||||
},
|
||||
expectedCfg: TxCreateValidatorConfig{
|
||||
IP: ip,
|
||||
From: "theNameFlag",
|
||||
Moniker: "theNameFlag",
|
||||
ChainID: chainID,
|
||||
NodeID: nodeID,
|
||||
TrustNode: true,
|
||||
PubKey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey),
|
||||
Amount: "100000000stake",
|
||||
CommissionRate: "0.1",
|
||||
CommissionMaxRate: "0.2",
|
||||
CommissionMaxChangeRate: "0.01",
|
||||
MinSelfDelegation: "1",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Custom amount",
|
||||
config: func() *cfg.Config {
|
||||
config := &cfg.Config{BaseConfig: cfg.TestBaseConfig()}
|
||||
config.Moniker = ""
|
||||
|
||||
return config
|
||||
},
|
||||
fsModify: func(fs *pflag.FlagSet) {
|
||||
fs.Set(flags.FlagName, "theNameFlag")
|
||||
fs.Set(FlagAmount, "2000stake")
|
||||
},
|
||||
expectedCfg: TxCreateValidatorConfig{
|
||||
IP: ip,
|
||||
From: "theNameFlag",
|
||||
Moniker: "theNameFlag",
|
||||
Moniker: moniker,
|
||||
ChainID: chainID,
|
||||
NodeID: nodeID,
|
||||
TrustNode: true,
|
||||
@@ -105,20 +62,12 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Custom commission rate",
|
||||
config: func() *cfg.Config {
|
||||
config := &cfg.Config{BaseConfig: cfg.TestBaseConfig()}
|
||||
config.Moniker = ""
|
||||
|
||||
return config
|
||||
},
|
||||
fsModify: func(fs *pflag.FlagSet) {
|
||||
fs.Set(flags.FlagName, "theNameFlag")
|
||||
fs.Set(FlagCommissionRate, "0.54")
|
||||
},
|
||||
expectedCfg: TxCreateValidatorConfig{
|
||||
IP: ip,
|
||||
From: "theNameFlag",
|
||||
Moniker: "theNameFlag",
|
||||
Moniker: moniker,
|
||||
ChainID: chainID,
|
||||
NodeID: nodeID,
|
||||
TrustNode: true,
|
||||
@@ -132,20 +81,12 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Custom commission max rate",
|
||||
config: func() *cfg.Config {
|
||||
config := &cfg.Config{BaseConfig: cfg.TestBaseConfig()}
|
||||
config.Moniker = ""
|
||||
|
||||
return config
|
||||
},
|
||||
fsModify: func(fs *pflag.FlagSet) {
|
||||
fs.Set(flags.FlagName, "theNameFlag")
|
||||
fs.Set(FlagCommissionMaxRate, "0.89")
|
||||
},
|
||||
expectedCfg: TxCreateValidatorConfig{
|
||||
IP: ip,
|
||||
From: "theNameFlag",
|
||||
Moniker: "theNameFlag",
|
||||
Moniker: moniker,
|
||||
ChainID: chainID,
|
||||
NodeID: nodeID,
|
||||
TrustNode: true,
|
||||
@@ -159,20 +100,12 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Custom commission max change rate",
|
||||
config: func() *cfg.Config {
|
||||
config := &cfg.Config{BaseConfig: cfg.TestBaseConfig()}
|
||||
config.Moniker = ""
|
||||
|
||||
return config
|
||||
},
|
||||
fsModify: func(fs *pflag.FlagSet) {
|
||||
fs.Set(flags.FlagName, "theNameFlag")
|
||||
fs.Set(FlagCommissionMaxChangeRate, "0.55")
|
||||
},
|
||||
expectedCfg: TxCreateValidatorConfig{
|
||||
IP: ip,
|
||||
From: "theNameFlag",
|
||||
Moniker: "theNameFlag",
|
||||
Moniker: moniker,
|
||||
ChainID: chainID,
|
||||
NodeID: nodeID,
|
||||
TrustNode: true,
|
||||
@@ -186,20 +119,12 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Custom min self delegations",
|
||||
config: func() *cfg.Config {
|
||||
config := &cfg.Config{BaseConfig: cfg.TestBaseConfig()}
|
||||
config.Moniker = ""
|
||||
|
||||
return config
|
||||
},
|
||||
fsModify: func(fs *pflag.FlagSet) {
|
||||
fs.Set(flags.FlagName, "theNameFlag")
|
||||
fs.Set(FlagMinSelfDelegation, "0.33")
|
||||
},
|
||||
expectedCfg: TxCreateValidatorConfig{
|
||||
IP: ip,
|
||||
From: "theNameFlag",
|
||||
Moniker: "theNameFlag",
|
||||
Moniker: moniker,
|
||||
ChainID: chainID,
|
||||
NodeID: nodeID,
|
||||
TrustNode: true,
|
||||
@@ -221,9 +146,7 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {
|
||||
|
||||
tc.fsModify(fs)
|
||||
|
||||
config := tc.config()
|
||||
|
||||
cvCfg, err := PrepareConfigForTxCreateValidator(config, fs, nodeID, chainID, valPubKey)
|
||||
cvCfg, err := PrepareConfigForTxCreateValidator(fs, moniker, nodeID, chainID, valPubKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, tc.expectedCfg, cvCfg)
|
||||
|
||||
Reference in New Issue
Block a user