Skip to content

Commit 59d8ca5

Browse files
authored
Store block delay on chain contract (#73)
1 parent 5fd807c commit 59d8ca5

File tree

58 files changed

+538
-488
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+538
-488
lines changed

.github/workflows/check-pr.yml

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ jobs:
1717
env:
1818
JAVA_OPTS: -Dfile.encoding=UTF-8
1919
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
20-
SBT_IT_TEST_THREADS: 2
21-
services:
22-
docker:
23-
image: docker:latest
24-
options: --privileged # Required for Docker-in-Docker
25-
volumes:
26-
- /var/run/docker.sock:/var/run/docker.sock
27-
ports:
28-
- 2375:2375
2920
steps:
3021
- uses: actions/checkout@v4
3122
- uses: actions/setup-java@v4
@@ -34,26 +25,9 @@ jobs:
3425
java-version: '11'
3526
cache: 'sbt'
3627
- uses: foundry-rs/foundry-toolchain@v1
37-
- name: Cache solc
38-
id: cache-solc
39-
uses: actions/cache@v4
40-
with:
41-
path: /home/runner/.solc
42-
key: solc-v0.8.29
43-
restore-keys: solc-
44-
- name: Get solc
45-
if: ${{ steps.cache-solc.outputs.cache-hit != 'true' }}
46-
run: |
47-
mkdir -p /home/runner/.solc/v0.8.29
48-
wget https://binaries.soliditylang.org/linux-amd64/solc-linux-amd64-v0.8.29+commit.ab55807c -O /home/runner/.solc/v0.8.29/solc-static-linux
49-
echo "/home/runner/.solc" >> $GITHUB_PATH
50-
ln -sf /home/runner/.solc/v0.8.29/solc-static-linux /home/runner/.solc/solc
51-
which solc || echo "Solc not found in PATH"
5228
- uses: sbt/setup-sbt@v1
5329
- name: Run tests
54-
run: |
55-
forge --version
56-
sbt --no-colors --color=never --batch "scalafmtCheck;test;docker;consensus-client-it/test"
30+
run: sbt -Dcc.it.max-parallel-suites=2 -Dlogback.test.level=OFF --batch "scalafmtCheck;test;docker;consensus-client-it/test"
5731
env:
5832
RUN_ID: ${{ github.head_ref }}-${{ github.run_number }}-${{ github.run_attempt }}
5933
- uses: scacap/action-surefire-report@5609ce4db72c09db044803b344a8968fd1f315da
@@ -70,3 +44,25 @@ jobs:
7044
path: consensus-client-it/target/test-logs
7145
if-no-files-found: warn
7246
retention-days: 14
47+
48+
local-network:
49+
name: Run Local Network tests
50+
timeout-minutes: 10
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v4
54+
with:
55+
submodules: recursive
56+
- uses: actions/setup-java@v4
57+
with:
58+
distribution: 'temurin'
59+
java-version: '11'
60+
cache: 'sbt'
61+
- uses: foundry-rs/foundry-toolchain@v1
62+
- uses: sbt/setup-sbt@v1
63+
- run: |
64+
sbt --batch docker
65+
cd local-network
66+
./restart.sh
67+
env:
68+
COMPOSE_PROFILES: tests

.github/workflows/publish-docker-image.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
id-token: write
2626
steps:
2727
- uses: actions/checkout@v4
28+
- uses: proudust/gh-describe@70f72d4f6304ea053cf5a3d71c36211d5acc0c73
29+
id: ghd
2830
- uses: actions/setup-java@v4
2931
with:
3032
distribution: 'temurin'
@@ -38,8 +40,9 @@ jobs:
3840
echo type=sha
3941
echo EOF
4042
} >> "$GITHUB_OUTPUT"
43+
echo "cc-version=$(echo ${{ steps.ghd.outputs.describe }} | cut -c 2-)" >> "$GITHUB_OUTPUT"
4144
id: tag-list
42-
- run: sbt --batch buildTarballsForDocker
45+
- run: sbt -Dproject.version=${{ steps.tag-list.outputs.cc-version }} --batch buildTarballsForDocker
4346
- uses: docker/login-action@v3
4447
with:
4548
registry: ghcr.io

.sbtopts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
-mem 2048
1+
--mem 2048

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git.uncommittedSignifier := Some("DIRTY")
99
inScope(Global)(
1010
Seq(
1111
onChangedBuildSource := ReloadOnSourceChanges,
12-
scalaVersion := "3.7.3",
12+
scalaVersion := "3.7.4",
1313
organization := "network.units",
1414
organizationName := "Units Network",
1515
resolvers ++= Seq(Resolver.sonatypeCentralSnapshots, Resolver.mavenLocal),

consensus-client-it/build.sbt

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import com.github.sbt.git.SbtGit.git.gitCurrentBranch
2+
import com.spotify.docker.client.DefaultDockerClient
23
import org.web3j.codegen.SolidityFunctionWrapperGenerator
34
import org.web3j.tx.Contract
45
import play.api.libs.json.Json
@@ -8,11 +9,13 @@ import java.io.FileInputStream
89
import java.time.LocalDateTime
910
import java.time.format.DateTimeFormatter
1011
import scala.sys.process.*
12+
import scala.sys.props
13+
import scala.util.control.NonFatal
1114

1215
description := "Consensus client integration tests"
1316

1417
libraryDependencies ++= Seq(
15-
"org.testcontainers" % "testcontainers" % "1.20.4",
18+
"org.testcontainers" % "testcontainers" % "2.0.1",
1619
"org.web3j" % "core" % "4.9.8"
1720
).map(_ % Test)
1821

@@ -57,11 +60,29 @@ Test / sourceGenerators += Def.task {
5760

5861
val logsDirectory = taskKey[File]("The directory for logs") // Task to evaluate and recreate the logs directory every time
5962

60-
Global / concurrentRestrictions := {
61-
val threadNumber = Option(System.getenv("SBT_IT_TEST_THREADS")).fold(1)(_.toInt)
62-
Seq(Tags.limit(Tags.ForkedTestGroup, threadNumber))
63-
}
63+
Global / concurrentRestrictions := Seq(
64+
Tags.limit(
65+
Tags.ForkedTestGroup,
66+
Option(Integer.getInteger("cc.it.max-parallel-suites"))
67+
.getOrElse[Integer] {
68+
try {
69+
val docker = DefaultDockerClient.fromEnv().build()
70+
try {
71+
val dockerCpu: Int = docker.info().cpus()
72+
sLog.value.info(s"Docker CPU count: $dockerCpu")
73+
dockerCpu * 2
74+
} finally docker.close()
75+
} catch {
76+
case NonFatal(_) =>
77+
sLog.value.warn(s"Could not connect to Docker, is the daemon running?")
78+
sLog.value.info(s"System CPU count: ${EvaluateTask.SystemProcessors}")
79+
EvaluateTask.SystemProcessors
80+
}
81+
}
82+
)
83+
)
6484

85+
val LogbackTestLevel = "logback.test.level"
6586
inConfig(Test)(
6687
Seq(
6788
logsDirectory := {
@@ -74,7 +95,8 @@ inConfig(Test)(
7495
s"-Dlogback.configurationFile=${(Test / resourceDirectory).value}/logback-test.xml", // Fixes a logback blaming for multiple configs
7596
s"-Dcc.it.configs.dir=${baseDirectory.value.getParent}/local-network/configs",
7697
s"-Dcc.it.docker.image=consensus-client:${gitCurrentBranch.value}",
77-
s"-Dcc.it.contracts.dir=${baseDirectory.value / ".." / "contracts" / "eth"}"
98+
s"-Dcc.it.contracts.dir=${baseDirectory.value / ".." / "contracts" / "eth"}",
99+
s"-D$LogbackTestLevel=${props.getOrElse(LogbackTestLevel, "TRACE")}"
78100
),
79101
testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-fFWD", ((Test / logsDirectory).value / "summary.log").toString),
80102
fork := true,

consensus-client-it/src/test/resources/logback-test.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
88
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
9-
<level>DEBUG</level>
9+
<level>${logback.test.level:-DEBUG}</level>
1010
</filter>
1111
<encoder>
1212
<pattern>${pattern}</pattern>

consensus-client-it/src/test/scala/com/wavesplatform/api/NodeHttpApi.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class NodeHttpApi(apiUri: Uri, backend: SttpBackend[Identity, ?], apiKeyValue: S
2626
extends IntegrationTestEventually
2727
with Matchers
2828
with ScorexLogging {
29-
def blockHeader(atHeight: Int)(implicit loggingOptions: LoggingOptions = LoggingOptions()): Option[BlockHeaderResponse] = {
29+
def blockHeader(atHeight: Height)(implicit loggingOptions: LoggingOptions = LoggingOptions()): Option[BlockHeaderResponse] = {
3030
if (loggingOptions.logRequest) log.debug(s"${loggingOptions.prefix} blockHeader($atHeight)")
3131
basicRequest
3232
.get(uri"$apiUri/blocks/headers/at/$atHeight")
@@ -45,7 +45,7 @@ class NodeHttpApi(apiUri: Uri, backend: SttpBackend[Identity, ?], apiKeyValue: S
4545
}
4646
}
4747

48-
def waitForHeight(atLeast: Int)(implicit loggingOptions: LoggingOptions = LoggingOptions()): Height = {
48+
def waitForHeight(atLeast: Height)(implicit loggingOptions: LoggingOptions = LoggingOptions()): Height = {
4949
if (loggingOptions.logCall) log.debug(s"${loggingOptions.prefix} waitForHeight($atLeast)")
5050
val subsequentLoggingOptions = loggingOptions.copy(logCall = false, logResult = false, logRequest = false)
5151
val currHeight = height()(using subsequentLoggingOptions)
@@ -258,7 +258,8 @@ object NodeHttpApi {
258258

259259
case class HeightResponse(height: Height)
260260
object HeightResponse {
261-
implicit val heightResponseFormat: OFormat[HeightResponse] = Json.format[HeightResponse]
261+
given Reads[Height] = Reads.IntReads.map(Height.apply)
262+
given OFormat[HeightResponse] = Json.format[HeightResponse]
262263
}
263264

264265
case class BroadcastResponse(id: String)
@@ -268,7 +269,8 @@ object NodeHttpApi {
268269

269270
case class TransactionInfoResponse(height: Height, applicationStatus: String)
270271
object TransactionInfoResponse {
271-
implicit val transactionInfoResponseFormat: OFormat[TransactionInfoResponse] = Json.format[TransactionInfoResponse]
272+
given Reads[Height] = Reads.IntReads.map(Height.apply)
273+
given OFormat[TransactionInfoResponse] = Json.format[TransactionInfoResponse]
272274
}
273275

274276
case class BalanceResponse(balance: Long)

consensus-client-it/src/test/scala/units/AssetRegistryTestSuite.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package units
22

3+
import com.wavesplatform.state.Height
4+
35
class AssetRegistryTestSuite extends BaseDockerTestSuite {
46
private val clRecipient = clRichAccount1
57
private val elSender = elRichAccount1
68

79
private val userAmount = 1
810
private val elAmount = UnitsConvert.toAtomic(userAmount, 18)
911

10-
private var activationEpoch = 0
12+
private var activationEpoch = Height(0)
1113

1214
"WAVES and issued asset are not registered before activation" in {
1315
standardBridge.isRegistered(TErc20Address, ignoreExceptions = true) shouldBe false

consensus-client-it/src/test/scala/units/BaseDockerTestSuite.scala

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ trait BaseDockerTestSuite
4646

4747
protected lazy val wavesGenesisConfigPath = generateWavesGenesisConfig()
4848

49-
private implicit val httpClientBackend: SttpBackend[Identity, Any] = new LoggingBackend(HttpClientSyncBackend())
49+
protected implicit val httpClientBackend: SttpBackend[Identity, Any] = new LoggingBackend(HttpClientSyncBackend())
5050

5151
/*
5252
* ipForNode(1) -> Ryuk
@@ -94,13 +94,7 @@ trait BaseDockerTestSuite
9494
step("Setup chain contract")
9595
val genesisBlock = ec1.engineApi.getBlockByNumber(BlockNumber.Number(0)).explicitGet().getOrElse(fail("No EL genesis block"))
9696
waves1.api.broadcastAndWait(
97-
ChainContract.setup(
98-
genesisBlock = genesisBlock,
99-
elMinerReward = rewardAmount.amount.longValue(),
100-
daoAddress = None,
101-
daoReward = 0,
102-
invoker = chainContractAccount
103-
)
97+
ChainContract.setup(genesisBlock, rewardAmount.amount.longValue(), None, 0, 2, invoker = chainContractAccount)
10498
)
10599
log.info(s"Native token id: ${chainContract.nativeTokenId}")
106100

consensus-client-it/src/test/scala/units/C2ENativeTokenTransfersViaDepositsTestSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class C2ENativeTokenTransfersViaDepositsTestSuite extends BaseDockerTestSuite {
5757
waves1.api.broadcastAndWait(
5858
TxHelpers.dataEntry(
5959
chainContractAccount,
60-
IntegerDataEntry("strictC2ETransfersActivationEpoch", activationEpoch)
60+
IntegerDataEntry("strictC2ETransfersActivationEpoch", activationEpoch.toInt)
6161
)
6262
)
6363

0 commit comments

Comments
 (0)