diff --git a/.github/workflows/check-pr.yml b/.github/workflows/check-pr.yml index 37c0c742..997acacd 100644 --- a/.github/workflows/check-pr.yml +++ b/.github/workflows/check-pr.yml @@ -27,11 +27,7 @@ jobs: - uses: sbt/setup-sbt@v1 - name: Run tests run: | - sbt --batch "\ - test; \ - consensus-client-it/Test/updateGenesis; \ - docker; \ - consensus-client-it/test" + sbt --batch "test;docker;consensus-client-it/test" - name: Archive logs uses: actions/upload-artifact@v4 if: always() diff --git a/consensus-client-it/build.sbt b/consensus-client-it/build.sbt index 5686a57d..03df1e85 100644 --- a/consensus-client-it/build.sbt +++ b/consensus-client-it/build.sbt @@ -12,7 +12,6 @@ libraryDependencies ++= Seq( ).map(_ % Test) val logsDirectory = taskKey[File]("The directory for logs") // Evaluates every time, so it recreates the logs directory -val updateGenesis = taskKey[Unit]("Updates the genesis.json file in local-network") inConfig(Test)( Seq( @@ -57,13 +56,6 @@ inConfig(Test)( ) ) } - }, - updateGenesis := Def.taskDyn { - val mainClass = "com.wavesplatform.GenesisBlockGenerator" - val wavesNodeConfigsDir = baseDirectory.value.getParentFile / "local-network" / "configs" / "wavesnode" - val templateFile = wavesNodeConfigsDir / "genesis-template.conf" - val outputFile = wavesNodeConfigsDir / "genesis.conf" - (Test / runMain).toTask(s" $mainClass $templateFile $outputFile") - }.value + } ) ) diff --git a/consensus-client-it/src/test/scala/units/BaseItTestSuite.scala b/consensus-client-it/src/test/scala/units/BaseItTestSuite.scala index 00f47acf..deba508a 100644 --- a/consensus-client-it/src/test/scala/units/BaseItTestSuite.scala +++ b/consensus-client-it/src/test/scala/units/BaseItTestSuite.scala @@ -1,22 +1,26 @@ package units import com.google.common.primitives.{Bytes, Ints} +import com.typesafe.config.ConfigFactory import com.wavesplatform.account.{AddressScheme, KeyPair, SeedKeyPair} import com.wavesplatform.api.HasRetry import com.wavesplatform.common.state.ByteStr -import com.wavesplatform.crypto import com.wavesplatform.utils.ScorexLogging -import monix.execution.atomic.AtomicBoolean +import com.wavesplatform.{GenesisBlockGenerator, crypto} import org.scalatest.freespec.AnyFreeSpec import org.scalatest.matchers.should.Matchers import org.scalatest.{BeforeAndAfterAll, EitherValues, OptionValues} import org.web3j.crypto.Credentials import units.client.contract.HasConsensusLayerDappTxHelpers +import units.docker.BaseContainer.ConfigsDir import units.docker.Networks import units.eth.{EthAddress, Gwei} import units.test.CustomMatchers +import java.io.PrintStream import java.nio.charset.StandardCharsets +import java.nio.file.Files +import scala.concurrent.duration.DurationInt trait BaseItTestSuite extends AnyFreeSpec @@ -72,11 +76,35 @@ trait BaseItTestSuite } object BaseItTestSuite { - private val initialized = AtomicBoolean(false) + private var initialized = false - def init(): Unit = - if (initialized.compareAndSet(expect = false, update = true)) + def init(): Unit = synchronized { + if (!initialized) { AddressScheme.current = new AddressScheme { override val chainId: Byte = 'D'.toByte } + + val templateFile = ConfigsDir.resolve("wavesnode/genesis-template.conf").toAbsolutePath + val genesisFile = ConfigsDir.resolve("wavesnode/genesis.conf").toAbsolutePath + + val origConfig = ConfigFactory.parseFile(templateFile.toFile) + val gap = 1.minute // To force node mining at start, otherwise it schedules + val overrides = ConfigFactory.parseString( + s"""genesis-generator { + | timestamp = ${System.currentTimeMillis() - gap.toMillis} + |}""".stripMargin + ) + + val genesisSettings = GenesisBlockGenerator.parseSettings(overrides.withFallback(origConfig)) + + val origOut = System.out + System.setOut(new PrintStream({ (_: Int) => })) + val config = GenesisBlockGenerator.createConfig(genesisSettings) + System.setOut(origOut) + + Files.writeString(genesisFile, config) + + initialized = true + } + } } diff --git a/consensus-client-it/src/test/scala/units/RewardTestSuite.scala b/consensus-client-it/src/test/scala/units/RewardTestSuite.scala index 11b75c88..29b41e49 100644 --- a/consensus-client-it/src/test/scala/units/RewardTestSuite.scala +++ b/consensus-client-it/src/test/scala/units/RewardTestSuite.scala @@ -20,7 +20,6 @@ class RewardTestSuite extends OneNodeTestSuite { val epoch1Number = epoch1FirstContractBlock.epoch val epoch2Number = epoch1Number + 1 - log.info(s"Wait for next epoch #$epoch2Number") waves1.api.waitForHeight(epoch2Number) log.info(s"Wait for epoch #$epoch2Number data on chain contract") diff --git a/consensus-client-it/src/test/scala/units/docker/BaseContainer.scala b/consensus-client-it/src/test/scala/units/docker/BaseContainer.scala index 098c49db..6f9a75e4 100644 --- a/consensus-client-it/src/test/scala/units/docker/BaseContainer.scala +++ b/consensus-client-it/src/test/scala/units/docker/BaseContainer.scala @@ -27,6 +27,7 @@ abstract class BaseContainer(val hostName: String) { } object BaseContainer { - val ConfigsDir: Path = Path.of(System.getProperty("cc.it.configs.dir")) - val DefaultLogsDir: Path = Path.of(System.getProperty("cc.it.logs.dir")) + val ConfigsDir: Path = Path.of(System.getProperty("cc.it.configs.dir")) + val DefaultLogsDir: Path = Path.of(System.getProperty("cc.it.logs.dir")) + val WavesDockerImage: String = System.getProperty("cc.it.docker.image") } diff --git a/consensus-client-it/src/test/scala/units/docker/WavesNodeContainer.scala b/consensus-client-it/src/test/scala/units/docker/WavesNodeContainer.scala index 35eab4a8..1cf6479c 100644 --- a/consensus-client-it/src/test/scala/units/docker/WavesNodeContainer.scala +++ b/consensus-client-it/src/test/scala/units/docker/WavesNodeContainer.scala @@ -9,7 +9,7 @@ import org.testcontainers.containers.Network.NetworkImpl import org.testcontainers.utility.DockerImageName import sttp.client3.{HttpClientSyncBackend, UriContext} import units.client.HttpChainContractClient -import units.docker.BaseContainer.{ConfigsDir, DefaultLogsDir} +import units.docker.BaseContainer.* import units.docker.WavesNodeContainer.ApiPort import java.io.File @@ -27,7 +27,7 @@ class WavesNodeContainer( private val logFile = new File(s"$DefaultLogsDir/waves-$number.log") Files.touch(logFile) - protected override val container = new GenericContainer(DockerImageName.parse(System.getProperty("cc.it.docker.image"))) + protected override val container = new GenericContainer(DockerImageName.parse(WavesDockerImage)) .withNetwork(network) .withExposedPorts(ApiPort) .withEnv(