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"
|
|
|
|
|
2018-03-02 09:25:30 +00:00
|
|
|
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
|
2018-03-20 18:35:28 +00:00
|
|
|
|
2018-06-08 11:29:50 +00:00
|
|
|
"github.com/status-im/status-go/api"
|
|
|
|
"github.com/status-im/status-go/node"
|
2018-05-03 07:35:58 +00:00
|
|
|
"github.com/status-im/status-go/signal"
|
2018-02-08 12:52:47 +00:00
|
|
|
. "github.com/status-im/status-go/t/utils" //nolint: golint
|
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")
|
|
|
|
|
2017-11-07 17:46:11 +00:00
|
|
|
func init() {
|
|
|
|
for id := range TestNetworkNames {
|
|
|
|
nodeConfig, err := MakeTestNodeConfig(id)
|
|
|
|
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) {
|
2017-10-23 16:03:07 +00:00
|
|
|
nodeConfig, err := MakeTestNodeConfig(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())
|
|
|
|
s.NoError(s.StatusNode.Start(nodeConfig))
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// BackendTestSuite is a test suite with api.StatusBackend initialized
|
|
|
|
// and a few utility methods to start and stop node or get various services.
|
|
|
|
type BackendTestSuite struct {
|
|
|
|
suite.Suite
|
2017-10-23 10:41:41 +00:00
|
|
|
Backend *api.StatusBackend
|
2017-10-11 14:20:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetupTest initializes Backend.
|
|
|
|
func (s *BackendTestSuite) SetupTest() {
|
|
|
|
s.Backend = api.NewStatusBackend()
|
|
|
|
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) {
|
|
|
|
nodeConfig, err := MakeTestNodeConfig(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
|
|
|
|
|
|
|
// start node
|
|
|
|
s.False(s.Backend.IsNodeRunning())
|
2018-02-09 13:37:56 +00:00
|
|
|
s.NoError(s.Backend.StartNode(nodeConfig))
|
2017-10-11 14:20:51 +00:00
|
|
|
s.True(s.Backend.IsNodeRunning())
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-02-09 13:37:56 +00:00
|
|
|
s.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
|
|
|
|
2018-04-04 17:39:38 +00:00
|
|
|
err = ImportTestAccount(keyStoreDir, GetAccount1PKFile())
|
2017-10-11 14:20:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-04-04 17:39:38 +00:00
|
|
|
return ImportTestAccount(keyStoreDir, GetAccount2PKFile())
|
2017-10-11 14:20:51 +00:00
|
|
|
}
|