From e927234725bd2018519e0a136d000eb3fd574dba Mon Sep 17 00:00:00 2001 From: Rootul P Date: Thu, 29 Feb 2024 11:12:40 -0500 Subject: [PATCH] chore: cherry-pick testnode config to main (#3136) Closes https://github.com/celestiaorg/celestia-app/issues/2198 Note: I couldn't actually `git cherry-pick` because the commits got squashed on main so I manually copied the modification over. --- go.work.sum | 3 +++ test/util/testnode/config.go | 6 ++++++ test/util/testnode/network.go | 20 +++++--------------- test/util/testnode/rpc_client.go | 6 +++++- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/go.work.sum b/go.work.sum index 87044c0f63..623aa594d1 100644 --- a/go.work.sum +++ b/go.work.sum @@ -439,6 +439,7 @@ github.com/Azure/go-autorest v11.1.2+incompatible h1:viZ3tV5l4gE2Sw0xrasFHytCGtz github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o= github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 h1:1BDTz0u9nC3//pOCMdNH+CiXJVYJh5UQNCOBG7jbELc= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4= @@ -799,6 +800,7 @@ github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/le github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4= github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8/go.mod h1:mC1jAcsrzbxHt8iiaC+zU4b1ylILSosueou12R++wfY= github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3/go.mod h1:RagcQ7I8IeTMnF8JTXieKnO4Z6JCsikNEzj0DwauVzE= +github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g= github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= github.com/moricho/tparallel v0.3.0/go.mod h1:leENX2cUv7Sv2qDgdi0D0fCftN8fRC67Bcn8pqzeYNI= github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ= @@ -839,6 +841,7 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1 github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4= github.com/protolambda/bls12-381-util v0.0.0-20220416220906-d8552aa452c7/go.mod h1:IToEjHuttnUzwZI5KBSM/LOOW3qLbbrHOEfp3SbECGY= +github.com/prysmaticlabs/gohashtree v0.0.1-alpha.0.20220714111606-acbb2962fb48/go.mod h1:4pWaT30XoEx1j8KNJf3TV+E3mQkaufn7mf+jRNb/Fuk= github.com/quasilyte/go-ruleguard v0.3.19/go.mod h1:lHSn69Scl48I7Gt9cX3VrbsZYvYiBYszZOZW4A+oTEw= github.com/quasilyte/gogrep v0.5.0/go.mod h1:Cm9lpz9NZjEoL1tgZ2OgeUKPIxL1meE7eo60Z6Sk+Ng= github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727/go.mod h1:rlzQ04UMyJXu/aOvhd8qT+hvDrFpiwqp8MRXDY9szc0= diff --git a/test/util/testnode/config.go b/test/util/testnode/config.go index 1aaff08ded..fe55d7742e 100644 --- a/test/util/testnode/config.go +++ b/test/util/testnode/config.go @@ -1,6 +1,7 @@ package testnode import ( + "fmt" "time" "github.com/celestiaorg/celestia-app/cmd/celestia-appd/cmd" @@ -156,5 +157,10 @@ func DefaultTendermintConfig() *tmconfig.Config { tmCfg.RPC.TimeoutBroadcastTxCommit = time.Minute + // set all the ports to random open ones + tmCfg.RPC.ListenAddress = fmt.Sprintf("tcp://127.0.0.1:%d", mustGetFreePort()) + tmCfg.P2P.ListenAddress = fmt.Sprintf("tcp://127.0.0.1:%d", mustGetFreePort()) + tmCfg.RPC.GRPCListenAddress = fmt.Sprintf("tcp://127.0.0.1:%d", mustGetFreePort()) + return tmCfg } diff --git a/test/util/testnode/network.go b/test/util/testnode/network.go index 7452c19801..c93f09f96d 100644 --- a/test/util/testnode/network.go +++ b/test/util/testnode/network.go @@ -2,7 +2,6 @@ package testnode import ( "context" - "fmt" "net" "testing" @@ -20,13 +19,8 @@ import ( func NewNetwork(t testing.TB, cfg *Config) (cctx Context, rpcAddr, grpcAddr string) { t.Helper() - tmCfg := cfg.TmConfig - tmCfg.RPC.ListenAddress = fmt.Sprintf("tcp://127.0.0.1:%d", mustGetFreePort()) - tmCfg.P2P.ListenAddress = fmt.Sprintf("tcp://127.0.0.1:%d", mustGetFreePort()) - tmCfg.RPC.GRPCListenAddress = fmt.Sprintf("tcp://127.0.0.1:%d", mustGetFreePort()) - // initialize the genesis file and validator files for the first validator. - baseDir, err := genesis.InitFiles(t.TempDir(), tmCfg, cfg.Genesis, 0) + baseDir, err := genesis.InitFiles(t.TempDir(), cfg.TmConfig, cfg.Genesis, 0) require.NoError(t, err) tmNode, app, err := NewCometNode(baseDir, &cfg.UniversalTestingConfig) @@ -37,19 +31,15 @@ func NewNetwork(t testing.TB, cfg *Config) (cctx Context, rpcAddr, grpcAddr stri cancel() }) - appCfg := cfg.AppConfig - appCfg.GRPC.Address = fmt.Sprintf("127.0.0.1:%d", mustGetFreePort()) - appCfg.API.Address = fmt.Sprintf("tcp://127.0.0.1:%d", mustGetFreePort()) - - cctx = NewContext(ctx, cfg.Genesis.Keyring(), tmCfg, cfg.Genesis.ChainID, appCfg.API.Address) + cctx = NewContext(ctx, cfg.Genesis.Keyring(), cfg.TmConfig, cfg.Genesis.ChainID, cfg.AppConfig.API.Address) cctx, stopNode, err := StartNode(tmNode, cctx) require.NoError(t, err) - cctx, cleanupGRPC, err := StartGRPCServer(app, appCfg, cctx) + cctx, cleanupGRPC, err := StartGRPCServer(app, cfg.AppConfig, cctx) require.NoError(t, err) - apiServer, err := StartAPIServer(app, *appCfg, cctx) + apiServer, err := StartAPIServer(app, *cfg.AppConfig, cctx) require.NoError(t, err) t.Cleanup(func() { @@ -74,7 +64,7 @@ func NewNetwork(t testing.TB, cfg *Config) (cctx Context, rpcAddr, grpcAddr stri } }) - return cctx, tmCfg.RPC.ListenAddress, appCfg.GRPC.Address + return cctx, cfg.TmConfig.RPC.ListenAddress, cfg.AppConfig.GRPC.Address } // getFreePort returns a free port and optionally an error. diff --git a/test/util/testnode/rpc_client.go b/test/util/testnode/rpc_client.go index 7c51163f77..fc70c4be42 100644 --- a/test/util/testnode/rpc_client.go +++ b/test/util/testnode/rpc_client.go @@ -1,6 +1,7 @@ package testnode import ( + "fmt" "os" "path" "strings" @@ -91,7 +92,10 @@ func StartGRPCServer(app srvtypes.Application, appCfg *srvconfig.Config, cctx Co // DefaultAppConfig wraps the default config described in the server func DefaultAppConfig() *srvconfig.Config { - return srvconfig.DefaultConfig() + appCfg := srvconfig.DefaultConfig() + appCfg.GRPC.Address = fmt.Sprintf("127.0.0.1:%d", mustGetFreePort()) + appCfg.API.Address = fmt.Sprintf("tcp://127.0.0.1:%d", mustGetFreePort()) + return appCfg } // removeDir removes the directory `rootDir`.