Skip to content

Commit

Permalink
feat: migrate command params
Browse files Browse the repository at this point in the history
Default to app.toml, add constants for config types, remove gas-adjustment in v0.51 config
  • Loading branch information
amedumer committed Nov 13, 2023
1 parent 2a3490f commit 49a3e48
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
17 changes: 10 additions & 7 deletions tools/confix/cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import (
"cosmossdk.io/tools/confix"
)

const (
AppConfigType = "app"
ClientConfigType = "client"
)

var (
FlagStdOut bool
FlagVerbose bool
Expand All @@ -22,18 +27,18 @@ func MigrateCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "migrate [target-version] <config-path> [config-type]",
Short: "Migrate Cosmos SDK configuration file to the specified version",
Long: `Migrate the contents of the Cosmos SDK configuration (app.toml or client.toml) to the specified version.
Long: `Migrate the contents of the Cosmos SDK configuration (app.toml or client.toml) to the specified version. Configuration type is app by default.
The output is written in-place unless --stdout is provided.
In case of any error in updating the file, no output is written.`,
Args: cobra.MinimumNArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
targetVersion := args[0]
configPath := args[1]
configType := "app" // Default to app configuration
configType := AppConfigType // Default to app configuration

if len(args) > 2 {
configType = strings.ToLower(args[2])
if configType != "app" && configType != "client" {
if configType != AppConfigType && configType != ClientConfigType {
return errors.New("config type must be 'app' or 'client'")
}
}
Expand All @@ -57,7 +62,6 @@ In case of any error in updating the file, no output is written.`,
if FlagStdOut {
outputPath = ""
}


if err := confix.Upgrade(ctx, plan(rawFile, targetVersion, configType), configPath, outputPath, FlagSkipValidate); err != nil {
return fmt.Errorf("failed to migrate config: %w", err)
Expand All @@ -66,11 +70,10 @@ In case of any error in updating the file, no output is written.`,
return nil
},
}



cmd.Flags().BoolVar(&FlagStdOut, "stdout", false, "print the updated config to stdout")
cmd.Flags().BoolVar(&FlagVerbose, "verbose", false, "log changes to stderr")
cmd.Flags().BoolVar(&FlagSkipValidate, "skip-validate", false, "skip configuration validation (allows to migrate unknown configurations)")

return cmd
}
}
6 changes: 3 additions & 3 deletions tools/confix/cmd/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
)

func TestMigradeCmd(t *testing.T) {
func TestMigrateCmd(t *testing.T) {
clientCtx, cleanup := initClientContext(t)
defer cleanup()

Expand All @@ -28,13 +28,13 @@ func TestMigradeCmd(t *testing.T) {
assert.ErrorContains(t, err, "failed to migrate config")

// try to migrate from client.toml - it should work and give us a big diff
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd.MigrateCommand(), []string{"v0.46", fmt.Sprintf("%s/config/client.toml", clientCtx.HomeDir),"app", "--skip-validate", "--verbose"})
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd.MigrateCommand(), []string{"v0.46", fmt.Sprintf("%s/config/client.toml", clientCtx.HomeDir), "--skip-validate", "--verbose"})
assert.NilError(t, err)
assert.Assert(t, strings.Contains(out.String(), "add app-db-backend key"))


// this should work
out, err = clitestutil.ExecTestCLICmd(clientCtx, cmd.MigrateCommand(), []string{"v0.51", fmt.Sprintf("%s/config/client.toml", clientCtx.HomeDir),"client", "--verbose"})
assert.NilError(t, err)
assert.Assert(t, strings.Contains(out.String(), "add gas-adjustment key"))
assert.Assert(t, strings.Contains(out.String(), "add keyring-default-keyname key"))
}
3 changes: 0 additions & 3 deletions tools/confix/data/v0.51-client.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,3 @@ output = "text"
node = "tcp://localhost:26657"
# Transaction broadcasting mode (sync|async)
broadcast-mode = "sync"
# This is default the gas adjustment factor used in tx commands.
# It can be overwriten by the --gas-adjustment flag in each tx command.
gas-adjustment = 1.5

0 comments on commit 49a3e48

Please sign in to comment.