-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ioctl] Build hdwallet derive command line into new ioctl #3418
Merged
CoderZhi
merged 22 commits into
iotexproject:master
from
LuckyPigeon:dev_hdwallet_derive
Jun 30, 2022
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
ca74a4b
[ioctl] build hdwallet derive command line into new ioctl
LuckyPigeon 6f1fbe8
Merge branch 'master' into dev_hdwallet_derive
LuckyPigeon 3c51320
inline DeriveKey
LuckyPigeon 899aa8b
adjust order
LuckyPigeon d2ae909
revert DeriveKey inline
LuckyPigeon 0f77970
Merge branch 'master' into dev_hdwallet_derive
LuckyPigeon f3cb430
create ExportHdwallet client interface
LuckyPigeon 0a1fa1b
Merge branch 'master' into dev_hdwallet_derive
huof6829 a56fa05
[ioctl] create main for ioctl/newcmd (#3296)
huof6829 0c8f894
change return type of HdwalletMnemonic
LuckyPigeon c4c4447
refactor unit test to cover the modification
LuckyPigeon 23aca4e
Merge branch 'master' into dev_hdwallet_derive
LuckyPigeon c6f16ee
refactor unit test to cover the modification
LuckyPigeon 78c2154
Merge branch 'master' into dev_hdwallet_derive
LuckyPigeon 941bf73
Merge branch 'master' into dev_hdwallet_derive
CoderZhi 10d72e2
Merge branch 'master' into dev_hdwallet_derive
LuckyPigeon 8384ca3
Merge branch 'master' into dev_hdwallet_derive
LuckyPigeon af4ed34
Merge branch 'master' into dev_hdwallet_derive
LuckyPigeon cef0bd5
fix commit
LuckyPigeon 5c61230
Merge branch 'master' into dev_hdwallet_derive
LuckyPigeon f2df4c1
Merge branch 'master' into dev_hdwallet_derive
LuckyPigeon 71a0a44
fix commit
LuckyPigeon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ | ||
// Copyright (c) 2022 IoTeX Foundation | ||
// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no | ||
// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent | ||
// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache | ||
// License 2.0 that can be found in the LICENSE file. | ||
|
||
package hdwallet | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/pkg/errors" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/iotexproject/iotex-core/ioctl/config" | ||
"github.com/iotexproject/iotex-core/ioctl/util" | ||
"github.com/iotexproject/iotex-core/test/mock/mock_ioctlclient" | ||
LuckyPigeon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
func TestNewHdwalletDeriveCmd(t *testing.T) { | ||
require := require.New(t) | ||
ctrl := gomock.NewController(t) | ||
client := mock_ioctlclient.NewMockClient(ctrl) | ||
mnemonic := "lake stove quarter shove dry matrix hire split wide attract argue core" | ||
|
||
client.EXPECT().SelectTranslation(gomock.Any()).Return("mockTranslationString", config.English).Times(6) | ||
client.EXPECT().ReadSecret().Return("cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", nil).Times(2) | ||
|
||
t.Run("get address from hdwallet", func(t *testing.T) { | ||
client.EXPECT().HdwalletMnemonic(gomock.Any()).Return(mnemonic, nil) | ||
|
||
cmd := NewHdwalletDeriveCmd(client) | ||
result, err := util.ExecuteCmd(cmd, "1/1/2") | ||
require.NoError(err) | ||
require.Contains(result, "address: io1pt2wml6v2tx683ctjn3k9mfgq97zx4c7rzwfuf") | ||
}) | ||
|
||
t.Run("invalid hdwallet key format", func(t *testing.T) { | ||
expectedErr := errors.New("invalid hdwallet key format") | ||
|
||
cmd := NewHdwalletDeriveCmd(client) | ||
_, err := util.ExecuteCmd(cmd, "1") | ||
require.Contains(err.Error(), expectedErr.Error()) | ||
}) | ||
|
||
t.Run("failed to export mnemonic", func(t *testing.T) { | ||
expectedErr := errors.New("failed to export mnemonic") | ||
client.EXPECT().HdwalletMnemonic(gomock.Any()).Return("", expectedErr) | ||
|
||
cmd := NewHdwalletDeriveCmd(client) | ||
_, err := util.ExecuteCmd(cmd, "1/1/2") | ||
require.Contains(err.Error(), expectedErr.Error()) | ||
}) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is it changed to client?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you're talking about
HdwalletMnemonic
.The main reason is that we don't want to expose
hdwalletConfigFile
, so we add it inclient
struct, which makes all the related function also needs to be inside the client interface.