Merge branch 'rigel/new-hooks' into rigel/fee-distribution
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"path"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@@ -515,6 +516,48 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
|
||||
require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf("steak").Int64())
|
||||
}
|
||||
|
||||
func TestGaiaCLIConfig(t *testing.T) {
|
||||
require.NoError(t, os.RemoveAll(gaiacliHome))
|
||||
require.NoError(t, os.RemoveAll(gaiadHome))
|
||||
servAddr, port, err := server.FreeTCPAddr()
|
||||
require.NoError(t, err)
|
||||
node := fmt.Sprintf("%s:%s", servAddr, port)
|
||||
chainID := executeInit(t, fmt.Sprintf("gaiad init -o --name=foo --home=%s --home-client=%s", gaiadHome, gaiacliHome))
|
||||
executeWrite(t, fmt.Sprintf("gaiacli --home=%s config", gaiadHome), gaiacliHome, node, "y")
|
||||
config, err := ioutil.ReadFile(path.Join(gaiacliHome, "config", "config.toml"))
|
||||
require.NoError(t, err)
|
||||
expectedConfig := fmt.Sprintf(`chain_id = "%s"
|
||||
encoding = "btc"
|
||||
home = "%s"
|
||||
node = "%s"
|
||||
output = "text"
|
||||
trace = false
|
||||
trust_node = true
|
||||
`, chainID, gaiacliHome, node)
|
||||
require.Equal(t, expectedConfig, string(config))
|
||||
// ensure a backup gets created
|
||||
executeWrite(t, "gaiacli config", gaiacliHome, node, "y", "y")
|
||||
configBackup, err := ioutil.ReadFile(path.Join(gaiacliHome, "config", "config.toml-old"))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedConfig, string(configBackup))
|
||||
|
||||
require.NoError(t, os.RemoveAll(gaiadHome))
|
||||
executeWrite(t, "gaiacli config", gaiacliHome, node, "y")
|
||||
|
||||
// ensure it works without an initialized gaiad state
|
||||
expectedConfig = fmt.Sprintf(`chain_id = ""
|
||||
encoding = "btc"
|
||||
home = "%s"
|
||||
node = "%s"
|
||||
output = "text"
|
||||
trace = false
|
||||
trust_node = true
|
||||
`, gaiacliHome, node)
|
||||
config, err = ioutil.ReadFile(path.Join(gaiacliHome, "config", "config.toml"))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedConfig, string(config))
|
||||
}
|
||||
|
||||
//___________________________________________________________________________________
|
||||
// helper methods
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@ import (
|
||||
stakecmd "github.com/cosmos/cosmos-sdk/x/stake/client/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
|
||||
"path"
|
||||
"os"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// rootCmd is the entry point for this binary
|
||||
@@ -36,6 +39,7 @@ func main() {
|
||||
// TODO: setup keybase, viper object, etc. to be passed into
|
||||
// the below functions and eliminate global vars, like we do
|
||||
// with the cdc
|
||||
rootCmd.AddCommand(client.ConfigCmd())
|
||||
|
||||
// add standard rpc commands
|
||||
rpc.AddCommands(rootCmd)
|
||||
@@ -146,9 +150,35 @@ func main() {
|
||||
|
||||
// prepare and add flags
|
||||
executor := cli.PrepareMainCmd(rootCmd, "GA", app.DefaultCLIHome)
|
||||
err := executor.Execute()
|
||||
err := initConfig(rootCmd)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = executor.Execute()
|
||||
if err != nil {
|
||||
// handle with #870
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func initConfig(cmd *cobra.Command) error {
|
||||
home, err := cmd.PersistentFlags().GetString(cli.HomeFlag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cfgFile := path.Join(home, "config", "config.toml")
|
||||
if _, err := os.Stat(cfgFile); err == nil {
|
||||
viper.SetConfigFile(cfgFile)
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := viper.BindPFlag(cli.EncodingFlag, cmd.PersistentFlags().Lookup(cli.EncodingFlag)); err != nil {
|
||||
return err
|
||||
}
|
||||
return viper.BindPFlag(cli.OutputFlag, cmd.PersistentFlags().Lookup(cli.OutputFlag))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user