diff --git a/consensus-client-it/src/test/scala/units/AlternativeChainTestSuite.scala b/consensus-client-it/src/test/scala/units/AlternativeChainTestSuite.scala index 60856809..aa6228cc 100644 --- a/consensus-client-it/src/test/scala/units/AlternativeChainTestSuite.scala +++ b/consensus-client-it/src/test/scala/units/AlternativeChainTestSuite.scala @@ -5,7 +5,7 @@ import com.wavesplatform.common.state.ByteStr import units.client.contract.HasConsensusLayerDappTxHelpers.EmptyE2CTransfersRootHashHex import units.docker.WavesNodeContainer -class AlternativeChainTestSuite extends OneNodeTestSuite { +class AlternativeChainTestSuite extends BaseDockerTestSuite { "L2-383 Start an alternative chain after not getting an EL-block" in { step("EL miner #2 join") waves1.api.broadcastAndWait( diff --git a/consensus-client-it/src/test/scala/units/BaseDockerTestSuite.scala b/consensus-client-it/src/test/scala/units/BaseDockerTestSuite.scala index a2e6567f..a5cf0599 100644 --- a/consensus-client-it/src/test/scala/units/BaseDockerTestSuite.scala +++ b/consensus-client-it/src/test/scala/units/BaseDockerTestSuite.scala @@ -4,6 +4,7 @@ import com.typesafe.config.ConfigFactory import com.wavesplatform.GenesisBlockGenerator import com.wavesplatform.account.AddressScheme import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.utils.ScorexLogging import monix.execution.atomic.AtomicBoolean import org.scalatest.freespec.AnyFreeSpec @@ -11,7 +12,8 @@ import org.scalatest.matchers.should.Matchers import org.scalatest.{BeforeAndAfterAll, EitherValues, OptionValues} import units.BaseDockerTestSuite.generateWavesGenesisConfig import units.client.contract.HasConsensusLayerDappTxHelpers -import units.docker.Networks +import units.client.engine.model.BlockNumber +import units.docker.{EcContainer, Networks, WavesNodeContainer} import units.eth.Gwei import units.test.TestEnvironment.* import units.test.{CustomMatchers, HasRetry} @@ -39,9 +41,71 @@ trait BaseDockerTestSuite protected lazy val wavesGenesisConfigPath = generateWavesGenesisConfig() - protected def startNodes(): Unit - protected def stopNodes(): Unit - protected def setupNetwork(): Unit + protected lazy val ec1: EcContainer = new EcContainer( + network = network, + number = 1, + ip = Networks.ipForNode(2) // ipForNode(1) is assigned to Ryuk + ) + + protected lazy val waves1: WavesNodeContainer = new WavesNodeContainer( + network = network, + number = 1, + ip = Networks.ipForNode(3), + baseSeed = "devnet-1", + clMinerKeyPair = mkKeyPair("devnet-1", 0), + chainContractAddress = chainContractAddress, + ecEngineApiUrl = s"http://${ec1.hostName}:${EcContainer.EnginePort}", + genesisConfigPath = wavesGenesisConfigPath + ) + + protected def startNodes(): Unit = { + ec1.start() + ec1.logPorts() + + waves1.start() + waves1.waitReady() + waves1.logPorts() + } + + protected def stopNodes(): Unit = { + waves1.stop() + ec1.stop() + } + + protected def setupNetwork(): Unit = { + log.info("Set script") + waves1.api.broadcastAndWait(chainContract.setScript()) + + log.info("Setup chain contract") + val genesisBlock = ec1.engineApi.getBlockByNumber(BlockNumber.Number(0)).explicitGet().getOrElse(failRetry("No EL genesis block")) + waves1.api.broadcastAndWait( + chainContract.setup( + genesisBlock = genesisBlock, + elMinerReward = rewardAmount.amount.longValue(), + daoAddress = None, + daoReward = 0, + invoker = chainContractAccount + ) + ) + log.info(s"Token id: ${waves1.chainContract.token}") + + log.info("EL miner #1 join") + val joinMiner1Result = waves1.api.broadcastAndWait( + chainContract.join( + minerAccount = miner11Account, + elRewardAddress = miner11RewardAddress + ) + ) + + val epoch1Number = joinMiner1Result.height + 1 + log.info(s"Wait for #$epoch1Number epoch") + waves1.api.waitForHeight(epoch1Number) + } + + override protected def step(text: String): Unit = { + super.step(text) + waves1.api.print(text) + } override def beforeAll(): Unit = { BaseDockerTestSuite.init() diff --git a/consensus-client-it/src/test/scala/units/BridgeC2ETestSuite.scala b/consensus-client-it/src/test/scala/units/BridgeC2ETestSuite.scala index 75530325..99976908 100644 --- a/consensus-client-it/src/test/scala/units/BridgeC2ETestSuite.scala +++ b/consensus-client-it/src/test/scala/units/BridgeC2ETestSuite.scala @@ -4,7 +4,7 @@ import com.wavesplatform.transaction.TxHelpers import units.client.engine.model.BlockNumber import units.eth.EthAddress -class BridgeC2ETestSuite extends OneNodeTestSuite { +class BridgeC2ETestSuite extends BaseDockerTestSuite { private val clSender = clRichAccount1 private val elReceiver = elRichAccount1 private val elReceiverAddress = EthAddress.unsafeFrom(elReceiver.getAddress) diff --git a/consensus-client-it/src/test/scala/units/BridgeE2CTestSuite.scala b/consensus-client-it/src/test/scala/units/BridgeE2CTestSuite.scala index 99f47f57..1bc84ebb 100644 --- a/consensus-client-it/src/test/scala/units/BridgeE2CTestSuite.scala +++ b/consensus-client-it/src/test/scala/units/BridgeE2CTestSuite.scala @@ -8,7 +8,7 @@ import org.web3j.protocol.exceptions.TransactionException import org.web3j.utils.Convert import units.el.ElBridgeClient -class BridgeE2CTestSuite extends OneNodeTestSuite { +class BridgeE2CTestSuite extends BaseDockerTestSuite { private val elSender = elRichAccount1 private val clRecipient = clRichAccount1 private val userAmount = 1 diff --git a/consensus-client-it/src/test/scala/units/OneNodeTestSuite.scala b/consensus-client-it/src/test/scala/units/OneNodeTestSuite.scala deleted file mode 100644 index 7f92f732..00000000 --- a/consensus-client-it/src/test/scala/units/OneNodeTestSuite.scala +++ /dev/null @@ -1,73 +0,0 @@ -package units - -import com.wavesplatform.common.utils.EitherExt2 -import units.client.engine.model.BlockNumber -import units.docker.{EcContainer, Networks, WavesNodeContainer} - -trait OneNodeTestSuite extends BaseDockerTestSuite { - protected lazy val ec1: EcContainer = new EcContainer( - network = network, - number = 1, - ip = Networks.ipForNode(2) // ipForNode(1) is assigned to Ryuk - ) - - protected lazy val waves1: WavesNodeContainer = new WavesNodeContainer( - network = network, - number = 1, - ip = Networks.ipForNode(3), - baseSeed = "devnet-1", - clMinerKeyPair = mkKeyPair("devnet-1", 0), - chainContractAddress = chainContractAddress, - ecEngineApiUrl = s"http://${ec1.hostName}:${EcContainer.EnginePort}", - genesisConfigPath = wavesGenesisConfigPath - ) - - override protected def startNodes(): Unit = { - ec1.start() - ec1.logPorts() - - waves1.start() - waves1.waitReady() - waves1.logPorts() - } - - override protected def stopNodes(): Unit = { - waves1.stop() - ec1.stop() - } - - override protected def setupNetwork(): Unit = { - log.info("Set script") - waves1.api.broadcastAndWait(chainContract.setScript()) - - log.info("Setup chain contract") - val genesisBlock = ec1.engineApi.getBlockByNumber(BlockNumber.Number(0)).explicitGet().getOrElse(failRetry("No EL genesis block")) - waves1.api.broadcastAndWait( - chainContract.setup( - genesisBlock = genesisBlock, - elMinerReward = rewardAmount.amount.longValue(), - daoAddress = None, - daoReward = 0, - invoker = chainContractAccount - ) - ) - log.info(s"Token id: ${waves1.chainContract.token}") - - log.info("EL miner #1 join") - val joinMiner1Result = waves1.api.broadcastAndWait( - chainContract.join( - minerAccount = miner11Account, - elRewardAddress = miner11RewardAddress - ) - ) - - val epoch1Number = joinMiner1Result.height + 1 - log.info(s"Wait for #$epoch1Number epoch") - waves1.api.waitForHeight(epoch1Number) - } - - override protected def step(text: String): Unit = { - super.step(text) - waves1.api.print(text) - } -} diff --git a/consensus-client-it/src/test/scala/units/RewardTestSuite.scala b/consensus-client-it/src/test/scala/units/RewardTestSuite.scala index 5374f173..98ba1d5b 100644 --- a/consensus-client-it/src/test/scala/units/RewardTestSuite.scala +++ b/consensus-client-it/src/test/scala/units/RewardTestSuite.scala @@ -3,7 +3,7 @@ package units import com.wavesplatform.common.utils.EitherExt2 import units.client.engine.model.BlockNumber -class RewardTestSuite extends OneNodeTestSuite { +class RewardTestSuite extends BaseDockerTestSuite { "L2-234 The reward for a previous epoch is in the first block withdrawals" in { val epoch1FirstEcBlock = retry { ec1.engineApi.getBlockByNumber(BlockNumber.Number(1)).explicitGet().get diff --git a/consensus-client-it/src/test/scala/units/SyncingTestSuite.scala b/consensus-client-it/src/test/scala/units/SyncingTestSuite.scala index acf79664..01c84f67 100644 --- a/consensus-client-it/src/test/scala/units/SyncingTestSuite.scala +++ b/consensus-client-it/src/test/scala/units/SyncingTestSuite.scala @@ -9,7 +9,7 @@ import org.web3j.utils.Convert import java.math.BigInteger -class SyncingTestSuite extends OneNodeTestSuite { +class SyncingTestSuite extends BaseDockerTestSuite { private val elSender = elRichAccount1 private val amount = Convert.toWei("1", Convert.Unit.ETHER).toBigInteger