2019-09-30 08:49:12 -07:00
|
|
|
package keys
|
|
|
|
|
|
|
|
import (
|
2020-10-08 10:41:35 -07:00
|
|
|
"context"
|
2020-07-06 12:50:09 -07:00
|
|
|
"fmt"
|
2019-09-30 08:49:12 -07:00
|
|
|
"testing"
|
|
|
|
|
2021-03-01 04:41:49 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2020-04-08 02:38:28 -07:00
|
|
|
"github.com/otiai10/copy"
|
2020-07-06 12:50:09 -07:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-04-08 02:38:28 -07:00
|
|
|
|
2019-09-30 08:49:12 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
2020-07-06 12:50:09 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
2020-07-09 05:21:20 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/testutil"
|
2019-09-30 08:49:12 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_runMigrateCmd(t *testing.T) {
|
2020-09-18 04:08:24 -07:00
|
|
|
kbHome := t.TempDir()
|
2020-10-08 10:41:35 -07:00
|
|
|
clientCtx := client.Context{}.WithKeyringDir(kbHome)
|
|
|
|
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)
|
|
|
|
|
2021-03-01 04:41:49 -08:00
|
|
|
require.NoError(t, copy.Copy("testdata", kbHome))
|
2019-09-30 08:49:12 -07:00
|
|
|
|
2021-03-01 04:41:49 -08:00
|
|
|
cmd := MigrateCommand()
|
2020-07-20 08:12:33 -07:00
|
|
|
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())
|
2021-03-01 04:41:49 -08:00
|
|
|
//mockIn := testutil.ApplyMockIODiscardOutErr(cmd)
|
|
|
|
mockIn, mockOut := testutil.ApplyMockIO(cmd)
|
2020-07-06 12:50:09 -07:00
|
|
|
|
|
|
|
cmd.SetArgs([]string{
|
2021-03-01 04:41:49 -08:00
|
|
|
kbHome,
|
|
|
|
//fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome),
|
2020-07-06 12:50:09 -07:00
|
|
|
fmt.Sprintf("--%s=true", flags.FlagDryRun),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest),
|
|
|
|
})
|
|
|
|
|
2021-03-01 04:41:49 -08:00
|
|
|
mockIn.Reset("\n12345678\n\n\n\n\n")
|
|
|
|
t.Log(mockOut.String())
|
2020-10-08 10:41:35 -07:00
|
|
|
assert.NoError(t, cmd.ExecuteContext(ctx))
|
2019-09-30 08:49:12 -07:00
|
|
|
}
|