Add GetNetworkID function for tests

This commit is contained in:
Alexander Ewetumo 2017-10-23 14:56:47 +01:00
parent d341e385fa
commit a98238ad97
1 changed files with 23 additions and 3 deletions

View File

@ -2,9 +2,12 @@ package e2e
import ( import (
"context" "context"
"flag"
"fmt"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strconv" "strconv"
"strings"
"testing" "testing"
gethcommon "github.com/ethereum/go-ethereum/common" gethcommon "github.com/ethereum/go-ethereum/common"
@ -17,9 +20,9 @@ var (
networkSelected string networkSelected string
) )
func init( func init() {
flag.StringVar(&networkSelected, "network", "statuschain","Set's the network to be used for testing") flag.StringVar(&networkSelected, "network", "statuschain", "-network=NETWORKNAME or -network=NETWORKID to select network used for tests")
) }
// TestNodeOption is a callback passed to StartTestNode which alters its config. // TestNodeOption is a callback passed to StartTestNode which alters its config.
type TestNodeOption func(config *params.NodeConfig) type TestNodeOption func(config *params.NodeConfig)
@ -88,3 +91,20 @@ func FirstBlockHash(nodeManager common.NodeManager) (string, error) {
return firstBlock.Hash.Hex(), nil 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
}