cfac906f92
* WIP setting up Ethereum key CLI commands * Functional key gen and showing Ethereum address * Cleaned up changes * WIP setting up Ethereum key CLI commands * Functional key gen and showing Ethereum address * Cleaned up changes * Changed address to cosmos specific address * Remove default bech32 prefixes and add basic add command test * Changed Private key type to slice of bytes for compatibility and storability * switch back to using cosmos crypto Keybase interfaces * Changed key output to ethereum addressing instead of bitcoin and key generation to allow seeding from mnemonic and bip39 password * Updated show command and added test * Remove prefix requirement for showing keys and added existing keys commands to CLI temporarily * Removed unnecessary duplicate code * Readd prefixes for accounts temporarily * Fix linting issue * Remove TODO for setting PK to specific length of bytes (all functions use slice) * Cleaned up descriptions to remove multi-sigs
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package keys
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/spf13/viper"
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
|
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
|
|
"github.com/cosmos/cosmos-sdk/tests"
|
|
)
|
|
|
|
func TestShowKeysCmd(t *testing.T) {
|
|
cmd := showKeysCmd()
|
|
assert.NotNil(t, cmd)
|
|
assert.Equal(t, "false", cmd.Flag(FlagAddress).DefValue)
|
|
assert.Equal(t, "false", cmd.Flag(FlagPublicKey).DefValue)
|
|
}
|
|
|
|
func TestRunShowCmd(t *testing.T) {
|
|
cmd := showKeysCmd()
|
|
|
|
err := runShowCmd(cmd, []string{"invalid"})
|
|
assert.EqualError(t, err, "Key invalid not found")
|
|
|
|
// Prepare a key base
|
|
// Now add a temporary keybase
|
|
kbHome, cleanUp := tests.NewTestCaseDir(t)
|
|
defer cleanUp()
|
|
viper.Set(flags.FlagHome, kbHome)
|
|
|
|
fakeKeyName1 := "runShowCmd_Key1"
|
|
fakeKeyName2 := "runShowCmd_Key2"
|
|
kb, err := clientkeys.NewKeyBaseFromHomeFlag()
|
|
assert.NoError(t, err)
|
|
_, err = kb.CreateAccount(fakeKeyName1, tests.TestMnemonic, "", "", 0, 0)
|
|
assert.NoError(t, err)
|
|
_, err = kb.CreateAccount(fakeKeyName2, tests.TestMnemonic, "", "", 0, 1)
|
|
assert.NoError(t, err)
|
|
|
|
// // Now try single key
|
|
// err = runShowCmd(cmd, []string{fakeKeyName1})
|
|
// assert.EqualError(t, err, "invalid Bech32 prefix encoding provided: ")
|
|
|
|
// // Now try single key - set bech to acc
|
|
// viper.Set(FlagBechPrefix, sdk.PrefixAccount)
|
|
err = runShowCmd(cmd, []string{fakeKeyName1})
|
|
assert.NoError(t, err)
|
|
err = runShowCmd(cmd, []string{fakeKeyName2})
|
|
assert.NoError(t, err)
|
|
}
|