cosmos-sdk/x/genutil/client/cli/migrate_test.go
Alexander Bezobchuk 9ebda4edb9
Server/simd: Viper Removal (#6599)
* init commit

* remove viper from tm cmds

* updates

* Undo x/bank/client/cli/tx.go

* Fix unit tests

* lint++

* rename var

* Fix genutil test

* fix test

* prefer cmd.Flags() over direct viper usage

* update

* fix ABCI error tests

* fix integration tests

* Add viper to context

* fix build

* fix unit test

* Implement and use AppOptions

* Revert Redact godoc

Co-authored-by: Alessio Treglia <alessio@tendermint.com>
2020-07-05 16:56:17 +00:00

64 lines
1.8 KiB
Go

package cli
import (
"io/ioutil"
"path"
"testing"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
"github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/libs/log"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/tests"
)
func setupCmd(genesisTime string, chainID string) *cobra.Command {
c := &cobra.Command{
Use: "c",
Args: cobra.ArbitraryArgs,
Run: func(_ *cobra.Command, args []string) {},
}
c.Flags().String(flagGenesisTime, genesisTime, "")
c.Flags().String(flagChainID, chainID, "")
return c
}
func TestGetMigrationCallback(t *testing.T) {
for _, version := range GetMigrationVersions() {
require.NotNil(t, GetMigrationCallback(version))
}
}
func TestMigrateGenesis(t *testing.T) {
home, cleanup := tests.NewTestCaseDir(t)
t.Cleanup(cleanup)
viper.Set(cli.HomeFlag, home)
viper.Set(flags.FlagName, "moniker")
logger := log.NewNopLogger()
cfg, err := tcmd.ParseConfig()
require.Nil(t, err)
ctx := server.NewContext(viper.New(), cfg, logger)
cdc := makeCodec()
genesisPath := path.Join(home, "genesis.json")
target := "v0.36"
// Reject if we dont' have the right parameters or genesis does not exists
require.Error(t, MigrateGenesisCmd(ctx, cdc).RunE(nil, []string{target, genesisPath}))
// Noop migration with minimal genesis
emptyGenesis := []byte(`{"chain_id":"test","app_state":{}}`)
err = ioutil.WriteFile(genesisPath, emptyGenesis, 0644)
require.Nil(t, err)
cmd := setupCmd("", "test2")
require.NoError(t, MigrateGenesisCmd(ctx, cdc).RunE(cmd, []string{target, genesisPath}))
// Every migration function shuold tests its own module separately
}