From dbf270397673cdd4aea11d936a075a617baf4e1e Mon Sep 17 00:00:00 2001 From: Francisco Moura Date: Mon, 15 Apr 2024 23:35:29 -0300 Subject: [PATCH] feat: add test port range Env --- internal/node/machinehash_test.go | 3 ++- pkg/ethutil/ethutil_test.go | 3 ++- pkg/testutil/testutil.go | 12 ++++++++++++ test/echo_test.go | 5 +++-- 4 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 pkg/testutil/testutil.go diff --git a/internal/node/machinehash_test.go b/internal/node/machinehash_test.go index fae7eac20..2c690deb9 100644 --- a/internal/node/machinehash_test.go +++ b/internal/node/machinehash_test.go @@ -12,6 +12,7 @@ import ( "github.com/cartesi/rollups-node/internal/deps" "github.com/cartesi/rollups-node/internal/machine" "github.com/cartesi/rollups-node/pkg/addresses" + "github.com/cartesi/rollups-node/pkg/testutil" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/suite" ) @@ -139,7 +140,7 @@ func startDevnet() (*deps.DepsContainers, error) { DockerImage: deps.DefaultDevnetDockerImage, BlockTime: deps.DefaultBlockTime, BlockToWaitForOnStartup: deps.DefaultBlockToWaitForOnStartup, - Port: "", + Port: testutil.GetCartesiTestDepsPortRange(), }, }) if err != nil { diff --git a/pkg/ethutil/ethutil_test.go b/pkg/ethutil/ethutil_test.go index dbb0f2b35..34a3d154d 100644 --- a/pkg/ethutil/ethutil_test.go +++ b/pkg/ethutil/ethutil_test.go @@ -11,6 +11,7 @@ import ( "github.com/cartesi/rollups-node/internal/deps" "github.com/cartesi/rollups-node/pkg/addresses" + "github.com/cartesi/rollups-node/pkg/testutil" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" "github.com/stretchr/testify/suite" @@ -97,7 +98,7 @@ func newDevNetContainer(ctx context.Context) (*deps.DepsContainers, error) { DockerImage: deps.DefaultDevnetDockerImage, BlockTime: deps.DefaultBlockTime, BlockToWaitForOnStartup: deps.DefaultBlockToWaitForOnStartup, - Port: "", + Port: testutil.GetCartesiTestDepsPortRange(), }, }) if err != nil { diff --git a/pkg/testutil/testutil.go b/pkg/testutil/testutil.go new file mode 100644 index 000000000..dfb689282 --- /dev/null +++ b/pkg/testutil/testutil.go @@ -0,0 +1,12 @@ +// (c) Cartesi and individual authors (see AUTHORS) +// SPDX-License-Identifier: Apache-2.0 (see LICENSE) + +// This package contains tests utilities. + +package testutil + +import "os" + +func GetCartesiTestDepsPortRange() string { + return os.Getenv("CARTESI_TEST_DEPS_PORT_RANGE") +} diff --git a/test/echo_test.go b/test/echo_test.go index c7b42b904..ab645d67c 100644 --- a/test/echo_test.go +++ b/test/echo_test.go @@ -22,6 +22,7 @@ import ( "github.com/cartesi/rollups-node/internal/node" "github.com/cartesi/rollups-node/pkg/ethutil" "github.com/cartesi/rollups-node/pkg/readerclient" + "github.com/cartesi/rollups-node/pkg/testutil" "github.com/stretchr/testify/suite" ) @@ -63,12 +64,12 @@ func (s *EchoInputTestSuite) SetupTest() { var depsConfig = deps.DepsConfig{ &deps.PostgresConfig{ DockerImage: deps.DefaultPostgresDockerImage, - Port: "", + Port: testutil.GetCartesiTestDepsPortRange(), Password: deps.DefaultPostgresPassword, }, &deps.DevnetConfig{ DockerImage: deps.DefaultDevnetDockerImage, - Port: "", + Port: testutil.GetCartesiTestDepsPortRange(), BlockTime: devNetMiningBlockTimeInSeconds, BlockToWaitForOnStartup: deps.DefaultBlockToWaitForOnStartup, },