diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index cfee96c260..7b32d418a2 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -36,9 +36,9 @@ jobs: # Close specified ports using lsof before testing / local port list compiled from ./integration/constants.go - name: Close Integration Test Ports run: | - killall -9 geth || true - killall -9 beacon || true - killall -9 validator || true + pkill -9 geth || true + pkill -9 beacon-chain || true + pkill -9 validator || true lowest_port=8000 # Lowest starting port highest_port=58000 # Highest port considering the offset @@ -77,6 +77,7 @@ jobs: integration/.build/noderunner/noderunner-*.txt integration/.build/wallet_extension/wal-ext-*.txt integration/.build/eth2/* + !integration/.build/eth2/**/geth.ipc integration/.build/faucet/* integration/.build/tenscan/* integration/.build/tengateway/* diff --git a/integration/constants.go b/integration/constants.go index 5b85cac7d4..8c3140c364 100644 --- a/integration/constants.go +++ b/integration/constants.go @@ -1,23 +1,8 @@ package integration -// Tracks the start ports handed out to different tests, in a bid to minimise conflicts. -// Note: the max should not exceed 30000 because the OS can use those ports and we'll get conflicts -const ( - StartPortEth2NetworkTests = 10000 - StartPortTenscanUnitTest = 11000 - StartPortNodeRunnerTest = 12000 - StartPortSimulationGethInMem = 14000 - StartPortSimulationInMem = 15000 - StartPortSimulationFullNetwork = 16000 - DoNotUse = 17000 // port conflict on this address - StartPortSmartContractTests = 18000 - StartPortContractDeployerTest1 = 19000 - StartPortContractDeployerTest2 = 21000 - StartPortFaucetUnitTest = 22000 - StartPortFaucetHTTPUnitTest = 23000 - StartPortTenGatewayUnitTest = 24000 - StartPortNetworkTests = 25000 +import "reflect" +const ( DefaultGethWSPortOffset = 100 DefaultGethAUTHPortOffset = 200 DefaultGethNetworkPortOffset = 300 @@ -43,3 +28,52 @@ const ( GethNodeAddress = "0x123463a4b065722e99115d6c222f267d9cabb524" GethNodePK = "2e0834786285daccd064ca17f1654f67b4aef298acbb82cef9ec422fb4975622" ) + +type Ports struct { + TestStartPosEth2NetworkPort int + TestTenscanPort int + TestCanStartStandaloneTenHostAndEnclavePort int + TestGethSimulationPort int + TestInMemoryMonteCarloSimulationPort int + TestFullNetworkMonteCarloSimulationPort int + DoNotUSePort int + TestManagementContractPort int + TestCanDeployLayer2ERC20ContractPort int + TestFaucetSendsFundsOnlyIfNeededPort int + TestFaucetPort int + TestFaucetHTTPPort int + TestTenGatewayPort int + NetworkTestsPort int +} + +var TestPorts = Ports{ + TestStartPosEth2NetworkPort: 10000, + TestTenscanPort: 11000, + TestCanStartStandaloneTenHostAndEnclavePort: 12000, + TestGethSimulationPort: 14000, + TestInMemoryMonteCarloSimulationPort: 15000, + TestFullNetworkMonteCarloSimulationPort: 16000, + DoNotUSePort: 17000, + TestManagementContractPort: 18000, + TestCanDeployLayer2ERC20ContractPort: 19000, + TestFaucetSendsFundsOnlyIfNeededPort: 21000, + TestFaucetPort: 22000, + TestFaucetHTTPPort: 23000, + TestTenGatewayPort: 24000, + NetworkTestsPort: 25000, +} + +// GetTestName looks up the test name from the port number using reflection +func GetTestName(port int) string { + port = port - DefaultGethNetworkPortOffset + val := reflect.ValueOf(TestPorts) + typ := reflect.TypeOf(TestPorts) + + for i := 0; i < val.NumField(); i++ { + fieldValue, ok := val.Field(i).Interface().(int) + if ok && fieldValue == port { + return typ.Field(i).Name + } + } + return "UnknownTest" +} diff --git a/integration/contractdeployer/contract_deployer_test.go b/integration/contractdeployer/contract_deployer_test.go index 95dcbf0198..11c51e60e9 100644 --- a/integration/contractdeployer/contract_deployer_test.go +++ b/integration/contractdeployer/contract_deployer_test.go @@ -45,7 +45,7 @@ func init() { //nolint:gochecknoinits } func TestCanDeployLayer2ERC20Contract(t *testing.T) { - startPort := integration.StartPortContractDeployerTest1 + startPort := integration.TestPorts.TestCanDeployLayer2ERC20ContractPort hostWSPort := startPort + integration.DefaultHostRPCWSOffset creatTenNetwork(t, startPort) // This sleep is required to ensure the initial rollup exists, and thus contract deployer can check its balance. @@ -81,7 +81,7 @@ func TestCanDeployLayer2ERC20Contract(t *testing.T) { } func TestFaucetSendsFundsOnlyIfNeeded(t *testing.T) { - startPort := integration.StartPortContractDeployerTest2 + startPort := integration.TestPorts.TestFaucetSendsFundsOnlyIfNeededPort hostWSPort := startPort + integration.DefaultHostRPCWSOffset creatTenNetwork(t, startPort) diff --git a/integration/eth2network/build_number.go b/integration/eth2network/build_number.go index 967db76fd5..7708fe0b94 100644 --- a/integration/eth2network/build_number.go +++ b/integration/eth2network/build_number.go @@ -30,7 +30,7 @@ func getBuildNumber() (int, error) { break } buildNumber++ - if buildNumber > 9999 { + if buildNumber > 99 { buildNumber = 1 } } diff --git a/integration/eth2network/pos_eth2_network.go b/integration/eth2network/pos_eth2_network.go index e3b811d1d2..c4b8981b71 100644 --- a/integration/eth2network/pos_eth2_network.go +++ b/integration/eth2network/pos_eth2_network.go @@ -54,6 +54,7 @@ type PosImpl struct { gethLogFile string prysmBeaconLogFile string prysmValidatorLogFile string + testNameLogFile string gethdataDir string beacondataDir string validatordataDir string @@ -98,9 +99,12 @@ func NewPosEth2Network(binDir string, gethNetworkPort, beaconP2PPort, gethRPCPor panic(err) } + testName := integration.GetTestName(gethNetworkPort) + gethLogFile := path.Join(buildDir, "geth.log") prysmBeaconLogFile := path.Join(buildDir, "beacon-chain.log") prysmValidatorLogFile := path.Join(buildDir, "validator.log") + testNameLogFile := path.Join(buildDir, fmt.Sprintf("%s.log", testName)) gethdataDir := path.Join(buildDir, "/gethdata") beacondataDir := path.Join(buildDir, "/beacondata") @@ -139,6 +143,7 @@ func NewPosEth2Network(binDir string, gethNetworkPort, beaconP2PPort, gethRPCPor gethLogFile: gethLogFile, prysmBeaconLogFile: prysmBeaconLogFile, prysmValidatorLogFile: prysmValidatorLogFile, + testNameLogFile: testNameLogFile, gethdataDir: gethdataDir, beacondataDir: beacondataDir, validatordataDir: validatordataDir, @@ -159,7 +164,7 @@ func (n *PosImpl) Start() error { go func() { n.gethProcessID, n.beaconProcessID, n.validatorProcessID, err = startNetworkScript(n.gethNetworkPort, n.beaconP2PPort, n.gethRPCPort, n.gethHTTPPort, n.gethWSPort, n.beaconRPCPort, n.beaconGatewayPort, n.chainID, n.buildDir, n.prysmBeaconLogFile, - n.prysmValidatorLogFile, n.gethLogFile, n.prysmBeaconBinaryPath, n.prysmBinaryPath, n.prysmValidatorBinaryPath, + n.prysmValidatorLogFile, n.gethLogFile, n.testNameLogFile, n.prysmBeaconBinaryPath, n.prysmBinaryPath, n.prysmValidatorBinaryPath, n.gethBinaryPath, n.gethdataDir, n.beacondataDir, n.validatordataDir) time.Sleep(time.Second) }() @@ -258,7 +263,7 @@ func (n *PosImpl) GenesisBytes() []byte { return n.gethGenesisBytes } -func startNetworkScript(gethNetworkPort, beaconP2PPort, gethRPCPort, gethHTTPPort, gethWSPort, beaconRPCPort, beaconGatewayPort, chainID int, buildDir, beaconLogFile, validatorLogFile, gethLogFile, +func startNetworkScript(gethNetworkPort, beaconP2PPort, gethRPCPort, gethHTTPPort, gethWSPort, beaconRPCPort, beaconGatewayPort, chainID int, buildDir, beaconLogFile, validatorLogFile, gethLogFile, testLogFile, beaconBinary, prysmBinary, validatorBinary, gethBinary, gethdataDir, beacondataDir, validatordataDir string, ) (int, int, int, error) { startScript := filepath.Join(basepath, "start-pos-network.sh") @@ -292,6 +297,7 @@ func startNetworkScript(gethNetworkPort, beaconP2PPort, gethRPCPort, gethHTTPPor "--gethdata-dir", gethdataDir, "--beacondata-dir", beacondataDir, "--validatordata-dir", validatordataDir, + "--test-log", testLogFile, ) fmt.Println(cmd.String()) diff --git a/integration/eth2network/pos_eth2_network_test.go b/integration/eth2network/pos_eth2_network_test.go index 37af521a4b..4d1fd2bd91 100644 --- a/integration/eth2network/pos_eth2_network_test.go +++ b/integration/eth2network/pos_eth2_network_test.go @@ -26,10 +26,6 @@ import ( gethlog "github.com/ethereum/go-ethereum/log" ) -const ( - _startPort = integration.StartPortEth2NetworkTests -) - func TestEnsureBinariesAreAvail(t *testing.T) { path, err := EnsureBinariesExist() assert.Nil(t, err) @@ -40,15 +36,16 @@ func TestStartPosEth2Network(t *testing.T) { binDir, err := EnsureBinariesExist() assert.Nil(t, err) + startPort := integration.TestPorts.TestStartPosEth2NetworkPort network := NewPosEth2Network( binDir, - _startPort+integration.DefaultGethNetworkPortOffset, - _startPort+integration.DefaultPrysmP2PPortOffset, - _startPort+integration.DefaultGethAUTHPortOffset, - _startPort+integration.DefaultGethWSPortOffset, - _startPort+integration.DefaultGethHTTPPortOffset, - _startPort+integration.DefaultPrysmRPCPortOffset, - _startPort+integration.DefaultPrysmGatewayPortOffset, + startPort+integration.DefaultGethNetworkPortOffset, + startPort+integration.DefaultPrysmP2PPortOffset, + startPort+integration.DefaultGethAUTHPortOffset, + startPort+integration.DefaultGethWSPortOffset, + startPort+integration.DefaultGethHTTPPortOffset, + startPort+integration.DefaultPrysmRPCPortOffset, + startPort+integration.DefaultPrysmGatewayPortOffset, integration.EthereumChainID, 3*time.Minute, ) @@ -60,12 +57,12 @@ func TestStartPosEth2Network(t *testing.T) { // test input configurations t.Run("areConfigsUphold", func(t *testing.T) { - areConfigsUphold(t, gethcommon.HexToAddress(integration.GethNodeAddress), integration.EthereumChainID) + areConfigsUphold(t, startPort, gethcommon.HexToAddress(integration.GethNodeAddress), integration.EthereumChainID) }) // test number of nodes t.Run("numberOfNodes", func(t *testing.T) { - numberOfNodes(t) + numberOfNodes(t, startPort) }) minerWallet := wallet.NewInMemoryWalletFromConfig( @@ -74,12 +71,12 @@ func TestStartPosEth2Network(t *testing.T) { gethlog.New()) t.Run("txsAreMinted", func(t *testing.T) { - txsAreMinted(t, minerWallet) + txsAreMinted(t, startPort, minerWallet) }) } -func areConfigsUphold(t *testing.T, addr gethcommon.Address, chainID int) { - url := fmt.Sprintf("http://127.0.0.1:%d", _startPort+integration.DefaultGethHTTPPortOffset) +func areConfigsUphold(t *testing.T, startPort int, addr gethcommon.Address, chainID int) { + url := fmt.Sprintf("http://127.0.0.1:%d", startPort+integration.DefaultGethHTTPPortOffset) conn, err := ethclient.Dial(url) assert.Nil(t, err) @@ -92,8 +89,8 @@ func areConfigsUphold(t *testing.T, addr gethcommon.Address, chainID int) { assert.Equal(t, int64(chainID), id.Int64()) } -func numberOfNodes(t *testing.T) { - url := fmt.Sprintf("http://127.0.0.1:%d", _startPort+integration.DefaultGethHTTPPortOffset) +func numberOfNodes(t *testing.T, startPort int) { + url := fmt.Sprintf("http://127.0.0.1:%d", startPort+integration.DefaultGethHTTPPortOffset) req, err := http.NewRequestWithContext( context.Background(), @@ -122,10 +119,10 @@ func numberOfNodes(t *testing.T) { assert.Equal(t, fmt.Sprintf("0x%x", 0), res["result"]) } -func txsAreMinted(t *testing.T, w wallet.Wallet) { +func txsAreMinted(t *testing.T, startPort int, w wallet.Wallet) { var err error - ethClient, err := ethadapter.NewEthClient("127.0.0.1", uint(_startPort+integration.DefaultGethWSPortOffset), 30*time.Second, common.L2Address{}, gethlog.New()) + ethClient, err := ethadapter.NewEthClient("127.0.0.1", uint(startPort+integration.DefaultGethWSPortOffset), 30*time.Second, common.L2Address{}, gethlog.New()) assert.Nil(t, err) toAddr := datagenerator.RandomAddress() diff --git a/integration/eth2network/start-pos-network.sh b/integration/eth2network/start-pos-network.sh index 65293c122a..092a142a22 100755 --- a/integration/eth2network/start-pos-network.sh +++ b/integration/eth2network/start-pos-network.sh @@ -21,6 +21,7 @@ GETH_LOG_FILE="./geth.log" GETHDATA_DIR="/gethdata" BEACONDATA_DIR="/beacondata" VALIDATORDATA_DIR="/validatordata" +TEST_LOG_FILE="./test.log" # Function to display usage usage() { @@ -68,6 +69,7 @@ while [[ "$#" -gt 0 ]]; do --gethdata-dir) GETHDATA_DIR="$2"; shift ;; --beacondata-dir) BEACONDATA_DIR="$2"; shift ;; --validatordata-dir) VALIDATORDATA_DIR="$2"; shift ;; + --test-log) TEST_LOG_FILE="$2"; shift ;; *) usage ;; esac shift @@ -76,6 +78,9 @@ done mkdir -p "$(dirname "${BEACON_LOG_FILE}")" mkdir -p "$(dirname "${VALIDATOR_LOG_FILE}")" mkdir -p "$(dirname "${GETH_LOG_FILE}")" +mkdir -p "$(dirname "${TEST_LOG_FILE}")" + +echo "Test" > "${TEST_LOG_FILE}" 2>&1 & ${PRYSMCTL_BINARY} testnet generate-genesis \ --fork deneb \ @@ -141,6 +146,7 @@ ${GETH_BINARY} --http \ --ws.origins "*" \ --authrpc.jwtsecret "${BASE_PATH}/jwt.hex" \ --authrpc.port "${GETH_RPC_PORT}" \ + --authrpc.vhosts "*" \ --port="${GETH_NETWORK_PORT}" \ --datadir="${GETHDATA_DIR}" \ --networkid="${CHAIN_ID}" \ diff --git a/integration/faucet/faucet_test.go b/integration/faucet/faucet_test.go index 03302d1ac5..5245877d0d 100644 --- a/integration/faucet/faucet_test.go +++ b/integration/faucet/faucet_test.go @@ -43,7 +43,7 @@ const ( func TestFaucet(t *testing.T) { t.Skip("Skipping because it is too flaky") - startPort := integration.StartPortFaucetUnitTest + startPort := integration.TestPorts.TestFaucetPort createObscuroNetwork(t, startPort) // This sleep is required to ensure the initial rollup exists, and thus contract deployer can check its balance. time.Sleep(2 * time.Second) @@ -54,7 +54,7 @@ func TestFaucet(t *testing.T) { PK: "0x" + contractDeployerPrivateKeyHex, JWTSecret: "This_is_secret", ChainID: big.NewInt(integration.TenChainID), - ServerPort: integration.StartPortFaucetHTTPUnitTest, + ServerPort: integration.TestPorts.TestFaucetHTTPPort, DefaultFundAmount: new(big.Int).Mul(big.NewInt(100), big.NewInt(1e18)), } faucetContainer, err := container.NewFaucetContainerFromConfig(faucetConfig) diff --git a/integration/noderunner/noderunner_test.go b/integration/noderunner/noderunner_test.go index 30b14c856c..b89f919a70 100644 --- a/integration/noderunner/noderunner_test.go +++ b/integration/noderunner/noderunner_test.go @@ -20,7 +20,6 @@ import ( const ( _testLogs = "../.build/noderunner/" _localhost = "127.0.0.1" - _startPort = integration.StartPortNodeRunnerTest ) // A smoke test to check that we can stand up a standalone TEN host and enclave. @@ -31,9 +30,9 @@ func TestCanStartStandaloneTenHostAndEnclave(t *testing.T) { TestSubtype: "test", LogLevel: gethlog.LvlInfo, }) - - // todo run the noderunner test with different obscuro node instances - newNode := createInMemoryNode() + startPort := integration.TestPorts.TestCanStartStandaloneTenHostAndEnclavePort + // todo run the noderunner test with different TEN node instances + newNode := createInMemoryNode(startPort) binDir, err := eth2network.EnsureBinariesExist() if err != nil { @@ -42,13 +41,13 @@ func TestCanStartStandaloneTenHostAndEnclave(t *testing.T) { network := eth2network.NewPosEth2Network( binDir, - _startPort+integration.DefaultGethNetworkPortOffset, - _startPort+integration.DefaultPrysmP2PPortOffset, - _startPort+integration.DefaultGethAUTHPortOffset, - _startPort+integration.DefaultGethWSPortOffset, - _startPort+integration.DefaultGethHTTPPortOffset, - _startPort+integration.DefaultPrysmRPCPortOffset, - _startPort+integration.DefaultPrysmGatewayPortOffset, + startPort+integration.DefaultGethNetworkPortOffset, + startPort+integration.DefaultPrysmP2PPortOffset, + startPort+integration.DefaultGethAUTHPortOffset, + startPort+integration.DefaultGethWSPortOffset, + startPort+integration.DefaultGethHTTPPortOffset, + startPort+integration.DefaultPrysmRPCPortOffset, + startPort+integration.DefaultPrysmGatewayPortOffset, integration.EthereumChainID, 3*time.Minute, ) @@ -66,7 +65,7 @@ func TestCanStartStandaloneTenHostAndEnclave(t *testing.T) { } // we create the node RPC client - wsURL := fmt.Sprintf("ws://127.0.0.1:%d", _startPort+integration.DefaultGethWSPortOffset) + wsURL := fmt.Sprintf("ws://127.0.0.1:%d", startPort+integration.DefaultGethWSPortOffset) var tenClient rpc.Client wait := 30 // max wait in seconds for { @@ -109,14 +108,14 @@ func TestCanStartStandaloneTenHostAndEnclave(t *testing.T) { t.Fatalf("Zero rollups have been produced after ten seconds. Something is wrong. Latest error was: %s", err) } -func createInMemoryNode() node.Node { +func createInMemoryNode(startPort int) node.Node { nodeCfg := node.NewNodeConfig( node.WithPrivateKey(integration.GethNodePK), node.WithHostID(integration.GethNodeAddress), - node.WithEnclaveWSPort(_startPort+integration.DefaultEnclaveOffset), - node.WithHostHTTPPort(_startPort+integration.DefaultHostRPCHTTPOffset), - node.WithHostWSPort(_startPort+integration.DefaultHostRPCWSOffset), - node.WithL1WebsocketURL(fmt.Sprintf("ws://%s:%d", _localhost, _startPort+integration.DefaultGethWSPortOffset)), + node.WithEnclaveWSPort(startPort+integration.DefaultEnclaveOffset), + node.WithHostHTTPPort(startPort+integration.DefaultHostRPCHTTPOffset), + node.WithHostWSPort(startPort+integration.DefaultHostRPCWSOffset), + node.WithL1WebsocketURL(fmt.Sprintf("ws://%s:%d", _localhost, startPort+integration.DefaultGethWSPortOffset)), node.WithGenesis(true), node.WithProfiler(true), node.WithL1BlockTime(1*time.Second), diff --git a/integration/simulation/devnetwork/config.go b/integration/simulation/devnetwork/config.go index 1602b3b7d8..c90fbde09f 100644 --- a/integration/simulation/devnetwork/config.go +++ b/integration/simulation/devnetwork/config.go @@ -42,7 +42,7 @@ type TenConfig struct { func DefaultTenConfig() *TenConfig { return &TenConfig{ - PortStart: integration.StartPortNetworkTests, + PortStart: integration.TestPorts.NetworkTestsPort, NumNodes: 4, InitNumValidators: 3, BatchInterval: 1 * time.Second, @@ -72,7 +72,7 @@ func LocalDevNetwork(tenConfigOpts ...TenConfigOption) *InMemDevNetwork { } l1Config := &L1Config{ - PortStart: integration.StartPortNetworkTests, + PortStart: integration.TestPorts.NetworkTestsPort, NumNodes: tenConfig.NumNodes, // we'll have 1 L1 node per L2 node AvgBlockDuration: 1 * time.Second, } diff --git a/integration/simulation/devnetwork/dev_network.go b/integration/simulation/devnetwork/dev_network.go index 904ad3cfb3..1ff7652670 100644 --- a/integration/simulation/devnetwork/dev_network.go +++ b/integration/simulation/devnetwork/dev_network.go @@ -150,7 +150,7 @@ func (s *InMemDevNetwork) Start() { // this is a new network, deploy the contracts to the L1 fmt.Println("Deploying TEN contracts to L1") s.deployTenNetworkContracts() - fmt.Printf("L1 Port - %d\n", integration.StartPortNetworkTests) + fmt.Printf("L1 Port - %d\n", integration.TestPorts.NetworkTestsPort) } fmt.Println("Starting TEN nodes") s.startNodes() diff --git a/integration/simulation/simulation_full_network_test.go b/integration/simulation/simulation_full_network_test.go index 903691d827..2f70330d03 100644 --- a/integration/simulation/simulation_full_network_test.go +++ b/integration/simulation/simulation_full_network_test.go @@ -28,7 +28,7 @@ func TestFullNetworkMonteCarloSimulation(t *testing.T) { SimulationTime: 120 * time.Second, L1EfficiencyThreshold: 0.2, Wallets: wallets, - StartPort: integration.StartPortSimulationFullNetwork, + StartPort: integration.TestPorts.TestFullNetworkMonteCarloSimulationPort, ReceiptTimeout: 20 * time.Second, StoppingDelay: 15 * time.Second, NodeWithInboundP2PDisabled: 2, diff --git a/integration/simulation/simulation_geth_in_mem_test.go b/integration/simulation/simulation_geth_in_mem_test.go index 6f24453691..4d156d3f05 100644 --- a/integration/simulation/simulation_geth_in_mem_test.go +++ b/integration/simulation/simulation_geth_in_mem_test.go @@ -11,7 +11,9 @@ import ( "github.com/ten-protocol/go-ten/integration/simulation/params" ) -const gethTestEnv = "GETH_TEST_ENABLED" +const ( + gethTestEnv = "GETH_TEST_ENABLED" +) // TestGethSimulation runs the simulation against a private geth network using Clique (PoA) func TestGethSimulation(t *testing.T) { @@ -31,7 +33,7 @@ func TestGethSimulation(t *testing.T) { SimulationTime: 35 * time.Second, L1EfficiencyThreshold: 0.2, Wallets: wallets, - StartPort: integration.StartPortSimulationGethInMem, + StartPort: integration.TestPorts.TestGethSimulationPort, IsInMem: true, ReceiptTimeout: 30 * time.Second, StoppingDelay: 10 * time.Second, diff --git a/integration/simulation/simulation_in_mem_test.go b/integration/simulation/simulation_in_mem_test.go index da278c6ed5..a6fd99293c 100644 --- a/integration/simulation/simulation_in_mem_test.go +++ b/integration/simulation/simulation_in_mem_test.go @@ -32,7 +32,7 @@ func TestInMemoryMonteCarloSimulation(t *testing.T) { MgmtContractLib: ethereummock.NewMgmtContractLibMock(), ERC20ContractLib: ethereummock.NewERC20ContractLibMock(), Wallets: wallets, - StartPort: integration.StartPortSimulationInMem, + StartPort: integration.TestPorts.TestInMemoryMonteCarloSimulationPort, IsInMem: true, L1TenData: ¶ms.L1TenData{}, ReceiptTimeout: 5 * time.Second, diff --git a/integration/smartcontract/smartcontracts_test.go b/integration/smartcontract/smartcontracts_test.go index 8cc404993c..4439858b17 100644 --- a/integration/smartcontract/smartcontracts_test.go +++ b/integration/smartcontract/smartcontracts_test.go @@ -24,8 +24,6 @@ import ( gethcommon "github.com/ethereum/go-ethereum/common" ) -const _startPort = integration.StartPortSmartContractTests - // netInfo is a bag holder struct for output data from the execution/run of a network type netInfo struct { ethClients []ethadapter.EthClient @@ -55,15 +53,16 @@ func runGethNetwork(t *testing.T) *netInfo { // prefund one wallet as the worker wallet workerWallet := datagenerator.RandomWallet(integration.EthereumChainID) + startPort := integration.TestPorts.TestManagementContractPort eth2Network := eth2network.NewPosEth2Network( binDir, - _startPort+integration.DefaultGethNetworkPortOffset, - _startPort+integration.DefaultPrysmP2PPortOffset, - _startPort+integration.DefaultGethAUTHPortOffset, // RPC - _startPort+integration.DefaultGethWSPortOffset, - _startPort+integration.DefaultGethHTTPPortOffset, - _startPort+integration.DefaultPrysmRPCPortOffset, - _startPort+integration.DefaultPrysmGatewayPortOffset, + startPort+integration.DefaultGethNetworkPortOffset, + startPort+integration.DefaultPrysmP2PPortOffset, + startPort+integration.DefaultGethAUTHPortOffset, // RPC + startPort+integration.DefaultGethWSPortOffset, + startPort+integration.DefaultGethHTTPPortOffset, + startPort+integration.DefaultPrysmRPCPortOffset, + startPort+integration.DefaultPrysmGatewayPortOffset, integration.EthereumChainID, 3*time.Minute, workerWallet.Address().String(), @@ -74,7 +73,7 @@ func runGethNetwork(t *testing.T) *netInfo { } // create a client that is connected to node 0 of the network - client, err := ethadapter.NewEthClient("127.0.0.1", integration.StartPortSmartContractTests+100, 60*time.Second, gethcommon.HexToAddress("0x0"), testlog.Logger()) + client, err := ethadapter.NewEthClient("127.0.0.1", uint(startPort+100), 60*time.Second, gethcommon.HexToAddress("0x0"), testlog.Logger()) if err != nil { t.Fatal(err) } diff --git a/integration/tengateway/tengateway_test.go b/integration/tengateway/tengateway_test.go index 4edf962914..00cf051f39 100644 --- a/integration/tengateway/tengateway_test.go +++ b/integration/tengateway/tengateway_test.go @@ -56,19 +56,19 @@ func init() { //nolint:gochecknoinits } const ( - testLogs = "../.build/tengateway/" - _startPort = integration.StartPortTenGatewayUnitTest + testLogs = "../.build/tengateway/" ) func TestTenGateway(t *testing.T) { - createTenNetwork(t, _startPort) + startPort := integration.TestPorts.TestTenGatewayPort + createTenNetwork(t, startPort) tenGatewayConf := wecommon.Config{ WalletExtensionHost: "127.0.0.1", - WalletExtensionPortHTTP: _startPort + integration.DefaultTenGatewayHTTPPortOffset, - WalletExtensionPortWS: _startPort + integration.DefaultTenGatewayWSPortOffset, - NodeRPCHTTPAddress: fmt.Sprintf("127.0.0.1:%d", _startPort+integration.DefaultHostRPCHTTPOffset), - NodeRPCWebsocketAddress: fmt.Sprintf("127.0.0.1:%d", _startPort+integration.DefaultHostRPCWSOffset), + WalletExtensionPortHTTP: startPort + integration.DefaultTenGatewayHTTPPortOffset, + WalletExtensionPortWS: startPort + integration.DefaultTenGatewayWSPortOffset, + NodeRPCHTTPAddress: fmt.Sprintf("127.0.0.1:%d", startPort+integration.DefaultHostRPCHTTPOffset), + NodeRPCWebsocketAddress: fmt.Sprintf("127.0.0.1:%d", startPort+integration.DefaultHostRPCWSOffset), LogPath: "sys_out", VerboseFlag: false, DBType: "sqlite", @@ -102,7 +102,7 @@ func TestTenGateway(t *testing.T) { w := wallet.NewInMemoryWalletFromConfig(genesis.TestnetPrefundedPK, integration.TenChainID, testlog.Logger()) // run the tests against the exis - for name, test := range map[string]func(*testing.T, string, string, wallet.Wallet){ + for name, test := range map[string]func(*testing.T, int, string, string, wallet.Wallet){ //"testAreTxsMinted": testAreTxsMinted, this breaks the other tests bc, enable once concurrency issues are fixed "testErrorHandling": testErrorHandling, "testMultipleAccountsSubscription": testMultipleAccountsSubscription, @@ -117,7 +117,7 @@ func TestTenGateway(t *testing.T) { "testRateLimiter": testRateLimiter, } { t.Run(name, func(t *testing.T) { - test(t, httpURL, wsURL, w) + test(t, startPort, httpURL, wsURL, w) }) } @@ -128,7 +128,7 @@ func TestTenGateway(t *testing.T) { assert.NoError(t, err) } -func testRateLimiter(t *testing.T, httpURL, wsURL string, w wallet.Wallet) { +func testRateLimiter(t *testing.T, _ int, httpURL, wsURL string, w wallet.Wallet) { user0, err := NewGatewayUser([]wallet.Wallet{w, datagenerator.RandomWallet(integration.TenChainID)}, httpURL, wsURL) require.NoError(t, err) testlog.Logger().Info("Created user with encryption token", "t", user0.tgClient.UserID()) @@ -167,7 +167,7 @@ func testRateLimiter(t *testing.T, httpURL, wsURL string, w wallet.Wallet) { require.Equal(t, "rate limit exceeded", err.Error()) } -func testNewHeadsSubscription(t *testing.T, httpURL, wsURL string, w wallet.Wallet) { +func testNewHeadsSubscription(t *testing.T, _ int, httpURL, wsURL string, w wallet.Wallet) { user0, err := NewGatewayUser([]wallet.Wallet{w, datagenerator.RandomWallet(integration.TenChainID)}, httpURL, wsURL) require.NoError(t, err) @@ -198,7 +198,7 @@ func testNewHeadsSubscription(t *testing.T, httpURL, wsURL string, w wallet.Wall require.True(t, len(receivedHeads) > 1) } -func testMultipleAccountsSubscription(t *testing.T, httpURL, wsURL string, w wallet.Wallet) { +func testMultipleAccountsSubscription(t *testing.T, _ int, httpURL, wsURL string, w wallet.Wallet) { user0, err := NewGatewayUser([]wallet.Wallet{w, datagenerator.RandomWallet(integration.TenChainID)}, httpURL, wsURL) require.NoError(t, err) testlog.Logger().Info("Created user with encryption token", "t", user0.tgClient.UserID()) @@ -356,7 +356,7 @@ func testMultipleAccountsSubscription(t *testing.T, httpURL, wsURL string, w wal require.NoError(t, err) } -func testSubscriptionTopics(t *testing.T, httpURL, wsURL string, w wallet.Wallet) { +func testSubscriptionTopics(t *testing.T, _ int, httpURL, wsURL string, w wallet.Wallet) { user0, err := NewGatewayUser([]wallet.Wallet{w}, httpURL, wsURL) require.NoError(t, err) @@ -476,7 +476,7 @@ func testAreTxsMinted(t *testing.T, httpURL, wsURL string, w wallet.Wallet) { // require.True(t, receipt.Status == 1) } -func testErrorHandling(t *testing.T, httpURL, wsURL string, w wallet.Wallet) { +func testErrorHandling(t *testing.T, startPort int, httpURL, wsURL string, w wallet.Wallet) { // set up the tgClient ogClient := lib.NewTenGatewayLibrary(httpURL, wsURL) @@ -521,7 +521,7 @@ func testErrorHandling(t *testing.T, httpURL, wsURL string, w wallet.Wallet) { require.NoError(t, err, req, response) // repeat the process for geth - _, response, err = httputil.PostDataJSON(fmt.Sprintf("http://localhost:%d", _startPort+integration.DefaultGethHTTPPortOffset), []byte(req)) + _, response, err = httputil.PostDataJSON(fmt.Sprintf("http://localhost:%d", startPort+integration.DefaultGethHTTPPortOffset), []byte(req)) require.NoError(t, err) // we only care about format @@ -531,7 +531,7 @@ func testErrorHandling(t *testing.T, httpURL, wsURL string, w wallet.Wallet) { } } -func testErrorsRevertedArePassed(t *testing.T, httpURL, wsURL string, w wallet.Wallet) { +func testErrorsRevertedArePassed(t *testing.T, _ int, httpURL, wsURL string, w wallet.Wallet) { // set up the tgClient ogClient := lib.NewTenGatewayLibrary(httpURL, wsURL) @@ -610,7 +610,7 @@ func testErrorsRevertedArePassed(t *testing.T, httpURL, wsURL string, w wallet.W require.Equal(t, "execution reverted: assert(false)", err.Error()) } -func testUnsubscribe(t *testing.T, httpURL, wsURL string, w wallet.Wallet) { +func testUnsubscribe(t *testing.T, _ int, httpURL, wsURL string, w wallet.Wallet) { // create a user with multiple accounts user, err := NewGatewayUser([]wallet.Wallet{w, datagenerator.RandomWallet(integration.TenChainID)}, httpURL, wsURL) require.NoError(t, err) @@ -666,7 +666,7 @@ func testUnsubscribe(t *testing.T, httpURL, wsURL string, w wallet.Wallet) { assert.Equal(t, 1, len(userLogs)) } -func testClosingConnectionWhileSubscribed(t *testing.T, httpURL, wsURL string, w wallet.Wallet) { +func testClosingConnectionWhileSubscribed(t *testing.T, _ int, httpURL, wsURL string, w wallet.Wallet) { // create a user with multiple accounts user, err := NewGatewayUser([]wallet.Wallet{w, datagenerator.RandomWallet(integration.TenChainID)}, httpURL, wsURL) require.NoError(t, err) @@ -730,7 +730,7 @@ func testClosingConnectionWhileSubscribed(t *testing.T, httpURL, wsURL string, w subscription.Unsubscribe() } -func testDifferentMessagesOnRegister(t *testing.T, httpURL, wsURL string, w wallet.Wallet) { +func testDifferentMessagesOnRegister(t *testing.T, _ int, httpURL, wsURL string, w wallet.Wallet) { user, err := NewGatewayUser([]wallet.Wallet{w, datagenerator.RandomWallet(integration.TenChainID)}, httpURL, wsURL) require.NoError(t, err) testlog.Logger().Info("Created user with encryption token: %s\n", user.tgClient.UserID()) @@ -744,7 +744,7 @@ func testDifferentMessagesOnRegister(t *testing.T, httpURL, wsURL string, w wall require.NoError(t, err) } -func testInvokeNonSensitiveMethod(t *testing.T, httpURL, wsURL string, w wallet.Wallet) { +func testInvokeNonSensitiveMethod(t *testing.T, _ int, httpURL, wsURL string, w wallet.Wallet) { user, err := NewGatewayUser([]wallet.Wallet{w}, httpURL, wsURL) require.NoError(t, err) @@ -756,7 +756,7 @@ func testInvokeNonSensitiveMethod(t *testing.T, httpURL, wsURL string, w wallet. } } -func testGetStorageAtForReturningUserID(t *testing.T, httpURL, wsURL string, w wallet.Wallet) { +func testGetStorageAtForReturningUserID(t *testing.T, _ int, httpURL, wsURL string, w wallet.Wallet) { user, err := NewGatewayUser([]wallet.Wallet{w}, httpURL, wsURL) require.NoError(t, err) diff --git a/integration/tenscan/tenscan_test.go b/integration/tenscan/tenscan_test.go index dd8fc17184..0ddb67a3ac 100644 --- a/integration/tenscan/tenscan_test.go +++ b/integration/tenscan/tenscan_test.go @@ -48,8 +48,8 @@ const ( ) func TestTenscan(t *testing.T) { - startPort := integration.StartPortTenscanUnitTest - createTenNetwork(t, startPort) + startPort := integration.TestPorts.TestTenscanPort + createTenNetwork(t, integration.TestPorts.TestTenscanPort) tenScanConfig := &config.Config{ NodeHostAddress: fmt.Sprintf("http://127.0.0.1:%d", startPort+integration.DefaultHostRPCHTTPOffset),