tune CLI for better docs experience (#1207)

This commit is contained in:
Adam Babik 2018-09-21 16:09:31 +02:00 committed by GitHub
parent 5d43eac31c
commit 8aef7c4f15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 271 additions and 487 deletions

View File

@ -239,7 +239,7 @@ func makeNodeConfig() (*params.NodeConfig, error) {
return nil, err return nil, err
} }
nodeConfig, err := params.NewNodeConfigWithDefaults(path.Join(workDir, ".ethereum"), params.FleetUndefined, uint64(params.RopstenNetworkID)) nodeConfig, err := params.NewNodeConfigWithDefaults(path.Join(workDir, ".ethereum"), uint64(params.RopstenNetworkID))
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -68,11 +68,11 @@ func TestStatusFlag(t *testing.T) {
for i, s := range scenarios { for i, s := range scenarios {
msg := fmt.Sprintf("scenario %d", i) msg := fmt.Sprintf("scenario %d", i)
c, err := params.NewNodeConfig("", params.FleetBeta, 0) c, err := params.NewNodeConfig("", 0)
require.Nil(t, err, msg) require.Nil(t, err, msg)
c.IPCEnabled = s.ipcEnabled c.IPCEnabled = s.ipcEnabled
c.RPCEnabled = s.httpEnabled c.HTTPEnabled = s.httpEnabled
c, err = configureStatusService(s.flag, c) c, err = configureStatusService(s.flag, c)

View File

@ -8,6 +8,7 @@ import (
stdlog "log" stdlog "log"
"os" "os"
"os/signal" "os/signal"
"path/filepath"
"runtime" "runtime"
"strings" "strings"
"time" "time"
@ -35,13 +36,17 @@ var (
var ( var (
configFiles configFlags configFiles configFlags
logLevel = flag.String("log", "", `Log level, one of: "ERROR", "WARN", "INFO", "DEBUG", and "TRACE"`) logLevel = flag.String("log", "", `Log level, one of: "ERROR", "WARN", "INFO", "DEBUG", and "TRACE"`)
logWithoutColors = flag.Bool("log-without-color", false, "Disables log colors")
cliEnabled = flag.Bool("cli", false, "Enable debugging CLI server") cliEnabled = flag.Bool("cli", false, "Enable debugging CLI server")
cliPort = flag.String("cli-port", debug.CLIPort, "CLI server's listening port") cliPort = flag.String("cli-port", debug.CLIPort, "CLI server's listening port")
pprofEnabled = flag.Bool("pprof", false, "Enable runtime profiling via pprof") pprofEnabled = flag.Bool("pprof", false, "Enable runtime profiling via pprof")
pprofPort = flag.Int("pprof-port", 52525, "Port for runtime profiling via pprof") pprofPort = flag.Int("pprof-port", 52525, "Port for runtime profiling via pprof")
logWithoutColors = flag.Bool("log-without-color", false, "Disables log colors")
version = flag.Bool("version", false, "Print version and dump configuration") version = flag.Bool("version", false, "Print version and dump configuration")
dataDir = flag.String("dir", getDefaultDataDir(), "Directory used by node to store data")
register = flag.Bool("register", false, "Register and make the node discoverable by other nodes")
mailserver = flag.Bool("mailserver", false, "Enable Mail Server with default configuration")
// don't change the name of this flag, https://github.com/ethereum/go-ethereum/blob/master/metrics/metrics.go#L41 // don't change the name of this flag, https://github.com/ethereum/go-ethereum/blob/master/metrics/metrics.go#L41
metrics = flag.Bool("metrics", false, "Expose ethereum metrics with debug_metrics jsonrpc call") metrics = flag.Bool("metrics", false, "Expose ethereum metrics with debug_metrics jsonrpc call")
@ -68,12 +73,18 @@ func init() {
} }
} }
// nolint:gocyclo
func main() { func main() {
opts := []params.Option{params.WithFleet(params.FleetBeta)}
if *mailserver {
opts = append(opts, params.WithMailserver())
}
config, err := params.NewNodeConfigWithDefaultsAndFiles( config, err := params.NewNodeConfigWithDefaultsAndFiles(
"statusd-data", *dataDir,
params.FleetBeta, uint64(params.RopstenNetworkID),
params.RopstenNetworkID, opts,
configFiles..., configFiles,
) )
if err != nil { if err != nil {
printUsage() printUsage()
@ -83,19 +94,14 @@ func main() {
os.Exit(1) os.Exit(1)
} }
if *logLevel != "" { if *register && *mailserver {
config.LogLevel = *logLevel config.RegisterTopics = append(config.RegisterTopics, params.MailServerDiscv5Topic)
} else if *register {
config.RegisterTopics = append(config.RegisterTopics, params.WhisperDiscv5Topic)
} }
colors := !(*logWithoutColors) && terminal.IsTerminal(int(os.Stdin.Fd())) // set up logging options
if err := logutils.OverrideRootLog( setupLogging(config)
logEnabled(config),
config.LogLevel,
config.LogFile,
colors,
); err != nil {
stdlog.Fatalf("Error initializing logger: %v", err)
}
// We want statusd to be distinct from StatusIM client. // We want statusd to be distinct from StatusIM client.
config.Name = serverClientName config.Name = serverClientName
@ -156,6 +162,29 @@ func main() {
} }
} }
func getDefaultDataDir() string {
if home := os.Getenv("HOME"); home != "" {
return filepath.Join(home, ".statusd")
}
return "./statusd-data"
}
func setupLogging(config *params.NodeConfig) {
if *logLevel != "" {
config.LogLevel = *logLevel
}
colors := !(*logWithoutColors) && terminal.IsTerminal(int(os.Stdin.Fd()))
if err := logutils.OverrideRootLog(
logEnabled(config),
config.LogLevel,
config.LogFile,
colors,
); err != nil {
stdlog.Fatalf("Error initializing logger: %v", err)
}
}
// startDebug starts the debugging API server. // startDebug starts the debugging API server.
func startDebug(backend *api.StatusBackend) error { func startDebug(backend *api.StatusBackend) error {
_, err := debug.New(backend, *cliPort) _, err := debug.New(backend, *cliPort)
@ -201,7 +230,7 @@ func configureStatusService(flagValue string, nodeConfig *params.NodeConfig) (*p
} }
nodeConfig.StatusServiceEnabled = true nodeConfig.StatusServiceEnabled = true
case "http": case "http":
if !nodeConfig.RPCEnabled { if !nodeConfig.HTTPEnabled {
return nil, errStatusServiceRequiresHTTP return nil, errStatusServiceRequiresHTTP
} }
nodeConfig.StatusServiceEnabled = true nodeConfig.StatusServiceEnabled = true
@ -237,6 +266,7 @@ func printUsage() {
usage := ` usage := `
Usage: statusd [options] Usage: statusd [options]
Examples: Examples:
statusd # run regular Whisper node that joins Status network
statusd -c ./default.json # run node with configuration specified in ./default.json file statusd -c ./default.json # run node with configuration specified in ./default.json file
statusd -c ./default.json -c ./standalone.json # run node with configuration specified in ./default.json file, after merging ./standalone.json file statusd -c ./default.json -c ./standalone.json # run node with configuration specified in ./default.json file, after merging ./standalone.json file
statusd -c ./default.json -metrics # run node with configuration specified in ./default.json file, and expose ethereum metrics with debug_metrics jsonrpc call statusd -c ./default.json -metrics # run node with configuration specified in ./default.json file, and expose ethereum metrics with debug_metrics jsonrpc call

View File

@ -0,0 +1,9 @@
{
"RegisterTopics": ["whispermail"],
"WhisperConfig": {
"Enabled": true,
"EnableNTPSync": true,
"EnableMailServer": true,
"MailServerPassword": "status-offline-inbox"
}
}

View File

@ -134,7 +134,7 @@ func newGethNodeConfig(config *params.NodeConfig) (*node.Config, error) {
HTTPVirtualHosts: []string{"localhost"}, HTTPVirtualHosts: []string{"localhost"},
} }
if config.RPCEnabled { if config.HTTPEnabled {
nc.HTTPHost = config.HTTPHost nc.HTTPHost = config.HTTPHost
nc.HTTPPort = config.HTTPPort nc.HTTPPort = config.HTTPPort
} }

View File

@ -24,7 +24,7 @@ import (
) )
func TestStatusNodeStart(t *testing.T) { func TestStatusNodeStart(t *testing.T) {
config, err := utils.MakeTestNodeConfigWithDataDir("", "", params.FleetUndefined, params.StatusChainNetworkID) config, err := utils.MakeTestNodeConfigWithDataDir("", "", params.StatusChainNetworkID)
require.NoError(t, err) require.NoError(t, err)
n := New() n := New()

View File

@ -3,11 +3,9 @@ package params
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"go/build"
"io/ioutil" "io/ioutil"
"net/url" "net/url"
"os" "os"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
@ -199,22 +197,22 @@ type NodeConfig struct {
// APIModules is a comma-separated list of API modules exposed via *any* (HTTP/WS/IPC) RPC interface. // APIModules is a comma-separated list of API modules exposed via *any* (HTTP/WS/IPC) RPC interface.
APIModules string APIModules string
// HTTPEnabled specifies whether the http RPC server is to be enabled by default.
HTTPEnabled bool
// HTTPHost is the host interface on which to start the HTTP RPC server. // HTTPHost is the host interface on which to start the HTTP RPC server.
// Pass empty string if no HTTP RPC interface needs to be started. // Pass empty string if no HTTP RPC interface needs to be started.
HTTPHost string HTTPHost string
// RPCEnabled specifies whether the http RPC server is to be enabled by default.
RPCEnabled bool
// HTTPPort is the TCP port number on which to start the Geth's HTTP RPC server. // HTTPPort is the TCP port number on which to start the Geth's HTTP RPC server.
HTTPPort int HTTPPort int
// IPCFile is filename of exposed IPC RPC Server
IPCFile string
// IPCEnabled specifies whether IPC-RPC Server is enabled or not // IPCEnabled specifies whether IPC-RPC Server is enabled or not
IPCEnabled bool IPCEnabled bool
// IPCFile is filename of exposed IPC RPC Server
IPCFile string
// TLSEnabled specifies whether TLS support should be enabled on node or not // TLSEnabled specifies whether TLS support should be enabled on node or not
// TLS support is only planned in go-ethereum, so we are using our own patch. // TLS support is only planned in go-ethereum, so we are using our own patch.
TLSEnabled bool TLSEnabled bool
@ -274,48 +272,71 @@ type NodeConfig struct {
MailServerRegistryAddress string MailServerRegistryAddress string
} }
// Option is an additional setting when creating a NodeConfig
// using NewNodeConfigWithDefaults.
type Option func(*NodeConfig) error
// WithFleet loads one of the preconfigured Status fleets.
func WithFleet(fleet string) Option {
return func(c *NodeConfig) error {
if fleet == FleetUndefined {
return nil
}
return loadConfigFromAsset(fmt.Sprintf("../config/cli/fleet-%s.json", fleet), c)
}
}
// WithLES enabled LES protocol.
func WithLES() Option {
return func(c *NodeConfig) error {
return loadConfigFromAsset("../config/cli/les-enabled.json", c)
}
}
// WithMailserver enables MailServer.
func WithMailserver() Option {
return func(c *NodeConfig) error {
return loadConfigFromAsset("../config/cli/mailserver-enabled.json", c)
}
}
// NewNodeConfigWithDefaults creates new node configuration object // NewNodeConfigWithDefaults creates new node configuration object
// with some defaults suitable for adhoc use. // with some defaults suitable for adhoc use.
func NewNodeConfigWithDefaults(dataDir, fleet string, networkID uint64) (*NodeConfig, error) { func NewNodeConfigWithDefaults(dataDir string, networkID uint64, opts ...Option) (*NodeConfig, error) {
nodeConfig, err := NewNodeConfig(dataDir, fleet, networkID) c, err := NewNodeConfig(dataDir, networkID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if dataDir != "" { c.HTTPHost = ""
nodeConfig.KeyStoreDir = path.Join(dataDir, "keystore") c.ListenAddr = ":30303"
nodeConfig.WhisperConfig.DataDir = path.Join(dataDir, "wnode") c.LogEnabled = true
} c.LogLevel = "INFO"
c.LogToStderr = true
c.WhisperConfig.Enabled = true
c.WhisperConfig.EnableNTPSync = true
if fleet != FleetUndefined { for _, opt := range opts {
statusConfigJSON, err := static.Asset(fmt.Sprintf("../config/cli/fleet-%s.json", fleet)) if err := opt(c); err != nil {
if err == nil { return nil, err
err = LoadConfigFromJSON(string(statusConfigJSON), nodeConfig)
}
if err != nil {
return nil, fmt.Errorf("default config could not be loaded: %s", err)
} }
} }
nodeConfig.HTTPHost = "" c.updatePeerLimits()
nodeConfig.ListenAddr = ":30303"
nodeConfig.LogEnabled = true
nodeConfig.LogLevel = "INFO"
nodeConfig.LogToStderr = true
nodeConfig.WhisperConfig.Enabled = true
nodeConfig.WhisperConfig.EnableNTPSync = true
nodeConfig.updatePeerLimits() if err := c.Validate(); err != nil {
return nil, err
}
return nodeConfig, nil return c, nil
} }
// NewNodeConfigWithDefaultsAndFiles creates new node configuration object // NewNodeConfigWithDefaultsAndFiles creates new node configuration object
// with some defaults suitable for adhoc use and applies config files on top. // with some defaults suitable for adhoc use and applies config files on top.
func NewNodeConfigWithDefaultsAndFiles( func NewNodeConfigWithDefaultsAndFiles(
dataDir, fleet string, networkID uint64, files ...string, dataDir string, networkID uint64, opts []Option, files []string,
) (*NodeConfig, error) { ) (*NodeConfig, error) {
c, err := NewNodeConfigWithDefaults(dataDir, fleet, networkID) c, err := NewNodeConfigWithDefaults(dataDir, networkID, opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -328,6 +349,10 @@ func NewNodeConfigWithDefaultsAndFiles(
c.updatePeerLimits() c.updatePeerLimits()
if err := c.Validate(); err != nil {
return nil, err
}
return c, nil return c, nil
} }
@ -346,12 +371,21 @@ func (c *NodeConfig) updatePeerLimits() {
} }
// NewNodeConfig creates new node configuration object with bare-minimum defaults // NewNodeConfig creates new node configuration object with bare-minimum defaults
func NewNodeConfig(dataDir, fleet string, networkID uint64) (*NodeConfig, error) { func NewNodeConfig(dataDir string, networkID uint64) (*NodeConfig, error) {
nodeConfig := &NodeConfig{ var keyStoreDir, wnodeDir string
if dataDir != "" {
keyStoreDir = filepath.Join(dataDir, "keystore")
}
if dataDir != "" {
wnodeDir = filepath.Join(dataDir, "wnode")
}
config := &NodeConfig{
NetworkID: networkID, NetworkID: networkID,
DataDir: dataDir, DataDir: dataDir,
KeyStoreDir: keyStoreDir,
Version: Version, Version: Version,
RPCEnabled: false,
HTTPHost: "localhost", HTTPHost: "localhost",
HTTPPort: 8545, HTTPPort: 8545,
ListenAddr: ":0", ListenAddr: ":0",
@ -365,66 +399,44 @@ func NewNodeConfig(dataDir, fleet string, networkID uint64) (*NodeConfig, error)
UpstreamConfig: UpstreamRPCConfig{ UpstreamConfig: UpstreamRPCConfig{
URL: getUpstreamURL(networkID), URL: getUpstreamURL(networkID),
}, },
ClusterConfig: ClusterConfig{
Enabled: fleet != FleetUndefined,
Fleet: fleet,
StaticNodes: []string{},
BootNodes: []string{},
},
LightEthConfig: LightEthConfig{ LightEthConfig: LightEthConfig{
Enabled: false,
DatabaseCache: 16, DatabaseCache: 16,
}, },
WhisperConfig: WhisperConfig{ WhisperConfig: WhisperConfig{
Enabled: false, DataDir: wnodeDir,
MinimumPoW: WhisperMinimumPoW, MinimumPoW: WhisperMinimumPoW,
TTL: WhisperTTL, TTL: WhisperTTL,
EnableNTPSync: false,
}, },
SwarmConfig: SwarmConfig{}, SwarmConfig: SwarmConfig{},
RegisterTopics: []discv5.Topic{}, RegisterTopics: []discv5.Topic{},
RequireTopics: map[discv5.Topic]Limits{}, RequireTopics: map[discv5.Topic]Limits{},
} }
return nodeConfig, nil return config, nil
} }
// NewConfigFromJSON parses incoming JSON and returned it as Config // NewConfigFromJSON parses incoming JSON and returned it as Config
func NewConfigFromJSON(configJSON string) (*NodeConfig, error) { func NewConfigFromJSON(configJSON string) (*NodeConfig, error) {
nodeConfig, err := NewNodeConfig("", FleetUndefined, 0) config, err := NewNodeConfig("", 0)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err := LoadConfigFromJSON(configJSON, nodeConfig); err != nil { if err := loadConfigFromJSON(configJSON, config); err != nil {
return nil, err return nil, err
} }
return nodeConfig, nil if err := config.Validate(); err != nil {
} return nil, err
// LoadConfigFromJSON parses incoming JSON and returned it as Config
func LoadConfigFromJSON(configJSON string, nodeConfig *NodeConfig) error {
if err := loadNodeConfig(configJSON, nodeConfig); err != nil {
return err
} }
if err := nodeConfig.Validate(); err != nil { return config, nil
return err
}
return nil
} }
func loadNodeConfig(configJSON string, nodeConfig *NodeConfig) error { func loadConfigFromJSON(configJSON string, nodeConfig *NodeConfig) error {
decoder := json.NewDecoder(strings.NewReader(configJSON)) decoder := json.NewDecoder(strings.NewReader(configJSON))
// override default configuration with values by JSON input // override default configuration with values by JSON input
if err := decoder.Decode(&nodeConfig); err != nil { return decoder.Decode(&nodeConfig)
return err
}
return nil
} }
func loadConfigConfigFromFile(path string, config *NodeConfig) error { func loadConfigConfigFromFile(path string, config *NodeConfig) error {
@ -432,24 +444,15 @@ func loadConfigConfigFromFile(path string, config *NodeConfig) error {
if err != nil { if err != nil {
return err return err
} }
return loadConfigFromJSON(string(jsonConfig), config)
if err = loadNodeConfig(string(jsonConfig), config); err != nil {
return err
}
return nil
} }
// LoadConfigFromFiles reads the configuration files specified in configFilePaths, func loadConfigFromAsset(name string, config *NodeConfig) error {
// merging the values in order in the config argument data, err := static.Asset(name)
func LoadConfigFromFiles(configFilePaths []string, config *NodeConfig) error { if err != nil {
for _, path := range configFilePaths { return err
if err := loadConfigConfigFromFile(path, config); err != nil {
return err
}
} }
return loadConfigFromJSON(string(data), config)
return nil
} }
// Validate checks if NodeConfig fields have valid values. // Validate checks if NodeConfig fields have valid values.
@ -667,15 +670,6 @@ func (c *NodeConfig) AddAPIModule(m string) {
c.APIModules = fmt.Sprintf("%s,%s", c.APIModules, m) c.APIModules = fmt.Sprintf("%s,%s", c.APIModules, m)
} }
// GetStatusHome gets home directory of status-go
func GetStatusHome() string {
gopath := os.Getenv("GOPATH")
if gopath == "" {
gopath = build.Default.GOPATH
}
return path.Join(gopath, "/src/github.com/status-im/status-go/")
}
// LesTopic returns discovery v5 topic derived from genesis of the provided network. // LesTopic returns discovery v5 topic derived from genesis of the provided network.
// 1 - mainnet, 3 - ropsten, 4 - rinkeby // 1 - mainnet, 3 - ropsten, 4 - rinkeby
func LesTopic(netid int) string { func LesTopic(netid int) string {

View File

@ -1,101 +1,62 @@
package params_test package params_test
import ( import (
"encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path"
"path/filepath" "path/filepath"
"testing" "testing"
"gopkg.in/go-playground/validator.v9" "gopkg.in/go-playground/validator.v9"
"github.com/ethereum/go-ethereum/p2p/discv5"
"github.com/status-im/status-go/params" "github.com/status-im/status-go/params"
"github.com/status-im/status-go/t/utils" "github.com/status-im/status-go/t/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var clusterConfigData = []byte(`{ func TestNewNodeConfigWithDefaults(t *testing.T) {
"ClusterConfig": { c, err := params.NewNodeConfigWithDefaults(
"staticnodes": [ "/some/data/path",
"enode://7ab298cedc4185a894d21d8a4615262ec6bdce66c9b6783878258e0d5b31013d30c9038932432f70e5b2b6a5cd323bf820554fcb22fbc7b45367889522e9c449@10.1.1.1:30303", params.RopstenNetworkID,
"enode://f59e8701f18c79c5cbc7618dc7bb928d44dc2f5405c7d693dad97da2d8585975942ec6fd36d3fe608bfdc7270a34a4dd00f38cfe96b2baa24f7cd0ac28d382a1@10.1.1.2:30303" params.WithFleet(params.FleetBeta),
] params.WithLES(),
} params.WithMailserver(),
}`) )
require.NoError(t, err)
var clusters = map[string]func() params.Cluster{ assert.Equal(t, "/some/data/path", c.DataDir)
params.FleetStaging: func() params.Cluster { assert.Equal(t, "/some/data/path/keystore", c.KeyStoreDir)
return params.Cluster{ // assert Whisper
BootNodes: []string{ assert.Equal(t, true, c.WhisperConfig.Enabled)
"enode://10a78c17929a7019ef4aa2249d7302f76ae8a06f40b2dc88b7b31ebff4a623fbb44b4a627acba296c1ced3775d91fbe18463c15097a6a36fdb2c804ff3fc5b35@35.238.97.234:30404", // boot-01.gc-us-central1-a.eth.staging assert.Equal(t, "/some/data/path/wnode", c.WhisperConfig.DataDir)
"enode://f79fb3919f72ca560ad0434dcc387abfe41e0666201ebdada8ede0462454a13deb05cda15f287d2c4bd85da81f0eb25d0a486bbbc8df427b971ac51533bd00fe@174.138.107.239:30404", // boot-01.do-ams3.eth.staging assert.Equal(t, true, c.WhisperConfig.EnableNTPSync)
}, // assert MailServer
StaticNodes: []string{ assert.Equal(t, true, c.WhisperConfig.EnableMailServer)
"enode://914c0b30f27bab30c1dfd31dad7652a46fda9370542aee1b062498b1345ee0913614b8b9e3e84622e84a7203c5858ae1d9819f63aece13ee668e4f6668063989@167.99.19.148:30305", // node-01.do-ams3.eth.staging assert.NotEmpty(t, c.WhisperConfig.MailServerPassword)
"enode://2d897c6e846949f9dcf10279f00e9b8325c18fe7fa52d658520ad7be9607c83008b42b06aefd97cfe1fdab571f33a2a9383ff97c5909ed51f63300834913237e@35.192.0.86:30305", // "node-01.gc-us-central1-a.eth.staging" // assert cluster
}, assert.Equal(t, false, c.NoDiscovery)
MailServers: []string{ assert.Equal(t, params.FleetBeta, c.ClusterConfig.Fleet)
"enode://69f72baa7f1722d111a8c9c68c39a31430e9d567695f6108f31ccb6cd8f0adff4991e7fdca8fa770e75bc8a511a87d24690cbc80e008175f40c157d6f6788d48@206.189.240.16:30504", // mail-01.do-ams3.eth.staging assert.NotEmpty(t, c.ClusterConfig.BootNodes)
"enode://e4fc10c1f65c8aed83ac26bc1bfb21a45cc1a8550a58077c8d2de2a0e0cd18e40fd40f7e6f7d02dc6cd06982b014ce88d6e468725ffe2c138e958788d0002a7f@35.239.193.41:30504", // mail-01.gc-us-central1-a.eth.staging assert.NotEmpty(t, c.ClusterConfig.StaticNodes)
}, assert.NotEmpty(t, c.ClusterConfig.RendezvousNodes)
RendezvousNodes: []string{ // assert LES
"/ip4/174.138.107.239/tcp/30703/ethv4/16Uiu2HAkyJHeetQ4DNpd4NZ2ntzxMo25zcdpvGQRqkD5pB9BE6RU", assert.Equal(t, true, c.LightEthConfig.Enabled)
"/ip4/35.238.97.234/tcp/30703/ethv4/16Uiu2HAm1sVyXmkMNjdeDWqK2urbyC3oBHi8MDpCdYkns1nYafqz", // assert peers limits
}, assert.Contains(t, c.RequireTopics, params.WhisperDiscv5Topic)
} assert.Contains(t, c.RequireTopics, discv5.Topic(params.LesTopic(int(c.NetworkID))))
}, // assert other
params.FleetBeta: func() params.Cluster { assert.Equal(t, false, c.HTTPEnabled)
return params.Cluster{ assert.Equal(t, false, c.IPCEnabled)
BootNodes: []string{
"enode://436cc6f674928fdc9a9f7990f2944002b685d1c37f025c1be425185b5b1f0900feaf1ccc2a6130268f9901be4a7d252f37302c8335a2c1a62736e9232691cc3a@174.138.105.243:30404", // boot-01.do-ams3.eth.beta
"enode://5395aab7833f1ecb671b59bf0521cf20224fe8162fc3d2675de4ee4d5636a75ec32d13268fc184df8d1ddfa803943906882da62a4df42d4fccf6d17808156a87@206.189.243.57:30404", // boot-02.do-ams3.eth.beta
"enode://7427dfe38bd4cf7c58bb96417806fab25782ec3e6046a8053370022cbaa281536e8d64ecd1b02e1f8f72768e295d06258ba43d88304db068e6f2417ae8bcb9a6@104.154.88.123:30404", // boot-01.gc-us-central1-a.eth.beta
"enode://ebefab39b69bbbe64d8cd86be765b3be356d8c4b24660f65d493143a0c44f38c85a257300178f7845592a1b0332811542e9a58281c835babdd7535babb64efc1@35.202.99.224:30404", // boot-02.gc-us-central1-a.eth.beta
},
StaticNodes: []string{
"enode://a6a2a9b3a7cbb0a15da74301537ebba549c990e3325ae78e1272a19a3ace150d03c184b8ac86cc33f1f2f63691e467d49308f02d613277754c4dccd6773b95e8@206.189.243.176:30304", // node-01.do-ams3.eth.beta
"enode://207e53d9bf66be7441e3daba36f53bfbda0b6099dba9a865afc6260a2d253fb8a56a72a48598a4f7ba271792c2e4a8e1a43aaef7f34857f520c8c820f63b44c8@35.224.15.65:30304", // node-01.gc-us-central1-a.eth.beta
},
MailServers: []string{
"enode://c42f368a23fa98ee546fd247220759062323249ef657d26d357a777443aec04db1b29a3a22ef3e7c548e18493ddaf51a31b0aed6079bd6ebe5ae838fcfaf3a49@206.189.243.162:30504", // mail-01.do-ams3.eth.beta
"enode://7aa648d6e855950b2e3d3bf220c496e0cae4adfddef3e1e6062e6b177aec93bc6cdcf1282cb40d1656932ebfdd565729da440368d7c4da7dbd4d004b1ac02bf8@206.189.243.169:30504", // mail-02.do-ams3.eth.beta
"enode://8a64b3c349a2e0ef4a32ea49609ed6eb3364be1110253c20adc17a3cebbc39a219e5d3e13b151c0eee5d8e0f9a8ba2cd026014e67b41a4ab7d1d5dd67ca27427@206.189.243.168:30504", // mail-03.do-ams3.eth.beta
"enode://7de99e4cb1b3523bd26ca212369540646607c721ad4f3e5c821ed9148150ce6ce2e72631723002210fac1fd52dfa8bbdf3555e05379af79515e1179da37cc3db@35.188.19.210:30504", // mail-01.gc-us-central1-a.eth.beta
"enode://015e22f6cd2b44c8a51bd7a23555e271e0759c7d7f52432719665a74966f2da456d28e154e836bee6092b4d686fe67e331655586c57b718be3997c1629d24167@35.226.21.19:30504", // mail-02.gc-us-central1-a.eth.beta
"enode://531e252ec966b7e83f5538c19bf1cde7381cc7949026a6e499b6e998e695751aadf26d4c98d5a4eabfb7cefd31c3c88d600a775f14ed5781520a88ecd25da3c6@35.225.227.79:30504", // mail-03.gc-us-central1-a.eth.beta
},
RendezvousNodes: []string{
"/ip4/174.138.105.243/tcp/30703/ethv4/16Uiu2HAmRHPzF3rQg55PgYPcQkyvPVH9n2hWsYPhUJBZ6kVjJgdV", // boot-01.do-ams3.eth.beta
"/ip4/206.189.243.57/tcp/30703/ethv4/16Uiu2HAmLqTXuY4Sb6G28HNooaFUXUKzpzKXCcgyJxgaEE2i5vnf", // boot-02.do-ams3.eth.beta
},
}
},
} }
// ClusterForFleet returns a cluster for a given fleet. func TestNewConfigFromJSON(t *testing.T) {
func ClusterForFleet(fleet string) (params.Cluster, bool) {
cluster, ok := clusters[fleet]
if ok {
return cluster(), true
}
return params.Cluster{}, false
}
func TestLoadNodeConfigFromFile(t *testing.T) {
tmpDir, err := ioutil.TempDir(os.TempDir(), "geth-config-tests") tmpDir, err := ioutil.TempDir(os.TempDir(), "geth-config-tests")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer os.RemoveAll(tmpDir) // nolint: errcheck defer os.RemoveAll(tmpDir) // nolint: errcheck
// create cluster config file
clusterFile := filepath.Join(tmpDir, "cluster.json")
err = ioutil.WriteFile(clusterFile, clusterConfigData, os.ModePerm)
require.NoError(t, err)
defer os.Remove(clusterFile)
c, err := params.NewConfigFromJSON(`{ c, err := params.NewConfigFromJSON(`{
"NetworkId": 3, "NetworkId": 3,
"DataDir": "` + tmpDir + `", "DataDir": "` + tmpDir + `",
@ -103,213 +64,9 @@ func TestLoadNodeConfigFromFile(t *testing.T) {
"NoDiscovery": true "NoDiscovery": true
}`) }`)
require.NoError(t, err) require.NoError(t, err)
err = params.LoadConfigFromFiles([]string{clusterFile}, c)
require.NoError(t, err)
require.Equal(t, uint64(3), c.NetworkID) require.Equal(t, uint64(3), c.NetworkID)
require.Equal(t, tmpDir, c.DataDir) require.Equal(t, tmpDir, c.DataDir)
require.Equal(t, tmpDir, c.KeyStoreDir) require.Equal(t, tmpDir, c.KeyStoreDir)
require.False(t, c.ClusterConfig.Enabled)
require.Len(t, c.ClusterConfig.StaticNodes, 2)
}
// TestGenerateAndLoadNodeConfig tests creating and loading config
// exactly as it's done by status-react.
func TestGenerateAndLoadNodeConfig(t *testing.T) {
tmpDir, err := ioutil.TempDir(os.TempDir(), "geth-config-tests")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpDir) // nolint: errcheck
var testCases = []struct {
Name string
Fleet string // optional; if omitted all fleets will be tested
NetworkID int // optional; if omitted all networks will be checked
Update func(*params.NodeConfig)
Validate func(t *testing.T, dataDir string, c *params.NodeConfig)
}{
{
Name: "DataDir and KeyStoreDir specified",
Update: func(c *params.NodeConfig) {},
Validate: func(t *testing.T, dataDir string, c *params.NodeConfig) {
require.Equal(t, tmpDir, c.DataDir)
require.Equal(t, tmpDir, c.KeyStoreDir)
require.False(t, c.UpstreamConfig.Enabled)
require.Equal(t, c.ClusterConfig.Fleet != params.FleetUndefined, c.ClusterConfig.Enabled)
require.True(t, c.WhisperConfig.Enabled)
require.False(t, c.LightEthConfig.Enabled)
require.False(t, c.SwarmConfig.Enabled)
},
},
{
Name: "custom network and upstream",
NetworkID: 333,
Update: func(c *params.NodeConfig) {
c.UpstreamConfig.Enabled = true
c.UpstreamConfig.URL = "http://custom.local"
},
Validate: func(t *testing.T, dataDir string, c *params.NodeConfig) {
require.Equal(t, uint64(333), c.NetworkID)
require.True(t, c.UpstreamConfig.Enabled)
require.Equal(t, "http://custom.local", c.UpstreamConfig.URL)
},
},
{
Name: "upstream config",
NetworkID: params.RopstenNetworkID,
Update: func(c *params.NodeConfig) {
c.UpstreamConfig.Enabled = true
c.UpstreamConfig.URL = params.RopstenEthereumNetworkURL
},
Validate: func(t *testing.T, dataDir string, c *params.NodeConfig) {
require.True(t, c.UpstreamConfig.Enabled)
require.Equal(t, params.RopstenEthereumNetworkURL, c.UpstreamConfig.URL)
},
},
{
Name: "loading LES config",
NetworkID: params.MainNetworkID,
Update: func(c *params.NodeConfig) {
c.LightEthConfig.Enabled = true
},
Validate: func(t *testing.T, dataDir string, c *params.NodeConfig) {
require.True(t, c.LightEthConfig.Enabled)
},
},
{
Name: "cluster nodes setup",
Update: func(c *params.NodeConfig) {
cc, _ := ClusterForFleet(c.ClusterConfig.Fleet)
c.Rendezvous = true
c.ClusterConfig.BootNodes = cc.BootNodes
c.ClusterConfig.StaticNodes = cc.StaticNodes
c.ClusterConfig.RendezvousNodes = cc.RendezvousNodes
c.ClusterConfig.TrustedMailServers = cc.MailServers
c.ClusterConfig.Enabled = true
c.RequireTopics[params.WhisperDiscv5Topic] = params.WhisperDiscv5Limits
},
Validate: func(t *testing.T, dataDir string, c *params.NodeConfig) {
require.True(t, c.Rendezvous)
require.True(t, c.ClusterConfig.Enabled)
require.NotEmpty(t, c.ClusterConfig.BootNodes)
require.NotEmpty(t, c.ClusterConfig.StaticNodes)
require.NotEmpty(t, c.ClusterConfig.TrustedMailServers)
require.Equal(t, params.WhisperDiscv5Limits, c.RequireTopics[params.WhisperDiscv5Topic])
},
},
{
Name: "custom bootnodes",
Update: func(c *params.NodeConfig) {
c.ClusterConfig.Enabled = true
c.ClusterConfig.BootNodes = []string{"a", "b", "c"}
},
Validate: func(t *testing.T, dataDir string, c *params.NodeConfig) {
require.True(t, c.ClusterConfig.Enabled)
require.Equal(t, []string{"a", "b", "c"}, c.ClusterConfig.BootNodes)
},
},
{
Name: "disabled Cluster configuration",
Update: func(c *params.NodeConfig) {
c.ClusterConfig.Enabled = false
c.ClusterConfig.BootNodes = []string{"a", "b", "c"}
},
Validate: func(t *testing.T, dataDir string, c *params.NodeConfig) {
require.False(t, c.ClusterConfig.Enabled)
},
},
{
Name: "peers discovery and topics",
Update: func(c *params.NodeConfig) {
c.NoDiscovery = false
c.ClusterConfig.BootNodes = []string{"a", "b", "c"}
c.RequireTopics[params.WhisperDiscv5Topic] = params.Limits{2, 2}
},
Validate: func(t *testing.T, dataDir string, c *params.NodeConfig) {
require.NotNil(t, c.RequireTopics)
require.False(t, c.NoDiscovery)
require.Contains(t, c.RequireTopics, params.WhisperDiscv5Topic)
require.Equal(t, params.WhisperDiscv5Limits, c.RequireTopics[params.WhisperDiscv5Topic])
},
},
{
Name: "verify NoDiscovery preserved",
Update: func(c *params.NodeConfig) {
c.NoDiscovery = true
},
Validate: func(t *testing.T, dataDir string, c *params.NodeConfig) {
require.True(t, c.NoDiscovery)
},
},
{
Name: "staging fleet",
Fleet: params.FleetStaging,
Update: func(c *params.NodeConfig) {
c.ClusterConfig.Enabled = true
c.ClusterConfig.Fleet = "eth.staging"
cc, _ := ClusterForFleet(c.ClusterConfig.Fleet)
c.ClusterConfig.BootNodes = cc.BootNodes
},
Validate: func(t *testing.T, dataDir string, c *params.NodeConfig) {
staging, ok := ClusterForFleet("eth.staging")
require.True(t, ok)
beta, ok := ClusterForFleet("eth.beta")
require.True(t, ok)
require.NotEqual(t, staging, beta)
// test case asserts
require.Equal(t, "eth.staging", c.ClusterConfig.Fleet)
require.Equal(t, staging.BootNodes, c.ClusterConfig.BootNodes)
},
},
{
Name: "Whisper light client",
Update: func(c *params.NodeConfig) {
c.WhisperConfig.Enabled = true
c.WhisperConfig.DataDir = path.Join(tmpDir, "wnode")
c.WhisperConfig.LightClient = true
},
Validate: func(t *testing.T, dataDir string, c *params.NodeConfig) {
require.Equal(t, path.Join(tmpDir, "wnode"), c.WhisperConfig.DataDir)
require.True(t, c.WhisperConfig.Enabled)
require.True(t, c.WhisperConfig.LightClient)
},
},
}
for _, tc := range testCases {
fleets := []string{params.FleetBeta, params.FleetStaging}
if tc.Fleet != params.FleetUndefined {
fleets = []string{tc.Fleet}
}
networks := []int{params.MainNetworkID, params.RinkebyNetworkID, params.RopstenNetworkID}
if tc.NetworkID != 0 {
networks = []int{tc.NetworkID}
}
for _, fleet := range fleets {
for _, networkID := range networks {
name := fmt.Sprintf("%s_%s_%d", tc.Name, fleet, networkID)
t.Run(name, func(t *testing.T) {
config, err := utils.MakeTestNodeConfigWithDataDir("", tmpDir, fleet, uint64(networkID))
require.NoError(t, err)
config.KeyStoreDir = tmpDir
// Corresponds to config update in status-react.
tc.Update(config)
configBytes, err := json.Marshal(config)
require.NoError(t, err)
// Corresponds to starting node and loading config from JSON blob.
loadedConfig, err := params.NewConfigFromJSON(string(configBytes))
require.NoError(t, err)
tc.Validate(t, tmpDir, loadedConfig)
})
}
}
}
} }
func TestConfigWriteRead(t *testing.T) { func TestConfigWriteRead(t *testing.T) {
@ -317,7 +74,7 @@ func TestConfigWriteRead(t *testing.T) {
require.Nil(t, err) require.Nil(t, err)
defer os.RemoveAll(tmpDir) // nolint: errcheck defer os.RemoveAll(tmpDir) // nolint: errcheck
nodeConfig, err := utils.MakeTestNodeConfigWithDataDir("", tmpDir, params.FleetBeta, params.RopstenNetworkID) nodeConfig, err := utils.MakeTestNodeConfigWithDataDir("", tmpDir, params.RopstenNetworkID)
require.Nil(t, err, "cannot create new config object") require.Nil(t, err, "cannot create new config object")
err = nodeConfig.Save() err = nodeConfig.Save()
@ -328,7 +85,6 @@ func TestConfigWriteRead(t *testing.T) {
loadedConfig := string(loadedConfigData) loadedConfig := string(loadedConfigData)
require.Contains(t, loadedConfig, fmt.Sprintf(`"NetworkId": %d`, params.RopstenNetworkID)) require.Contains(t, loadedConfig, fmt.Sprintf(`"NetworkId": %d`, params.RopstenNetworkID))
require.Contains(t, loadedConfig, fmt.Sprintf(`"DataDir": "%s"`, tmpDir)) require.Contains(t, loadedConfig, fmt.Sprintf(`"DataDir": "%s"`, tmpDir))
require.Contains(t, loadedConfig, fmt.Sprintf(`"Fleet": "%s"`, params.FleetBeta))
} }
// TestNodeConfigValidate checks validation of individual fields. // TestNodeConfigValidate checks validation of individual fields.

View File

@ -54,6 +54,9 @@ const (
// WhisperDiscv5Topic used to register and search for whisper peers using discovery v5. // WhisperDiscv5Topic used to register and search for whisper peers using discovery v5.
WhisperDiscv5Topic = discv5.Topic("whisper") WhisperDiscv5Topic = discv5.Topic("whisper")
// MailServerDiscv5Topic used to register and search for mail server peers using discovery v5.
MailServerDiscv5Topic = discv5.Topic("whispermail")
// LESDiscoveryIdentifier is a prefix for topic used for LES peers discovery. // LESDiscoveryIdentifier is a prefix for topic used for LES peers discovery.
LESDiscoveryIdentifier = "LES2@" LESDiscoveryIdentifier = "LES2@"
) )

View File

@ -1,17 +1,18 @@
// Code generated by go-bindata. DO NOT EDIT. // Code generated by go-bindata.
// sources: // sources:
// ../config/cli/fleet-eth.beta.json (3.237kB) // ../config/cli/fleet-eth.beta.json
// ../config/cli/fleet-eth.staging.json (1.838kB) // ../config/cli/fleet-eth.staging.json
// ../config/cli/fleet-eth.test.json (1.519kB) // ../config/cli/fleet-eth.test.json
// ../config/cli/les-enabled.json (58B) // ../config/cli/les-enabled.json
// ../config/status-chain-genesis.json (612B) // ../config/cli/mailserver-enabled.json
// ../config/status-chain-genesis.json
// DO NOT EDIT!
package static package static
import ( import (
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"crypto/sha256"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@ -42,9 +43,8 @@ func bindataRead(data []byte, name string) ([]byte, error) {
} }
type asset struct { type asset struct {
bytes []byte bytes []byte
info os.FileInfo info os.FileInfo
digest [sha256.Size]byte
} }
type bindataFileInfo struct { type bindataFileInfo struct {
@ -88,8 +88,8 @@ func ConfigCliFleetEthBetaJson() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "../config/cli/fleet-eth.beta.json", size: 3237, mode: os.FileMode(436), modTime: time.Unix(1537422313, 0)} info := bindataFileInfo{name: "../config/cli/fleet-eth.beta.json", size: 3237, mode: os.FileMode(420), modTime: time.Unix(1537450683, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x8d, 0xd4, 0x40, 0xa9, 0x70, 0x6f, 0x20, 0x42, 0x70, 0x9d, 0x3c, 0x4d, 0x3, 0x8e, 0x3, 0xe6, 0x46, 0xb3, 0x16, 0x73, 0xd3, 0x7d, 0x5e, 0x36, 0x9d, 0xeb, 0x79, 0xf, 0x97, 0xb2, 0x16, 0x7b}} a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }
@ -108,8 +108,8 @@ func ConfigCliFleetEthStagingJson() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "../config/cli/fleet-eth.staging.json", size: 1838, mode: os.FileMode(436), modTime: time.Unix(1537422313, 0)} info := bindataFileInfo{name: "../config/cli/fleet-eth.staging.json", size: 1838, mode: os.FileMode(420), modTime: time.Unix(1537450683, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xb, 0xbd, 0x9d, 0x55, 0xe8, 0x60, 0xf3, 0xb9, 0xa6, 0xb9, 0x34, 0x36, 0x24, 0x69, 0x6b, 0xa9, 0x4c, 0x78, 0xc2, 0x50, 0x72, 0xae, 0x92, 0x4e, 0xc9, 0xde, 0xd0, 0x24, 0x99, 0xd4, 0xe7, 0x7e}} a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }
@ -128,8 +128,8 @@ func ConfigCliFleetEthTestJson() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "../config/cli/fleet-eth.test.json", size: 1519, mode: os.FileMode(436), modTime: time.Unix(1537422313, 0)} info := bindataFileInfo{name: "../config/cli/fleet-eth.test.json", size: 1519, mode: os.FileMode(420), modTime: time.Unix(1537450683, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x1, 0xdc, 0x8e, 0x4e, 0x7e, 0x27, 0xfc, 0x81, 0x3, 0x89, 0x88, 0xd2, 0xf7, 0xae, 0x86, 0x30, 0xcc, 0x8c, 0x57, 0x4a, 0xe1, 0x7b, 0x7f, 0xcc, 0x5, 0x32, 0xc2, 0xd2, 0xa8, 0x81, 0x93, 0xf5}} a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }
@ -148,8 +148,28 @@ func ConfigCliLesEnabledJson() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "../config/cli/les-enabled.json", size: 58, mode: os.FileMode(436), modTime: time.Unix(1537334879, 0)} info := bindataFileInfo{name: "../config/cli/les-enabled.json", size: 58, mode: os.FileMode(420), modTime: time.Unix(1537450683, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x7e, 0xee, 0x27, 0xa7, 0x74, 0xa0, 0x46, 0xa1, 0x41, 0xed, 0x4d, 0x16, 0x5b, 0xf3, 0xf0, 0x7c, 0xc8, 0x2f, 0x6f, 0x47, 0xa4, 0xbb, 0x5f, 0x43, 0x33, 0xd, 0x9, 0x9d, 0xea, 0x9e, 0x15, 0xee}} a := &asset{bytes: bytes, info: info}
return a, nil
}
var _ConfigCliMailserverEnabledJson = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xaa\xe6\x52\x50\x50\x50\x50\x0a\xcf\xc8\x2c\x2e\x48\x2d\x72\xce\xcf\x4b\xcb\x4c\x57\xb2\x52\x80\x08\x83\xa5\x5c\xf3\x12\x93\x72\x52\x7d\x13\x33\x73\x82\x53\x8b\xca\x52\x8b\x94\xac\x14\x4a\x8a\x4a\x53\x75\x10\x2a\x10\x72\x01\x89\xc5\xc5\xe5\xf9\x45\x29\x4a\x56\x0a\x4a\xc5\x25\x89\x25\xa5\xc5\xba\xf9\x69\x69\x39\x99\x79\xa9\xba\x99\x79\x49\xf9\x15\x4a\x60\x4d\xb5\x5c\xb5\x5c\x80\x00\x00\x00\xff\xff\x84\xf6\x09\xc4\x78\x00\x00\x00")
func ConfigCliMailserverEnabledJsonBytes() ([]byte, error) {
return bindataRead(
_ConfigCliMailserverEnabledJson,
"../config/cli/mailserver-enabled.json",
)
}
func ConfigCliMailserverEnabledJson() (*asset, error) {
bytes, err := ConfigCliMailserverEnabledJsonBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "../config/cli/mailserver-enabled.json", size: 120, mode: os.FileMode(420), modTime: time.Unix(1537450683, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }
@ -168,8 +188,8 @@ func ConfigStatusChainGenesisJson() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "../config/status-chain-genesis.json", size: 612, mode: os.FileMode(436), modTime: time.Unix(1537334879, 0)} info := bindataFileInfo{name: "../config/status-chain-genesis.json", size: 612, mode: os.FileMode(420), modTime: time.Unix(1537450683, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xb, 0xf0, 0xc, 0x1, 0x95, 0x65, 0x6, 0x55, 0x48, 0x8f, 0x83, 0xa0, 0xb4, 0x81, 0xda, 0xad, 0x30, 0x6d, 0xb2, 0x78, 0x1b, 0x26, 0x4, 0x13, 0x12, 0x9, 0x6, 0xae, 0x3a, 0x2c, 0x1, 0x71}} a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }
@ -177,8 +197,8 @@ func ConfigStatusChainGenesisJson() (*asset, error) {
// It returns an error if the asset could not be found or // It returns an error if the asset could not be found or
// could not be loaded. // could not be loaded.
func Asset(name string) ([]byte, error) { func Asset(name string) ([]byte, error) {
canonicalName := strings.Replace(name, "\\", "/", -1) cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[canonicalName]; ok { if f, ok := _bindata[cannonicalName]; ok {
a, err := f() a, err := f()
if err != nil { if err != nil {
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
@ -188,12 +208,6 @@ func Asset(name string) ([]byte, error) {
return nil, fmt.Errorf("Asset %s not found", name) return nil, fmt.Errorf("Asset %s not found", name)
} }
// AssetString returns the asset contents as a string (instead of a []byte).
func AssetString(name string) (string, error) {
data, err := Asset(name)
return string(data), err
}
// MustAsset is like Asset but panics when Asset would return an error. // MustAsset is like Asset but panics when Asset would return an error.
// It simplifies safe initialization of global variables. // It simplifies safe initialization of global variables.
func MustAsset(name string) []byte { func MustAsset(name string) []byte {
@ -205,18 +219,12 @@ func MustAsset(name string) []byte {
return a return a
} }
// MustAssetString is like AssetString but panics when Asset would return an
// error. It simplifies safe initialization of global variables.
func MustAssetString(name string) string {
return string(MustAsset(name))
}
// AssetInfo loads and returns the asset info for the given name. // AssetInfo loads and returns the asset info for the given name.
// It returns an error if the asset could not be found or // It returns an error if the asset could not be found or
// could not be loaded. // could not be loaded.
func AssetInfo(name string) (os.FileInfo, error) { func AssetInfo(name string) (os.FileInfo, error) {
canonicalName := strings.Replace(name, "\\", "/", -1) cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[canonicalName]; ok { if f, ok := _bindata[cannonicalName]; ok {
a, err := f() a, err := f()
if err != nil { if err != nil {
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
@ -226,33 +234,6 @@ func AssetInfo(name string) (os.FileInfo, error) {
return nil, fmt.Errorf("AssetInfo %s not found", name) return nil, fmt.Errorf("AssetInfo %s not found", name)
} }
// AssetDigest returns the digest of the file with the given name. It returns an
// error if the asset could not be found or the digest could not be loaded.
func AssetDigest(name string) ([sha256.Size]byte, error) {
canonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[canonicalName]; ok {
a, err := f()
if err != nil {
return [sha256.Size]byte{}, fmt.Errorf("AssetDigest %s can't read by error: %v", name, err)
}
return a.digest, nil
}
return [sha256.Size]byte{}, fmt.Errorf("AssetDigest %s not found", name)
}
// Digests returns a map of all known files and their checksums.
func Digests() (map[string][sha256.Size]byte, error) {
mp := make(map[string][sha256.Size]byte, len(_bindata))
for name := range _bindata {
a, err := _bindata[name]()
if err != nil {
return nil, err
}
mp[name] = a.digest
}
return mp, nil
}
// AssetNames returns the names of the assets. // AssetNames returns the names of the assets.
func AssetNames() []string { func AssetNames() []string {
names := make([]string, 0, len(_bindata)) names := make([]string, 0, len(_bindata))
@ -265,13 +246,10 @@ func AssetNames() []string {
// _bindata is a table, holding each asset generator, mapped to its name. // _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() (*asset, error){ var _bindata = map[string]func() (*asset, error){
"../config/cli/fleet-eth.beta.json": ConfigCliFleetEthBetaJson, "../config/cli/fleet-eth.beta.json": ConfigCliFleetEthBetaJson,
"../config/cli/fleet-eth.staging.json": ConfigCliFleetEthStagingJson, "../config/cli/fleet-eth.staging.json": ConfigCliFleetEthStagingJson,
"../config/cli/fleet-eth.test.json": ConfigCliFleetEthTestJson, "../config/cli/fleet-eth.test.json": ConfigCliFleetEthTestJson,
"../config/cli/les-enabled.json": ConfigCliLesEnabledJson, "../config/cli/les-enabled.json": ConfigCliLesEnabledJson,
"../config/cli/mailserver-enabled.json": ConfigCliMailserverEnabledJson,
"../config/status-chain-genesis.json": ConfigStatusChainGenesisJson, "../config/status-chain-genesis.json": ConfigStatusChainGenesisJson,
} }
@ -284,15 +262,15 @@ var _bindata = map[string]func() (*asset, error){
// img/ // img/
// a.png // a.png
// b.png // b.png
// then AssetDir("data") would return []string{"foo.txt", "img"}, // then AssetDir("data") would return []string{"foo.txt", "img"}
// AssetDir("data/img") would return []string{"a.png", "b.png"}, // AssetDir("data/img") would return []string{"a.png", "b.png"}
// AssetDir("foo.txt") and AssetDir("notexist") would return an error, and // AssetDir("foo.txt") and AssetDir("notexist") would return an error
// AssetDir("") will return []string{"data"}. // AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error) { func AssetDir(name string) ([]string, error) {
node := _bintree node := _bintree
if len(name) != 0 { if len(name) != 0 {
canonicalName := strings.Replace(name, "\\", "/", -1) cannonicalName := strings.Replace(name, "\\", "/", -1)
pathList := strings.Split(canonicalName, "/") pathList := strings.Split(cannonicalName, "/")
for _, p := range pathList { for _, p := range pathList {
node = node.Children[p] node = node.Children[p]
if node == nil { if node == nil {
@ -314,22 +292,22 @@ type bintree struct {
Func func() (*asset, error) Func func() (*asset, error)
Children map[string]*bintree Children map[string]*bintree
} }
var _bintree = &bintree{nil, map[string]*bintree{ var _bintree = &bintree{nil, map[string]*bintree{
"..": &bintree{nil, map[string]*bintree{ "..": &bintree{nil, map[string]*bintree{
"config": &bintree{nil, map[string]*bintree{ "config": &bintree{nil, map[string]*bintree{
"cli": &bintree{nil, map[string]*bintree{ "cli": &bintree{nil, map[string]*bintree{
"fleet-eth.beta.json": &bintree{ConfigCliFleetEthBetaJson, map[string]*bintree{}}, "fleet-eth.beta.json": &bintree{ConfigCliFleetEthBetaJson, map[string]*bintree{}},
"fleet-eth.staging.json": &bintree{ConfigCliFleetEthStagingJson, map[string]*bintree{}}, "fleet-eth.staging.json": &bintree{ConfigCliFleetEthStagingJson, map[string]*bintree{}},
"fleet-eth.test.json": &bintree{ConfigCliFleetEthTestJson, map[string]*bintree{}}, "fleet-eth.test.json": &bintree{ConfigCliFleetEthTestJson, map[string]*bintree{}},
"les-enabled.json": &bintree{ConfigCliLesEnabledJson, map[string]*bintree{}}, "les-enabled.json": &bintree{ConfigCliLesEnabledJson, map[string]*bintree{}},
"mailserver-enabled.json": &bintree{ConfigCliMailserverEnabledJson, map[string]*bintree{}},
}}, }},
"status-chain-genesis.json": &bintree{ConfigStatusChainGenesisJson, map[string]*bintree{}}, "status-chain-genesis.json": &bintree{ConfigStatusChainGenesisJson, map[string]*bintree{}},
}}, }},
}}, }},
}} }}
// RestoreAsset restores an asset under the given directory. // RestoreAsset restores an asset under the given directory
func RestoreAsset(dir, name string) error { func RestoreAsset(dir, name string) error {
data, err := Asset(name) data, err := Asset(name)
if err != nil { if err != nil {
@ -347,10 +325,14 @@ func RestoreAsset(dir, name string) error {
if err != nil { if err != nil {
return err return err
} }
return os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
if err != nil {
return err
}
return nil
} }
// RestoreAssets restores an asset under the given directory recursively. // RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error { func RestoreAssets(dir, name string) error {
children, err := AssetDir(name) children, err := AssetDir(name)
// File // File
@ -368,6 +350,7 @@ func RestoreAssets(dir, name string) error {
} }
func _filePath(dir, name string) string { func _filePath(dir, name string) string {
canonicalName := strings.Replace(name, "\\", "/", -1) cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(canonicalName, "/")...)...) return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
} }

View File

@ -143,7 +143,7 @@ func (s *DebugAPISuite) addPeerToCurrentNode(dir string) {
// newNode creates, configures and starts a new peer. // newNode creates, configures and starts a new peer.
func (s *DebugAPISuite) newPeer(name, dir string) *node.StatusNode { func (s *DebugAPISuite) newPeer(name, dir string) *node.StatusNode {
// network id is irrelevant // network id is irrelevant
cfg, err := MakeTestNodeConfigWithDataDir(name, dir, params.FleetUndefined, 777) cfg, err := MakeTestNodeConfigWithDataDir(name, dir, 777)
s.Require().NoError(err) s.Require().NoError(err)
n := node.New() n := node.New()
s.Require().NoError(n.Start(cfg)) s.Require().NoError(n.Start(cfg))

View File

@ -30,7 +30,7 @@ func (s *MailServiceSuite) TestShhextRequestMessagesRPCMethodAvailability() {
r := s.Require() r := s.Require()
s.StartTestNode(func(config *params.NodeConfig) { s.StartTestNode(func(config *params.NodeConfig) {
config.RPCEnabled = true config.HTTPEnabled = true
config.AddAPIModule("shhext") config.AddAPIModule("shhext")
}) })
defer s.StopTestNode() defer s.StopTestNode()

View File

@ -11,7 +11,6 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6" whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
"github.com/status-im/status-go/node" "github.com/status-im/status-go/node"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/signal" "github.com/status-im/status-go/signal"
"github.com/status-im/status-go/t/utils" "github.com/status-im/status-go/t/utils"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
@ -33,7 +32,7 @@ func (s *WhisperExtensionSuite) SetupTest() {
dir, err := ioutil.TempDir("", "test-shhext-") dir, err := ioutil.TempDir("", "test-shhext-")
s.NoError(err) s.NoError(err)
// network id is irrelevant // network id is irrelevant
cfg, err := utils.MakeTestNodeConfigWithDataDir(fmt.Sprintf("test-shhext-%d", i), dir, params.FleetUndefined, 777) cfg, err := utils.MakeTestNodeConfigWithDataDir(fmt.Sprintf("test-shhext-%d", i), dir, 777)
s.Require().NoError(err) s.Require().NoError(err)
s.nodes[i] = node.New() s.nodes[i] = node.New()
s.Require().NoError(s.nodes[i].Start(cfg)) s.Require().NoError(s.nodes[i].Start(cfg))

View File

@ -7,6 +7,7 @@ import (
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
"go/build"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
@ -273,8 +274,8 @@ func MakeTestNodeConfig(networkID int) (*params.NodeConfig, error) {
// MakeTestNodeConfigWithDataDir defines a function to return a params.NodeConfig // MakeTestNodeConfigWithDataDir defines a function to return a params.NodeConfig
// where specific network addresses are assigned based on provided network id, and assigns // where specific network addresses are assigned based on provided network id, and assigns
// a given name and data dir. // a given name and data dir.
func MakeTestNodeConfigWithDataDir(name, dataDir, fleet string, networkID uint64) (*params.NodeConfig, error) { func MakeTestNodeConfigWithDataDir(name, dataDir string, networkID uint64) (*params.NodeConfig, error) {
cfg, err := params.NewNodeConfig(dataDir, fleet, networkID) cfg, err := params.NewNodeConfig(dataDir, networkID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -321,11 +322,20 @@ type testConfig struct {
const passphraseEnvName = "ACCOUNT_PASSWORD" const passphraseEnvName = "ACCOUNT_PASSWORD"
// getStatusHome gets home directory of status-go
func getStatusHome() string {
gopath := os.Getenv("GOPATH")
if gopath == "" {
gopath = build.Default.GOPATH
}
return path.Join(gopath, "/src/github.com/status-im/status-go/")
}
// loadTestConfig loads test configuration values from disk // loadTestConfig loads test configuration values from disk
func loadTestConfig() (*testConfig, error) { func loadTestConfig() (*testConfig, error) {
var config testConfig var config testConfig
pathOfConfig := path.Join(params.GetStatusHome(), "/t/config") pathOfConfig := path.Join(getStatusHome(), "/t/config")
err := getTestConfigFromFile(path.Join(pathOfConfig, "test-data.json"), &config) err := getTestConfigFromFile(path.Join(pathOfConfig, "test-data.json"), &config)
if err != nil { if err != nil {
return nil, err return nil, err
@ -363,7 +373,7 @@ func ImportTestAccount(keystoreDir, accountFile string) error {
} }
dst := filepath.Join(keystoreDir, accountFile) dst := filepath.Join(keystoreDir, accountFile)
err := copyFile(path.Join(params.GetStatusHome(), "static/keys/", accountFile), dst) err := copyFile(path.Join(getStatusHome(), "static/keys/", accountFile), dst)
if err != nil { if err != nil {
logger.Warn("cannot copy test account PK", "error", err) logger.Warn("cannot copy test account PK", "error", err)
} }

View File

@ -54,7 +54,7 @@ func (s *TransactorSuite) SetupTest() {
rpcClient, _ := rpc.NewClient(s.client, params.UpstreamRPCConfig{}) rpcClient, _ := rpc.NewClient(s.client, params.UpstreamRPCConfig{})
// expected by simulated backend // expected by simulated backend
chainID := gethparams.AllEthashProtocolChanges.ChainID.Uint64() chainID := gethparams.AllEthashProtocolChanges.ChainID.Uint64()
nodeConfig, err := MakeTestNodeConfigWithDataDir("", "/tmp", params.FleetBeta, chainID) nodeConfig, err := MakeTestNodeConfigWithDataDir("", "/tmp", chainID)
s.Require().NoError(err) s.Require().NoError(err)
s.nodeConfig = nodeConfig s.nodeConfig = nodeConfig