diff --git a/.github/workflows/check-pr.yml b/.github/workflows/check-pr.yml index a30f84e1..38b335b0 100644 --- a/.github/workflows/check-pr.yml +++ b/.github/workflows/check-pr.yml @@ -24,15 +24,19 @@ jobs: java-version: '17' cache: 'sbt' - uses: foundry-rs/foundry-toolchain@v1 + with: + # Pinned: "stable" follows the latest release, so a new forge version could change CI unannounced + version: v1.10.0 - uses: sbt/setup-sbt@508b753e53cb6095967669e0911487d2b9bc9f41 # v1.1.22 - name: Run tests - run: sbt -Dcc.it.max-parallel-suites=2 -Dlogback.test.level=OFF --batch "scalafmtCheck;test;docker;consensus-client-it/test" + # --server: under sbt 2 the default thin client does not pass -D options to the build. testFull: sbt 2's test is incremental + run: sbt --server -Dcc.it.max-parallel-suites=2 -Dlogback.test.level=OFF --batch "scalafmtCheck;testFull;docker;consensus-client-it/testFull" env: RUN_ID: ${{ github.head_ref }}-${{ github.run_number }}-${{ github.run_attempt }} - uses: scacap/action-surefire-report@5609ce4db72c09db044803b344a8968fd1f315da if: always() with: - report_paths: '**/target/test-reports/*.xml' + report_paths: 'target/out/**/test-reports/*.xml' create_check: false check_name: 'Check PR' - name: Archive logs @@ -40,7 +44,7 @@ jobs: if: always() with: name: test-logs_${{ github.run_id }}_${{ github.run_attempt }} - path: consensus-client-it/target/test-logs + path: target/out/jvm/*/consensus-client-it/test-logs if-no-files-found: warn retention-days: 14 @@ -58,9 +62,12 @@ jobs: java-version: '17' cache: 'sbt' - uses: foundry-rs/foundry-toolchain@v1 + with: + # Pinned: "stable" follows the latest release, so a new forge version could change CI unannounced + version: v1.10.0 - uses: sbt/setup-sbt@508b753e53cb6095967669e0911487d2b9bc9f41 # v1.1.22 - run: | - sbt --batch docker + sbt --server --batch docker cd local-network ./restart.sh env: diff --git a/README.md b/README.md index df444eab..2d10f688 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,4 @@ ```bash sbt "consensus-client-it/test" ``` - 3. See logs in `consensus-client-it/target/test-logs`. + 3. See logs in `target/out/jvm/scala-/consensus-client-it/test-logs`. diff --git a/build.sbt b/build.sbt index 5e6e3924..7bb0fb31 100644 --- a/build.sbt +++ b/build.sbt @@ -1,17 +1,12 @@ import com.github.sbt.git.SbtGit.GitKeys.gitCurrentBranch +import sbtcompat.PluginCompat.{FileRef, parseArtifactStrAttribute, parseModuleIDStrAttribute} import scala.sys.process.{Process, ProcessLogger} -enablePlugins(UniversalDeployPlugin, GitVersioning, VersionObject) - -git.useGitDescribe := true -git.baseVersion := "1.4.2" -git.uncommittedSignifier := Some("DIRTY") - inScope(Global)( Seq( onChangedBuildSource := ReloadOnSourceChanges, - scalaVersion := "3.8.4", + scalaVersion := "3.10.1", organization := "network.units", organizationName := "Units Network", resolvers ++= Seq(Resolver.sonatypeCentralSnapshots, Resolver.mavenLocal), @@ -31,51 +26,10 @@ inScope(Global)( ) ) -name := "consensus-client" -maintainer := "Units Network Team" - -def nettyModule(module: String): ModuleID = "io.netty" % s"netty-$module" % "4.2.17.Final" +// Keep these in sync with the versions Waves Node pins in its project/Dependencies.scala +def nettyModule(module: String): ModuleID = "io.netty" % s"netty-$module" % "4.2.20.Final" -// These overrides are needed so that there are no different versions of the same component on the classpath when the extension is installed -dependencyOverrides ++= Seq( - "org.playframework" %% "play-json" % "3.0.6", - "com.squareup.okhttp3" % "okhttp" % "4.12.0", - "com.squareup.okhttp3" % "logging-interceptor" % "4.12.0", - "com.squareup.okio" % "okio" % "3.6.0", - "com.squareup.okio" % "okio-jvm" % "3.17.0", - "org.apache.httpcomponents" % "httpclient" % "4.5.14", - "org.reactivestreams" % "reactive-streams" % "1.0.4", - "org.jetbrains.kotlin" % "kotlin-stdlib" % "2.1.21", - "org.jetbrains.kotlin" % "kotlin-stdlib-jdk7" % "1.8.21", - "org.jetbrains.kotlin" % "kotlin-stdlib-jdk8" % "1.8.21", - "org.bouncycastle" % "bcprov-jdk18on" % "1.85.2", - nettyModule("codec-http2"), - nettyModule("codec-http"), - nettyModule("handler-proxy"), - nettyModule("codec-socks"), - nettyModule("transport-native-unix-common"), - nettyModule("resolver-dns") -) - -libraryDependencies ++= { - val node = "1.6.4" - val sttpVersion = "3.11.0" - Seq( - "com.wavesplatform" % "node-testkit" % node % Test, - "com.wavesplatform" % "node" % node % Provided, - "com.softwaremill.sttp.client3" %% "core" % sttpVersion, - "com.softwaremill.sttp.client3" %% "play-json" % sttpVersion, - "com.github.jwt-scala" %% "jwt-play-json" % "11.0.4", - ("org.web3j" % "core" % "4.13.0").excludeAll( - ExclusionRule("org.slf4j", "slf4j-api"), - ExclusionRule("org.bouncycastle", "bcprov-jdk15on"), - ExclusionRule("software.amazon.awssdk", "kms"), - ExclusionRule("com.github.jnr", "jnr-unixsocket") - ) - ) -} - -Compile / packageDoc / publishArtifact := false +def jacksonModule(group: String, module: String): ModuleID = s"com.fasterxml.jackson.$group" % s"jackson-$module" % "2.21.8" def makeJarName( org: String, @@ -91,64 +45,117 @@ def makeJarName( artifactClassifier.filterNot(_.isEmpty).map("-" + _).getOrElse("") + ".jar" -def getJarFullFilename(dep: Attributed[File]): String = { +def getJarFullFilename(dep: Attributed[FileRef]): String = { val filename: Option[String] = for { - module <- dep.metadata.get(AttributeKey[ModuleID]("moduleID")) - artifact <- dep.metadata.get(AttributeKey[Artifact]("artifact")) + module <- dep.metadata.get(moduleIDStr).map(parseModuleIDStrAttribute) + artifact <- dep.metadata.get(artifactStr).map(parseArtifactStrAttribute) } yield makeJarName(module.organization, module.name, module.revision, artifact.name, artifact.classifier) - filename.getOrElse(dep.data.getName) + filename.getOrElse(dep.data.name) } -def universalDepMappings(deps: Seq[Attributed[File]]): Seq[(File, String)] = +def universalDepMappings(deps: Seq[Attributed[FileRef]]): Seq[(FileRef, String)] = for { dep <- deps } yield dep.data -> ("lib/" + getJarFullFilename(dep)) -Universal / mappings += { - val jar = (Compile / packageBin).value - val id = projectID.value - val art = (Compile / packageBin / artifact).value - jar -> ("lib/" + makeJarName(id.organization, id.name, id.revision, art.name, art.classifier)) -} -Universal / mappings ++= universalDepMappings((Runtime / dependencyClasspath).value.filterNot { p => - p.get(AttributeKey[ModuleID]("moduleID")).exists { m => - m.organization == "org.scala-lang" || - m.organization.startsWith("com.fasterxml.jackson") - } -}) - lazy val buildTarballsForDocker = taskKey[Unit]("Package consensus-client tarball and copy it to docker/target") -buildTarballsForDocker := { - IO.copyFile( - (Universal / packageZipTarball).value, - baseDirectory.value / "docker" / "target" / "consensus-client.tgz" - ) -} - -val docker = taskKey[Unit]("Build docker image for integration tests") -docker := { - val log = streams.value.log - - val cwd = baseDirectory.value / "docker" - - val cmd = Seq("docker", "build", "-t", "consensus-client:local", "-t", s"consensus-client:${gitCurrentBranch.value}", ".") - log.info(s"Running `${cmd.mkString(" ")}` from $cwd") - - val processLogger = ProcessLogger( - (out: String) => log.info(out), - (err: String) => log.info(err) // Redirect STDERR to info - ) - - val exit = Process(cmd, cwd).!(processLogger) - if (exit != 0) sys.error(s"Docker build failed with exit code $exit") -} - -docker := docker.dependsOn(LocalRootProject / buildTarballsForDocker).value +lazy val docker = taskKey[Unit]("Build docker image for integration tests") +// sbt 2 applies bare settings in build.sbt to every subproject, so the root project's own settings live here lazy val `consensus-client` = project .in(file(".")) + .enablePlugins(UniversalDeployPlugin, GitVersioning, VersionObject) .settings( - Test / resources += baseDirectory.value / "contracts" / "waves" / "src" / "main.ride" + git.useGitDescribe := true, + git.baseVersion := "1.4.4", + git.uncommittedSignifier := Some("DIRTY"), + name := "consensus-client", + maintainer := "Units Network Team", + // These overrides are needed so that there are no different versions of the same component on the classpath when the extension is installed + dependencyOverrides ++= Seq( + "org.playframework" %% "play-json" % "3.0.6", + "com.squareup.okhttp3" % "okhttp" % "4.12.0", + "com.squareup.okhttp3" % "logging-interceptor" % "4.12.0", + "com.squareup.okio" % "okio" % "3.6.0", + "com.squareup.okio" % "okio-jvm" % "3.18.2", + "org.apache.httpcomponents" % "httpclient" % "4.5.14", + "org.reactivestreams" % "reactive-streams" % "1.0.4", + "org.jetbrains.kotlin" % "kotlin-stdlib" % "2.1.21", + "org.jetbrains.kotlin" % "kotlin-stdlib-jdk7" % "1.8.21", + "org.jetbrains.kotlin" % "kotlin-stdlib-jdk8" % "1.8.21", + "org.bouncycastle" % "bcprov-jdk18on" % "1.87", + "com.google.code.gson" % "gson" % "2.15.0", + "org.slf4j" % "slf4j-api" % "2.0.20", + "org.msgpack" % "msgpack-core" % "0.9.12", + jacksonModule("core", "core"), + jacksonModule("core", "databind"), + jacksonModule("datatype", "datatype-jdk8"), + jacksonModule("datatype", "datatype-jsr310"), + "tools.jackson.core" % "jackson-core" % "3.3.0", + "tools.jackson.core" % "jackson-databind" % "3.3.0", + nettyModule("codec-http2"), + nettyModule("codec-http"), + nettyModule("handler-proxy"), + nettyModule("codec-socks"), + nettyModule("transport-native-unix-common"), + nettyModule("resolver-dns") + ), + libraryDependencies ++= { + val node = "1.6.6" + val sttpVersion = "3.11.0" + Seq( + "com.wavesplatform" % "node-testkit" % node % Test, + "com.wavesplatform" % "node" % node % Provided, + "com.softwaremill.sttp.client3" %% "core" % sttpVersion, + "com.softwaremill.sttp.client3" %% "play-json" % sttpVersion, + "com.github.jwt-scala" %% "jwt-play-json" % "11.0.4", + ("org.web3j" % "core" % "4.13.0").excludeAll( + ExclusionRule("org.slf4j", "slf4j-api"), + ExclusionRule("org.bouncycastle", "bcprov-jdk15on"), + ExclusionRule("software.amazon.awssdk", "kms"), + ExclusionRule("com.github.jnr", "jnr-unixsocket") + ) + ) + }, + Compile / packageDoc / publishArtifact := false, + Test / unmanagedResourceDirectories += baseDirectory.value / "contracts" / "waves" / "src", // main.ride + Universal / mappings += { + val jar = (Compile / packageBin).value + val id = projectID.value + val art = (Compile / packageBin / artifact).value + jar -> ("lib/" + makeJarName(id.organization, id.name, id.revision, art.name, art.classifier)) + }, + Universal / mappings ++= universalDepMappings((Runtime / dependencyClasspath).value.filterNot { p => + p.get(moduleIDStr).map(parseModuleIDStrAttribute).exists { m => + m.organization == "org.scala-lang" || + m.organization.startsWith("com.fasterxml.jackson") + } + }), + // Uncached: docker/target is outside sbt's tracked outputs, so a cache hit would skip the copy + buildTarballsForDocker := Def.uncached { + IO.copyFile( + fileConverter.value.toPath((Universal / packageZipTarball).value).toFile, + baseDirectory.value / "docker" / "target" / "consensus-client.tgz" + ) + }, + // Uncached: building the image is a side effect sbt does not track + docker := Def.uncached { + val log = streams.value.log + + val cwd = baseDirectory.value / "docker" + + val cmd = Seq("docker", "build", "-t", "consensus-client:local", "-t", s"consensus-client:${gitCurrentBranch.value}", ".") + log.info(s"Running `${cmd.mkString(" ")}` from $cwd") + + val processLogger = ProcessLogger( + (out: String) => log.info(out), + (err: String) => log.info(err) // Redirect STDERR to info + ) + + val exit = Process(cmd, cwd).!(processLogger) + if (exit != 0) sys.error(s"Docker build failed with exit code $exit") + }, + docker := docker.dependsOn(buildTarballsForDocker).value ) lazy val `consensus-client-it` = project diff --git a/consensus-client-it/build.sbt b/consensus-client-it/build.sbt index 080450fc..ab336d2e 100644 --- a/consensus-client-it/build.sbt +++ b/consensus-client-it/build.sbt @@ -24,7 +24,7 @@ Test / sourceGenerators += Def.task { val contractSources = baseDirectory.value / ".." / "contracts" / "eth" val compiledDir = contractSources / "target" // --silent to bypass garbage "Counting objects" git logs - s"forge build --silent --config-path ${contractSources / "foundry.toml"} --contracts ${contractSources / "src"}" ! + s"forge build --silent --config-path ${contractSources / "foundry.toml"} --contracts ${contractSources / "src"}".! generateSourcesFromContracts.foreach { contract => val json = Json.parse(new FileInputStream(compiledDir / s"$contract.sol" / s"$contract.json")) @@ -81,7 +81,7 @@ Global / concurrentRestrictions := Seq( val LogbackTestLevel = "logback.test.level" inConfig(Test)( Seq( - logsDirectory := { + logsDirectory := Def.uncached { val runId: String = Option(System.getenv("RUN_ID")).getOrElse(DateTimeFormatter.ofPattern("MM-dd--HH_mm_ss").format(LocalDateTime.now)) val r = target.value / "test-logs" / runId r.mkdirs() @@ -97,7 +97,7 @@ inConfig(Test)( testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-fFWD", ((Test / logsDirectory).value / "summary.log").toString), fork := true, testForkedParallel := true, - testGrouping := { + testGrouping := Def.uncached { val javaHomeVal = (test / javaHome).value val baseLogDirVal = (Test / logsDirectory).value val envVarsVal = (Test / envVars).value diff --git a/consensus-client-it/src/test/scala/units/BaseDockerTestSuite.scala b/consensus-client-it/src/test/scala/units/BaseDockerTestSuite.scala index 71bbcd31..a1d93f74 100644 --- a/consensus-client-it/src/test/scala/units/BaseDockerTestSuite.scala +++ b/consensus-client-it/src/test/scala/units/BaseDockerTestSuite.scala @@ -22,7 +22,8 @@ import units.eth.{EthAddress, Gwei} import units.test.{CustomMatchers, IntegrationTestEventually, TestEnvironment} import java.nio.channels.FileChannel -import java.nio.file.{Path, StandardOpenOption} +import java.nio.file.{Files, Path, StandardOpenOption} +import scala.annotation.tailrec import scala.sys.process.{Process, ProcessLogger} trait BaseDockerTestSuite @@ -120,11 +121,30 @@ trait BaseDockerTestSuite protected def deploySolidityContracts(): Unit = { step("Deploy contracts on EL") val exitCode = BaseDockerTestSuite.withForgeLock { - Process( - s"forge script -vvvvv scripts/IT.s.sol:IT --private-key $elRichAccount1PrivateKey --fork-url http://localhost:${ec1.rpcPort} --broadcast", + // Every suite deploys to a fresh chain, so a previous broadcast for this chain id is never worth resuming. Newer forge versions refuse to + // --broadcast over an unfinished one, which makes a single failed deployment fail every suite after it. + BaseDockerTestSuite.deleteRecursively(TestEnvironment.ContractsDir.toPath.resolve(s"broadcast/IT.s.sol/${EcContainer.ChainId}")) + + def runForge(mode: String): Int = Process( + s"forge script -vvvvv scripts/IT.s.sol:IT --private-key $elRichAccount1PrivateKey --fork-url http://localhost:${ec1.rpcPort} $mode", TestEnvironment.ContractsDir, "CHAIN_ID" -> EcContainer.ChainId.toString ).!(ProcessLogger(out => log.info(out), err => log.error(err))) + + // op-geth answers eth_getTransactionReceipt with "transaction indexing is in progress" until it indexes a new block, and forge gives up + // after a few retries within milliseconds. The transactions are already sent by then, so --resume picks up the same broadcast and polls + // their receipts again, keeping the contract addresses the tests expect. + @tailrec def loop(mode: String, resumesLeft: Int): Int = { + val r = runForge(mode) + if (r == 0 || resumesLeft == 0) r + else { + log.warn(s"forge script exited with $r, resuming ($resumesLeft attempts left)") + Thread.sleep(2000) + loop("--resume", resumesLeft - 1) + } + } + + loop("--broadcast", resumesLeft = 3) } withClue("forge script exit code:")(exitCode shouldBe 0) @@ -173,6 +193,13 @@ object BaseDockerTestSuite { } finally channel.close() } + def deleteRecursively(dir: Path): Unit = + if (Files.exists(dir)) { + val walk = Files.walk(dir) + try walk.sorted(java.util.Comparator.reverseOrder()).forEach(p => Files.delete(p)) + finally walk.close() + } + def init(): Unit = if (initialized.compareAndSet(expect = false, update = true)) AddressScheme.current = new AddressScheme { diff --git a/docker/Dockerfile b/docker/Dockerfile index e261780e..25e91e9e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -ARG baseImage=ghcr.io/wavesplatform/waves:1.6.5 +ARG baseImage=ghcr.io/wavesplatform/waves:1.6.6 FROM $baseImage RUN --mount=type=bind,source=target,target=/tmp/ \ tar zxvf /tmp/consensus-client.tgz -C $WAVES_INSTALL_PATH --strip-components=1 diff --git a/local-network/consensus_client-image-build.sh b/local-network/consensus_client-image-build.sh index 2d0e24ac..8f23ba5a 100755 --- a/local-network/consensus_client-image-build.sh +++ b/local-network/consensus_client-image-build.sh @@ -5,4 +5,4 @@ set -eu DIR="$(cd "$(dirname "$0")" && pwd)" cd "${DIR}/.." || exit -sbt -J-Xmx4G -J-Xss4m -Dfile.encoding=UTF-8 -Dsbt.supershell=false "docker" +sbt --server -J-Xmx4G -J-Xss4m -Dfile.encoding=UTF-8 -Dsbt.supershell=false "docker" diff --git a/project/build.properties b/project/build.properties index c605beba..f1fd7cdf 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.12.3 +sbt.version=2.1.0 diff --git a/project/plugins.sbt b/project/plugins.sbt index 0469efdd..2a2ae1fb 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -5,12 +5,13 @@ resolvers ++= Seq( libraryDependencies ++= Seq( "org.web3j" % "codegen" % "4.9.8", - "com.typesafe.play" %% "play-json" % "2.10.8", + "org.playframework" %% "play-json" % "3.0.6", "com.spotify" % "docker-client" % "8.16.0" ) Seq( - "com.github.sbt" % "sbt-native-packager" % "1.10.0", - "com.github.sbt" % "sbt-ci-release" % "1.5.12", - "org.scalameta" % "sbt-scalafmt" % "2.5.4" + "com.github.sbt" % "sbt-git" % "3.0.0", + "com.github.sbt" % "sbt-native-packager" % "1.13.0", + "org.scalameta" % "sbt-scalafmt" % "2.6.2", + "com.github.sbt" % "sbt2-compat" % "0.2.0" ).map(addSbtPlugin)