2018-02-19 15:32:58 +00:00
|
|
|
package e2e
|
2017-10-11 14:20:51 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-09-13 16:31:29 +00:00
|
|
|
"path"
|
2017-10-11 14:20:51 +00:00
|
|
|
|
|
|
|
gethcommon "github.com/ethereum/go-ethereum/common"
|
2020-01-02 09:10:19 +00:00
|
|
|
|
2018-06-08 11:29:50 +00:00
|
|
|
"github.com/status-im/status-go/node"
|
|
|
|
"github.com/status-im/status-go/params"
|
2017-10-11 14:20:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// TestNodeOption is a callback passed to StartTestNode which alters its config.
|
|
|
|
type TestNodeOption func(config *params.NodeConfig)
|
|
|
|
|
|
|
|
// WithUpstream returns TestNodeOption which enabled UpstreamConfig.
|
|
|
|
func WithUpstream(url string) TestNodeOption {
|
|
|
|
return func(config *params.NodeConfig) {
|
|
|
|
config.UpstreamConfig.Enabled = true
|
|
|
|
config.UpstreamConfig.URL = url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-14 16:32:36 +00:00
|
|
|
// WithDataDir returns TestNodeOption that allows to set another data dir.
|
2018-09-13 16:31:29 +00:00
|
|
|
func WithDataDir(dataDir string) TestNodeOption {
|
2018-02-14 16:32:36 +00:00
|
|
|
return func(config *params.NodeConfig) {
|
2018-09-13 16:31:29 +00:00
|
|
|
config.DataDir = dataDir
|
|
|
|
config.KeyStoreDir = path.Join(dataDir, "keystore")
|
2021-05-14 10:55:42 +00:00
|
|
|
config.WakuConfig.DataDir = path.Join(dataDir, "wnode")
|
2018-02-14 16:32:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-05 09:45:26 +00:00
|
|
|
// FirstBlockHash validates Attach operation for the StatusNode.
|
|
|
|
func FirstBlockHash(statusNode *node.StatusNode) (string, error) {
|
2017-10-11 14:20:51 +00:00
|
|
|
// obtain RPC client for running node
|
2018-04-16 12:36:09 +00:00
|
|
|
runningNode := statusNode.GethNode()
|
|
|
|
if runningNode == nil {
|
|
|
|
return "", node.ErrNoGethNode
|
2017-10-11 14:20:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpcClient, err := runningNode.Attach()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
// get first block
|
|
|
|
var firstBlock struct {
|
|
|
|
Hash gethcommon.Hash `json:"hash"`
|
|
|
|
}
|
|
|
|
|
|
|
|
err = rpcClient.CallContext(context.Background(), &firstBlock, "eth_getBlockByNumber", "0x0", true)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return firstBlock.Hash.Hex(), nil
|
|
|
|
}
|