Update code with network id and url returner

This commit is contained in:
Alexander Ewetumo 2017-10-25 13:08:33 +01:00
parent 6b9298fbc1
commit ed61a1b19c
4 changed files with 69 additions and 17 deletions

View File

@ -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(GetNetworkHash(), 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(GetNetworkHashFromID(params.RinkebyNetworkID), firstHash)
nodeStopped, err = s.NodeManager.StopNode()
s.NoError(err)
@ -274,11 +274,14 @@ func (s *ManagerTestSuite) TestNetworkSwitching() {
}
func (s *ManagerTestSuite) TestStartNodeWithUpstreamEnabled() {
nodeConfig, err := e2e.MakeTestNodeConfig(GetNetworkID())
nodeConfig, err := e2e.MakeTestNodeConfig(params.RopstenNetworkID)
s.NoError(err)
networkURL, err := GetNetworkURLFromID(params.RopstenNetworkID)
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)
@ -308,7 +311,7 @@ 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("0x28c4da1cca48d0107ea5ea29a40ac15fca86899c52d02309fa12ea39b86d219c", firstHash)
s.Equal(GetNetworkHash(), firstHash)
}
func (s *ManagerTestSuite) TestRestartNode() {
@ -325,7 +328,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("0x28c4da1cca48d0107ea5ea29a40ac15fca86899c52d02309fa12ea39b86d219c", firstHash)
s.Equal(GetNetworkHash(), firstHash)
}
// TODO(adam): race conditions should be tested with -race flag and unit tests, if possible.

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,7 @@ package integration
import (
"bytes"
"errors"
"flag"
"fmt"
"io"
@ -16,6 +17,10 @@ import (
var (
networkSelected = flag.String("network", "statuschain", "-network=NETWORKID to select network used for tests")
networkURL = flag.String("networkurl", "", "-networkurl=https://ropsten.bob.com/433JU78sdw= to provide a URL for giving network.")
// ErrStatusPrivateNetwork is returned when network id is for a private chain network, whoes URL must be provided.
ErrStatusPrivateNetwork = errors.New("network id reserves for private chain network, provide URL")
// TestConfig defines the default config usable at package-level.
TestConfig *common.TestConfig
@ -115,6 +120,50 @@ func EnsureNodeSync(nodeManager common.NodeManager) {
}
}
// GetNetworkURLFromID returns asociated network url for giving network id.
func GetNetworkURLFromID(id int) (string, error) {
switch id {
case params.MainNetworkID:
return params.MainnetEthereumNetworkURL, nil
case params.RinkebyNetworkID:
return params.RinkebyEthereumNetworkURL, nil
case params.RopstenNetworkID:
return params.RopstenEthereumNetworkURL, nil
}
return "", ErrStatusPrivateNetwork
}
// GetNetworkHashFromID returns the hash associated with a given network id.
func GetNetworkHashFromID(id int) string {
switch id {
case params.MainNetworkID:
return "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
case params.RinkebyNetworkID:
return "0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177"
case params.RopstenNetworkID:
return "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d"
case params.StatusChainNetworkID:
return "0x28c4da1cca48d0107ea5ea29a40ac15fca86899c52d02309fa12ea39b86d219c"
}
return ""
}
// GetNetworkHash returns the hash associated with a given network id.
func GetNetworkHash() string {
return GetNetworkHashFromID(GetNetworkID())
}
// GetNetworkURL returns appropriate network
func GetNetworkURL() (string, error) {
if *networkURL != "" {
return *networkURL, nil
}
return GetNetworkURLFromID(GetNetworkID())
}
// GetNetworkID returns appropriate network id for test based on
// default or provided -network flag.
func GetNetworkID() int {
@ -123,7 +172,7 @@ func GetNetworkID() int {
return params.MainNetworkID
case fmt.Sprintf("%d", params.RinkebyNetworkID), "rinkeby":
return params.RinkebyNetworkID
case fmt.Sprintf("%d", params.RopstenNetworkID), "ropsten":
case fmt.Sprintf("%d", params.RopstenNetworkID), "ropsten", "testnet":
return params.RopstenNetworkID
case fmt.Sprintf("%d", params.StatusChainNetworkID), "statuschain":
return params.StatusChainNetworkID