2019-05-30 08:44:28 -07:00
|
|
|
package keys
|
|
|
|
|
|
|
|
import (
|
2020-07-06 12:50:09 -07:00
|
|
|
"fmt"
|
2019-05-30 08:44:28 -07:00
|
|
|
"testing"
|
|
|
|
|
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"
|
2020-07-09 05:21:20 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/testutil"
|
2020-04-08 02:38:28 -07:00
|
|
|
|
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"
|
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) {
|
2020-07-06 12:50:09 -07:00
|
|
|
cmd := ExportKeyCommand()
|
2020-07-20 08:12:33 -07:00
|
|
|
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())
|
2020-07-09 23:55:48 -07:00
|
|
|
mockIn := testutil.ApplyMockIODiscardOutErr(cmd)
|
2019-05-30 08:44:28 -07:00
|
|
|
|
|
|
|
// Now add a temporary keybase
|
2020-07-09 05:21:20 -07:00
|
|
|
kbHome, cleanUp := testutil.NewTestCaseDir(t)
|
2020-03-01 16:16:23 -08:00
|
|
|
t.Cleanup(cleanUp)
|
2019-05-30 08:44:28 -07:00
|
|
|
|
|
|
|
// create a key
|
2020-07-06 12:50:09 -07:00
|
|
|
kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, 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()
|
2020-07-09 05:21:20 -07:00
|
|
|
_, err = kb.NewAccount("keyname1", testutil.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")
|
2020-07-06 12:50:09 -07:00
|
|
|
cmd.SetArgs([]string{
|
|
|
|
"keyname1",
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest),
|
|
|
|
})
|
|
|
|
|
|
|
|
require.NoError(t, cmd.Execute())
|
2019-05-30 08:44:28 -07:00
|
|
|
}
|