Add -network flag for Makefile to chose a network to run tests on #430

PR adds test flag -network to e2e pacakge, for the selection of the desired blockchain network for running tests. It updates readme to demonstrates usage of flag.
This commit is contained in:
Ivan Tomilov 2017-10-26 22:51:04 +03:00 committed by GitHub
commit 21beb685b4
19 changed files with 223 additions and 103 deletions

View File

@ -5,6 +5,7 @@ include ./static/tools/mk/lint.mk
GOBIN = build/bin
GO ?= latest
networkid ?=
# This is a code for automatic help generator.
# It supports ANSI colors and categories.
@ -101,14 +102,14 @@ test-unit-coverage: ##@tests Run unit and integration tests with coverage
test-e2e: ##@tests Run e2e tests
# order: reliability then alphabetical
# TODO(tiabc): make a single command out of them adding `-p 1` flag.
build/env.sh go test -timeout 5m ./e2e/accounts/...
build/env.sh go test -timeout 5m ./e2e/api/...
build/env.sh go test -timeout 5m ./e2e/node/...
build/env.sh go test -timeout 15m ./e2e/jail/...
build/env.sh go test -timeout 20m ./e2e/rpc/...
build/env.sh go test -timeout 20m ./e2e/whisper/...
build/env.sh go test -timeout 10m ./e2e/transactions/...
build/env.sh go test -timeout 40m ./cmd/statusd
build/env.sh go test -timeout 5m ./e2e/accounts/... -network=$(networkid)
build/env.sh go test -timeout 5m ./e2e/api/... -network=$(networkid)
build/env.sh go test -timeout 5m ./e2e/node/... -network=$(networkid)
build/env.sh go test -timeout 15m ./e2e/jail/... -network=$(networkid)
build/env.sh go test -timeout 20m ./e2e/rpc/... -network=$(networkid)
build/env.sh go test -timeout 20m ./e2e/whisper/... -network=$(networkid)
build/env.sh go test -timeout 10m ./e2e/transactions/... -network=$(networkid)
build/env.sh go test -timeout 40m ./cmd/statusd -network=$(networkid)
ci: lint mock-install mock test-unit test-e2e ##@tests Run all linters and tests at once

View File

@ -30,6 +30,8 @@ Use following Makefile commands:
# Testing
To test statusgo, use: `make ci`.
To test statusgo using a giving network by name, use: `make ci networkid=rinkeby`.
To test statusgo using a giving network by id number, use: `make ci networkid=3`.
If you want to launch specific test, for instance `RPCSendTransactions`, use the following command:
```

View File

@ -7,6 +7,27 @@ These tests are run against public testnets: Ropsten and Rinkeby.
e2e package contains a few utilities which are described in a [godoc](https://godoc.org/github.com/status-im/status-go/e2e).
### Flags
#### 1. `-network`
The `-network` flag is used to provide either a network id or network name which specifies the ethereum network to use
for running all test. It by default uses the `StatusChain` network.
#### Usage
To use the `ropsten` network for testing using network name:
```bash
go test -v ./e2e/... -network=ropsten
```
To use the `rinkeby` network with chain id `4` for testing:
```bash
go test -v ./e2e/... -network=4
```
## Run
`make test-e2e`

View File

@ -19,7 +19,7 @@ type AccountsRPCTestSuite struct {
}
func (s *AccountsTestSuite) TestRPCEthAccounts() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
// log into test account
@ -43,14 +43,17 @@ func (s *AccountsTestSuite) TestRPCEthAccountsWithUpstream() {
// FIXME(tiabc): Stop skipping after https://github.com/status-im/status-go/issues/424
s.T().Skip()
s.StartTestBackend(
params.RopstenNetworkID,
e2e.WithUpstream("https://ropsten.infura.io/z6GCTmjdP3FETEJmMBI4"),
)
if GetNetworkID() == params.StatusChainNetworkID {
s.T().Skip()
}
addr, err := GetRemoteURL()
s.NoError(err)
s.StartTestBackend(e2e.WithUpstream(addr))
defer s.StopTestBackend()
// log into test account
err := s.Backend.AccountManager().SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password)
err = s.Backend.AccountManager().SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password)
s.NoError(err)
rpcClient := s.Backend.NodeManager().RPCClient()

View File

@ -8,7 +8,6 @@ import (
"github.com/status-im/status-go/e2e"
"github.com/status-im/status-go/geth/account"
"github.com/status-im/status-go/geth/common"
"github.com/status-im/status-go/geth/params"
. "github.com/status-im/status-go/testing"
"github.com/stretchr/testify/suite"
)
@ -22,7 +21,7 @@ type AccountsTestSuite struct {
}
func (s *AccountsTestSuite) TestAccountsList() {
s.StartTestBackend(params.RinkebyNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
accounts, err := s.Backend.AccountManager().Accounts()
@ -83,7 +82,7 @@ func (s *AccountsTestSuite) TestAccountsList() {
}
func (s *AccountsTestSuite) TestCreateChildAccount() {
s.StartTestBackend(params.RinkebyNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
keyStore, err := s.Backend.NodeManager().AccountKeyStore()
@ -131,7 +130,7 @@ func (s *AccountsTestSuite) TestCreateChildAccount() {
}
func (s *AccountsTestSuite) TestRecoverAccount() {
s.StartTestBackend(params.RinkebyNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
keyStore, err := s.Backend.NodeManager().AccountKeyStore()
@ -183,7 +182,7 @@ func (s *AccountsTestSuite) TestRecoverAccount() {
}
func (s *AccountsTestSuite) TestSelectAccount() {
s.StartTestBackend(params.RinkebyNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
// test to see if the account was injected in whisper
@ -218,7 +217,7 @@ func (s *AccountsTestSuite) TestSelectAccount() {
}
func (s *AccountsTestSuite) TestSelectedAccountOnRestart() {
s.StartTestBackend(params.RinkebyNetworkID)
s.StartTestBackend()
// we need to make sure that selected account is injected as identity into Whisper
whisperService := s.WhisperService()

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(params.StatusChainNetworkID)
nodeConfig1, err := e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
nodeConfig2, err := e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
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(params.StatusChainNetworkID)
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(params.StatusChainNetworkID)
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(params.StatusChainNetworkID)
nodeConfig1, err := e2e.MakeTestNodeConfig(GetNetworkID())
require.NoError(err)
nodeConfig2, err := e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
nodeConfig2, err := e2e.MakeTestNodeConfig(GetNetworkID())
require.NoError(err)
nodeConfigs := []*params.NodeConfig{nodeConfig1, nodeConfig2}
@ -191,7 +191,7 @@ func (s *APIBackendTestSuite) TestRaceConditions() {
// so this test should only check StatusBackend logic with a mocked version of the underlying NodeManager.
func (s *APIBackendTestSuite) TestNetworkSwitching() {
// get Ropsten config
nodeConfig, err := e2e.MakeTestNodeConfig(params.RopstenNetworkID)
nodeConfig, err := e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
s.False(s.Backend.IsNodeRunning())
@ -203,7 +203,7 @@ func (s *APIBackendTestSuite) TestNetworkSwitching() {
firstHash, err := e2e.FirstBlockHash(s.Backend.NodeManager())
s.NoError(err)
s.Equal("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d", firstHash)
s.Equal(GetHeadHash(), firstHash)
// now stop node, and make sure that a new node, on different network can be started
nodeStopped, err := s.Backend.StopNode()
@ -211,7 +211,7 @@ func (s *APIBackendTestSuite) TestNetworkSwitching() {
<-nodeStopped
// start new node with completely different config
nodeConfig, err = e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
nodeConfig, err = e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
s.False(s.Backend.IsNodeRunning())
@ -224,7 +224,7 @@ func (s *APIBackendTestSuite) TestNetworkSwitching() {
// make sure we are on another network indeed
firstHash, err = e2e.FirstBlockHash(s.Backend.NodeManager())
s.NoError(err)
s.Equal("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177", firstHash)
s.Equal(GetHeadHash(), firstHash)
nodeStopped, err = s.Backend.StopNode()
s.NoError(err)
@ -239,7 +239,7 @@ func (s *APIBackendTestSuite) TestResetChainData() {
require := s.Require()
require.NotNil(s.Backend)
s.StartTestBackend(params.RinkebyNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
EnsureNodeSync(s.Backend.NodeManager())
@ -253,7 +253,7 @@ func (s *APIBackendTestSuite) TestResetChainData() {
// make sure we can read the first byte, and it is valid (for Rinkeby)
firstHash, err := e2e.FirstBlockHash(s.Backend.NodeManager())
s.NoError(err)
s.Equal("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177", firstHash)
s.Equal(GetHeadHash(), firstHash)
}
// FIXME(tiabc): There's also a test with the same name in geth/node/manager_test.go
@ -262,12 +262,20 @@ func (s *APIBackendTestSuite) TestRestartNode() {
require := s.Require()
require.NotNil(s.Backend)
s.StartTestBackend(params.RinkebyNetworkID)
defer s.StopTestBackend()
// get config
nodeConfig, err := e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
s.False(s.Backend.IsNodeRunning())
nodeStarted, err := s.Backend.StartNode(nodeConfig)
s.NoError(err)
<-nodeStarted // wait till node is started
s.True(s.Backend.IsNodeRunning())
firstHash, err := e2e.FirstBlockHash(s.Backend.NodeManager())
s.NoError(err)
s.Equal("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177", firstHash)
s.Equal(GetHeadHash(), firstHash)
s.True(s.Backend.IsNodeRunning())
nodeRestarted, err := s.Backend.RestartNode()
@ -278,5 +286,5 @@ func (s *APIBackendTestSuite) TestRestartNode() {
// make sure we can read the first byte, and it is valid (for Rinkeby)
firstHash, err = e2e.FirstBlockHash(s.Backend.NodeManager())
s.NoError(err)
s.Equal("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177", firstHash)
s.Equal(GetHeadHash(), firstHash)
}

View File

@ -36,7 +36,7 @@ func (s *JailRPCTestSuite) SetupTest() {
}
func (s *JailRPCTestSuite) TestJailRPCSend() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
EnsureNodeSync(s.Backend.NodeManager())
@ -69,7 +69,7 @@ func (s *JailRPCTestSuite) TestJailRPCSend() {
}
func (s *JailRPCTestSuite) TestIsConnected() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
s.jail.Parse(testChatID, "")
@ -96,7 +96,7 @@ func (s *JailRPCTestSuite) TestIsConnected() {
// regression test: eth_getTransactionReceipt with invalid transaction hash should return null
func (s *JailRPCTestSuite) TestRegressionGetTransactionReceipt() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
rpcClient := s.Backend.NodeManager().RPCClient()
@ -109,7 +109,7 @@ func (s *JailRPCTestSuite) TestRegressionGetTransactionReceipt() {
}
func (s *JailRPCTestSuite) TestContractDeployment() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
EnsureNodeSync(s.Backend.NodeManager())
@ -191,7 +191,7 @@ func (s *JailRPCTestSuite) TestContractDeployment() {
}
func (s *JailRPCTestSuite) TestJailVMPersistence() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
EnsureNodeSync(s.Backend.NodeManager())

View File

@ -126,7 +126,7 @@ func (s *ManagerTestSuite) TestReferencesWithoutStartedNode() {
}
func (s *ManagerTestSuite) TestReferencesWithStartedNode() {
s.StartTestNode(params.RinkebyNetworkID)
s.StartTestNode()
defer s.StopTestNode()
var testCases = []struct {
@ -194,7 +194,7 @@ func (s *ManagerTestSuite) TestReferencesWithStartedNode() {
}
func (s *ManagerTestSuite) TestNodeStartStop() {
nodeConfig, err := e2e.MakeTestNodeConfig(params.StatusChainNetworkID)
nodeConfig, err := e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
// try stopping non-started node
@ -235,7 +235,7 @@ func (s *ManagerTestSuite) TestNodeStartStop() {
func (s *ManagerTestSuite) TestNetworkSwitching() {
// get Ropsten config
nodeConfig, err := e2e.MakeTestNodeConfig(params.RopstenNetworkID)
nodeConfig, err := e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
s.False(s.NodeManager.IsNodeRunning())
nodeStarted, err := s.NodeManager.StartNode(nodeConfig)
@ -246,7 +246,7 @@ func (s *ManagerTestSuite) TestNetworkSwitching() {
firstHash, err := e2e.FirstBlockHash(s.NodeManager)
s.NoError(err)
s.Equal("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d", firstHash)
s.Equal(GetHeadHash(), firstHash)
// now stop node, and make sure that a new node, on different network can be started
nodeStopped, err := s.NodeManager.StopNode()
@ -266,7 +266,7 @@ func (s *ManagerTestSuite) TestNetworkSwitching() {
// make sure we are on another network indeed
firstHash, err = e2e.FirstBlockHash(s.NodeManager)
s.NoError(err)
s.Equal("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177", firstHash)
s.Equal(GetHeadHashFromNetworkID(params.RinkebyNetworkID), firstHash)
nodeStopped, err = s.NodeManager.StopNode()
s.NoError(err)
@ -274,11 +274,18 @@ func (s *ManagerTestSuite) TestNetworkSwitching() {
}
func (s *ManagerTestSuite) TestStartNodeWithUpstreamEnabled() {
nodeConfig, err := e2e.MakeTestNodeConfig(params.RopstenNetworkID)
if GetNetworkID() == params.StatusChainNetworkID {
s.T().Skip()
}
nodeConfig, err := e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
networkURL, err := GetRemoteURL()
s.NoError(err)
nodeConfig.UpstreamConfig.Enabled = true
nodeConfig.UpstreamConfig.URL = "https://ropsten.infura.io/nKmXgiFgc2KqtoQ8BCGJ"
nodeConfig.UpstreamConfig.URL = networkURL
nodeStarted, err := s.NodeManager.StartNode(nodeConfig)
s.NoError(err)
@ -293,7 +300,7 @@ func (s *ManagerTestSuite) TestStartNodeWithUpstreamEnabled() {
func (s *ManagerTestSuite) TestResetChainData() {
s.T().Skip()
s.StartTestNode(params.RinkebyNetworkID)
s.StartTestNode()
defer s.StopTestNode()
EnsureNodeSync(s.NodeManager)
@ -308,11 +315,11 @@ func (s *ManagerTestSuite) TestResetChainData() {
// make sure we can read the first byte, and it is valid (for Rinkeby)
firstHash, err := e2e.FirstBlockHash(s.NodeManager)
s.NoError(err)
s.Equal("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177", firstHash)
s.Equal(GetHeadHash(), firstHash)
}
func (s *ManagerTestSuite) TestRestartNode() {
s.StartTestNode(params.RinkebyNetworkID)
s.StartTestNode()
defer s.StopTestNode()
s.True(s.NodeManager.IsNodeRunning())
@ -325,7 +332,7 @@ func (s *ManagerTestSuite) TestRestartNode() {
// make sure we can read the first byte, and it is valid (for Rinkeby)
firstHash, err := e2e.FirstBlockHash(s.NodeManager)
s.NoError(err)
s.Equal("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177", firstHash)
s.Equal(GetHeadHash(), firstHash)
}
// TODO(adam): race conditions should be tested with -race flag and unit tests, if possible.
@ -335,10 +342,10 @@ func (s *ManagerTestSuite) TestRaceConditions() {
progress := make(chan struct{}, cnt)
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
nodeConfig1, e := e2e.MakeTestNodeConfig(params.RopstenNetworkID)
nodeConfig1, e := e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(e)
nodeConfig2, e := e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
nodeConfig2, e := e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(e)
nodeConfigs := []*params.NodeConfig{nodeConfig1, nodeConfig2}
@ -466,7 +473,7 @@ func (s *ManagerTestSuite) TestNodeStartCrash() {
}
})
nodeConfig, err := e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
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

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

View File

@ -2,6 +2,7 @@ package rpc
import (
"context"
"fmt"
"sync"
"testing"
"time"
@ -30,8 +31,12 @@ func (s *RPCTestSuite) SetupTest() {
}
func (s *RPCTestSuite) TestCallRPC() {
if GetNetworkID() == params.StatusChainNetworkID {
s.T().Skip()
}
for _, upstreamEnabled := range []bool{false, true} {
nodeConfig, err := e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
nodeConfig, err := e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
nodeConfig.IPCEnabled = false
@ -39,8 +44,11 @@ func (s *RPCTestSuite) TestCallRPC() {
nodeConfig.HTTPHost = "" // to make sure that no HTTP interface is started
if upstreamEnabled {
networkURL, err := GetRemoteURL()
s.NoError(err)
nodeConfig.UpstreamConfig.Enabled = true
nodeConfig.UpstreamConfig.URL = "https://rinkeby.infura.io/nKmXgiFgc2KqtoQ8BCGJ"
nodeConfig.UpstreamConfig.URL = networkURL
}
nodeStarted, err := s.NodeManager.StartNode(nodeConfig)
@ -72,7 +80,7 @@ func (s *RPCTestSuite) TestCallRPC() {
{
`{"jsonrpc":"2.0","method":"net_version","params":[],"id":67}`,
func(resultJSON string) {
expected := `{"jsonrpc":"2.0","id":67,"result":"4"}`
expected := `{"jsonrpc":"2.0","id":67,"result":"` + fmt.Sprintf("%d", GetNetworkID()) + `"}`
s.Equal(expected, resultJSON)
},
},
@ -86,7 +94,7 @@ func (s *RPCTestSuite) TestCallRPC() {
{
`[{"jsonrpc":"2.0","method":"net_version","params":[],"id":67},{"jsonrpc":"2.0","method":"web3_sha3","params":["0x68656c6c6f20776f726c64"],"id":68}]`,
func(resultJSON string) {
expected := `[{"jsonrpc":"2.0","id":67,"result":"4"},{"jsonrpc":"2.0","id":68,"result":"0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"}]`
expected := `[{"jsonrpc":"2.0","id":67,"result":"` + fmt.Sprintf("%d", GetNetworkID()) + `"},{"jsonrpc":"2.0","id":68,"result":"0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"}]`
s.Equal(expected, resultJSON)
},
},
@ -122,7 +130,7 @@ func (s *RPCTestSuite) TestCallRPC() {
// TestCallRawResult checks if returned response is a valid JSON-RPC response.
func (s *RPCTestSuite) TestCallRawResult() {
nodeConfig, err := e2e.MakeTestNodeConfig(params.StatusChainNetworkID)
nodeConfig, err := e2e.MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
nodeStarted, err := s.NodeManager.StartNode(nodeConfig)
@ -141,7 +149,7 @@ func (s *RPCTestSuite) TestCallRawResult() {
// TestCallContextResult checks if result passed to CallContext
// is set accordingly to its underlying memory layout.
func (s *RPCTestSuite) TestCallContextResult() {
s.StartTestNode(params.StatusChainNetworkID)
s.StartTestNode()
defer s.StopTestNode()
EnsureNodeSync(s.NodeManager)

View File

@ -6,6 +6,7 @@ import (
"github.com/status-im/status-go/geth/api"
"github.com/status-im/status-go/geth/common"
"github.com/status-im/status-go/geth/signal"
. "github.com/status-im/status-go/testing" //nolint: golint
"github.com/stretchr/testify/suite"
)
@ -17,8 +18,8 @@ type NodeManagerTestSuite struct {
// StartTestNode initiazes a NodeManager instances with configuration retrieved
// from the test config.
func (s *NodeManagerTestSuite) StartTestNode(networkID int, opts ...TestNodeOption) {
nodeConfig, err := MakeTestNodeConfig(networkID)
func (s *NodeManagerTestSuite) StartTestNode(opts ...TestNodeOption) {
nodeConfig, err := MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
// Apply any options altering node config.
@ -66,8 +67,8 @@ func (s *BackendTestSuite) TearDownTest() {
}
// StartTestBackend imports some keys and starts a node.
func (s *BackendTestSuite) StartTestBackend(networkID int, opts ...TestNodeOption) {
nodeConfig, err := MakeTestNodeConfig(networkID)
func (s *BackendTestSuite) StartTestBackend(opts ...TestNodeOption) {
nodeConfig, err := MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
// Apply any options altering node config.

View File

@ -32,7 +32,7 @@ type TransactionsTestSuite struct {
}
func (s *TransactionsTestSuite) TestCallRPCSendTransaction() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
EnsureNodeSync(s.Backend.NodeManager())
@ -83,13 +83,16 @@ func (s *TransactionsTestSuite) TestCallRPCSendTransactionUpstream() {
// FIXME(tiabc): Stop skipping after https://github.com/status-im/status-go/issues/424
s.T().Skip()
s.StartTestBackend(
params.RopstenNetworkID,
e2e.WithUpstream("https://ropsten.infura.io/nKmXgiFgc2KqtoQ8BCGJ"),
)
if GetNetworkID() == params.StatusChainNetworkID {
s.T().Skip()
}
addr, err := GetRemoteURL()
s.NoError(err)
s.StartTestBackend(e2e.WithUpstream(addr))
defer s.StopTestBackend()
err := s.Backend.AccountManager().SelectAccount(TestConfig.Account2.Address, TestConfig.Account2.Password)
err = s.Backend.AccountManager().SelectAccount(TestConfig.Account2.Address, TestConfig.Account2.Password)
s.NoError(err)
transactionCompleted := make(chan struct{})
@ -139,7 +142,7 @@ func (s *TransactionsTestSuite) TestCallRPCSendTransactionUpstream() {
// FIXME(tiabc): Sometimes it fails due to "no suitable peers found".
func (s *TransactionsTestSuite) TestSendContractTx() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
EnsureNodeSync(s.Backend.NodeManager())
@ -226,7 +229,7 @@ func (s *TransactionsTestSuite) TestSendContractTx() {
}
func (s *TransactionsTestSuite) TestSendEther() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
EnsureNodeSync(s.Backend.NodeManager())
@ -312,13 +315,16 @@ func (s *TransactionsTestSuite) TestSendEtherTxUpstream() {
// FIXME(tiabc): Stop skipping after https://github.com/status-im/status-go/issues/424
s.T().Skip()
s.StartTestBackend(
params.RopstenNetworkID,
e2e.WithUpstream("https://ropsten.infura.io/z6GCTmjdP3FETEJmMBI4"),
)
if GetNetworkID() == params.StatusChainNetworkID {
s.T().Skip()
}
addr, err := GetRemoteURL()
s.NoError(err)
s.StartTestBackend(e2e.WithUpstream(addr))
defer s.StopTestBackend()
err := s.Backend.AccountManager().SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password)
err = s.Backend.AccountManager().SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password)
s.NoError(err)
completeQueuedTransaction := make(chan struct{})
@ -366,7 +372,7 @@ func (s *TransactionsTestSuite) TestSendEtherTxUpstream() {
}
func (s *TransactionsTestSuite) TestDoubleCompleteQueuedTransactions() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
EnsureNodeSync(s.Backend.NodeManager())
@ -443,7 +449,7 @@ func (s *TransactionsTestSuite) TestDoubleCompleteQueuedTransactions() {
}
func (s *TransactionsTestSuite) TestDiscardQueuedTransaction() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
EnsureNodeSync(s.Backend.NodeManager())
@ -523,7 +529,7 @@ func (s *TransactionsTestSuite) TestDiscardQueuedTransaction() {
}
func (s *TransactionsTestSuite) TestCompleteMultipleQueuedTransactions() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
EnsureNodeSync(s.Backend.NodeManager())
@ -616,7 +622,7 @@ func (s *TransactionsTestSuite) TestCompleteMultipleQueuedTransactions() {
}
func (s *TransactionsTestSuite) TestDiscardMultipleQueuedTransactions() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
EnsureNodeSync(s.Backend.NodeManager())
@ -732,7 +738,7 @@ func (s *TransactionsTestSuite) TestDiscardMultipleQueuedTransactions() {
}
func (s *TransactionsTestSuite) TestNonExistentQueuedTransactions() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
backend := s.LightEthereumService().StatusBackend
@ -751,7 +757,7 @@ func (s *TransactionsTestSuite) TestNonExistentQueuedTransactions() {
}
func (s *TransactionsTestSuite) TestEvictionOfQueuedTransactions() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
backend := s.LightEthereumService().StatusBackend

View File

@ -13,7 +13,6 @@ import (
whisper "github.com/ethereum/go-ethereum/whisper/whisperv5"
"github.com/status-im/status-go/e2e"
"github.com/status-im/status-go/geth/common"
"github.com/status-im/status-go/geth/params"
"github.com/status-im/status-go/static"
. "github.com/status-im/status-go/testing"
"github.com/stretchr/testify/suite"
@ -46,8 +45,8 @@ type WhisperJailTestSuite struct {
Jail common.JailManager
}
func (s *WhisperJailTestSuite) StartTestBackend(networkID int, opts ...e2e.TestNodeOption) {
s.BackendTestSuite.StartTestBackend(networkID, opts...)
func (s *WhisperJailTestSuite) StartTestBackend(opts ...e2e.TestNodeOption) {
s.BackendTestSuite.StartTestBackend(opts...)
s.WhisperAPI = whisper.NewPublicWhisperAPI(s.WhisperService())
s.Jail = s.Backend.JailManager()
@ -82,7 +81,7 @@ func (s *WhisperJailTestSuite) GetAccountKey(account struct {
// TODO(adamb) Uncomment when issue #336 is fixed.
/*
func (s *WhisperJailTestSuite) DontTestJailWhisper() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
_, accountKey1Hex, err := s.GetAccountKey(TestConfig.Account1)
@ -376,7 +375,7 @@ func (s *WhisperJailTestSuite) DontTestJailWhisper() {
*/
func (s *WhisperJailTestSuite) TestEncryptedAnonymousMessage() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
accountKey2, accountKey2Hex, err := s.GetAccountKey(TestConfig.Account2)

View File

@ -9,7 +9,6 @@ import (
"github.com/status-im/status-go/e2e"
"github.com/status-im/status-go/geth/account"
"github.com/status-im/status-go/geth/node"
"github.com/status-im/status-go/geth/params"
. "github.com/status-im/status-go/testing"
"github.com/stretchr/testify/suite"
)
@ -30,7 +29,7 @@ func (s *WhisperTestSuite) SetupTest() {
// TODO(adam): can anyone explain what this test is testing?
// I don't see any race condition testing here.
func (s *WhisperTestSuite) TestWhisperFilterRace() {
s.StartTestNode(params.RinkebyNetworkID)
s.StartTestNode()
defer s.StopTestNode()
whisperService, err := s.NodeManager.WhisperService()
@ -95,7 +94,7 @@ func (s *WhisperTestSuite) TestWhisperFilterRace() {
}
func (s *WhisperTestSuite) TestLogout() {
s.StartTestNode(params.RinkebyNetworkID)
s.StartTestNode()
defer s.StopTestNode()
whisperService, err := s.NodeManager.WhisperService()

View File

@ -239,6 +239,10 @@ func (m *StatusBackend) DiscardTransactions(ids []common.QueuedTxID) map[common.
// registerHandlers attaches Status callback handlers to running node
func (m *StatusBackend) registerHandlers() error {
rpcClient := m.NodeManager().RPCClient()
if rpcClient == nil {
return node.ErrRPCClient
}
rpcClient.RegisterHandler("eth_accounts", m.accountManager.AccountsRPCHandler())
rpcClient.RegisterHandler("eth_sendTransaction", m.txQueueManager.SendTransactionRPCHandler)

View File

@ -543,11 +543,11 @@ func (c *NodeConfig) updateUpstreamConfig() error {
switch c.NetworkID {
case MainNetworkID:
c.UpstreamConfig.URL = UpstreamMainNetEthereumNetworkURL
c.UpstreamConfig.URL = MainnetEthereumNetworkURL
case RopstenNetworkID:
c.UpstreamConfig.URL = UpstreamRopstenEthereumNetworkURL
c.UpstreamConfig.URL = RopstenEthereumNetworkURL
case RinkebyNetworkID:
c.UpstreamConfig.URL = UpstreamRinkebyEthereumNetworkURL
c.UpstreamConfig.URL = RinkebyEthereumNetworkURL
}
return nil

View File

@ -79,17 +79,17 @@ const (
// FirebaseNotificationTriggerURL is URL where FCM notification requests are sent to
FirebaseNotificationTriggerURL = "https://fcm.googleapis.com/fcm/send"
// UpstreamMainNetEthereumNetworkURL is URL where the upstream ethereum network is loaded to
// MainnetEthereumNetworkURL is URL where the upstream ethereum network is loaded to
// allow us avoid syncing node.
UpstreamMainNetEthereumNetworkURL = "https://mainnet.infura.io/nKmXgiFgc2KqtoQ8BCGJ"
MainnetEthereumNetworkURL = "https://mainnet.infura.io/nKmXgiFgc2KqtoQ8BCGJ"
// UpstreamRopstenEthereumNetworkURL is URL where the upstream ethereum network is loaded to
// RopstenEthereumNetworkURL is URL where the upstream ethereum network is loaded to
// allow us avoid syncing node.
UpstreamRopstenEthereumNetworkURL = "https://ropsten.infura.io/nKmXgiFgc2KqtoQ8BCGJ"
RopstenEthereumNetworkURL = "https://ropsten.infura.io/nKmXgiFgc2KqtoQ8BCGJ"
// UpstreamRinkebyEthereumNetworkURL is URL where the upstream ethereum network is loaded to
// RinkebyEthereumNetworkURL is URL where the upstream ethereum network is loaded to
// allow us avoid syncing node.
UpstreamRinkebyEthereumNetworkURL = "https://rinkeby.infura.io/nKmXgiFgc2KqtoQ8BCGJ"
RinkebyEthereumNetworkURL = "https://rinkeby.infura.io/nKmXgiFgc2KqtoQ8BCGJ"
// MainNetworkID is id of the main network
MainNetworkID = 1

View File

@ -2,6 +2,9 @@ package integration
import (
"bytes"
"errors"
"flag"
"fmt"
"io"
"os"
"path/filepath"
@ -13,6 +16,11 @@ import (
)
var (
networkSelected = flag.String("network", "statuschain", "-network=NETWORKID or -network=NETWORKNAME to select network used for tests")
// ErrNoRemoteURL is returned when network id has no associated url.
ErrNoRemoteURL = errors.New("network id requires a remote URL")
// TestConfig defines the default config usable at package-level.
TestConfig *common.TestConfig
@ -110,3 +118,57 @@ func EnsureNodeSync(nodeManager common.NodeManager) {
}
}
}
// GetRemoteURLFromNetworkID returns asociated network url for giving network id.
func GetRemoteURLFromNetworkID(id int) (url string, err error) {
switch id {
case params.MainNetworkID:
url = params.MainnetEthereumNetworkURL
case params.RinkebyNetworkID:
url = params.RinkebyEthereumNetworkURL
case params.RopstenNetworkID:
url = params.RopstenEthereumNetworkURL
}
err = ErrNoRemoteURL
return
}
// GetHeadHashFromNetworkID returns the hash associated with a given network id.
func GetHeadHashFromNetworkID(id int) string {
switch id {
case params.RinkebyNetworkID:
return "0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177"
case params.RopstenNetworkID:
return "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d"
case params.StatusChainNetworkID:
return "0x28c4da1cca48d0107ea5ea29a40ac15fca86899c52d02309fa12ea39b86d219c"
}
return ""
}
// GetRemoteURL returns the url associated with a given network id.
func GetRemoteURL() (string, error) {
return GetRemoteURLFromNetworkID(GetNetworkID())
}
// GetHeadHash returns the hash associated with a given network id.
func GetHeadHash() string {
return GetHeadHashFromNetworkID(GetNetworkID())
}
// 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.RinkebyNetworkID), "rinkeby":
return params.RinkebyNetworkID
case fmt.Sprintf("%d", params.RopstenNetworkID), "ropsten", "testnet":
return params.RopstenNetworkID
case fmt.Sprintf("%d", params.StatusChainNetworkID), "statuschain":
return params.StatusChainNetworkID
}
return params.StatusChainNetworkID
}