Gaiad gentx optional flags (#3897)
Add website, details and identity to gentx Closes: #3858
This commit is contained in:
parent
82d437f206
commit
8550d14071
|
@ -0,0 +1 @@
|
||||||
|
#3858 add website, details and identity to gentx cli command
|
|
@ -47,6 +47,7 @@ func GenTxCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "gentx",
|
Use: "gentx",
|
||||||
Short: "Generate a genesis tx carrying a self delegation",
|
Short: "Generate a genesis tx carrying a self delegation",
|
||||||
|
Args: cobra.NoArgs,
|
||||||
Long: fmt.Sprintf(`This command is an alias of the 'gaiad tx create-validator' command'.
|
Long: fmt.Sprintf(`This command is an alias of the 'gaiad tx create-validator' command'.
|
||||||
|
|
||||||
It creates a genesis piece carrying a self delegation with the
|
It creates a genesis piece carrying a self delegation with the
|
||||||
|
@ -111,8 +112,12 @@ following delegation and commission default parameters:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
website := viper.GetString(cli.FlagWebsite)
|
||||||
|
details := viper.GetString(cli.FlagDetails)
|
||||||
|
identity := viper.GetString(cli.FlagIdentity)
|
||||||
|
|
||||||
// Set flags for creating gentx
|
// Set flags for creating gentx
|
||||||
prepareFlagsForTxCreateValidator(config, nodeID, ip, genDoc.ChainID, valPubKey)
|
prepareFlagsForTxCreateValidator(config, nodeID, ip, genDoc.ChainID, valPubKey, website, details, identity)
|
||||||
|
|
||||||
// Fetch the amount of coins staked
|
// Fetch the amount of coins staked
|
||||||
amount := viper.GetString(cli.FlagAmount)
|
amount := viper.GetString(cli.FlagAmount)
|
||||||
|
@ -200,6 +205,9 @@ following delegation and commission default parameters:
|
||||||
"write the genesis transaction JSON document to the given file instead of the default location")
|
"write the genesis transaction JSON document to the given file instead of the default location")
|
||||||
cmd.Flags().String(cli.FlagIP, ip, "The node's public IP")
|
cmd.Flags().String(cli.FlagIP, ip, "The node's public IP")
|
||||||
cmd.Flags().String(cli.FlagNodeID, "", "The node's NodeID")
|
cmd.Flags().String(cli.FlagNodeID, "", "The node's NodeID")
|
||||||
|
cmd.Flags().String(cli.FlagWebsite, "", "The validator's (optional) website")
|
||||||
|
cmd.Flags().String(cli.FlagDetails, "", "The validator's (optional) details")
|
||||||
|
cmd.Flags().String(cli.FlagIdentity, "", "The (optional) identity signature (ex. UPort or Keybase)")
|
||||||
cmd.Flags().AddFlagSet(cli.FsCommissionCreate)
|
cmd.Flags().AddFlagSet(cli.FsCommissionCreate)
|
||||||
cmd.Flags().AddFlagSet(cli.FsMinSelfDelegation)
|
cmd.Flags().AddFlagSet(cli.FsMinSelfDelegation)
|
||||||
cmd.Flags().AddFlagSet(cli.FsAmount)
|
cmd.Flags().AddFlagSet(cli.FsAmount)
|
||||||
|
@ -237,9 +245,8 @@ func accountInGenesis(genesisState app.GenesisState, key sdk.AccAddress, coins s
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareFlagsForTxCreateValidator(
|
func prepareFlagsForTxCreateValidator(
|
||||||
config *cfg.Config, nodeID, ip, chainID string, valPubKey crypto.PubKey,
|
config *cfg.Config, nodeID, ip, chainID string, valPubKey crypto.PubKey, website, details, identity string,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
viper.Set(tmcli.HomeFlag, viper.GetString(flagClientHome))
|
viper.Set(tmcli.HomeFlag, viper.GetString(flagClientHome))
|
||||||
viper.Set(client.FlagChainID, chainID)
|
viper.Set(client.FlagChainID, chainID)
|
||||||
viper.Set(client.FlagFrom, viper.GetString(client.FlagName))
|
viper.Set(client.FlagFrom, viper.GetString(client.FlagName))
|
||||||
|
@ -247,6 +254,9 @@ func prepareFlagsForTxCreateValidator(
|
||||||
viper.Set(cli.FlagIP, ip)
|
viper.Set(cli.FlagIP, ip)
|
||||||
viper.Set(cli.FlagPubKey, sdk.MustBech32ifyConsPub(valPubKey))
|
viper.Set(cli.FlagPubKey, sdk.MustBech32ifyConsPub(valPubKey))
|
||||||
viper.Set(cli.FlagMoniker, config.Moniker)
|
viper.Set(cli.FlagMoniker, config.Moniker)
|
||||||
|
viper.Set(cli.FlagWebsite, website)
|
||||||
|
viper.Set(cli.FlagDetails, details)
|
||||||
|
viper.Set(cli.FlagIdentity, identity)
|
||||||
|
|
||||||
if config.Moniker == "" {
|
if config.Moniker == "" {
|
||||||
viper.Set(cli.FlagMoniker, viper.GetString(client.FlagName))
|
viper.Set(cli.FlagMoniker, viper.GetString(client.FlagName))
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
package init
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/server"
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/staking/client/cli"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||||
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
|
"github.com/tendermint/tendermint/crypto"
|
||||||
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_prepareFlagsForTxCreateValidator(t *testing.T) {
|
||||||
|
defer server.SetupViper(t)()
|
||||||
|
defer setupClientHome(t)()
|
||||||
|
config, err := tcmd.ParseConfig()
|
||||||
|
require.Nil(t, err)
|
||||||
|
logger := log.NewNopLogger()
|
||||||
|
ctx := server.NewContext(config, logger)
|
||||||
|
|
||||||
|
valPubKey, _ := sdk.GetConsPubKeyBech32("cosmosvalconspub1zcjduepq7jsrkl9fgqk0wj3ahmfr8pgxj6vakj2wzn656s8pehh0zhv2w5as5gd80a")
|
||||||
|
|
||||||
|
type args struct {
|
||||||
|
config *cfg.Config
|
||||||
|
nodeID string
|
||||||
|
ip string
|
||||||
|
chainID string
|
||||||
|
valPubKey crypto.PubKey
|
||||||
|
website string
|
||||||
|
details string
|
||||||
|
identity string
|
||||||
|
}
|
||||||
|
|
||||||
|
type extraParams struct {
|
||||||
|
amount string
|
||||||
|
commissionRate string
|
||||||
|
commissionMaxRate string
|
||||||
|
commissionMaxChangeRate string
|
||||||
|
minSelfDelegation string
|
||||||
|
}
|
||||||
|
|
||||||
|
type testcase struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
}
|
||||||
|
|
||||||
|
runTest := func(t *testing.T, tt testcase, params extraParams) {
|
||||||
|
prepareFlagsForTxCreateValidator(tt.args.config, tt.args.nodeID, tt.args.ip, tt.args.chainID, tt.args.valPubKey, tt.args.website, tt.args.details, tt.args.identity)
|
||||||
|
require.Equal(t, tt.args.website, viper.GetString(cli.FlagWebsite))
|
||||||
|
require.Equal(t, tt.args.details, viper.GetString(cli.FlagDetails))
|
||||||
|
require.Equal(t, tt.args.identity, viper.GetString(cli.FlagIdentity))
|
||||||
|
require.Equal(t, params.amount, viper.GetString(cli.FlagAmount))
|
||||||
|
require.Equal(t, params.commissionRate, viper.GetString(cli.FlagCommissionRate))
|
||||||
|
require.Equal(t, params.commissionMaxRate, viper.GetString(cli.FlagCommissionMaxRate))
|
||||||
|
require.Equal(t, params.commissionMaxChangeRate, viper.GetString(cli.FlagCommissionMaxChangeRate))
|
||||||
|
require.Equal(t, params.minSelfDelegation, viper.GetString(cli.FlagMinSelfDelegation))
|
||||||
|
}
|
||||||
|
|
||||||
|
tests := []testcase{
|
||||||
|
{"No parameters", args{ctx.Config, "X", "0.0.0.0", "chainId", valPubKey, "", "", ""}},
|
||||||
|
{"Optional parameters fed", args{ctx.Config, "X", "0.0.0.0", "chainId", valPubKey, "cosmos.network", "details", "identity"}},
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultParams := extraParams{defaultAmount, defaultCommissionRate, defaultCommissionMaxRate, defaultCommissionMaxChangeRate, defaultMinSelfDelegation}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
t.Run(tt.name, func(t *testing.T) { runTest(t, tt, defaultParams) })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Override default params
|
||||||
|
params := extraParams{"5stake", "1.0", "1.0", "1.0", "1.0"}
|
||||||
|
viper.Set(cli.FlagAmount, params.amount)
|
||||||
|
viper.Set(cli.FlagCommissionRate, params.commissionRate)
|
||||||
|
viper.Set(cli.FlagCommissionMaxRate, params.commissionMaxRate)
|
||||||
|
viper.Set(cli.FlagCommissionMaxChangeRate, params.commissionMaxChangeRate)
|
||||||
|
viper.Set(cli.FlagMinSelfDelegation, params.minSelfDelegation)
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) { runTest(t, tt, params) })
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue