From f15d16ba1e89ccfde2dd13b0965499ded6defd9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caner=20=C3=87=C4=B1dam?= Date: Mon, 18 Dec 2017 17:08:31 +0300 Subject: [PATCH] add test cases for SelectAccount --- geth/account/accounts_test.go | 79 +++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/geth/account/accounts_test.go b/geth/account/accounts_test.go index 78120b210..5c841294b 100644 --- a/geth/account/accounts_test.go +++ b/geth/account/accounts_test.go @@ -11,6 +11,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/keystore" gethcommon "github.com/ethereum/go-ethereum/common" + whisper "github.com/ethereum/go-ethereum/whisper/whisperv5" "github.com/golang/mock/gomock" "github.com/status-im/status-go/geth/account" "github.com/status-im/status-go/geth/common" @@ -184,3 +185,81 @@ func TestCreateAndRecoverAccountFail_KeyStore(t *testing.T) { _, _, err = accManager.RecoverAccount(password, mnemonic) require.Equal(t, err, expectedErr) } + +func TestSelectAccount(t *testing.T) { + accManager, nodeManager := newTestManager(t) + + password := "some-pass" + + keyStore, keyStoreDir := newTestKeyStore(t, "accounts") + defer os.RemoveAll(keyStoreDir) //nolint: errcheck + + nodeManager.EXPECT().AccountKeyStore().Return(keyStore, nil) + addr, _, _, err := accManager.CreateAccount(password) + require.NoError(t, err) + + w := whisper.New(nil) + + testCases := []struct { + name string + accountKeyStoreReturn []interface{} + whisperServiceReturn []interface{} + address string + password string + fail bool + }{ + { + "success", + []interface{}{keyStore, nil}, + []interface{}{w, nil}, + addr, + password, + false, + }, + { + "fail_keyStore", + []interface{}{nil, errors.New("Can't return you a key store")}, + []interface{}{w, nil}, + addr, + password, + true, + }, + { + "fail_whisperService", + []interface{}{keyStore, nil}, + []interface{}{nil, errors.New("Can't return you a whisper service")}, + addr, + password, + true, + }, + { + "fail_wrongAddress", + []interface{}{keyStore, nil}, + []interface{}{w, nil}, + "wrong-address", + password, + true, + }, + { + "fail_wrongPassword", + []interface{}{keyStore, nil}, + []interface{}{w, nil}, + addr, + "wrong-password", + true, + }, + } + + for _, testCase := range testCases { + t.Run(testCase.name, func(t *testing.T) { + nodeManager.EXPECT().AccountKeyStore().Return(testCase.accountKeyStoreReturn...).Times(2) + nodeManager.EXPECT().WhisperService().Return(testCase.whisperServiceReturn...) + err = accManager.SelectAccount(testCase.address, testCase.password) + if testCase.fail { + require.Error(t, err) + } else { + require.NoError(t, err) + } + }) + } +}