Revert "Initialize status keystore instance before starting ethereum node"
This reverts commit 476240fbd1
.
This commit is contained in:
parent
ce7b0fc376
commit
cb769ccca9
1
Makefile
1
Makefile
|
@ -232,6 +232,7 @@ mock-install: ##@other Install mocking tools
|
|||
mock: ##@other Regenerate mocks
|
||||
mockgen -package=fcm -destination=notifications/push/fcm/client_mock.go -source=notifications/push/fcm/client.go
|
||||
mockgen -package=fake -destination=transactions/fake/mock.go -source=transactions/fake/txservice.go
|
||||
mockgen -package=account -destination=account/accounts_mock.go -source=account/accounts.go
|
||||
mockgen -package=status -destination=services/status/account_mock.go -source=services/status/service.go
|
||||
mockgen -package=peer -destination=services/peer/discoverer_mock.go -source=services/peer/service.go
|
||||
|
||||
|
|
|
@ -30,16 +30,21 @@ var (
|
|||
ErrInvalidMasterKeyCreated = errors.New("can not create master extended key")
|
||||
ErrOnboardingNotStarted = errors.New("onboarding must be started before choosing an account")
|
||||
ErrOnboardingAccountNotFound = errors.New("cannot find onboarding account with the given id")
|
||||
ErrAccountKeyStoreMissing = errors.New("account key store is not set")
|
||||
)
|
||||
|
||||
var zeroAddress = common.Address{}
|
||||
|
||||
// GethServiceProvider provides required geth services.
|
||||
type GethServiceProvider interface {
|
||||
AccountManager() (*accounts.Manager, error)
|
||||
AccountKeyStore() (*keystore.KeyStore, error)
|
||||
}
|
||||
|
||||
// Manager represents account manager interface.
|
||||
type Manager struct {
|
||||
mu sync.RWMutex
|
||||
keystore *keystore.KeyStore
|
||||
manager *accounts.Manager
|
||||
geth GethServiceProvider
|
||||
|
||||
mu sync.RWMutex
|
||||
|
||||
accountsGenerator *generator.Generator
|
||||
onboarding *Onboarding
|
||||
|
@ -50,43 +55,15 @@ type Manager struct {
|
|||
}
|
||||
|
||||
// NewManager returns new node account manager.
|
||||
func NewManager() *Manager {
|
||||
m := &Manager{}
|
||||
m.accountsGenerator = generator.New(m)
|
||||
return m
|
||||
}
|
||||
|
||||
// InitKeystore sets key manager and key store.
|
||||
func (m *Manager) InitKeystore(keydir string) error {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
manager, err := makeAccountManager(keydir)
|
||||
if err != nil {
|
||||
return err
|
||||
func NewManager(geth GethServiceProvider) *Manager {
|
||||
manager := &Manager{
|
||||
geth: geth,
|
||||
}
|
||||
m.manager = manager
|
||||
backends := manager.Backends(keystore.KeyStoreType)
|
||||
if len(backends) == 0 {
|
||||
return ErrAccountKeyStoreMissing
|
||||
}
|
||||
keyStore, ok := backends[0].(*keystore.KeyStore)
|
||||
if !ok {
|
||||
return ErrAccountKeyStoreMissing
|
||||
}
|
||||
m.keystore = keyStore
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Manager) GetKeystore() *keystore.KeyStore {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
return m.keystore
|
||||
}
|
||||
accountsGenerator := generator.New(manager)
|
||||
manager.accountsGenerator = accountsGenerator
|
||||
|
||||
func (m *Manager) GetManager() *accounts.Manager {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
return m.manager
|
||||
return manager
|
||||
}
|
||||
|
||||
// AccountsGenerator returns accountsGenerator.
|
||||
|
@ -293,22 +270,24 @@ func (m *Manager) Logout() {
|
|||
|
||||
// ImportAccount imports the account specified with privateKey.
|
||||
func (m *Manager) ImportAccount(privateKey *ecdsa.PrivateKey, password string) (common.Address, error) {
|
||||
if m.keystore == nil {
|
||||
return common.Address{}, ErrAccountKeyStoreMissing
|
||||
keyStore, err := m.geth.AccountKeyStore()
|
||||
if err != nil {
|
||||
return common.Address{}, err
|
||||
}
|
||||
|
||||
account, err := m.keystore.ImportECDSA(privateKey, password)
|
||||
account, err := keyStore.ImportECDSA(privateKey, password)
|
||||
|
||||
return account.Address, err
|
||||
}
|
||||
|
||||
func (m *Manager) ImportSingleExtendedKey(extKey *extkeys.ExtendedKey, password string) (address, pubKey string, err error) {
|
||||
if m.keystore == nil {
|
||||
return "", "", ErrAccountKeyStoreMissing
|
||||
keyStore, err := m.geth.AccountKeyStore()
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
// imports extended key, create key file (if necessary)
|
||||
account, err := m.keystore.ImportSingleExtendedKey(extKey, password)
|
||||
account, err := keyStore.ImportSingleExtendedKey(extKey, password)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
@ -316,7 +295,7 @@ func (m *Manager) ImportSingleExtendedKey(extKey *extkeys.ExtendedKey, password
|
|||
address = account.Address.Hex()
|
||||
|
||||
// obtain public key to return
|
||||
account, key, err := m.keystore.AccountDecryptedKey(account, password)
|
||||
account, key, err := keyStore.AccountDecryptedKey(account, password)
|
||||
if err != nil {
|
||||
return address, "", err
|
||||
}
|
||||
|
@ -329,19 +308,20 @@ func (m *Manager) ImportSingleExtendedKey(extKey *extkeys.ExtendedKey, password
|
|||
// importExtendedKey processes incoming extended key, extracts required info and creates corresponding account key.
|
||||
// Once account key is formed, that key is put (if not already) into keystore i.e. key is *encoded* into key file.
|
||||
func (m *Manager) importExtendedKey(keyPurpose extkeys.KeyPurpose, extKey *extkeys.ExtendedKey, password string) (address, pubKey string, err error) {
|
||||
if m.keystore == nil {
|
||||
return "", "", ErrAccountKeyStoreMissing
|
||||
keyStore, err := m.geth.AccountKeyStore()
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
// imports extended key, create key file (if necessary)
|
||||
account, err := m.keystore.ImportExtendedKeyForPurpose(keyPurpose, extKey, password)
|
||||
account, err := keyStore.ImportExtendedKeyForPurpose(keyPurpose, extKey, password)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
address = account.Address.Hex()
|
||||
|
||||
// obtain public key to return
|
||||
account, key, err := m.keystore.AccountDecryptedKey(account, password)
|
||||
account, key, err := keyStore.AccountDecryptedKey(account, password)
|
||||
if err != nil {
|
||||
return address, "", err
|
||||
}
|
||||
|
@ -355,6 +335,7 @@ func (m *Manager) importExtendedKey(keyPurpose extkeys.KeyPurpose, extKey *extke
|
|||
func (m *Manager) Accounts() ([]gethcommon.Address, error) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
|
||||
addresses := make([]gethcommon.Address, 0)
|
||||
if m.mainAccountAddress != zeroAddress {
|
||||
addresses = append(addresses, m.mainAccountAddress)
|
||||
|
@ -416,8 +397,9 @@ func (m *Manager) ImportOnboardingAccount(id string, password string) (Info, str
|
|||
// The running node, has a keystore directory which is loaded on start. Key file
|
||||
// for a given address is expected to be in that directory prior to node start.
|
||||
func (m *Manager) AddressToDecryptedAccount(address, password string) (accounts.Account, *keystore.Key, error) {
|
||||
if m.keystore == nil {
|
||||
return accounts.Account{}, nil, ErrAccountKeyStoreMissing
|
||||
keyStore, err := m.geth.AccountKeyStore()
|
||||
if err != nil {
|
||||
return accounts.Account{}, nil, err
|
||||
}
|
||||
|
||||
account, err := ParseAccountString(address)
|
||||
|
@ -426,7 +408,7 @@ func (m *Manager) AddressToDecryptedAccount(address, password string) (accounts.
|
|||
}
|
||||
|
||||
var key *keystore.Key
|
||||
account, key, err = m.keystore.AccountDecryptedKey(account, password)
|
||||
account, key, err = keyStore.AccountDecryptedKey(account, password)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("%s: %s", ErrAccountToKeyMappingFailure, err)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: account/accounts.go
|
||||
|
||||
// Package account is a generated GoMock package.
|
||||
package account
|
||||
|
||||
import (
|
||||
accounts "github.com/ethereum/go-ethereum/accounts"
|
||||
keystore "github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// MockGethServiceProvider is a mock of GethServiceProvider interface
|
||||
type MockGethServiceProvider struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockGethServiceProviderMockRecorder
|
||||
}
|
||||
|
||||
// MockGethServiceProviderMockRecorder is the mock recorder for MockGethServiceProvider
|
||||
type MockGethServiceProviderMockRecorder struct {
|
||||
mock *MockGethServiceProvider
|
||||
}
|
||||
|
||||
// NewMockGethServiceProvider creates a new mock instance
|
||||
func NewMockGethServiceProvider(ctrl *gomock.Controller) *MockGethServiceProvider {
|
||||
mock := &MockGethServiceProvider{ctrl: ctrl}
|
||||
mock.recorder = &MockGethServiceProviderMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use
|
||||
func (m *MockGethServiceProvider) EXPECT() *MockGethServiceProviderMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// AccountManager mocks base method
|
||||
func (m *MockGethServiceProvider) AccountManager() (*accounts.Manager, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "AccountManager")
|
||||
ret0, _ := ret[0].(*accounts.Manager)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// AccountManager indicates an expected call of AccountManager
|
||||
func (mr *MockGethServiceProviderMockRecorder) AccountManager() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AccountManager", reflect.TypeOf((*MockGethServiceProvider)(nil).AccountManager))
|
||||
}
|
||||
|
||||
// AccountKeyStore mocks base method
|
||||
func (m *MockGethServiceProvider) AccountKeyStore() (*keystore.KeyStore, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "AccountKeyStore")
|
||||
ret0, _ := ret[0].(*keystore.KeyStore)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// AccountKeyStore indicates an expected call of AccountKeyStore
|
||||
func (mr *MockGethServiceProviderMockRecorder) AccountKeyStore() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AccountKeyStore", reflect.TypeOf((*MockGethServiceProvider)(nil).AccountKeyStore))
|
||||
}
|
|
@ -9,16 +9,20 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
gethcommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/golang/mock/gomock"
|
||||
. "github.com/status-im/status-go/t/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
func TestVerifyAccountPassword(t *testing.T) {
|
||||
accManager := NewManager()
|
||||
accManager := NewManager(nil)
|
||||
keyStoreDir, err := ioutil.TempDir(os.TempDir(), "accounts")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(keyStoreDir) //nolint: errcheck
|
||||
|
@ -104,22 +108,70 @@ func TestVerifyAccountPasswordWithAccountBeforeEIP55(t *testing.T) {
|
|||
err = ImportTestAccount(keyStoreDir, "test-account3-before-eip55.pk")
|
||||
require.NoError(t, err)
|
||||
|
||||
accManager := NewManager()
|
||||
accManager := NewManager(nil)
|
||||
|
||||
address := gethcommon.HexToAddress(TestConfig.Account3.WalletAddress)
|
||||
_, err = accManager.VerifyAccountPassword(keyStoreDir, address.Hex(), TestConfig.Account3.Password)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
var errKeyStore = errors.New("Can't return a key store")
|
||||
|
||||
func TestManagerTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(ManagerTestSuite))
|
||||
gethServiceProvider := newMockGethServiceProvider(t)
|
||||
accManager := NewManager(gethServiceProvider)
|
||||
|
||||
keyStoreDir, err := ioutil.TempDir(os.TempDir(), "accounts")
|
||||
require.NoError(t, err)
|
||||
keyStore := keystore.NewKeyStore(keyStoreDir, keystore.LightScryptN, keystore.LightScryptP)
|
||||
defer os.RemoveAll(keyStoreDir) //nolint: errcheck
|
||||
|
||||
testPassword := "test-password"
|
||||
|
||||
// Initial test - create test account
|
||||
gethServiceProvider.EXPECT().AccountKeyStore().Return(keyStore, nil)
|
||||
accountInfo, mnemonic, err := accManager.CreateAccount(testPassword)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, accountInfo.WalletAddress)
|
||||
require.NotEmpty(t, accountInfo.WalletPubKey)
|
||||
require.NotEmpty(t, accountInfo.ChatAddress)
|
||||
require.NotEmpty(t, accountInfo.ChatPubKey)
|
||||
require.NotEmpty(t, mnemonic)
|
||||
|
||||
// Before the complete decoupling of the keys, wallet and chat keys are the same
|
||||
assert.Equal(t, accountInfo.WalletAddress, accountInfo.ChatAddress)
|
||||
assert.Equal(t, accountInfo.WalletPubKey, accountInfo.ChatPubKey)
|
||||
|
||||
s := &ManagerTestSuite{
|
||||
testAccount: testAccount{
|
||||
"test-password",
|
||||
accountInfo.WalletAddress,
|
||||
accountInfo.WalletPubKey,
|
||||
accountInfo.ChatAddress,
|
||||
accountInfo.ChatPubKey,
|
||||
mnemonic,
|
||||
},
|
||||
gethServiceProvider: gethServiceProvider,
|
||||
accManager: accManager,
|
||||
keyStore: keyStore,
|
||||
gethAccManager: accounts.NewManager(),
|
||||
}
|
||||
|
||||
suite.Run(t, s)
|
||||
}
|
||||
|
||||
func newMockGethServiceProvider(t *testing.T) *MockGethServiceProvider {
|
||||
ctrl := gomock.NewController(t)
|
||||
return NewMockGethServiceProvider(ctrl)
|
||||
}
|
||||
|
||||
type ManagerTestSuite struct {
|
||||
suite.Suite
|
||||
testAccount
|
||||
accManager *Manager
|
||||
keydir string
|
||||
gethServiceProvider *MockGethServiceProvider
|
||||
accManager *Manager
|
||||
keyStore *keystore.KeyStore
|
||||
gethAccManager *accounts.Manager
|
||||
}
|
||||
|
||||
type testAccount struct {
|
||||
|
@ -131,52 +183,43 @@ type testAccount struct {
|
|||
mnemonic string
|
||||
}
|
||||
|
||||
// reinitMock is for reassigning a new mock node manager to account manager.
|
||||
// Stating the amount of times for mock calls kills the flexibility for
|
||||
// development so this is a good workaround to use with EXPECT().Func().AnyTimes()
|
||||
func (s *ManagerTestSuite) reinitMock() {
|
||||
s.gethServiceProvider = newMockGethServiceProvider(s.T())
|
||||
s.accManager.geth = s.gethServiceProvider
|
||||
}
|
||||
|
||||
// SetupTest is used here for reinitializing the mock before every
|
||||
// test function to avoid faulty execution.
|
||||
func (s *ManagerTestSuite) SetupTest() {
|
||||
s.accManager = NewManager()
|
||||
|
||||
keyStoreDir, err := ioutil.TempDir(os.TempDir(), "accounts")
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(s.accManager.InitKeystore(keyStoreDir))
|
||||
s.keydir = keyStoreDir
|
||||
|
||||
testPassword := "test-password"
|
||||
|
||||
// Initial test - create test account
|
||||
accountInfo, mnemonic, err := s.accManager.CreateAccount(testPassword)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotEmpty(accountInfo.WalletAddress)
|
||||
s.Require().NotEmpty(accountInfo.WalletPubKey)
|
||||
s.Require().NotEmpty(accountInfo.ChatAddress)
|
||||
s.Require().NotEmpty(accountInfo.ChatPubKey)
|
||||
s.Require().NotEmpty(mnemonic)
|
||||
|
||||
// Before the complete decoupling of the keys, wallet and chat keys are the same
|
||||
s.Equal(accountInfo.WalletAddress, accountInfo.ChatAddress)
|
||||
s.Equal(accountInfo.WalletPubKey, accountInfo.ChatPubKey)
|
||||
|
||||
s.testAccount = testAccount{
|
||||
testPassword,
|
||||
accountInfo.WalletAddress,
|
||||
accountInfo.WalletPubKey,
|
||||
accountInfo.ChatAddress,
|
||||
accountInfo.ChatPubKey,
|
||||
mnemonic,
|
||||
}
|
||||
s.reinitMock()
|
||||
}
|
||||
|
||||
func (s *ManagerTestSuite) TearDownTest() {
|
||||
s.Require().NoError(os.RemoveAll(s.keydir))
|
||||
func (s *ManagerTestSuite) TestCreateAccount() {
|
||||
// Don't fail on empty password
|
||||
s.gethServiceProvider.EXPECT().AccountKeyStore().Return(s.keyStore, nil)
|
||||
_, _, err := s.accManager.CreateAccount(s.password)
|
||||
s.NoError(err)
|
||||
|
||||
s.gethServiceProvider.EXPECT().AccountKeyStore().Return(nil, errKeyStore)
|
||||
_, _, err = s.accManager.CreateAccount(s.password)
|
||||
s.Equal(errKeyStore, err)
|
||||
}
|
||||
|
||||
func (s *ManagerTestSuite) TestRecoverAccount() {
|
||||
s.gethServiceProvider.EXPECT().AccountKeyStore().Return(s.keyStore, nil)
|
||||
accountInfo, err := s.accManager.RecoverAccount(s.password, s.mnemonic)
|
||||
s.NoError(err)
|
||||
s.Equal(s.walletAddress, accountInfo.WalletAddress)
|
||||
s.Equal(s.walletPubKey, accountInfo.WalletPubKey)
|
||||
s.Equal(s.chatAddress, accountInfo.ChatAddress)
|
||||
s.Equal(s.chatPubKey, accountInfo.ChatPubKey)
|
||||
|
||||
s.gethServiceProvider.EXPECT().AccountKeyStore().Return(nil, errKeyStore)
|
||||
_, err = s.accManager.RecoverAccount(s.password, s.mnemonic)
|
||||
s.Equal(errKeyStore, err)
|
||||
}
|
||||
|
||||
func (s *ManagerTestSuite) TestOnboarding() {
|
||||
|
@ -197,6 +240,7 @@ func (s *ManagerTestSuite) TestOnboarding() {
|
|||
// choose one account and encrypt it with password
|
||||
password := "test-onboarding-account"
|
||||
account := accounts[0]
|
||||
s.gethServiceProvider.EXPECT().AccountKeyStore().Return(s.keyStore, nil)
|
||||
info, mnemonic, err := s.accManager.ImportOnboardingAccount(account.ID, password)
|
||||
s.Require().NoError(err)
|
||||
s.Equal(account.Info, info)
|
||||
|
@ -204,6 +248,7 @@ func (s *ManagerTestSuite) TestOnboarding() {
|
|||
s.Nil(s.accManager.onboarding)
|
||||
|
||||
// try to decrypt it with password to check if it's been imported correctly
|
||||
s.gethServiceProvider.EXPECT().AccountKeyStore().Return(s.keyStore, nil)
|
||||
decAccount, _, err := s.accManager.AddressToDecryptedAccount(info.WalletAddress, password)
|
||||
s.Require().NoError(err)
|
||||
s.Equal(info.WalletAddress, decAccount.Address.Hex())
|
||||
|
@ -217,43 +262,79 @@ func (s *ManagerTestSuite) TestOnboarding() {
|
|||
s.Nil(s.accManager.onboarding)
|
||||
}
|
||||
|
||||
func (s *ManagerTestSuite) TestSelectAccountSuccess() {
|
||||
s.testSelectAccount(common.HexToAddress(s.testAccount.chatAddress), common.HexToAddress(s.testAccount.walletAddress), s.testAccount.password, nil)
|
||||
}
|
||||
|
||||
func (s *ManagerTestSuite) TestSelectAccountWrongAddress() {
|
||||
s.testSelectAccount(common.HexToAddress("0x0000000000000000000000000000000000000001"), common.HexToAddress(s.testAccount.walletAddress), s.testAccount.password, errors.New("cannot retrieve a valid key for a given account: no key for given address or file"))
|
||||
}
|
||||
|
||||
func (s *ManagerTestSuite) TestSelectAccountWrongPassword() {
|
||||
s.testSelectAccount(common.HexToAddress(s.testAccount.chatAddress), common.HexToAddress(s.testAccount.walletAddress), "wrong", errors.New("cannot retrieve a valid key for a given account: could not decrypt key with given passphrase"))
|
||||
}
|
||||
|
||||
func (s *ManagerTestSuite) testSelectAccount(chat, wallet common.Address, password string, expErr error) {
|
||||
loginParams := LoginParams{
|
||||
ChatAddress: chat,
|
||||
MainAccount: wallet,
|
||||
Password: password,
|
||||
}
|
||||
err := s.accManager.SelectAccount(loginParams)
|
||||
s.Require().Equal(expErr, err)
|
||||
|
||||
selectedMainAccountAddress, walletErr := s.accManager.MainAccountAddress()
|
||||
selectedChatAccount, chatErr := s.accManager.SelectedChatAccount()
|
||||
|
||||
if expErr == nil {
|
||||
s.Require().NoError(walletErr)
|
||||
s.Require().NoError(chatErr)
|
||||
s.Equal(wallet, selectedMainAccountAddress)
|
||||
s.Equal(chat, crypto.PubkeyToAddress(selectedChatAccount.AccountKey.PrivateKey.PublicKey))
|
||||
} else {
|
||||
s.Equal(common.Address{}, selectedMainAccountAddress)
|
||||
s.Nil(selectedChatAccount)
|
||||
s.Equal(walletErr, ErrNoAccountSelected)
|
||||
s.Equal(chatErr, ErrNoAccountSelected)
|
||||
func (s *ManagerTestSuite) TestSelectAccount() {
|
||||
testCases := []struct {
|
||||
name string
|
||||
accountKeyStoreReturn []interface{}
|
||||
walletAddress string
|
||||
chatAddress string
|
||||
password string
|
||||
expectedError error
|
||||
}{
|
||||
{
|
||||
"success",
|
||||
[]interface{}{s.keyStore, nil},
|
||||
s.walletAddress,
|
||||
s.chatAddress,
|
||||
s.password,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"fail_keyStore",
|
||||
[]interface{}{nil, errKeyStore},
|
||||
s.walletAddress,
|
||||
s.chatAddress,
|
||||
s.password,
|
||||
errKeyStore,
|
||||
},
|
||||
{
|
||||
"fail_wrongChatAddress",
|
||||
[]interface{}{s.keyStore, nil},
|
||||
s.walletAddress,
|
||||
"0x0000000000000000000000000000000000000001",
|
||||
s.password,
|
||||
errors.New("cannot retrieve a valid key for a given account: no key for given address or file"),
|
||||
},
|
||||
{
|
||||
"fail_wrongPassword",
|
||||
[]interface{}{s.keyStore, nil},
|
||||
s.walletAddress,
|
||||
s.chatAddress,
|
||||
"wrong-password",
|
||||
errors.New("cannot retrieve a valid key for a given account: could not decrypt key with given passphrase"),
|
||||
},
|
||||
}
|
||||
|
||||
s.accManager.Logout()
|
||||
for _, testCase := range testCases {
|
||||
s.T().Run(testCase.name, func(t *testing.T) {
|
||||
s.reinitMock()
|
||||
s.gethServiceProvider.EXPECT().AccountKeyStore().Return(testCase.accountKeyStoreReturn...).AnyTimes()
|
||||
loginParams := LoginParams{
|
||||
ChatAddress: common.HexToAddress(testCase.chatAddress),
|
||||
MainAccount: common.HexToAddress(testCase.walletAddress),
|
||||
Password: testCase.password,
|
||||
}
|
||||
err := s.accManager.SelectAccount(loginParams)
|
||||
s.Equal(testCase.expectedError, err)
|
||||
|
||||
selectedMainAccountAddress, walletErr := s.accManager.MainAccountAddress()
|
||||
selectedChatAccount, chatErr := s.accManager.SelectedChatAccount()
|
||||
|
||||
if testCase.expectedError == nil {
|
||||
s.Equal(testCase.walletAddress, selectedMainAccountAddress.String())
|
||||
s.Equal(testCase.chatAddress, crypto.PubkeyToAddress(selectedChatAccount.AccountKey.PrivateKey.PublicKey).Hex())
|
||||
s.NoError(walletErr)
|
||||
s.NoError(chatErr)
|
||||
} else {
|
||||
s.Equal(common.Address{}, selectedMainAccountAddress)
|
||||
s.Nil(selectedChatAccount)
|
||||
s.Equal(walletErr, ErrNoAccountSelected)
|
||||
s.Equal(chatErr, ErrNoAccountSelected)
|
||||
}
|
||||
|
||||
s.accManager.Logout()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ManagerTestSuite) TestSetChatAccount() {
|
||||
|
@ -286,6 +367,7 @@ func (s *ManagerTestSuite) TestLogout() {
|
|||
// TestAccounts tests cases for (*Manager).Accounts.
|
||||
func (s *ManagerTestSuite) TestAccounts() {
|
||||
// Select the test account
|
||||
s.gethServiceProvider.EXPECT().AccountKeyStore().Return(s.keyStore, nil).AnyTimes()
|
||||
loginParams := LoginParams{
|
||||
MainAccount: common.HexToAddress(s.walletAddress),
|
||||
ChatAddress: common.HexToAddress(s.chatAddress),
|
||||
|
@ -295,36 +377,70 @@ func (s *ManagerTestSuite) TestAccounts() {
|
|||
s.NoError(err)
|
||||
|
||||
// Success
|
||||
s.gethServiceProvider.EXPECT().AccountManager().Return(s.gethAccManager, nil)
|
||||
accs, err := s.accManager.Accounts()
|
||||
s.NoError(err)
|
||||
s.NotNil(accs)
|
||||
|
||||
// Selected main account address is zero address but doesn't fail
|
||||
s.accManager.mainAccountAddress = common.Address{}
|
||||
s.gethServiceProvider.EXPECT().AccountManager().Return(s.gethAccManager, nil)
|
||||
accs, err = s.accManager.Accounts()
|
||||
s.NoError(err)
|
||||
s.NotNil(accs)
|
||||
}
|
||||
|
||||
func (s *ManagerTestSuite) TestAddressToDecryptedAccountSuccess() {
|
||||
s.testAddressToDecryptedAccount(s.walletAddress, s.password, nil)
|
||||
}
|
||||
func (s *ManagerTestSuite) TestAddressToDecryptedAccount() {
|
||||
testCases := []struct {
|
||||
name string
|
||||
accountKeyStoreReturn []interface{}
|
||||
walletAddress string
|
||||
password string
|
||||
expectedError error
|
||||
}{
|
||||
{
|
||||
"success",
|
||||
[]interface{}{s.keyStore, nil},
|
||||
s.walletAddress,
|
||||
s.password,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"fail_keyStore",
|
||||
[]interface{}{nil, errKeyStore},
|
||||
s.walletAddress,
|
||||
s.password,
|
||||
errKeyStore,
|
||||
},
|
||||
{
|
||||
"fail_wrongWalletAddress",
|
||||
[]interface{}{s.keyStore, nil},
|
||||
"wrong-wallet-address",
|
||||
s.password,
|
||||
ErrAddressToAccountMappingFailure,
|
||||
},
|
||||
{
|
||||
"fail_wrongPassword",
|
||||
[]interface{}{s.keyStore, nil},
|
||||
s.walletAddress,
|
||||
"wrong-password",
|
||||
errors.New("cannot retrieve a valid key for a given account: could not decrypt key with given passphrase"),
|
||||
},
|
||||
}
|
||||
|
||||
func (s *ManagerTestSuite) TestAddressToDecryptedAccountWrongAddress() {
|
||||
s.testAddressToDecryptedAccount("0x0001", s.password, ErrAddressToAccountMappingFailure)
|
||||
}
|
||||
|
||||
func (s *ManagerTestSuite) TestAddressToDecryptedAccountWrongPassword() {
|
||||
s.testAddressToDecryptedAccount(s.walletAddress, "wrong", errors.New("cannot retrieve a valid key for a given account: could not decrypt key with given passphrase"))
|
||||
}
|
||||
|
||||
func (s *ManagerTestSuite) testAddressToDecryptedAccount(wallet, password string, expErr error) {
|
||||
acc, key, err := s.accManager.AddressToDecryptedAccount(wallet, password)
|
||||
if expErr != nil {
|
||||
s.Equal(expErr, err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(acc)
|
||||
s.Require().NotNil(key)
|
||||
s.Equal(acc.Address, key.Address)
|
||||
for _, testCase := range testCases {
|
||||
s.T().Run(testCase.name, func(t *testing.T) {
|
||||
s.reinitMock()
|
||||
s.gethServiceProvider.EXPECT().AccountKeyStore().Return(testCase.accountKeyStoreReturn...).AnyTimes()
|
||||
acc, key, err := s.accManager.AddressToDecryptedAccount(testCase.walletAddress, testCase.password)
|
||||
if testCase.expectedError != nil {
|
||||
s.Equal(testCase.expectedError, err)
|
||||
} else {
|
||||
s.NoError(err)
|
||||
s.NotNil(acc)
|
||||
s.NotNil(key)
|
||||
s.Equal(acc.Address, key.Address)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
package account
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
)
|
||||
|
||||
// makeAccountManager creates ethereum accounts.Manager with single disk backend and lightweight kdf.
|
||||
// If keydir is empty new temporary directory with go-ethereum-keystore will be intialized.
|
||||
func makeAccountManager(keydir string) (manager *accounts.Manager, err error) {
|
||||
if keydir == "" {
|
||||
// There is no datadir.
|
||||
keydir, err = ioutil.TempDir("", "go-ethereum-keystore")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := os.MkdirAll(keydir, 0700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return accounts.NewManager(keystore.NewKeyStore(keydir, keystore.LightScryptN, keystore.LightScryptP)), nil
|
||||
}
|
|
@ -42,6 +42,7 @@ func ParseLoginParams(paramsJSON string) (LoginParams, error) {
|
|||
params LoginParams
|
||||
zeroAddress common.Address
|
||||
)
|
||||
|
||||
if err := json.Unmarshal([]byte(paramsJSON), ¶ms); err != nil {
|
||||
return params, err
|
||||
}
|
||||
|
@ -59,6 +60,7 @@ func ParseLoginParams(paramsJSON string) (LoginParams, error) {
|
|||
return params, newErrZeroAddress("WatchAddresses")
|
||||
}
|
||||
}
|
||||
|
||||
return params, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ func NewStatusBackend() *StatusBackend {
|
|||
defer log.Info("Status backend initialized", "version", params.Version, "commit", params.GitCommit)
|
||||
|
||||
statusNode := node.New()
|
||||
accountManager := account.NewManager()
|
||||
accountManager := account.NewManager(statusNode)
|
||||
transactor := transactions.NewTransactor()
|
||||
personalAPI := personal.NewAPI()
|
||||
notificationManager := fcm.NewNotification(fcmServerKey)
|
||||
|
@ -149,17 +149,12 @@ func (b *StatusBackend) startNode(config *params.NodeConfig) (err error) {
|
|||
services = appendIf(config.UpstreamConfig.Enabled, services, b.rpcFiltersService())
|
||||
services = append(services, b.subscriptionService())
|
||||
|
||||
manager := b.accountManager.GetManager()
|
||||
if manager == nil {
|
||||
return errors.New("ethereum accounts.Manager is nil")
|
||||
}
|
||||
if err = b.statusNode.StartWithOptions(config, node.StartOptions{
|
||||
Services: services,
|
||||
// The peers discovery protocols are started manually after
|
||||
// `node.ready` signal is sent.
|
||||
// It was discussed in https://github.com/status-im/status-go/pull/1333.
|
||||
StartDiscovery: false,
|
||||
AccountsManager: manager,
|
||||
StartDiscovery: false,
|
||||
}); err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -627,6 +622,7 @@ func (b *StatusBackend) startWallet(password string) error {
|
|||
allAddresses := make([]common.Address, len(watchAddresses)+1)
|
||||
allAddresses[0] = mainAccountAddress
|
||||
copy(allAddresses[1:], watchAddresses)
|
||||
|
||||
path := path.Join(b.statusNode.Config().DataDir, fmt.Sprintf("wallet-%x.sql", mainAccountAddress))
|
||||
return wallet.StartReactor(path, password,
|
||||
b.statusNode.RPCClient().Ethclient(),
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/status-im/status-go/account"
|
||||
"github.com/status-im/status-go/node"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/signal"
|
||||
"github.com/status-im/status-go/t/utils"
|
||||
|
@ -24,16 +23,11 @@ const (
|
|||
func TestSubscriptionEthWithParamsDict(t *testing.T) {
|
||||
// a simple test to check the parameter parsing for eth_* filter subscriptions
|
||||
backend := NewStatusBackend()
|
||||
// initNodeAndLogin can fail and terminate the test, in that case stopNode must be executed anyway.
|
||||
defer func() {
|
||||
err := backend.StopNode()
|
||||
if err != node.ErrNoRunningNode {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}()
|
||||
|
||||
initNodeAndLogin(t, backend)
|
||||
|
||||
defer func() { require.NoError(t, backend.StopNode()) }()
|
||||
|
||||
createSubscription(t, backend, fmt.Sprintf(`"eth_newFilter", [
|
||||
{
|
||||
"fromBlock":"earliest",
|
||||
|
@ -46,15 +40,11 @@ func TestSubscriptionEthWithParamsDict(t *testing.T) {
|
|||
func TestSubscriptionPendingTransaction(t *testing.T) {
|
||||
backend := NewStatusBackend()
|
||||
backend.allowAllRPC = true
|
||||
defer func() {
|
||||
err := backend.StopNode()
|
||||
if err != node.ErrNoRunningNode {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}()
|
||||
|
||||
account, _ := initNodeAndLogin(t, backend)
|
||||
|
||||
defer func() { require.NoError(t, backend.StopNode()) }()
|
||||
|
||||
signals := make(chan string)
|
||||
defer func() {
|
||||
signal.ResetDefaultNodeNotificationHandler()
|
||||
|
@ -98,15 +88,11 @@ func TestSubscriptionPendingTransaction(t *testing.T) {
|
|||
|
||||
func TestSubscriptionWhisperEnvelopes(t *testing.T) {
|
||||
backend := NewStatusBackend()
|
||||
defer func() {
|
||||
err := backend.StopNode()
|
||||
if err != node.ErrNoRunningNode {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}()
|
||||
|
||||
initNodeAndLogin(t, backend)
|
||||
|
||||
defer func() { require.NoError(t, backend.StopNode()) }()
|
||||
|
||||
signals := make(chan string)
|
||||
defer func() {
|
||||
signal.ResetDefaultNodeNotificationHandler()
|
||||
|
@ -236,9 +222,9 @@ func initNodeAndLogin(t *testing.T, backend *StatusBackend) (string, string) {
|
|||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
||||
err = backend.StartNode(config)
|
||||
require.NoError(t, err)
|
||||
|
||||
info, _, err := backend.AccountManager().CreateAccount(password)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ func TestBackendStartNodeConcurrently(t *testing.T) {
|
|||
backend := NewStatusBackend()
|
||||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
||||
count := 2
|
||||
resultCh := make(chan error)
|
||||
|
||||
|
@ -59,8 +58,9 @@ func TestBackendRestartNodeConcurrently(t *testing.T) {
|
|||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
require.NoError(t, err)
|
||||
count := 3
|
||||
require.NoError(t, backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
||||
require.NoError(t, backend.StartNode(config))
|
||||
|
||||
err = backend.StartNode(config)
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
require.NoError(t, backend.StopNode())
|
||||
}()
|
||||
|
@ -84,7 +84,7 @@ func TestBackendGettersConcurrently(t *testing.T) {
|
|||
backend := NewStatusBackend()
|
||||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
||||
|
||||
err = backend.StartNode(config)
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
|
@ -136,7 +136,7 @@ func TestBackendAccountsConcurrently(t *testing.T) {
|
|||
backend := NewStatusBackend()
|
||||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
||||
|
||||
err = backend.StartNode(config)
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
|
@ -196,7 +196,6 @@ func TestBackendInjectChatAccount(t *testing.T) {
|
|||
backend := NewStatusBackend()
|
||||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
||||
err = backend.StartNode(config)
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
|
@ -270,7 +269,6 @@ func TestBackendCallRPCConcurrently(t *testing.T) {
|
|||
backend := NewStatusBackend()
|
||||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
||||
count := 3
|
||||
|
||||
err = backend.StartNode(config)
|
||||
|
@ -344,7 +342,6 @@ func TestBlockedRPCMethods(t *testing.T) {
|
|||
backend := NewStatusBackend()
|
||||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
||||
err = backend.StartNode(config)
|
||||
require.NoError(t, err)
|
||||
defer func() { require.NoError(t, backend.StopNode()) }()
|
||||
|
@ -382,7 +379,6 @@ func TestStartStopMultipleTimes(t *testing.T) {
|
|||
backend := NewStatusBackend()
|
||||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
||||
config.NoDiscovery = false
|
||||
// doesn't have to be running. just any valid enode to bypass validation.
|
||||
config.ClusterConfig.BootNodes = []string{
|
||||
|
@ -399,7 +395,6 @@ func TestSignHash(t *testing.T) {
|
|||
backend := NewStatusBackend()
|
||||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
||||
|
||||
require.NoError(t, backend.StartNode(config))
|
||||
defer func() {
|
||||
|
@ -437,7 +432,6 @@ func TestHashTypedData(t *testing.T) {
|
|||
backend := NewStatusBackend()
|
||||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
||||
err = backend.StartNode(config)
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
|
|
|
@ -16,7 +16,6 @@ func TestHashMessage(t *testing.T) {
|
|||
backend := NewStatusBackend()
|
||||
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
||||
err = backend.StartNode(config)
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
|
|
|
@ -337,13 +337,6 @@ func Login(loginParamsJSON *C.char) *C.char {
|
|||
return makeJSONResponse(err)
|
||||
}
|
||||
|
||||
// InitKeystore initialize keystore before doing any operations with keys.
|
||||
//export InitKeystore
|
||||
func InitKeystore(keydir *C.char) *C.char {
|
||||
err := statusBackend.AccountManager().InitKeystore(C.GoString(keydir))
|
||||
return makeJSONResponse(err)
|
||||
}
|
||||
|
||||
// LoginWithKeycard initializes an account with a chat key and encryption key used for PFS.
|
||||
// It purges all the previous identities from Whisper, and injects the key as shh identity.
|
||||
//export LoginWithKeycard
|
||||
|
|
|
@ -102,7 +102,6 @@ func testExportedAPI(t *testing.T, done chan struct{}) {
|
|||
if err := ImportTestAccount(testKeyDir, GetAccount2PKFile()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_ = InitKeystore(C.CString(testKeyDir))
|
||||
|
||||
// FIXME(tiabc): All of that is done because usage of cgo is not supported in tests.
|
||||
// Probably, there should be a cleaner way, for example, test cgo bindings in e2e tests
|
||||
|
@ -392,11 +391,7 @@ func testCallPrivateRPCWithPrivateAPI(t *testing.T) bool {
|
|||
}
|
||||
|
||||
func testRecoverAccount(t *testing.T) bool { //nolint: gocyclo
|
||||
keyStore := statusBackend.AccountManager().GetKeystore()
|
||||
if keyStore == nil {
|
||||
t.Errorf("keystore is nil")
|
||||
return false
|
||||
}
|
||||
keyStore, _ := statusBackend.StatusNode().AccountKeyStore()
|
||||
|
||||
// create an account
|
||||
accountInfo, mnemonic, err := statusBackend.AccountManager().CreateAccount(TestConfig.Account1.Password)
|
||||
|
@ -850,7 +845,6 @@ func startTestNode(t *testing.T) <-chan struct{} {
|
|||
if err := ImportTestAccount(testKeyDir, GetAccount2PKFile()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_ = InitKeystore(C.CString(testKeyDir))
|
||||
|
||||
waitForNodeStart := make(chan struct{}, 1)
|
||||
signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) {
|
||||
|
|
|
@ -336,12 +336,6 @@ func Login(loginParamsJSON string) string {
|
|||
return makeJSONResponse(err)
|
||||
}
|
||||
|
||||
// InitKeystore initialize keystore before doing any operations with keys.
|
||||
func InitKeystore(keydir string) string {
|
||||
err := statusBackend.AccountManager().InitKeystore(keydir)
|
||||
return makeJSONResponse(err)
|
||||
}
|
||||
|
||||
// LoginWithKeycard initializes an account with a chat key and encryption key used for PFS.
|
||||
// It purges all the previous identities from Whisper, and injects the key as shh identity.
|
||||
func LoginWithKeycard(chatKeyData, encryptionKeyData string) string {
|
||||
|
|
24
node/node.go
24
node/node.go
|
@ -9,7 +9,6 @@ import (
|
|||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
gethcommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
|
@ -58,7 +57,7 @@ var (
|
|||
var logger = log.New("package", "status-go/node")
|
||||
|
||||
// MakeNode creates a geth node entity
|
||||
func MakeNode(config *params.NodeConfig, accs *accounts.Manager, db *leveldb.DB) (*node.Node, error) {
|
||||
func MakeNode(config *params.NodeConfig, db *leveldb.DB) (*node.Node, error) {
|
||||
// If DataDir is empty, it means we want to create an ephemeral node
|
||||
// keeping data only in memory.
|
||||
if config.DataDir != "" {
|
||||
|
@ -83,17 +82,17 @@ func MakeNode(config *params.NodeConfig, accs *accounts.Manager, db *leveldb.DB)
|
|||
return nil, fmt.Errorf(ErrNodeMakeFailureFormat, err.Error())
|
||||
}
|
||||
|
||||
err = activateServices(stack, config, accs, db)
|
||||
err = activateServices(stack, config, db)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return stack, nil
|
||||
}
|
||||
|
||||
func activateServices(stack *node.Node, config *params.NodeConfig, accs *accounts.Manager, db *leveldb.DB) error {
|
||||
func activateServices(stack *node.Node, config *params.NodeConfig, db *leveldb.DB) error {
|
||||
// start Ethereum service if we are not expected to use an upstream server
|
||||
if !config.UpstreamConfig.Enabled {
|
||||
if err := activateLightEthService(stack, accs, config); err != nil {
|
||||
if err := activateLightEthService(stack, config); err != nil {
|
||||
return fmt.Errorf("%v: %v", ErrLightEthRegistrationFailure, err)
|
||||
}
|
||||
} else {
|
||||
|
@ -108,7 +107,7 @@ func activateServices(stack *node.Node, config *params.NodeConfig, accs *account
|
|||
// Usually, they are provided by an ETH or a LES service, but when using
|
||||
// upstream, we don't start any of these, so we need to start our own
|
||||
// implementation.
|
||||
if err := activatePersonalService(stack, accs, config); err != nil {
|
||||
if err := activatePersonalService(stack, config); err != nil {
|
||||
return fmt.Errorf("%v: %v", ErrPersonalServiceRegistrationFailure, err)
|
||||
}
|
||||
}
|
||||
|
@ -249,7 +248,7 @@ func defaultStatusChainGenesisBlock() (*core.Genesis, error) {
|
|||
}
|
||||
|
||||
// activateLightEthService configures and registers the eth.Ethereum service with a given node.
|
||||
func activateLightEthService(stack *node.Node, accs *accounts.Manager, config *params.NodeConfig) error {
|
||||
func activateLightEthService(stack *node.Node, config *params.NodeConfig) error {
|
||||
if !config.LightEthConfig.Enabled {
|
||||
logger.Info("LES protocol is disabled")
|
||||
return nil
|
||||
|
@ -270,18 +269,13 @@ func activateLightEthService(stack *node.Node, accs *accounts.Manager, config *p
|
|||
MinTrustedFraction: config.LightEthConfig.MinTrustedFraction,
|
||||
}
|
||||
return stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
||||
// NOTE(dshulyak) here we set our instance of the accounts manager.
|
||||
// without sharing same instance selected account won't be visible for personal_* methods.
|
||||
nctx := &node.ServiceContext{}
|
||||
*nctx = *ctx
|
||||
nctx.AccountManager = accs
|
||||
return les.New(nctx, ðConf)
|
||||
return les.New(ctx, ðConf)
|
||||
})
|
||||
}
|
||||
|
||||
func activatePersonalService(stack *node.Node, accs *accounts.Manager, config *params.NodeConfig) error {
|
||||
func activatePersonalService(stack *node.Node, config *params.NodeConfig) error {
|
||||
return stack.Register(func(*node.ServiceContext) (node.Service, error) {
|
||||
svc := personal.New(accs)
|
||||
svc := personal.New(stack.AccountManager())
|
||||
return svc, nil
|
||||
})
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package node
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
whisper "github.com/status-im/whisper/whisperv6"
|
||||
|
||||
"github.com/status-im/status-go/params"
|
||||
|
@ -18,7 +17,7 @@ func TestWhisperLightModeEnabledSetsEmptyBloomFilter(t *testing.T) {
|
|||
},
|
||||
}
|
||||
node := New()
|
||||
require.NoError(t, node.Start(&config, &accounts.Manager{}))
|
||||
require.NoError(t, node.Start(&config))
|
||||
defer func() {
|
||||
require.NoError(t, node.Stop())
|
||||
}()
|
||||
|
@ -40,7 +39,7 @@ func TestWhisperLightModeEnabledSetsNilBloomFilter(t *testing.T) {
|
|||
},
|
||||
}
|
||||
node := New()
|
||||
require.NoError(t, node.Start(&config, &accounts.Manager{}))
|
||||
require.NoError(t, node.Start(&config))
|
||||
defer func() {
|
||||
require.NoError(t, node.Stop())
|
||||
}()
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||
"github.com/status-im/status-go/params"
|
||||
|
@ -24,7 +23,7 @@ func TestMakeNodeDefaultConfig(t *testing.T) {
|
|||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = MakeNode(config, &accounts.Manager{}, db)
|
||||
_, err = MakeNode(config, db)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
@ -41,7 +40,7 @@ func TestMakeNodeWellFormedBootnodes(t *testing.T) {
|
|||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = MakeNode(config, &accounts.Manager{}, db)
|
||||
_, err = MakeNode(config, db)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
@ -59,7 +58,7 @@ func TestMakeNodeMalformedBootnodes(t *testing.T) {
|
|||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = MakeNode(config, &accounts.Manager{}, db)
|
||||
_, err = MakeNode(config, db)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
"github.com/ethereum/go-ethereum/les"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/node"
|
||||
|
@ -104,19 +105,17 @@ func (n *StatusNode) Server() *p2p.Server {
|
|||
|
||||
// Start starts current StatusNode, failing if it's already started.
|
||||
// It accepts a list of services that should be added to the node.
|
||||
func (n *StatusNode) Start(config *params.NodeConfig, accs *accounts.Manager, services ...node.ServiceConstructor) error {
|
||||
func (n *StatusNode) Start(config *params.NodeConfig, services ...node.ServiceConstructor) error {
|
||||
return n.StartWithOptions(config, StartOptions{
|
||||
Services: services,
|
||||
StartDiscovery: true,
|
||||
AccountsManager: accs,
|
||||
Services: services,
|
||||
StartDiscovery: true,
|
||||
})
|
||||
}
|
||||
|
||||
// StartOptions allows to control some parameters of Start() method.
|
||||
type StartOptions struct {
|
||||
Services []node.ServiceConstructor
|
||||
StartDiscovery bool
|
||||
AccountsManager *accounts.Manager
|
||||
Services []node.ServiceConstructor
|
||||
StartDiscovery bool
|
||||
}
|
||||
|
||||
// StartWithOptions starts current StatusNode, failing if it's already started.
|
||||
|
@ -134,12 +133,12 @@ func (n *StatusNode) StartWithOptions(config *params.NodeConfig, options StartOp
|
|||
|
||||
db, err := db.Create(config.DataDir, params.StatusDatabase)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create database at %s: %v", config.DataDir, err)
|
||||
return err
|
||||
}
|
||||
|
||||
n.db = db
|
||||
|
||||
err = n.startWithDB(config, options.AccountsManager, db, options.Services)
|
||||
err = n.startWithDB(config, db, options.Services)
|
||||
|
||||
// continue only if there was no error when starting node with a db
|
||||
if err == nil && options.StartDiscovery && n.discoveryEnabled() {
|
||||
|
@ -157,8 +156,8 @@ func (n *StatusNode) StartWithOptions(config *params.NodeConfig, options StartOp
|
|||
return nil
|
||||
}
|
||||
|
||||
func (n *StatusNode) startWithDB(config *params.NodeConfig, accs *accounts.Manager, db *leveldb.DB, services []node.ServiceConstructor) error {
|
||||
if err := n.createNode(config, accs, db); err != nil {
|
||||
func (n *StatusNode) startWithDB(config *params.NodeConfig, db *leveldb.DB, services []node.ServiceConstructor) error {
|
||||
if err := n.createNode(config, db); err != nil {
|
||||
return err
|
||||
}
|
||||
n.config = config
|
||||
|
@ -174,8 +173,8 @@ func (n *StatusNode) startWithDB(config *params.NodeConfig, accs *accounts.Manag
|
|||
return nil
|
||||
}
|
||||
|
||||
func (n *StatusNode) createNode(config *params.NodeConfig, accs *accounts.Manager, db *leveldb.DB) (err error) {
|
||||
n.gethNode, err = MakeNode(config, accs, db)
|
||||
func (n *StatusNode) createNode(config *params.NodeConfig, db *leveldb.DB) (err error) {
|
||||
n.gethNode, err = MakeNode(config, db)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -639,6 +638,29 @@ func (n *StatusNode) AccountManager() (*accounts.Manager, error) {
|
|||
return n.gethNode.AccountManager(), nil
|
||||
}
|
||||
|
||||
// AccountKeyStore exposes reference to accounts key store
|
||||
func (n *StatusNode) AccountKeyStore() (*keystore.KeyStore, error) {
|
||||
n.mu.RLock()
|
||||
defer n.mu.RUnlock()
|
||||
|
||||
if n.gethNode == nil {
|
||||
return nil, ErrNoGethNode
|
||||
}
|
||||
|
||||
accountManager := n.gethNode.AccountManager()
|
||||
backends := accountManager.Backends(keystore.KeyStoreType)
|
||||
if len(backends) == 0 {
|
||||
return nil, ErrAccountKeyStoreMissing
|
||||
}
|
||||
|
||||
keyStore, ok := backends[0].(*keystore.KeyStore)
|
||||
if !ok {
|
||||
return nil, ErrAccountKeyStoreMissing
|
||||
}
|
||||
|
||||
return keyStore, nil
|
||||
}
|
||||
|
||||
// RPCClient exposes reference to RPC client connected to the running node.
|
||||
func (n *StatusNode) RPCClient() *rpc.Client {
|
||||
n.mu.RLock()
|
||||
|
|
|
@ -58,7 +58,7 @@ func createAndStartStatusNode(config *params.NodeConfig) (*node.StatusNode, erro
|
|||
},
|
||||
}
|
||||
statusNode := node.New()
|
||||
return statusNode, statusNode.Start(config, nil, services...)
|
||||
return statusNode, statusNode.Start(config, services...)
|
||||
}
|
||||
|
||||
func TestNodeRPCClientCallOnlyPublicAPIs(t *testing.T) {
|
||||
|
|
|
@ -36,8 +36,13 @@ func TestStatusNodeStart(t *testing.T) {
|
|||
require.Nil(t, n.Config())
|
||||
require.Nil(t, n.RPCClient())
|
||||
require.Equal(t, 0, n.PeerCount())
|
||||
_, err = n.AccountManager()
|
||||
require.EqualError(t, err, ErrNoGethNode.Error())
|
||||
_, err = n.AccountKeyStore()
|
||||
require.EqualError(t, err, ErrNoGethNode.Error())
|
||||
|
||||
// start node
|
||||
require.NoError(t, n.Start(config, nil))
|
||||
require.NoError(t, n.Start(config))
|
||||
|
||||
// checks after node is started
|
||||
require.True(t, n.IsRunning())
|
||||
|
@ -48,8 +53,11 @@ func TestStatusNodeStart(t *testing.T) {
|
|||
accountManager, err := n.AccountManager()
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, accountManager)
|
||||
keyStore, err := n.AccountKeyStore()
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, keyStore)
|
||||
// try to start already started node
|
||||
require.EqualError(t, n.Start(config, nil), ErrNodeRunning.Error())
|
||||
require.EqualError(t, n.Start(config), ErrNodeRunning.Error())
|
||||
|
||||
// stop node
|
||||
require.NoError(t, n.Stop())
|
||||
|
@ -60,6 +68,10 @@ func TestStatusNodeStart(t *testing.T) {
|
|||
require.Nil(t, n.GethNode())
|
||||
require.Nil(t, n.RPCClient())
|
||||
require.Equal(t, 0, n.PeerCount())
|
||||
_, err = n.AccountManager()
|
||||
require.EqualError(t, err, ErrNoGethNode.Error())
|
||||
_, err = n.AccountKeyStore()
|
||||
require.EqualError(t, err, ErrNoGethNode.Error())
|
||||
}
|
||||
|
||||
func TestStatusNodeWithDataDir(t *testing.T) {
|
||||
|
@ -82,7 +94,7 @@ func TestStatusNodeWithDataDir(t *testing.T) {
|
|||
}
|
||||
n := New()
|
||||
|
||||
require.NoError(t, n.Start(&config, nil))
|
||||
require.NoError(t, n.Start(&config))
|
||||
require.NoError(t, n.Stop())
|
||||
}
|
||||
|
||||
|
@ -128,7 +140,7 @@ func TestStatusNodeServiceGetters(t *testing.T) {
|
|||
require.Nil(t, instance)
|
||||
|
||||
// start node
|
||||
require.NoError(t, n.Start(&config, nil))
|
||||
require.NoError(t, n.Start(&config))
|
||||
|
||||
// checks after node is started
|
||||
instance, err = service.getter()
|
||||
|
@ -172,7 +184,7 @@ func TestStatusNodeAddPeer(t *testing.T) {
|
|||
config := params.NodeConfig{
|
||||
MaxPeers: math.MaxInt32,
|
||||
}
|
||||
require.NoError(t, n.Start(&config, nil))
|
||||
require.NoError(t, n.Start(&config))
|
||||
defer func() { require.NoError(t, n.Stop()) }()
|
||||
|
||||
errCh := helpers.WaitForPeerAsync(n.Server(), peerURL, p2p.PeerEventTypeAdd, time.Second*5)
|
||||
|
@ -214,7 +226,7 @@ func TestStatusNodeReconnectStaticPeers(t *testing.T) {
|
|||
StaticNodes: []string{peerURL},
|
||||
},
|
||||
}
|
||||
require.NoError(t, n.Start(&config, nil))
|
||||
require.NoError(t, n.Start(&config))
|
||||
defer func() { require.NoError(t, n.Stop()) }()
|
||||
|
||||
// checks after node is started
|
||||
|
@ -274,7 +286,7 @@ func TestStatusNodeRendezvousDiscovery(t *testing.T) {
|
|||
AdvertiseAddr: "127.0.0.1",
|
||||
}
|
||||
n := New()
|
||||
require.NoError(t, n.Start(&config, nil))
|
||||
require.NoError(t, n.Start(&config))
|
||||
require.NotNil(t, n.discovery)
|
||||
require.True(t, n.discovery.Running())
|
||||
require.IsType(t, &discovery.Rendezvous{}, n.discovery)
|
||||
|
@ -308,7 +320,7 @@ func TestStatusNodeDiscoverNode(t *testing.T) {
|
|||
ListenAddr: "127.0.0.1:0",
|
||||
}
|
||||
n := New()
|
||||
require.NoError(t, n.Start(&config, nil))
|
||||
require.NoError(t, n.Start(&config))
|
||||
node, err := n.discoverNode()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, net.ParseIP("127.0.0.1").To4(), node.IP())
|
||||
|
@ -319,7 +331,7 @@ func TestStatusNodeDiscoverNode(t *testing.T) {
|
|||
ListenAddr: "127.0.0.1:0",
|
||||
}
|
||||
n = New()
|
||||
require.NoError(t, n.Start(&config, nil))
|
||||
require.NoError(t, n.Start(&config))
|
||||
node, err = n.discoverNode()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, net.ParseIP("127.0.0.2").To4(), node.IP())
|
||||
|
@ -345,7 +357,7 @@ func TestChaosModeCheckRPCClientsUpstreamURL(t *testing.T) {
|
|||
},
|
||||
}
|
||||
n := New()
|
||||
require.NoError(t, n.Start(&config, nil))
|
||||
require.NoError(t, n.Start(&config))
|
||||
defer func() { require.NoError(t, n.Stop()) }()
|
||||
require.NotNil(t, n.RPCClient())
|
||||
|
||||
|
|
|
@ -55,7 +55,6 @@ func (s *DevNodeSuite) SetupTest() {
|
|||
config.WalletConfig.Enabled = true
|
||||
config.UpstreamConfig.URL = s.miner.IPCEndpoint()
|
||||
s.backend = api.NewStatusBackend()
|
||||
s.Require().NoError(s.backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
||||
s.Require().NoError(s.backend.StartNode(config))
|
||||
s.Remote, err = s.miner.Attach()
|
||||
s.Require().NoError(err)
|
||||
|
|
|
@ -67,7 +67,8 @@ func (s *AccountsTestSuite) TestImportSingleExtendedKey() {
|
|||
s.StartTestBackend()
|
||||
defer s.StopTestBackend()
|
||||
|
||||
keyStore := s.Backend.AccountManager().GetKeystore()
|
||||
keyStore, err := s.Backend.StatusNode().AccountKeyStore()
|
||||
s.NoError(err)
|
||||
s.NotNil(keyStore)
|
||||
|
||||
// create a master extended key
|
||||
|
@ -94,7 +95,8 @@ func (s *AccountsTestSuite) TestImportAccount() {
|
|||
s.StartTestBackend()
|
||||
defer s.StopTestBackend()
|
||||
|
||||
keyStore := s.Backend.AccountManager().GetKeystore()
|
||||
keyStore, err := s.Backend.StatusNode().AccountKeyStore()
|
||||
s.NoError(err)
|
||||
s.NotNil(keyStore)
|
||||
|
||||
// create a private key
|
||||
|
@ -117,8 +119,8 @@ func (s *AccountsTestSuite) TestRecoverAccount() {
|
|||
s.StartTestBackend()
|
||||
defer s.StopTestBackend()
|
||||
|
||||
keyStore := s.Backend.AccountManager().GetKeystore()
|
||||
s.NotNil(keyStore)
|
||||
keyStore, err := s.Backend.StatusNode().AccountKeyStore()
|
||||
s.NoError(err)
|
||||
|
||||
// create an acc
|
||||
accountInfo, mnemonic, err := s.Backend.AccountManager().CreateAccount(TestConfig.Account1.Password)
|
||||
|
|
|
@ -90,7 +90,6 @@ func (s *APITestSuite) TestRaceConditions() {
|
|||
if rnd.Intn(100) > 75 { // introduce random delays
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
s.NoError(s.backend.AccountManager().InitKeystore(randConfig.KeyStoreDir))
|
||||
go randFunc(randConfig)
|
||||
}
|
||||
|
||||
|
@ -125,7 +124,6 @@ func (s *APITestSuite) TestEventsNodeStartStop() {
|
|||
|
||||
nodeConfig, err := MakeTestNodeConfig(GetNetworkID())
|
||||
s.NoError(err)
|
||||
s.NoError(s.backend.AccountManager().InitKeystore(nodeConfig.KeyStoreDir))
|
||||
s.Require().NoError(s.backend.StartNode(nodeConfig))
|
||||
s.NoError(s.backend.StopNode())
|
||||
s.verifyEnvelopes(envelopes, signal.EventNodeStarted, signal.EventNodeReady, signal.EventNodeStopped)
|
||||
|
@ -170,13 +168,12 @@ func (s *APITestSuite) TestNodeStartCrash() {
|
|||
defer func() { s.NoError(db.Close()) }()
|
||||
|
||||
// start node outside the manager (on the same port), so that manager node.Start() method fails
|
||||
outsideNode, err := node.MakeNode(nodeConfig, nil, db)
|
||||
outsideNode, err := node.MakeNode(nodeConfig, db)
|
||||
s.NoError(err)
|
||||
err = outsideNode.Start()
|
||||
s.NoError(err)
|
||||
|
||||
// now try starting using node manager, it should fail (error is irrelevant as it is implementation detail)
|
||||
s.NoError(s.backend.AccountManager().InitKeystore(nodeConfig.KeyStoreDir))
|
||||
s.Error(<-api.RunAsync(func() error { return s.backend.StartNode(nodeConfig) }))
|
||||
|
||||
select {
|
||||
|
|
|
@ -25,7 +25,7 @@ func (s *APIBackendTestSuite) TestNetworkSwitching() {
|
|||
// Get test node configuration.
|
||||
nodeConfig, err := MakeTestNodeConfig(GetNetworkID())
|
||||
s.NoError(err)
|
||||
s.NoError(s.Backend.AccountManager().InitKeystore(nodeConfig.KeyStoreDir))
|
||||
|
||||
s.False(s.Backend.IsNodeRunning())
|
||||
s.Require().NoError(s.Backend.StartNode(nodeConfig))
|
||||
s.True(s.Backend.IsNodeRunning())
|
||||
|
@ -87,7 +87,6 @@ func (s *APIBackendTestSuite) TestRestartNode() {
|
|||
// get config
|
||||
nodeConfig, err := MakeTestNodeConfig(GetNetworkID())
|
||||
s.NoError(err)
|
||||
s.NoError(s.Backend.AccountManager().InitKeystore(nodeConfig.KeyStoreDir))
|
||||
|
||||
s.False(s.Backend.IsNodeRunning())
|
||||
require.NoError(s.Backend.StartNode(nodeConfig))
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
"github.com/ethereum/go-ethereum/les"
|
||||
gethnode "github.com/ethereum/go-ethereum/node"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
|
@ -70,6 +71,20 @@ func (s *ManagerTestSuite) TestReferencesWithoutStartedNode() {
|
|||
},
|
||||
node.ErrNoRunningNode,
|
||||
},
|
||||
{
|
||||
"non-null manager, no running node, get AccountManager",
|
||||
func() (interface{}, error) {
|
||||
return s.StatusNode.AccountManager()
|
||||
},
|
||||
node.ErrNoGethNode,
|
||||
},
|
||||
{
|
||||
"non-null manager, no running node, get AccountKeyStore",
|
||||
func() (interface{}, error) {
|
||||
return s.StatusNode.AccountKeyStore()
|
||||
},
|
||||
node.ErrNoGethNode,
|
||||
},
|
||||
{
|
||||
"non-null manager, no running node, get RPC Client",
|
||||
func() (interface{}, error) {
|
||||
|
@ -133,6 +148,13 @@ func (s *ManagerTestSuite) TestReferencesWithStartedNode() {
|
|||
},
|
||||
&accounts.Manager{},
|
||||
},
|
||||
{
|
||||
"node is running, get AccountKeyStore",
|
||||
func() (interface{}, error) {
|
||||
return s.StatusNode.AccountKeyStore()
|
||||
},
|
||||
&keystore.KeyStore{},
|
||||
},
|
||||
{
|
||||
"node is running, get RPC Client",
|
||||
func() (interface{}, error) {
|
||||
|
@ -161,12 +183,12 @@ func (s *ManagerTestSuite) TestNodeStartStop() {
|
|||
|
||||
// start node
|
||||
s.False(s.StatusNode.IsRunning())
|
||||
s.NoError(s.StatusNode.Start(nodeConfig, nil))
|
||||
s.NoError(s.StatusNode.Start(nodeConfig))
|
||||
// wait till node is started
|
||||
s.True(s.StatusNode.IsRunning())
|
||||
|
||||
// try starting another node (w/o stopping the previously started node)
|
||||
s.Equal(node.ErrNodeRunning, s.StatusNode.Start(nodeConfig, nil))
|
||||
s.Equal(node.ErrNodeRunning, s.StatusNode.Start(nodeConfig))
|
||||
|
||||
// now stop node
|
||||
time.Sleep(100 * time.Millisecond) //https://github.com/status-im/status-go/issues/429#issuecomment-339663163
|
||||
|
@ -174,7 +196,7 @@ func (s *ManagerTestSuite) TestNodeStartStop() {
|
|||
s.False(s.StatusNode.IsRunning())
|
||||
|
||||
// start new node with exactly the same config
|
||||
s.NoError(s.StatusNode.Start(nodeConfig, nil))
|
||||
s.NoError(s.StatusNode.Start(nodeConfig))
|
||||
s.True(s.StatusNode.IsRunning())
|
||||
|
||||
// finally stop the node
|
||||
|
@ -187,7 +209,7 @@ func (s *ManagerTestSuite) TestNetworkSwitching() {
|
|||
nodeConfig, err := MakeTestNodeConfig(GetNetworkID())
|
||||
s.NoError(err)
|
||||
s.False(s.StatusNode.IsRunning())
|
||||
s.NoError(s.StatusNode.Start(nodeConfig, nil))
|
||||
s.NoError(s.StatusNode.Start(nodeConfig))
|
||||
// wait till node is started
|
||||
s.Require().True(s.StatusNode.IsRunning())
|
||||
|
||||
|
@ -203,7 +225,7 @@ func (s *ManagerTestSuite) TestNetworkSwitching() {
|
|||
// start new node with completely different config
|
||||
nodeConfig, err = MakeTestNodeConfig(params.RinkebyNetworkID)
|
||||
s.NoError(err)
|
||||
s.NoError(s.StatusNode.Start(nodeConfig, nil))
|
||||
s.NoError(s.StatusNode.Start(nodeConfig))
|
||||
s.True(s.StatusNode.IsRunning())
|
||||
|
||||
// make sure we are on another network indeed
|
||||
|
@ -229,7 +251,7 @@ func (s *ManagerTestSuite) TestStartWithUpstreamEnabled() {
|
|||
nodeConfig.UpstreamConfig.Enabled = true
|
||||
nodeConfig.UpstreamConfig.URL = networkURL
|
||||
|
||||
s.NoError(s.StatusNode.Start(nodeConfig, nil))
|
||||
s.NoError(s.StatusNode.Start(nodeConfig))
|
||||
s.True(s.StatusNode.IsRunning())
|
||||
|
||||
time.Sleep(100 * time.Millisecond) //https://github.com/status-im/status-go/issues/429#issuecomment-339663163
|
||||
|
|
|
@ -49,7 +49,7 @@ func (s *RPCTestSuite) TestCallRPC() {
|
|||
nodeConfig.UpstreamConfig.URL = networkURL
|
||||
}
|
||||
|
||||
s.NoError(s.StatusNode.Start(nodeConfig, nil))
|
||||
s.NoError(s.StatusNode.Start(nodeConfig))
|
||||
|
||||
rpcClient := s.StatusNode.RPCClient()
|
||||
s.NotNil(rpcClient)
|
||||
|
@ -127,7 +127,7 @@ func (s *RPCTestSuite) TestCallRawResult() {
|
|||
nodeConfig, err := MakeTestNodeConfig(GetNetworkID())
|
||||
s.NoError(err)
|
||||
|
||||
s.NoError(s.StatusNode.Start(nodeConfig, nil))
|
||||
s.NoError(s.StatusNode.Start(nodeConfig))
|
||||
|
||||
client := s.StatusNode.RPCPrivateClient()
|
||||
s.NotNil(client)
|
||||
|
@ -145,7 +145,7 @@ func (s *RPCTestSuite) TestCallRawResultGetTransactionReceipt() {
|
|||
nodeConfig, err := MakeTestNodeConfig(GetNetworkID())
|
||||
s.NoError(err)
|
||||
|
||||
s.NoError(s.StatusNode.Start(nodeConfig, nil))
|
||||
s.NoError(s.StatusNode.Start(nodeConfig))
|
||||
|
||||
client := s.StatusNode.RPCClient()
|
||||
s.NotNil(client)
|
||||
|
|
|
@ -73,7 +73,6 @@ func (s *BaseJSONRPCSuite) SetupTest(upstreamEnabled, statusServiceEnabled, debu
|
|||
|
||||
nodeConfig, err := utils.MakeTestNodeConfig(utils.GetNetworkID())
|
||||
s.NoError(err)
|
||||
s.NoError(s.Backend.AccountManager().InitKeystore(nodeConfig.KeyStoreDir))
|
||||
|
||||
nodeConfig.IPCEnabled = false
|
||||
nodeConfig.EnableStatusService = statusServiceEnabled
|
||||
|
|
|
@ -51,7 +51,7 @@ func (s *StatusNodeTestSuite) StartTestNode(opts ...TestNodeOption) {
|
|||
s.NoError(importTestAccounts(nodeConfig.KeyStoreDir))
|
||||
|
||||
s.False(s.StatusNode.IsRunning())
|
||||
s.NoError(s.StatusNode.Start(nodeConfig, nil))
|
||||
s.NoError(s.StatusNode.Start(nodeConfig))
|
||||
s.True(s.StatusNode.IsRunning())
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ func (s *BackendTestSuite) StartTestBackend(opts ...TestNodeOption) {
|
|||
for i := range opts {
|
||||
opts[i](nodeConfig)
|
||||
}
|
||||
s.NoError(s.Backend.AccountManager().InitKeystore(nodeConfig.KeyStoreDir))
|
||||
|
||||
// import account keys
|
||||
s.NoError(importTestAccounts(nodeConfig.KeyStoreDir))
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ func (s *WhisperExtensionSuite) SetupTest() {
|
|||
cfg, err := utils.MakeTestNodeConfigWithDataDir(fmt.Sprintf("test-shhext-%d", i), dir, 777)
|
||||
s.Require().NoError(err)
|
||||
s.nodes[i] = node.New()
|
||||
s.Require().NoError(s.nodes[i].Start(cfg, nil))
|
||||
s.Require().NoError(s.nodes[i].Start(cfg))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -708,10 +708,7 @@ func (s *WhisperMailboxSuite) startBackend(name string) (*api.StatusBackend, fun
|
|||
backend := api.NewStatusBackend()
|
||||
nodeConfig, err := utils.MakeTestNodeConfig(utils.GetNetworkID())
|
||||
nodeConfig.DataDir = datadir
|
||||
nodeConfig.KeyStoreDir = filepath.Join(datadir, "keystore")
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(backend.AccountManager().InitKeystore(nodeConfig.KeyStoreDir))
|
||||
|
||||
s.Require().False(backend.IsNodeRunning())
|
||||
|
||||
nodeConfig.WhisperConfig.LightClient = true
|
||||
|
@ -751,7 +748,6 @@ func (s *WhisperMailboxSuite) startMailboxBackendWithCallback(
|
|||
s.Require().NoError(err)
|
||||
|
||||
mailboxBackend := api.NewStatusBackend()
|
||||
s.Require().NoError(mailboxBackend.AccountManager().InitKeystore(mailboxConfig.KeyStoreDir))
|
||||
datadir := filepath.Join(utils.RootDir, ".ethereumtest/mailbox", name)
|
||||
|
||||
mailboxConfig.LightEthConfig.Enabled = false
|
||||
|
|
|
@ -40,7 +40,7 @@ func (s *WhisperTestSuite) TestWhisperFilterRace() {
|
|||
whisperService, err := s.Backend.StatusNode().WhisperService()
|
||||
s.NoError(err)
|
||||
|
||||
accountManager := s.Backend.AccountManager()
|
||||
accountManager := account.NewManager(s.Backend.StatusNode())
|
||||
s.NotNil(accountManager)
|
||||
|
||||
whisperAPI := whisper.NewPublicWhisperAPI(whisperService)
|
||||
|
|
Loading…
Reference in New Issue