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
|
|
|
|
2020-04-08 02:38:28 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
|
|
|
|
2019-05-30 08:44:28 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
2020-03-25 08:20:36 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
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-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-04-08 02:38:28 -07:00
|
|
|
kb, err := keyring.New(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), kbHome, mockIn)
|
2019-11-14 06:17:21 -08:00
|
|
|
require.NoError(t, err)
|
2020-03-30 11:30:50 -07:00
|
|
|
t.Cleanup(func() {
|
2020-04-08 02:38:28 -07:00
|
|
|
kb.Delete("keyname1") // nolint:errcheck
|
2020-03-30 11:30:50 -07:00
|
|
|
})
|
|
|
|
|
2020-04-08 02:38:28 -07:00
|
|
|
path := sdk.GetConfig().GetFullFundraiserPath()
|
|
|
|
_, err = kb.NewAccount("keyname1", tests.TestMnemonic, "", path, hd.Secp256k1)
|
2019-11-14 06:17:21 -08:00
|
|
|
require.NoError(t, err)
|
2019-05-30 08:44:28 -07:00
|
|
|
|
|
|
|
// Now enter password
|
2020-03-30 11:30:50 -07:00
|
|
|
mockIn.Reset("123456789\n123456789\n")
|
2019-11-14 06:17:21 -08:00
|
|
|
require.NoError(t, runExportCmd(exportKeyCommand, []string{"keyname1"}))
|
2019-05-30 08:44:28 -07:00
|
|
|
}
|