Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .github/workflows/check-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,27 @@ 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
uses: actions/upload-artifact@v4
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

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-<version>/consensus-client-it/test-logs`.
199 changes: 103 additions & 96 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -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),
Expand All @@ -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,
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions consensus-client-it/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down
33 changes: 30 additions & 3 deletions consensus-client-it/src/test/scala/units/BaseDockerTestSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion local-network/consensus_client-image-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.12.3
sbt.version=2.1.0
Loading
Loading