2018-02-19 15:32:58 +00:00
|
|
|
package e2e
|
2017-10-11 14:20:51 +00:00
|
|
|
|
|
|
|
import (
|
2018-03-20 18:35:28 +00:00
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
|
|
|
2019-12-09 10:36:14 +00:00
|
|
|
"github.com/status-im/status-go/whisper/v6"
|
2018-03-20 18:35:28 +00:00
|
|
|
|
2018-06-08 11:29:50 +00:00
|
|
|
"github.com/status-im/status-go/api"
|
2019-08-29 08:06:22 +00:00
|
|
|
"github.com/status-im/status-go/multiaccounts"
|
|
|
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
2018-06-08 11:29:50 +00:00
|
|
|
"github.com/status-im/status-go/node"
|
2018-05-03 07:35:58 +00:00
|
|
|
"github.com/status-im/status-go/signal"
|
2019-10-04 15:21:24 +00:00
|
|
|
"github.com/status-im/status-go/t/utils"
|
2018-06-08 11:29:50 +00:00
|
|
|
"github.com/status-im/status-go/transactions"
|
2017-10-11 14:20:51 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
2018-04-05 09:45:26 +00:00
|
|
|
// StatusNodeTestSuite defines a test suite with StatusNode.
|
|
|
|
type StatusNodeTestSuite struct {
|
2017-10-11 14:20:51 +00:00
|
|
|
suite.Suite
|
2018-04-05 09:45:26 +00:00
|
|
|
StatusNode *node.StatusNode
|
2017-10-16 22:36:36 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 18:35:28 +00:00
|
|
|
// All general log messages in this package should be routed through this logger.
|
|
|
|
var logger = log.New("package", "status-go/t/e2e")
|
|
|
|
|
2019-10-04 15:21:24 +00:00
|
|
|
func Init() {
|
|
|
|
utils.Init()
|
|
|
|
for id := range utils.TestNetworkNames {
|
|
|
|
nodeConfig, err := utils.MakeTestNodeConfig(id)
|
2017-11-07 17:46:11 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2018-02-18 16:14:27 +00:00
|
|
|
err = importTestAccounts(nodeConfig.KeyStoreDir)
|
2017-11-07 17:46:11 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-05 09:45:26 +00:00
|
|
|
// StartTestNode initiazes a StatusNode instances with configuration retrieved
|
2017-10-11 14:20:51 +00:00
|
|
|
// from the test config.
|
2018-04-05 09:45:26 +00:00
|
|
|
func (s *StatusNodeTestSuite) StartTestNode(opts ...TestNodeOption) {
|
2019-10-04 15:21:24 +00:00
|
|
|
nodeConfig, err := utils.MakeTestNodeConfig(utils.GetNetworkID())
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
// Apply any options altering node config.
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](nodeConfig)
|
|
|
|
}
|
|
|
|
|
|
|
|
// import account keys
|
2018-02-18 16:14:27 +00:00
|
|
|
s.NoError(importTestAccounts(nodeConfig.KeyStoreDir))
|
2017-10-11 14:20:51 +00:00
|
|
|
|
2018-04-05 09:45:26 +00:00
|
|
|
s.False(s.StatusNode.IsRunning())
|
2019-08-20 15:38:40 +00:00
|
|
|
s.NoError(s.StatusNode.Start(nodeConfig, nil))
|
2018-04-05 09:45:26 +00:00
|
|
|
s.True(s.StatusNode.IsRunning())
|
2017-10-11 14:20:51 +00:00
|
|
|
}
|
|
|
|
|
2018-04-05 09:45:26 +00:00
|
|
|
// StopTestNode attempts to stop initialized StatusNode.
|
|
|
|
func (s *StatusNodeTestSuite) StopTestNode() {
|
|
|
|
s.NotNil(s.StatusNode)
|
|
|
|
s.True(s.StatusNode.IsRunning())
|
|
|
|
s.NoError(s.StatusNode.Stop())
|
|
|
|
s.False(s.StatusNode.IsRunning())
|
2017-10-11 14:20:51 +00:00
|
|
|
}
|
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
// BackendTestSuite is a test suite with api.GethStatusBackend initialized
|
2017-10-11 14:20:51 +00:00
|
|
|
// and a few utility methods to start and stop node or get various services.
|
|
|
|
type BackendTestSuite struct {
|
|
|
|
suite.Suite
|
2019-11-23 17:57:05 +00:00
|
|
|
Backend *api.GethStatusBackend
|
2017-10-11 14:20:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetupTest initializes Backend.
|
|
|
|
func (s *BackendTestSuite) SetupTest() {
|
2019-11-23 17:57:05 +00:00
|
|
|
s.Backend = api.NewGethStatusBackend()
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NotNil(s.Backend)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TearDownTest cleans up the packages state.
|
|
|
|
func (s *BackendTestSuite) TearDownTest() {
|
|
|
|
signal.ResetDefaultNodeNotificationHandler()
|
|
|
|
}
|
|
|
|
|
|
|
|
// StartTestBackend imports some keys and starts a node.
|
2017-10-23 16:03:07 +00:00
|
|
|
func (s *BackendTestSuite) StartTestBackend(opts ...TestNodeOption) {
|
2019-10-04 15:21:24 +00:00
|
|
|
nodeConfig, err := utils.MakeTestNodeConfig(utils.GetNetworkID())
|
2018-09-13 16:31:29 +00:00
|
|
|
s.Require().NoError(err)
|
2017-10-11 14:20:51 +00:00
|
|
|
|
|
|
|
// Apply any options altering node config.
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](nodeConfig)
|
|
|
|
}
|
2019-08-20 15:38:40 +00:00
|
|
|
s.NoError(s.Backend.AccountManager().InitKeystore(nodeConfig.KeyStoreDir))
|
2017-10-11 14:20:51 +00:00
|
|
|
// import account keys
|
2018-02-18 16:14:27 +00:00
|
|
|
s.NoError(importTestAccounts(nodeConfig.KeyStoreDir))
|
2017-10-11 14:20:51 +00:00
|
|
|
|
|
|
|
// start node
|
|
|
|
s.False(s.Backend.IsNodeRunning())
|
2018-09-13 16:31:29 +00:00
|
|
|
s.Require().NoError(s.Backend.StartNode(nodeConfig))
|
2017-10-11 14:20:51 +00:00
|
|
|
s.True(s.Backend.IsNodeRunning())
|
|
|
|
}
|
|
|
|
|
2019-08-29 08:06:22 +00:00
|
|
|
func (s *BackendTestSuite) StartTestBackendWithAccount(account multiaccounts.Account, password string, subaccs []accounts.Account, opts ...TestNodeOption) {
|
2019-10-04 15:21:24 +00:00
|
|
|
nodeConfig, err := utils.MakeTestNodeConfig(utils.GetNetworkID())
|
2019-08-29 08:06:22 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Apply any options altering node config.
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](nodeConfig)
|
|
|
|
}
|
|
|
|
// accounts must be imported before keystore is initialized
|
|
|
|
s.NoError(importTestAccounts(nodeConfig.KeyStoreDir))
|
|
|
|
s.Backend.UpdateRootDataDir(nodeConfig.DataDir)
|
|
|
|
s.NoError(s.Backend.OpenAccounts())
|
|
|
|
s.NoError(s.Backend.AccountManager().InitKeystore(nodeConfig.KeyStoreDir))
|
|
|
|
|
|
|
|
s.Require().NoError(s.Backend.StartNodeWithAccountAndConfig(account, password, nodeConfig, subaccs))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *BackendTestSuite) LogoutAndStop() {
|
|
|
|
s.NoError(s.Backend.Logout())
|
|
|
|
s.StopTestBackend()
|
|
|
|
}
|
|
|
|
|
2017-10-11 14:20:51 +00:00
|
|
|
// StopTestBackend stops the node.
|
|
|
|
func (s *BackendTestSuite) StopTestBackend() {
|
|
|
|
s.True(s.Backend.IsNodeRunning())
|
2018-02-09 13:37:56 +00:00
|
|
|
s.NoError(s.Backend.StopNode())
|
2017-10-11 14:20:51 +00:00
|
|
|
s.False(s.Backend.IsNodeRunning())
|
|
|
|
}
|
|
|
|
|
|
|
|
// RestartTestNode restarts a currently running node.
|
|
|
|
func (s *BackendTestSuite) RestartTestNode() {
|
|
|
|
s.True(s.Backend.IsNodeRunning())
|
2018-09-13 16:31:29 +00:00
|
|
|
s.Require().NoError(s.Backend.RestartNode())
|
2017-10-11 14:20:51 +00:00
|
|
|
s.True(s.Backend.IsNodeRunning())
|
|
|
|
}
|
|
|
|
|
|
|
|
// WhisperService returns a reference to the Whisper service.
|
|
|
|
func (s *BackendTestSuite) WhisperService() *whisper.Whisper {
|
2018-04-05 09:45:26 +00:00
|
|
|
whisperService, err := s.Backend.StatusNode().WhisperService()
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
|
|
|
s.NotNil(whisperService)
|
|
|
|
|
|
|
|
return whisperService
|
|
|
|
}
|
|
|
|
|
2018-04-09 08:18:22 +00:00
|
|
|
// Transactor returns a reference to the Transactor.
|
|
|
|
func (s *BackendTestSuite) Transactor() *transactions.Transactor {
|
|
|
|
return s.Backend.Transactor()
|
|
|
|
}
|
|
|
|
|
2018-02-18 16:14:27 +00:00
|
|
|
func importTestAccounts(keyStoreDir string) (err error) {
|
2018-03-20 18:35:28 +00:00
|
|
|
logger.Debug("Import accounts to", "dir", keyStoreDir)
|
2017-11-07 17:46:11 +00:00
|
|
|
|
2019-10-04 15:21:24 +00:00
|
|
|
err = utils.ImportTestAccount(keyStoreDir, utils.GetAccount1PKFile())
|
2017-10-11 14:20:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-10-04 15:21:24 +00:00
|
|
|
return utils.ImportTestAccount(keyStoreDir, utils.GetAccount2PKFile())
|
2017-10-11 14:20:51 +00:00
|
|
|
}
|