Skip to content

Commit

Permalink
[Hotfix] Fix failing TestBroadcast on local (#461)
Browse files Browse the repository at this point in the history
* Specify IP addresses for test servers in e2e

* Remove duplicate definions for test server's address configurations

* Fix default IP for test server
  • Loading branch information
Kourin1996 committed Mar 16, 2022
1 parent 8f5a1ad commit 06e11ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
39 changes: 26 additions & 13 deletions e2e/framework/testserver.go
Expand Up @@ -6,10 +6,6 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/0xPolygon/polygon-edge/command"
ibftSwitch "github.com/0xPolygon/polygon-edge/command/ibft/switch"
initCmd "github.com/0xPolygon/polygon-edge/command/secrets/init"
"google.golang.org/grpc/credentials/insecure"
"io"
"math/big"
"os"
Expand All @@ -20,7 +16,10 @@ import (
"testing"
"time"

"github.com/0xPolygon/polygon-edge/command"
"github.com/0xPolygon/polygon-edge/command/genesis"
ibftSwitch "github.com/0xPolygon/polygon-edge/command/ibft/switch"
initCmd "github.com/0xPolygon/polygon-edge/command/secrets/init"
"github.com/0xPolygon/polygon-edge/command/server"
"github.com/0xPolygon/polygon-edge/consensus/ibft"
ibftOp "github.com/0xPolygon/polygon-edge/consensus/ibft/proto"
Expand All @@ -37,12 +36,14 @@ import (
"github.com/umbracle/go-web3"
"github.com/umbracle/go-web3/jsonrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
empty "google.golang.org/protobuf/types/known/emptypb"
)

type TestServerConfigCallback func(*TestServerConfig)

const (
serverIP = "127.0.0.1"
initialPort = 12000
binaryName = "polygon-edge"
)
Expand Down Expand Up @@ -84,15 +85,27 @@ func NewTestServer(t *testing.T, rootDir string, callback TestServerConfigCallba
}

func (t *TestServer) GrpcAddr() string {
return fmt.Sprintf("http://127.0.0.1:%d", t.Config.GRPCPort)
return fmt.Sprintf("%s:%d", serverIP, t.Config.GRPCPort)
}

func (t *TestServer) LibP2PAddr() string {
return fmt.Sprintf("%s:%d", serverIP, t.Config.LibP2PPort)
}

func (t *TestServer) JSONRPCAddr() string {
return fmt.Sprintf("http://127.0.0.1:%d", t.Config.JSONRPCPort)
return fmt.Sprintf("%s:%d", serverIP, t.Config.JSONRPCPort)
}

func (t *TestServer) HTTPJSONRPCURL() string {
return fmt.Sprintf("http://%s", t.JSONRPCAddr())
}

func (t *TestServer) WSJSONRPCURL() string {
return fmt.Sprintf("ws://%s/ws", t.JSONRPCAddr())
}

func (t *TestServer) JSONRPC() *jsonrpc.Client {
clt, err := jsonrpc.NewClient(t.JSONRPCAddr())
clt, err := jsonrpc.NewClient(t.HTTPJSONRPCURL())
if err != nil {
t.t.Fatal(err)
}
Expand All @@ -102,7 +115,7 @@ func (t *TestServer) JSONRPC() *jsonrpc.Client {

func (t *TestServer) Operator() proto.SystemClient {
conn, err := grpc.Dial(
fmt.Sprintf("127.0.0.1:%d", t.Config.GRPCPort),
t.GrpcAddr(),
grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.t.Fatal(err)
Expand All @@ -113,7 +126,7 @@ func (t *TestServer) Operator() proto.SystemClient {

func (t *TestServer) TxnPoolOperator() txpoolProto.TxnPoolOperatorClient {
conn, err := grpc.Dial(
fmt.Sprintf("127.0.0.1:%d", t.Config.GRPCPort),
t.GrpcAddr(),
grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.t.Fatal(err)
Expand All @@ -124,7 +137,7 @@ func (t *TestServer) TxnPoolOperator() txpoolProto.TxnPoolOperatorClient {

func (t *TestServer) IBFTOperator() ibftOp.IbftOperatorClient {
conn, err := grpc.Dial(
fmt.Sprintf("127.0.0.1:%d", t.Config.GRPCPort),
t.GrpcAddr(),
grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.t.Fatal(err)
Expand Down Expand Up @@ -292,11 +305,11 @@ func (t *TestServer) Start(ctx context.Context) error {
// add custom chain
"--chain", filepath.Join(t.Config.RootDir, "genesis.json"),
// enable grpc
"--grpc-address", fmt.Sprintf(":%d", t.Config.GRPCPort),
"--grpc-address", t.GrpcAddr(),
// enable libp2p
"--libp2p", fmt.Sprintf(":%d", t.Config.LibP2PPort),
"--libp2p", t.LibP2PAddr(),
// enable jsonrpc
"--jsonrpc", fmt.Sprintf(":%d", t.Config.JSONRPCPort),
"--jsonrpc", t.JSONRPCAddr(),
}

switch t.Config.Consensus {
Expand Down
3 changes: 1 addition & 2 deletions e2e/websocket_test.go
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"math/big"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -70,7 +69,7 @@ func TestWS_Response(t *testing.T) {
srv := srvs[0]

// Convert the default JSONRPC address to a WebSocket one
wsURL := "ws" + strings.TrimPrefix(srv.JSONRPCAddr(), "http") + "/ws"
wsURL := srv.WSJSONRPCURL()

// Connect to the websocket server
ws, _, err := websocket.DefaultDialer.Dial(wsURL, nil)
Expand Down

0 comments on commit 06e11ea

Please sign in to comment.