status-go/t/e2e/testing.go

54 lines
1.3 KiB
Go
Raw Normal View History

package e2e
import (
"context"
gethcommon "github.com/ethereum/go-ethereum/common"
2018-03-27 16:30:37 +00:00
"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
}
}
2018-02-14 16:32:36 +00:00
// 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 := statusNode.GethNode()
if runningNode == nil {
return "", node.ErrNoGethNode
}
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
}