0g-chain/tests/util/grpc.go
Robert Pirtle ff5b0e814e
add initial E2E testing setup (#1475)
* setup e2e test that starts kava chain

* refactor into a testify suite

* setup ethClient

* add example test checking chain id

* cleanup

* refactor & support funded accounts with txs

* ignore e2e tests in CI & consolidate makefiles

* remove circular go.mod dependency

vendors `signing` and `grpc` packages from `kava-labs/go-tools` to
refrain from a circular dep and fix pulled in dep versions

* add min fee for evm side

* prune nothing in e2e node
2023-02-22 15:40:56 -08:00

37 lines
759 B
Go

package util
import (
"crypto/tls"
"fmt"
"net/url"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)
// NewGrpcConnection parses a GRPC endpoint and creates a connection to it
func NewGrpcConnection(endpoint string) (*grpc.ClientConn, error) {
grpcUrl, err := url.Parse(endpoint)
if err != nil {
return nil, err
}
var secureOpt grpc.DialOption
switch grpcUrl.Scheme {
case "http":
secureOpt = grpc.WithInsecure()
case "https":
creds := credentials.NewTLS(&tls.Config{})
secureOpt = grpc.WithTransportCredentials(creds)
default:
return nil, fmt.Errorf("unknown grpc url scheme: %s", grpcUrl.Scheme)
}
grpcConn, err := grpc.Dial(grpcUrl.Host, secureOpt)
if err != nil {
return nil, err
}
return grpcConn, nil
}