2019-05-30 08:44:28 -07:00
|
|
|
package keys
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
2019-11-14 06:17:21 -08:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-05-30 08:44:28 -07:00
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
2020-01-14 07:40:10 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
2019-05-30 08:44:28 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/tests"
|
2020-01-22 09:54:56 -08:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-05-30 08:44:28 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_runExportCmd(t *testing.T) {
|
2019-11-14 06:17:21 -08:00
|
|
|
runningUnattended := isRunningUnattended()
|
2019-12-12 13:52:24 -08:00
|
|
|
exportKeyCommand := ExportKeyCommand()
|
2019-11-14 06:17:21 -08:00
|
|
|
mockIn, _, _ := tests.ApplyMockIO(exportKeyCommand)
|
2019-05-30 08:44:28 -07:00
|
|
|
|
|
|
|
// Now add a temporary keybase
|
|
|
|
kbHome, cleanUp := tests.NewTestCaseDir(t)
|
2020-03-01 16:16:23 -08:00
|
|
|
t.Cleanup(cleanUp)
|
2019-05-30 08:44:28 -07:00
|
|
|
viper.Set(flags.FlagHome, kbHome)
|
|
|
|
|
|
|
|
// create a key
|
2020-01-23 10:47:11 -08:00
|
|
|
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
|
2019-11-14 06:17:21 -08:00
|
|
|
require.NoError(t, err)
|
|
|
|
if !runningUnattended {
|
2020-03-01 16:16:23 -08:00
|
|
|
t.Cleanup(func() {
|
2019-11-14 06:17:21 -08:00
|
|
|
kb.Delete("keyname1", "", false)
|
2020-03-01 16:16:23 -08:00
|
|
|
})
|
2019-11-14 06:17:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if runningUnattended {
|
|
|
|
mockIn.Reset("testpass1\ntestpass1\n")
|
|
|
|
}
|
2020-01-14 07:40:10 -08:00
|
|
|
_, err = kb.CreateAccount("keyname1", tests.TestMnemonic, "", "123456789", "", keys.Secp256k1)
|
2019-11-14 06:17:21 -08:00
|
|
|
require.NoError(t, err)
|
2019-05-30 08:44:28 -07:00
|
|
|
|
|
|
|
// Now enter password
|
2019-11-14 06:17:21 -08:00
|
|
|
if runningUnattended {
|
|
|
|
mockIn.Reset("123456789\n123456789\ntestpass1\n")
|
|
|
|
} else {
|
|
|
|
mockIn.Reset("123456789\n123456789\n")
|
|
|
|
}
|
|
|
|
require.NoError(t, runExportCmd(exportKeyCommand, []string{"keyname1"}))
|
2019-05-30 08:44:28 -07:00
|
|
|
}
|