forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR cosmos#3586: Fix keybase storage of ledger accounts
- Loading branch information
1 parent
69eddb7
commit 94dccf3
Showing
11 changed files
with
161 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//+build ledger,test_ledger_mock | ||
|
||
package keys | ||
|
||
import ( | ||
"bufio" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/crypto/keys" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/spf13/viper" | ||
"github.com/tendermint/tendermint/libs/cli" | ||
|
||
"github.com/cosmos/cosmos-sdk/tests" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_runAddCmdLedger(t *testing.T) { | ||
cmd := addKeyCommand() | ||
assert.NotNil(t, cmd) | ||
|
||
// Prepare a keybase | ||
kbHome, kbCleanUp := tests.NewTestCaseDir(t) | ||
assert.NotNil(t, kbHome) | ||
defer kbCleanUp() | ||
viper.Set(cli.HomeFlag, kbHome) | ||
viper.Set(client.FlagUseLedger, true) | ||
|
||
/// Test Text | ||
viper.Set(cli.OutputFlag, OutputFormatText) | ||
// Now enter password | ||
cleanUp1 := client.OverrideStdin(bufio.NewReader(strings.NewReader("test1234\ntest1234\n"))) | ||
defer cleanUp1() | ||
err := runAddCmd(cmd, []string{"keyname1"}) | ||
assert.NoError(t, err) | ||
|
||
// Now check that it has been stored properly | ||
kb, err := NewKeyBaseFromHomeFlag() | ||
assert.NoError(t, err) | ||
assert.NotNil(t, kb) | ||
key1, err := kb.Get("keyname1") | ||
assert.NoError(t, err) | ||
assert.NotNil(t, key1) | ||
|
||
assert.Equal(t, "keyname1", key1.GetName()) | ||
assert.Equal(t, keys.TypeLedger, key1.GetType()) | ||
assert.Equal(t, | ||
"cosmospub1addwnpepqd87l8xhcnrrtzxnkql7k55ph8fr9jarf4hn6udwukfprlalu8lgw0urza0", | ||
sdk.MustBech32ifyAccPub(key1.GetPubKey())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package keys | ||
|
||
import ( | ||
"encoding/hex" | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/crypto/keys/hd" | ||
"github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/tendermint/tendermint/crypto/secp256k1" | ||
) | ||
|
||
func Test_writeReadLedgerInfo(t *testing.T) { | ||
var tmpKey secp256k1.PubKeySecp256k1 | ||
bz, _ := hex.DecodeString("035AD6810A47F073553FF30D2FCC7E0D3B1C0B74B61A1AAA2582344037151E143A") | ||
copy(tmpKey[:], bz) | ||
|
||
lInfo := ledgerInfo{ | ||
"some_name", | ||
tmpKey, | ||
*hd.NewFundraiserParams(5, 1)} | ||
assert.Equal(t, TypeLedger, lInfo.GetType()) | ||
assert.Equal(t, "44'/118'/5'/0/1", lInfo.GetPath().String()) | ||
assert.Equal(t, | ||
"cosmospub1addwnpepqddddqg2glc8x4fl7vxjlnr7p5a3czm5kcdp4239sg6yqdc4rc2r5wmxv8p", | ||
types.MustBech32ifyAccPub(lInfo.GetPubKey())) | ||
|
||
// Serialize and restore | ||
serialized := writeInfo(lInfo) | ||
restoredInfo, err := readInfo(serialized) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, restoredInfo) | ||
|
||
// Check both keys match | ||
assert.Equal(t, lInfo.GetName(), restoredInfo.GetName()) | ||
assert.Equal(t, lInfo.GetType(), restoredInfo.GetType()) | ||
assert.Equal(t, lInfo.GetPubKey(), restoredInfo.GetPubKey()) | ||
|
||
assert.Equal(t, lInfo.GetPath(), restoredInfo.(ledgerInfo).GetPath()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters