From 8c1b1e265c3e63880dc8e560f604c9781bdef1bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caner=20=C3=87=C4=B1dam?= Date: Tue, 19 Dec 2017 20:32:10 +0300 Subject: [PATCH] add TestAddressToDecryptedAccount --- geth/account/accounts_test.go | 60 +++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/geth/account/accounts_test.go b/geth/account/accounts_test.go index cfd56139f..9fbb7e323 100644 --- a/geth/account/accounts_test.go +++ b/geth/account/accounts_test.go @@ -436,3 +436,63 @@ func (s *ManagerTestSuite) TestAccounts() { s.NoError(err) s.NotNil(accs) } + +func (s *ManagerTestSuite) TestAddressToDecryptedAccount() { + s.reinitMock() + + s.nodeManager.EXPECT().AccountKeyStore().Return(s.keyStore, nil) + addr, _, _, err := s.accManager.CreateAccount(s.password) + s.NoError(err) + + testCases := []struct { + name string + accountKeyStoreReturn []interface{} + address string + password string + fail bool + }{ + { + "success", + []interface{}{s.keyStore, nil}, + addr, + s.password, + false, + }, + { + "fail_keyStore", + []interface{}{nil, testErrKeyStore}, + addr, + s.password, + true, + }, + { + "fail_wrongAddress", + []interface{}{s.keyStore, nil}, + "wrong-address", + s.password, + true, + }, + { + "fail_wrongPassword", + []interface{}{s.keyStore, nil}, + addr, + "wrong-password", + true, + }, + } + + for _, testCase := range testCases { + s.T().Run(testCase.name, func(t *testing.T) { + s.reinitMock() + s.nodeManager.EXPECT().AccountKeyStore().Return(testCase.accountKeyStoreReturn...).AnyTimes() + acc, keyStore, err := s.accManager.AddressToDecryptedAccount(testCase.address, testCase.password) + if testCase.fail { + s.Error(err) + } else { + s.NoError(err) + s.NotNil(acc) + s.NotNil(keyStore) + } + }) + } +}