Skip to content

Commit

Permalink
fix(systemtests): avoid HTTP server on port 8080 conflict when AddFul…
Browse files Browse the repository at this point in the history
…lnode (#22810)
  • Loading branch information
mmsqe authored Dec 10, 2024
1 parent 332d0b1 commit e07fee5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
4 changes: 4 additions & 0 deletions systemtests/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Ref: https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.j

## [Unreleased]

## [v1.0.0-rc.4] - 2024-12-10

* [#22810](https://github.com/cosmos/cosmos-sdk/pull/22810) Avoid HTTP server conflicts on port 8080

## [v1.0.0-rc.3] - 2024-12-05

* [#22774](https://github.com/cosmos/cosmos-sdk/pull/22774) Add greater than or equal support in Rest test suite
Expand Down
21 changes: 16 additions & 5 deletions systemtests/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
client "github.com/cometbft/cometbft/rpc/client/http"
ctypes "github.com/cometbft/cometbft/rpc/core/types"
tmtypes "github.com/cometbft/cometbft/types"
"github.com/creachadair/tomledit"
"github.com/stretchr/testify/require"
"github.com/tidwall/sjson"

Expand All @@ -38,7 +39,11 @@ var (

MaxGas = 10_000_000
// DefaultApiPort is the port for the node to interact with
DefaultApiPort = 1317
DefaultApiPort = 1317
DefaultRpcPort = 26657
DefaultRestPort = 8080
DefaultGrpcPort = 9090
DefaultP2PPort = 16656
)

type TestnetInitializer interface {
Expand Down Expand Up @@ -719,15 +724,21 @@ func (s *SystemUnderTest) AddFullnode(t *testing.T, beforeStart ...func(nodeNumb

configPath := filepath.Join(WorkDir, nodePath, "config")

// start node
allNodes := s.AllNodes(t)
node := allNodes[len(allNodes)-1]
// quick hack: copy config and overwrite by start params
for _, tomlFile := range []string{"config.toml", "app.toml"} {
configFile := filepath.Join(configPath, tomlFile)
_ = os.Remove(configFile)
_ = MustCopyFile(filepath.Join(WorkDir, s.nodePath(0), "config", tomlFile), configFile)
if tomlFile == "app.toml" && IsV2() {
file := filepath.Join(WorkDir, s.nodePath(nodeNumber), "config", tomlFile)
EditToml(file, func(doc *tomledit.Document) {
SetValue(doc, fmt.Sprintf("%s:%d", node.IP, DefaultRestPort+nodeNumber), "rest", "address")
})
}
}
// start node
allNodes := s.AllNodes(t)
node := allNodes[len(allNodes)-1]
peers := make([]string, len(allNodes)-1)
for i, n := range allNodes[0 : len(allNodes)-1] {
peers[i] = n.PeerAddr()
Expand All @@ -740,7 +751,7 @@ func (s *SystemUnderTest) AddFullnode(t *testing.T, beforeStart ...func(nodeNumb
"--p2p.persistent_peers=" + strings.Join(peers, ","),
fmt.Sprintf("--p2p.laddr=tcp://localhost:%d", node.P2PPort),
fmt.Sprintf("--rpc.laddr=tcp://localhost:%d", node.RPCPort),
fmt.Sprintf("--grpc.address=localhost:%d", 9090+nodeNumber),
fmt.Sprintf("--grpc.address=localhost:%d", DefaultGrpcPort+nodeNumber),
"--p2p.pex=false",
"--moniker=" + moniker,
"--log_level=info",
Expand Down
17 changes: 5 additions & 12 deletions systemtests/testnet_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,6 @@ func NewModifyConfigYamlInitializer(exec string, s *SystemUnderTest) *ModifyConf
}
}

const (
rpcPortStart = 26657
apiPortStart = 1317
grpcPortStart = 9090
p2pPortStart = 16656
)

func (s ModifyConfigYamlInitializer) Initialize() {
// init with legacy testnet command
args := []string{
Expand Down Expand Up @@ -154,16 +147,16 @@ func (s ModifyConfigYamlInitializer) Initialize() {
for i := 0; i < s.initialNodesCount; i++ {
nodeDir := filepath.Join(WorkDir, NodePath(i, s.outputDir, s.projectName), "config")
id := string(mustV(p2p.LoadNodeKey(filepath.Join(nodeDir, "node_key.json"))).ID())
nodeAddresses[i] = fmt.Sprintf("%s@127.0.0.1:%d", id, p2pPortStart+i)
nodeAddresses[i] = fmt.Sprintf("%s@127.0.0.1:%d", id, DefaultP2PPort+i)
}

// then update configs
for i := 0; i < s.initialNodesCount; i++ {
nodeDir := filepath.Join(WorkDir, NodePath(i, s.outputDir, s.projectName), "config")
nodeNumber := i
EditToml(filepath.Join(nodeDir, "config.toml"), func(doc *tomledit.Document) {
UpdatePort(doc, rpcPortStart+i, "rpc", "laddr")
UpdatePort(doc, p2pPortStart+i, "p2p", "laddr")
UpdatePort(doc, DefaultRpcPort+i, "rpc", "laddr")
UpdatePort(doc, DefaultP2PPort+i, "p2p", "laddr")
SetBool(doc, false, "p2p", "addr_book_strict")
SetBool(doc, false, "p2p", "pex")
SetBool(doc, true, "p2p", "allow_duplicate_ip")
Expand All @@ -174,8 +167,8 @@ func (s ModifyConfigYamlInitializer) Initialize() {
SetValue(doc, s.commitTimeout.String(), "consensus", "timeout_commit")
})
EditToml(filepath.Join(nodeDir, "app.toml"), func(doc *tomledit.Document) {
UpdatePort(doc, apiPortStart+i, "api", "address")
UpdatePort(doc, grpcPortStart+i, "grpc", "address")
UpdatePort(doc, DefaultApiPort+i, "api", "address")
UpdatePort(doc, DefaultGrpcPort+i, "grpc", "address")
})
}
}
Expand Down

0 comments on commit e07fee5

Please sign in to comment.