github.com/iotexproject/iotex-core@v1.14.1-rc1/ioctl/newcmd/hdwallet/hdwalletexport_test.go (about) 1 // Copyright (c) 2022 IoTeX 2 // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability 3 // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. 4 // This source code is governed by Apache License 2.0 that can be found in the LICENSE file. 5 6 package hdwallet 7 8 import ( 9 "testing" 10 11 "github.com/golang/mock/gomock" 12 "github.com/pkg/errors" 13 "github.com/stretchr/testify/require" 14 15 "github.com/iotexproject/iotex-core/ioctl/config" 16 "github.com/iotexproject/iotex-core/ioctl/util" 17 "github.com/iotexproject/iotex-core/test/mock/mock_ioctlclient" 18 ) 19 20 func TestNewHdwalletExportCmd(t *testing.T) { 21 require := require.New(t) 22 ctrl := gomock.NewController(t) 23 client := mock_ioctlclient.NewMockClient(ctrl) 24 client.EXPECT().SelectTranslation(gomock.Any()).Return("mockTranslationString", config.English).AnyTimes() 25 mnemonic := "lake stove quarter shove dry matrix hire split wide attract argue core" 26 password := "123" 27 28 t.Run("export hdwallet", func(t *testing.T) { 29 client.EXPECT().ReadSecret().Return(password, nil) 30 client.EXPECT().HdwalletMnemonic(gomock.Any()).Return(mnemonic, nil) 31 32 cmd := NewHdwalletExportCmd(client) 33 result, err := util.ExecuteCmd(cmd) 34 require.NoError(err) 35 require.Contains(result, mnemonic) 36 }) 37 38 t.Run("failed to export mnemonic", func(t *testing.T) { 39 expectedErr := errors.New("failed to export mnemonic") 40 client.EXPECT().ReadSecret().Return(password, nil) 41 client.EXPECT().HdwalletMnemonic(gomock.Any()).Return("", expectedErr) 42 43 cmd := NewHdwalletExportCmd(client) 44 _, err := util.ExecuteCmd(cmd) 45 require.Contains(err.Error(), expectedErr.Error()) 46 }) 47 }