github.com/iotexproject/iotex-core@v1.14.1-rc1/ioctl/newcmd/account/accountverify_test.go (about) 1 // Copyright (c) 2022 IoTeX Foundation 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 account 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/identityset" 18 "github.com/iotexproject/iotex-core/test/mock/mock_ioctlclient" 19 ) 20 21 func TestNewAccountVerify(t *testing.T) { 22 require := require.New(t) 23 ctrl := gomock.NewController(t) 24 client := mock_ioctlclient.NewMockClient(ctrl) 25 client.EXPECT().SelectTranslation(gomock.Any()).Return("mockTranslationString", config.English).AnyTimes() 26 27 t.Run("verify account successfully", func(t *testing.T) { 28 client.EXPECT().ReadSecret().Return("cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", nil) 29 30 cmd := NewAccountVerify(client) 31 result, err := util.ExecuteCmd(cmd) 32 require.NoError(err) 33 require.Contains(result, identityset.PrivateKey(27).PublicKey().Address().String()) 34 require.Contains(result, identityset.PrivateKey(27).PublicKey().HexString()) 35 }) 36 37 t.Run("failed to covert hex string to private key", func(t *testing.T) { 38 client.EXPECT().ReadSecret().Return("1234", nil) 39 expectedErr := errors.New("invalid private key") 40 41 cmd := NewAccountVerify(client) 42 _, err := util.ExecuteCmd(cmd) 43 require.Contains(err.Error(), expectedErr.Error()) 44 }) 45 }