Skip to content

Commit

Permalink
chore: remove unused code from server (#14437)
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle authored Dec 27, 2022
1 parent 1fab762 commit 3684966
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 33 deletions.
26 changes: 0 additions & 26 deletions server/test_helpers.go

This file was deleted.

12 changes: 6 additions & 6 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
apiListenAddr = cfg.APIAddress
} else {
var err error
apiListenAddr, _, err = server.FreeTCPAddr()
apiListenAddr, _, err = FreeTCPAddr()
if err != nil {
return nil, err
}
Expand All @@ -357,7 +357,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
if cfg.RPCAddress != "" {
tmCfg.RPC.ListenAddress = cfg.RPCAddress
} else {
rpcAddr, _, err := server.FreeTCPAddr()
rpcAddr, _, err := FreeTCPAddr()
if err != nil {
return nil, err
}
Expand All @@ -367,15 +367,15 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
if cfg.GRPCAddress != "" {
appCfg.GRPC.Address = cfg.GRPCAddress
} else {
_, grpcPort, err := server.FreeTCPAddr()
_, grpcPort, err := FreeTCPAddr()
if err != nil {
return nil, err
}
appCfg.GRPC.Address = fmt.Sprintf("0.0.0.0:%s", grpcPort)
}
appCfg.GRPC.Enable = true

_, grpcWebPort, err := server.FreeTCPAddr()
_, grpcWebPort, err := FreeTCPAddr()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -409,13 +409,13 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
tmCfg.Moniker = nodeDirName
monikers[i] = nodeDirName

proxyAddr, _, err := server.FreeTCPAddr()
proxyAddr, _, err := FreeTCPAddr()
if err != nil {
return nil, err
}
tmCfg.ProxyApp = proxyAddr

p2pAddr, _, err := server.FreeTCPAddr()
p2pAddr, _, err := FreeTCPAddr()
if err != nil {
return nil, err
}
Expand Down
20 changes: 20 additions & 0 deletions testutil/network/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package network
import (
"encoding/json"
"fmt"
"net"
"os"
"path/filepath"
"time"

sdkerrors "cosmossdk.io/errors"
"github.com/tendermint/tendermint/node"
"github.com/tendermint/tendermint/p2p"
pvm "github.com/tendermint/tendermint/privval"
Expand Down Expand Up @@ -202,3 +204,21 @@ func writeFile(name string, dir string, contents []byte) error {

return nil
}

// Get a free address for a test tendermint server
// protocol is either tcp, http, etc
func FreeTCPAddr() (addr, port string, err error) {
l, err := net.Listen("tcp", "localhost:0")
if err != nil {
return "", "", err
}

if err := l.Close(); err != nil {
return "", "", sdkerrors.Wrap(err, "couldn't close the listener")
}

portI := l.Addr().(*net.TCPAddr).Port
port = fmt.Sprintf("%d", portI)
addr = fmt.Sprintf("tcp://0.0.0.0:%s", port)
return
}
3 changes: 2 additions & 1 deletion x/genutil/client/cli/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/mock"
"github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/genutil"
Expand Down Expand Up @@ -208,7 +209,7 @@ func TestStartStandAlone(t *testing.T) {
app, err := mock.NewApp(home, logger)
require.NoError(t, err)

svrAddr, _, err := server.FreeTCPAddr()
svrAddr, _, err := network.FreeTCPAddr()
require.NoError(t, err)

svr, err := abci_server.NewServer(svrAddr, "socket", app)
Expand Down

0 comments on commit 3684966

Please sign in to comment.