Update readme and update code for testing

This commit is contained in:
Alexander Ewetumo 2017-10-24 11:23:53 +01:00
parent a257d1c201
commit a1668add06
9 changed files with 42 additions and 44 deletions

View File

@ -15,18 +15,18 @@ for running all test. It by default uses the `StatusChain` network.
#### Usage
To use the `mainnet` network for testing using network name:
```bash
go test -v ./e2e/... -network=mainnet
```
To use the `ropsten` network for testing using network id:
To use the `ropsten` network for testing using network name:
```bash
go test -v ./e2e/... -network=3
```
To use the `rinkeby` network for testing using network id:
```bash
go test -v ./e2e/... -network=4
```
## Run

View File

@ -56,10 +56,10 @@ func (s *APITestSuite) TestRaceConditions() {
progress := make(chan struct{}, cnt)
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
nodeConfig1, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
nodeConfig1, err := e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
nodeConfig2, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
nodeConfig2, err := e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
nodeConfigs := []*params.NodeConfig{nodeConfig1, nodeConfig2}
@ -129,7 +129,7 @@ func (s *APITestSuite) TestCellsRemovedAfterSwitchAccount() {
}
)
config, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
config, err := e2e.MakeTestNodeConfig(GetNetworkID())
require.NoError(err)
err = s.api.StartNode(config)
require.NoError(err)
@ -166,7 +166,7 @@ func (s *APITestSuite) TestLogoutRemovesCells() {
require = s.Require()
)
config, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
config, err := e2e.MakeTestNodeConfig(GetNetworkID())
require.NoError(err)
err = s.api.StartNode(config)
require.NoError(err)

View File

@ -34,10 +34,10 @@ func (s *APIBackendTestSuite) TestRaceConditions() {
progress := make(chan struct{}, cnt)
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
nodeConfig1, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
nodeConfig1, err := e2e.MakeTestNodeConfig(GetNetworkID())
require.NoError(err)
nodeConfig2, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
nodeConfig2, err := e2e.MakeTestNodeConfig(GetNetworkID())
require.NoError(err)
nodeConfigs := []*params.NodeConfig{nodeConfig1, nodeConfig2}

View File

@ -11,6 +11,7 @@ import (
"github.com/status-im/status-go/geth/jail"
"github.com/status-im/status-go/geth/signal"
"github.com/status-im/status-go/static"
. "github.com/status-im/status-go/testing" //nolint: golint
"github.com/stretchr/testify/suite"
)

View File

@ -194,7 +194,7 @@ func (s *ManagerTestSuite) TestReferencesWithStartedNode() {
}
func (s *ManagerTestSuite) TestNodeStartStop() {
nodeConfig, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
nodeConfig, err := e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
// try stopping non-started node
@ -274,7 +274,7 @@ func (s *ManagerTestSuite) TestNetworkSwitching() {
}
func (s *ManagerTestSuite) TestStartNodeWithUpstreamEnabled() {
nodeConfig, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
nodeConfig, err := e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
nodeConfig.UpstreamConfig.Enabled = true
@ -335,10 +335,10 @@ func (s *ManagerTestSuite) TestRaceConditions() {
progress := make(chan struct{}, cnt)
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
nodeConfig1, e := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
nodeConfig1, e := e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(e)
nodeConfig2, e := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
nodeConfig2, e := e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(e)
nodeConfigs := []*params.NodeConfig{nodeConfig1, nodeConfig2}
@ -466,7 +466,7 @@ func (s *ManagerTestSuite) TestNodeStartCrash() {
}
})
nodeConfig, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
nodeConfig, err := e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
// start node outside the manager (on the same port), so that manager node.Start() method fails

View File

@ -6,6 +6,7 @@ import (
"github.com/status-im/status-go/e2e"
"github.com/status-im/status-go/geth/node"
"github.com/status-im/status-go/geth/rpc"
. "github.com/status-im/status-go/testing" //nolint: golint
"github.com/stretchr/testify/suite"
)
@ -23,7 +24,7 @@ func (s *RPCClientTestSuite) SetupTest() {
}
func (s *RPCClientTestSuite) TestNewClient() {
config, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
config, err := e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
nodeStarted, err := s.NodeManager.StartNode(config)

View File

@ -122,7 +122,7 @@ func (s *RPCTestSuite) TestCallRPC() {
// TestCallRawResult checks if returned response is a valid JSON-RPC response.
func (s *RPCTestSuite) TestCallRawResult() {
nodeConfig, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
nodeConfig, err := e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
nodeStarted, err := s.NodeManager.StartNode(nodeConfig)

View File

@ -2,12 +2,9 @@ package e2e
import (
"context"
"flag"
"fmt"
"path/filepath"
"runtime"
"strconv"
"strings"
"testing"
gethcommon "github.com/ethereum/go-ethereum/common"
@ -16,10 +13,6 @@ import (
. "github.com/status-im/status-go/testing" //nolint: golint
)
var (
networkSelected = flag.String("network", "statuschain", "-network=NETWORKNAME or -network=NETWORKID to select network used for tests")
)
// TestNodeOption is a callback passed to StartTestNode which alters its config.
type TestNodeOption func(config *params.NodeConfig)
@ -87,20 +80,3 @@ func FirstBlockHash(nodeManager common.NodeManager) (string, error) {
return firstBlock.Hash.Hex(), nil
}
// GetNetworkID returns appropriate network id for test based on
// default or provided -network flag.
func GetNetworkID() int {
switch strings.ToLower(*networkSelected) {
case fmt.Sprintf("%d", params.MainNetworkID), "mainnet":
return params.MainNetworkID
case fmt.Sprintf("%d", params.RinkebyNetworkID), "rinkeby":
return params.RinkebyNetworkID
case fmt.Sprintf("%d", params.RopstenNetworkID), "ropsten":
return params.RopstenNetworkID
case fmt.Sprintf("%d", params.StatusChainNetworkID), "statuschain":
return params.StatusChainNetworkID
}
return params.StatusChainNetworkID
}

View File

@ -3,6 +3,7 @@ package integration
import (
"bytes"
"errors"
"flag"
"io"
"os"
"path/filepath"
@ -14,6 +15,8 @@ import (
)
var (
networkSelected = flag.Int("network", "statuschain", "-network=NETWORKID to select network used for tests")
// TestConfig defines the default config usable at package-level.
TestConfig *common.TestConfig
@ -112,3 +115,20 @@ func EnsureNodeSync(nodeManager common.NodeManager) error {
}
}
}
// GetNetworkID returns appropriate network id for test based on
// default or provided -network flag.
func GetNetworkID() int {
switch strings.ToLower(*networkSelected) {
case params.MainNetworkID:
return params.MainNetworkID
case params.RinkebyNetworkID:
return params.RinkebyNetworkID
case params.RopstenNetworkID:
return params.RopstenNetworkID
case params.StatusChainNetworkID:
return params.StatusChainNetworkID
}
return params.StatusChainNetworkID
}