Skip to content

Commit

Permalink
switch rpc ci to http (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother authored Mar 29, 2023
1 parent 336f9dd commit 24a953f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rpc-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ concurrency:
cancel-in-progress: true

env:
ETHLIBS_TEST_WS_URL: wss://goerli.infura.io/ws/v3/
ETHLIBS_TEST_URL: https://goerli.infura.io/v3/
AUTH_ID: ${{ secrets.INFURA_PROJECT_ID }}
AUTH_PASS: ${{ secrets.INFURA_API_KEY }}

Expand Down
4 changes: 2 additions & 2 deletions node/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"bytes"
"context"
"encoding/json"
"net/url"
"net/http"
"net/url"

"github.com/pkg/errors"

Expand All @@ -30,7 +30,7 @@ func NewClient(ctx context.Context, rawURL string, requestHeader http.Header) (C

switch parsedURL.Scheme {
case "http", "https":
transport, err = newHTTPTransport(ctx, parsedURL)
transport, err = newHTTPTransport(ctx, parsedURL, requestHeader)
case "wss", "ws":
transport, err = newWebsocketTransport(ctx, parsedURL, requestHeader)
default:
Expand Down
5 changes: 4 additions & 1 deletion node/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import (
"github.com/pkg/errors"
)

func newHTTPTransport(ctx context.Context, parsedURL *url.URL) (transport, error) {
func newHTTPTransport(ctx context.Context, parsedURL *url.URL, header http.Header) (transport, error) {
return &httpTransport{
header: header,
rawURL: parsedURL.String(),
}, nil
}

type httpTransport struct {
header http.Header
rawURL string
client *http.Client
once sync.Once
Expand Down Expand Up @@ -72,6 +74,7 @@ func (t *httpTransport) dispatchBytes(ctx context.Context, input []byte) ([]byte
}

r = r.WithContext(ctx)
r.Header = t.header
r.Header.Add("Content-Type", "application/json")

resp, err := t.client.Do(r)
Expand Down
25 changes: 12 additions & 13 deletions node/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package node_test

import (
"context"
ob64 "encoding/base64"
"fmt"
"net/http"
"os"
"testing"
"net/http"
ob64 "encoding/base64"
"fmt"

"github.com/stretchr/testify/require"

Expand All @@ -15,27 +15,26 @@ import (
)

func getClient(t *testing.T, ctx context.Context) node.Client {
// These test require a ropsten websocket URL to test with, for example ws://localhost:8546 or wss://ropsten.infura.io/ws/v3/:YOUR_PROJECT_ID
base_url := os.Getenv("ETHLIBS_TEST_WS_URL")
base_url := os.Getenv("ETHLIBS_TEST_URL")
if base_url == "" {
t.Skip("ETHLIBS_TEST_WS_URL not set, skipping test. Set to a valid websocket URL to execute this test.")
t.Skip("ETHLIBS_TEST_URL not set, skipping test. Set to a valid websocket URL to execute this test.")
}
auth_id := os.Getenv("AUTH_ID")
if auth_id == "" {
t.Skip("AUTH_ID not set, skipping test.")
}
url := fmt.Sprintf("%s%s", base_url, auth_id)
url := fmt.Sprintf("%s%s", base_url, auth_id)

auth_pass := os.Getenv("AUTH_PASS")
if auth_pass == "" {
auth_pass := os.Getenv("AUTH_PASS")
if auth_pass == "" {
t.Skip("AUTH_PASS not set, skipping test.")
}

base64Header := ob64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", auth_id, auth_pass)))
base64Header := ob64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", auth_id, auth_pass)))

header := http.Header{
"Authorization": {fmt.Sprintf("Basic %s", base64Header)},
}
header := http.Header{
"Authorization": {fmt.Sprintf("Basic %s", base64Header)},
}
conn, err := node.NewClient(ctx, url, header)
require.NoError(t, err, "creating websocket connection should not fail")
return conn
Expand Down

0 comments on commit 24a953f

Please sign in to comment.