Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
tests: networking configuration fixed (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanchon committed Oct 28, 2021
1 parent 778534b commit b4e3d1a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
4 changes: 3 additions & 1 deletion tests/e2e/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2e

import (
"context"
"fmt"
"math/big"
"testing"

Expand Down Expand Up @@ -40,7 +41,8 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.Require().NoError(err)

if s.network.Validators[0].JSONRPCClient == nil {
s.network.Validators[0].JSONRPCClient, err = ethclient.Dial(s.network.Validators[0].JSONRPCAddress)
address := fmt.Sprintf("http://%s", s.network.Validators[0].AppConfig.JSONRPC.Address)
s.network.Validators[0].JSONRPCClient, err = ethclient.Dial(address)
s.Require().NoError(err)
}
}
Expand Down
37 changes: 22 additions & 15 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,20 @@ type (
// a client can make RPC and API calls and interact with any client command
// or handler.
Validator struct {
AppConfig *config.Config
ClientCtx client.Context
Ctx *server.Context
Dir string
NodeID string
PubKey cryptotypes.PubKey
Moniker string
APIAddress string
RPCAddress string
P2PAddress string
JSONRPCAddress string
Address sdk.AccAddress
ValAddress sdk.ValAddress
RPCClient tmclient.Client
JSONRPCClient *ethclient.Client
AppConfig *config.Config
ClientCtx client.Context
Ctx *server.Context
Dir string
NodeID string
PubKey cryptotypes.PubKey
Moniker string
APIAddress string
RPCAddress string
P2PAddress string
Address sdk.AccAddress
ValAddress sdk.ValAddress
RPCClient tmclient.Client
JSONRPCClient *ethclient.Client

tmNode *node.Node
api *api.Server
Expand Down Expand Up @@ -251,6 +250,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
appCfg.API.Enable = true
appCfg.API.Swagger = false
appCfg.Telemetry.Enabled = false
appCfg.Telemetry.GlobalLabels = [][]string{{"chain_id", cfg.ChainID}}

ctx := server.NewDefaultContext()
tmCfg := ctx.Config
Expand Down Expand Up @@ -473,6 +473,13 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
srvconfig.SetConfigTemplate(customAppTemplate)
srvconfig.WriteConfigFile(filepath.Join(nodeDir, "config/app.toml"), appCfg)

ctx.Viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_"))
ctx.Viper.SetConfigFile(filepath.Join(nodeDir, "config/app.toml"))
err = ctx.Viper.ReadInConfig()
if err != nil {
return nil, err
}

clientCtx := client.Context{}.
WithKeyringDir(clientDir).
WithKeyring(kb).
Expand Down
13 changes: 8 additions & 5 deletions testutil/network/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,24 @@ func startInProcess(cfg Config, val *Validator) error {
}
}

fmt.Println(val.Moniker, val.JSONRPCAddress, val.AppConfig.JSONRPC.Enable)
if val.AppConfig.JSONRPC.Enable && val.JSONRPCAddress != "" {
if val.AppConfig.JSONRPC.Enable && val.AppConfig.JSONRPC.Address != "" {
if val.Ctx == nil || val.Ctx.Viper == nil {
return fmt.Errorf("validator %s context is nil", val.Moniker)
}

tmEndpoint := "/websocket"
val.jsonrpc, val.jsonrpcDone, err = server.StartJSONRPC(val.Ctx, val.ClientCtx, val.JSONRPCAddress, tmEndpoint, *val.AppConfig)
tmRPCAddr := fmt.Sprintf("tcp://%s", val.AppConfig.GRPC.Address)

val.jsonrpc, val.jsonrpcDone, err = server.StartJSONRPC(val.Ctx, val.ClientCtx, tmRPCAddr, tmEndpoint, *val.AppConfig)
if err != nil {
return err
}

val.JSONRPCClient, err = ethclient.Dial(val.JSONRPCAddress)
address := fmt.Sprintf("http://%s", val.AppConfig.JSONRPC.Address)

val.JSONRPCClient, err = ethclient.Dial(address)
if err != nil {
return fmt.Errorf("failed to dial JSON-RPC at %s: %w", val.JSONRPCAddress, err)
return fmt.Errorf("failed to dial JSON-RPC at %s: %w", val.AppConfig.JSONRPC.Address, err)
}
}

Expand Down

0 comments on commit b4e3d1a

Please sign in to comment.