status-go/t/e2e/testing.go
Adrià Cidre 359b3621e9 [#797] Simplify node.Manager public api and rename it to StatusNode
- [x] [#797] : Remove unused methods PopulateStaticPeers, ReconnectStaticPeers, removeStaticPeers, removePeer
- [x] [#797] : Rename node.Manager to node. StatusNode and simplify its public api
- [x] [#797] : Rename all references to nodeManager to statusNode
2018-04-05 16:47:27 +02:00

54 lines
1.3 KiB
Go

package e2e
import (
"context"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/status-im/status-go/geth/node"
"github.com/status-im/status-go/geth/params"
)
// 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
}
}
// WithDataDir returns TestNodeOption that allows to set another data dir.
func WithDataDir(path string) TestNodeOption {
return func(config *params.NodeConfig) {
config.DataDir = path
}
}
// FirstBlockHash validates Attach operation for the StatusNode.
func FirstBlockHash(statusNode *node.StatusNode) (string, error) {
// obtain RPC client for running node
runningNode, err := statusNode.GethNode()
if err != nil {
return "", err
}
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
}