From b7dcf24d2bec3b6da40d8e0870d23c97eab43bd1 Mon Sep 17 00:00:00 2001 From: ccellado Date: Thu, 7 Mar 2024 15:47:44 +0400 Subject: [PATCH 1/2] Fix ergo-core publishing in build.sbt Add ergo-core testing and publishing snapshot on PR branch push --- .github/workflows/ci.yml | 43 ++++++++++++++++++++++++++++++++++++++++ ergo-core/build.sbt | 3 +++ 2 files changed, 46 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de56162027..2aa3589726 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,6 +57,49 @@ jobs: SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + test_core: + name: Run ergo-core tests and publish a ergo-core snapshot + env: + HAS_SECRETS: ${{ secrets.SONATYPE_PASSWORD != '' }} + strategy: + matrix: + os: [ubuntu-latest] + scala: [2.13.12, 2.12.18, 2.11.12] + java: [adopt@1.8] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout current branch (full) + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup Java and Scala + uses: olafurpg/setup-scala@v10 + with: + java-version: ${{ matrix.java }} + + - name: Cache sbt + uses: actions/cache@v2 + with: + path: | + ~/.sbt + ~/.ivy2/cache + ~/.coursier/cache/v1 + ~/.cache/coursier/v1 + ~/AppData/Local/Coursier/Cache/v1 + ~/Library/Caches/Coursier/v1 + key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }} + + - name: Runs ergo-core tests + run: sbt ++${{ matrix.scala }} ergoCore/test + + - name: Publish a wallet snapshot ${{ github.ref }} + if: env.HAS_SECRETS == 'true' + run: sbt ++${{ matrix.scala }} ergoCore/publish + env: + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + test_node: name: Run node tests strategy: diff --git a/ergo-core/build.sbt b/ergo-core/build.sbt index 33edb4387e..9b965392b7 100644 --- a/ergo-core/build.sbt +++ b/ergo-core/build.sbt @@ -12,6 +12,9 @@ val deps212 = Seq( "io.circe" %% "circe-generic" % "0.13.0", "io.circe" %% "circe-parser" % "0.13.0") +publishMavenStyle := true +publishArtifact in Test := false + libraryDependencies ++= Seq() ++ (if (scalaVersion.value == scala211) deps211 else deps212) From 11ec4f3d002f7ec814f355458e260c625b3ce21a Mon Sep 17 00:00:00 2001 From: ccellado Date: Thu, 7 Mar 2024 17:40:17 +0400 Subject: [PATCH 2/2] Fix ergo-core multiversion tests --- .../avltree/batch/benchmark/OOMTest.scala | 7 +++++ .../settings/ModifierIdReader.scala | 7 +++-- .../settings/PowSchemeReaders.scala | 27 ++++++++++--------- .../mining/AutolykosPowSchemeSpec.scala | 1 + .../DifficultyAdjustmentSpecification.scala | 2 +- .../mempool/ErgoTransactionSpec.scala | 17 +++++++----- .../JsonSerializationCoreSpec.scala | 1 + .../settings/VotingSpecification.scala | 1 + .../ErgoCoreTransactionGenerators.scala | 4 +-- 9 files changed, 42 insertions(+), 25 deletions(-) diff --git a/avldb/src/test/scala/scorex/crypto/authds/avltree/batch/benchmark/OOMTest.scala b/avldb/src/test/scala/scorex/crypto/authds/avltree/batch/benchmark/OOMTest.scala index 03b34284e2..3547549ee2 100644 --- a/avldb/src/test/scala/scorex/crypto/authds/avltree/batch/benchmark/OOMTest.scala +++ b/avldb/src/test/scala/scorex/crypto/authds/avltree/batch/benchmark/OOMTest.scala @@ -11,9 +11,16 @@ import scorex.crypto.hash.{Blake2b256, Digest32} import scorex.db.{ByteArrayWrapper, LDBVersionedStore} import scala.collection.immutable.SortedMap +import scala.math.Ordering.Implicits._ object OOMTest extends App { + implicit val ordering: Ordering[Array[Byte]] = + new Ordering[Array[Byte]] { + override def compare(o1: Array[Byte], o2: Array[Byte]): Int = + implicitly[Ordering[Seq[Int]]].compare(o1.toSeq.map(_ & 0xFF), o2.toSeq.map(_ & 0xFF)) + } + type Box = (ADKey, ADValue) type HF = Blake2b256.type diff --git a/ergo-core/src/main/scala/org/ergoplatform/settings/ModifierIdReader.scala b/ergo-core/src/main/scala/org/ergoplatform/settings/ModifierIdReader.scala index 7f1ae6f394..adaf296f39 100644 --- a/ergo-core/src/main/scala/org/ergoplatform/settings/ModifierIdReader.scala +++ b/ergo-core/src/main/scala/org/ergoplatform/settings/ModifierIdReader.scala @@ -1,12 +1,15 @@ package org.ergoplatform.settings +import com.typesafe.config.Config import net.ceedubs.ficus.readers.ValueReader import scorex.util.ModifierId trait ModifierIdReader { - implicit val modifierIdReader: ValueReader[ModifierId] = { (cfg, path) => - ModifierId @@ cfg.getString(path) + implicit val modifierIdReader: ValueReader[ModifierId] = new ValueReader[ModifierId] { + override def read(cfg: Config, path: String): ModifierId = { + ModifierId @@ cfg.getString(path) + } } } diff --git a/ergo-core/src/main/scala/org/ergoplatform/settings/PowSchemeReaders.scala b/ergo-core/src/main/scala/org/ergoplatform/settings/PowSchemeReaders.scala index 57ca4b167b..e9a19082bf 100644 --- a/ergo-core/src/main/scala/org/ergoplatform/settings/PowSchemeReaders.scala +++ b/ergo-core/src/main/scala/org/ergoplatform/settings/PowSchemeReaders.scala @@ -1,25 +1,26 @@ package org.ergoplatform.settings -import com.typesafe.config.ConfigException +import com.typesafe.config.{Config, ConfigException} import net.ceedubs.ficus.Ficus._ import net.ceedubs.ficus.readers.ValueReader import org.ergoplatform.mining._ trait PowSchemeReaders { - implicit val powSchemeReader: ValueReader[AutolykosPowScheme] = { (cfg, path) => - val schemeNameKey = s"$path.powType" - val schemeName = cfg.getString(schemeNameKey) - val n = cfg.as[Int](s"$path.n") - val k = cfg.as[Int](s"$path.k") - if (schemeName == "autolykos") { - new AutolykosPowScheme(k, n) - } else if (schemeName == "fake") { - new DefaultFakePowScheme(k, n) - } else { - throw new ConfigException.BadValue(schemeNameKey, schemeName) + implicit val powSchemeReader: ValueReader[AutolykosPowScheme] = new ValueReader[AutolykosPowScheme] { + override def read(cfg: Config, path: String): AutolykosPowScheme = { + val schemeNameKey = s"$path.powType" + val schemeName = cfg.getString(schemeNameKey) + val n = cfg.as[Int](s"$path.n") + val k = cfg.as[Int](s"$path.k") + if (schemeName == "autolykos") { + new AutolykosPowScheme(k, n) + } else if (schemeName == "fake") { + new DefaultFakePowScheme(k, n) + } else { + throw new ConfigException.BadValue(schemeNameKey, schemeName) + } } } - } diff --git a/ergo-core/src/test/scala/org/ergoplatform/mining/AutolykosPowSchemeSpec.scala b/ergo-core/src/test/scala/org/ergoplatform/mining/AutolykosPowSchemeSpec.scala index 98a8c7f60c..5c0d1e24c4 100644 --- a/ergo-core/src/test/scala/org/ergoplatform/mining/AutolykosPowSchemeSpec.scala +++ b/ergo-core/src/test/scala/org/ergoplatform/mining/AutolykosPowSchemeSpec.scala @@ -7,6 +7,7 @@ import org.ergoplatform.utils.ErgoCorePropertyTest import org.scalacheck.Gen import scorex.crypto.hash.Blake2b256 import scorex.util.encode.Base16 +import cats.syntax.either._ class AutolykosPowSchemeSpec extends ErgoCorePropertyTest { import org.ergoplatform.utils.ErgoCoreTestConstants._ diff --git a/ergo-core/src/test/scala/org/ergoplatform/mining/difficulty/DifficultyAdjustmentSpecification.scala b/ergo-core/src/test/scala/org/ergoplatform/mining/difficulty/DifficultyAdjustmentSpecification.scala index 1ba457230a..1d8605f911 100644 --- a/ergo-core/src/test/scala/org/ergoplatform/mining/difficulty/DifficultyAdjustmentSpecification.scala +++ b/ergo-core/src/test/scala/org/ergoplatform/mining/difficulty/DifficultyAdjustmentSpecification.scala @@ -13,7 +13,7 @@ class DifficultyAdjustmentSpecification extends ErgoCorePropertyTest { import org.ergoplatform.utils.generators.ErgoCoreGenerators._ val precision = 0.0001 - val minDiff: BigInt = (BigDecimal(1) / precision).toBigInt() + val minDiff: BigInt = (BigDecimal(1) / precision).toBigInt val Epoch = 123 val UseLastEpochs = 4 diff --git a/ergo-core/src/test/scala/org/ergoplatform/modifiers/mempool/ErgoTransactionSpec.scala b/ergo-core/src/test/scala/org/ergoplatform/modifiers/mempool/ErgoTransactionSpec.scala index 556e1fe111..003e2b0372 100644 --- a/ergo-core/src/test/scala/org/ergoplatform/modifiers/mempool/ErgoTransactionSpec.scala +++ b/ergo-core/src/test/scala/org/ergoplatform/modifiers/mempool/ErgoTransactionSpec.scala @@ -14,6 +14,9 @@ import sigmastate.crypto.CryptoConstants import sigmastate.crypto.DLogProtocol.ProveDlog import sigmastate.eval._ import sigmastate.interpreter.{ContextExtension, ProverResult} +import cats.syntax.either._ +import sigmastate.utils.Helpers._ + class ErgoTransactionSpec extends ErgoCorePropertyTest { import org.ergoplatform.utils.ErgoCoreTestConstants._ @@ -37,12 +40,13 @@ class ErgoTransactionSpec extends ErgoCorePropertyTest { CryptoConstants.dlogGroup.ctx.decodePoint(point) ) }.get + val inputs: IndexedSeq[Input] = IndexedSeq( new Input(ADKey @@ Base16.decode("c95c2ccf55e03cac6659f71ca4df832d28e2375569cec178dcb17f3e2e5f7742").get, new ProverResult(Base16.decode("b4a04b4201da0578be3dac11067b567a73831f35b024a2e623c1f8da230407f63bab62c62ed9b93808b106b5a7e8b1751fa656f4c5de4674").get, ContextExtension.empty)), new Input(ADKey @@ Base16.decode("ca796a4fc9c0d746a69702a77bd78b1a80a5ef5bf5713bbd95d93a4f23b27ead").get, - new ProverResult(Base16.decode("5aea4d78a234c35accacdf8996b0af5b51e26fee29ea5c05468f23707d31c0df39400127391cd57a70eb856710db48bb9833606e0bf90340").get, ContextExtension.empty)), - ) + new ProverResult(Base16.decode("5aea4d78a234c35accacdf8996b0af5b51e26fee29ea5c05468f23707d31c0df39400127391cd57a70eb856710db48bb9833606e0bf90340").get, ContextExtension.empty))) + val outputCandidates: IndexedSeq[ErgoBoxCandidate] = IndexedSeq( new ErgoBoxCandidate(1000000000L, minerPk, height, Colls.emptyColl, Map()), new ErgoBoxCandidate(1000000L, chainSettings.monetary.feeProposition, height, Colls.emptyColl, Map()) @@ -64,16 +68,15 @@ class ErgoTransactionSpec extends ErgoCorePropertyTest { R4 -> ByteConstant(1), R5 -> SigmaPropConstant(minerPk), R7 -> LongArrayConstant(Array(1L, 2L, 1234123L)), - R8 -> ByteArrayConstant(Base16.decode("123456123456123456123456123456123456123456123456123456123456123456").get), - )), - new ErgoBoxCandidate(1000000000L, minerPk, height, Colls.emptyColl, Map()) - ) + R8 -> ByteArrayConstant(Base16.decode("123456123456123456123456123456123456123456123456123456123456123456").get)) + ), + new ErgoBoxCandidate(1000000000L, minerPk, height, Colls.emptyColl, Map())) val tx2 = ErgoTransaction(inputs: IndexedSeq[Input], outputCandidates2: IndexedSeq[ErgoBoxCandidate]) Base16.encode(tx2.bytes) shouldBe "02c95c2ccf55e03cac6659f71ca4df832d28e2375569cec178dcb17f3e2e5f774238b4a04b4201da0578be3dac11067b567a73831f35b024a2e623c1f8da230407f63bab62c62ed9b93808b106b5a7e8b1751fa656f4c5de467400ca796a4fc9c0d746a69702a77bd78b1a80a5ef5bf5713bbd95d93a4f23b27ead385aea4d78a234c35accacdf8996b0af5b51e26fee29ea5c05468f23707d31c0df39400127391cd57a70eb856710db48bb9833606e0bf90340000000028094ebdc030008cd0326df75ea615c18acc6bb4b517ac82795872f388d5d180aac90eaa84de750b942e8070005020108cd0326df75ea615c18acc6bb4b517ac82795872f388d5d180aac90eaa84de750b94204141103020496d396010e211234561234561234561234561234561234561234561234561234561234561234568094ebdc030008cd0326df75ea615c18acc6bb4b517ac82795872f388d5d180aac90eaa84de750b942e8070000" check(Base16.encode(tx2.bytes), "02c95c2ccf55e03cac6659f71ca4df832d28e2375569cec178dcb17f3e2e5f77420000ca796a4fc9c0d746a69702a77bd78b1a80a5ef5bf5713bbd95d93a4f23b27ead00000000028094ebdc030008cd0326df75ea615c18acc6bb4b517ac82795872f388d5d180aac90eaa84de750b942e8070005020108cd0326df75ea615c18acc6bb4b517ac82795872f388d5d180aac90eaa84de750b94204141103020496d396010e211234561234561234561234561234561234561234561234561234561234561234568094ebdc030008cd0326df75ea615c18acc6bb4b517ac82795872f388d5d180aac90eaa84de750b942e8070000", "{\"id\":\"bd04a93f67fda77d89afc38cd8237f142ad5a349405929fd1f7b7f24c4ea2e80\",\"inputs\":[{\"boxId\":\"c95c2ccf55e03cac6659f71ca4df832d28e2375569cec178dcb17f3e2e5f7742\",\"spendingProof\":{\"proofBytes\":\"b4a04b4201da0578be3dac11067b567a73831f35b024a2e623c1f8da230407f63bab62c62ed9b93808b106b5a7e8b1751fa656f4c5de4674\",\"extension\":{}}},{\"boxId\":\"ca796a4fc9c0d746a69702a77bd78b1a80a5ef5bf5713bbd95d93a4f23b27ead\",\"spendingProof\":{\"proofBytes\":\"5aea4d78a234c35accacdf8996b0af5b51e26fee29ea5c05468f23707d31c0df39400127391cd57a70eb856710db48bb9833606e0bf90340\",\"extension\":{}}}],\"dataInputs\":[],\"outputs\":[{\"boxId\":\"1baffa8e5ffce634a8e70530023c16a5c177d2b5ab756ae89a8dce2a23ba433c\",\"value\":1000000000,\"ergoTree\":\"0008cd0326df75ea615c18acc6bb4b517ac82795872f388d5d180aac90eaa84de750b942\",\"assets\":[],\"creationHeight\":1000,\"additionalRegisters\":{\"R4\":\"0201\",\"R5\":\"08cd0326df75ea615c18acc6bb4b517ac82795872f388d5d180aac90eaa84de750b942\",\"R6\":\"0414\",\"R7\":\"1103020496d39601\",\"R8\":\"0e21123456123456123456123456123456123456123456123456123456123456123456\"},\"transactionId\":\"bd04a93f67fda77d89afc38cd8237f142ad5a349405929fd1f7b7f24c4ea2e80\",\"index\":0},{\"boxId\":\"33eff46f94067b32073d5f81984607be559108f58bc3f53906a1e8db7cf0f708\",\"value\":1000000000,\"ergoTree\":\"0008cd0326df75ea615c18acc6bb4b517ac82795872f388d5d180aac90eaa84de750b942\",\"assets\":[],\"creationHeight\":1000,\"additionalRegisters\":{},\"transactionId\":\"bd04a93f67fda77d89afc38cd8237f142ad5a349405929fd1f7b7f24c4ea2e80\",\"index\":1}],\"size\":356}") -// + // tx with 2 inputs, 1 data input, 3 outputs with tokens 0326df75ea615c18acc6bb4b517ac82795872f388d5d180aac90eaa84de750b942 check("02e76bf387ab2e63ba8f4e23267bc88265b5fee4950030199e2e2c214334251c6400002e9798d7eb0cd867f6dc29872f80de64c04cef10a99a58d007ef7855f0acbdb9000001f97d1dc4626de22db836270fe1aa004b99970791e4557de8f486f6d433b81195026df03fffc9042bf0edb0d0d36d7a675239b83a9080d39716b9aa0a64cccb9963e76bf387ab2e63ba8f4e23267bc88265b5fee4950030199e2e2c214334251c6403da92a8b8e3ad770008cd02db0ce4d301d6dc0b7a5fbe749588ef4ef68f2c94435020a3c31764ffd36a2176000200daa4eb6b01aec8d1ff0100da92a8b8e3ad770008cd02db0ce4d301d6dc0b7a5fbe749588ef4ef68f2c94435020a3c31764ffd36a2176000200daa4eb6b01aec8d1ff0100fa979af8988ce7010008cd02db0ce4d301d6dc0b7a5fbe749588ef4ef68f2c94435020a3c31764ffd36a2176000000", "02e76bf387ab2e63ba8f4e23267bc88265b5fee4950030199e2e2c214334251c6400002e9798d7eb0cd867f6dc29872f80de64c04cef10a99a58d007ef7855f0acbdb9000001f97d1dc4626de22db836270fe1aa004b99970791e4557de8f486f6d433b81195026df03fffc9042bf0edb0d0d36d7a675239b83a9080d39716b9aa0a64cccb9963e76bf387ab2e63ba8f4e23267bc88265b5fee4950030199e2e2c214334251c6403da92a8b8e3ad770008cd02db0ce4d301d6dc0b7a5fbe749588ef4ef68f2c94435020a3c31764ffd36a2176000200daa4eb6b01aec8d1ff0100da92a8b8e3ad770008cd02db0ce4d301d6dc0b7a5fbe749588ef4ef68f2c94435020a3c31764ffd36a2176000200daa4eb6b01aec8d1ff0100fa979af8988ce7010008cd02db0ce4d301d6dc0b7a5fbe749588ef4ef68f2c94435020a3c31764ffd36a2176000000", diff --git a/ergo-core/src/test/scala/org/ergoplatform/serialization/JsonSerializationCoreSpec.scala b/ergo-core/src/test/scala/org/ergoplatform/serialization/JsonSerializationCoreSpec.scala index 23aca5306a..7a765c0fd0 100644 --- a/ergo-core/src/test/scala/org/ergoplatform/serialization/JsonSerializationCoreSpec.scala +++ b/ergo-core/src/test/scala/org/ergoplatform/serialization/JsonSerializationCoreSpec.scala @@ -14,6 +14,7 @@ import org.ergoplatform.wallet.Constants.ScanId import org.ergoplatform.wallet.boxes.TrackedBox import sigmastate.SType import sigmastate.Values.{ErgoTree, EvaluatedValue} +import cats.syntax.either._ class JsonSerializationCoreSpec extends ErgoCorePropertyTest with ApiCodecs { diff --git a/ergo-core/src/test/scala/org/ergoplatform/settings/VotingSpecification.scala b/ergo-core/src/test/scala/org/ergoplatform/settings/VotingSpecification.scala index 07832ebbf4..72f4292c3a 100644 --- a/ergo-core/src/test/scala/org/ergoplatform/settings/VotingSpecification.scala +++ b/ergo-core/src/test/scala/org/ergoplatform/settings/VotingSpecification.scala @@ -7,6 +7,7 @@ import org.ergoplatform.settings.ValidationRules.rulesSpec import org.ergoplatform.utils.ErgoCorePropertyTest import org.ergoplatform.validation.{DisabledRule, ReplacedRule, ValidationRules => VR} import scorex.crypto.authds.ADDigest +import sigmastate.utils.Helpers._ import scala.util.Try diff --git a/ergo-core/src/test/scala/org/ergoplatform/utils/generators/ErgoCoreTransactionGenerators.scala b/ergo-core/src/test/scala/org/ergoplatform/utils/generators/ErgoCoreTransactionGenerators.scala index 5aec3dfd3f..40a748d7c4 100644 --- a/ergo-core/src/test/scala/org/ergoplatform/utils/generators/ErgoCoreTransactionGenerators.scala +++ b/ergo-core/src/test/scala/org/ergoplatform/utils/generators/ErgoCoreTransactionGenerators.scala @@ -85,8 +85,8 @@ object ErgoCoreTransactionGenerators extends ScorexLogging { to: IndexedSeq[ErgoBoxCandidate] <- reallySmallInt.flatMap(i => Gen.listOfN(i + 1, ergoBoxCandidateGen(prop)).map(_.toIndexedSeq)) } yield ErgoTransaction(from, dataInputs, to) - def disperseTokens(inputsCount: Int, tokensCount: Byte): Gen[IndexedSeq[Seq[(TokenId, Long)]]] = { - val tokensDistribution = mutable.IndexedSeq.fill(inputsCount)(Seq[(TokenId, Long)]()) + def disperseTokens(inputsCount: Int, tokensCount: Byte): Gen[mutable.IndexedSeq[Seq[(TokenId, Long)]]] = { + val tokensDistribution: mutable.IndexedSeq[Seq[(TokenId, Time)]] = mutable.IndexedSeq.fill(inputsCount)(Seq[(TokenId, Long)]()) (1 to tokensCount).foreach { i => val (id, amt) = Blake2b256(s"$i" + Random.nextString(5)).toTokenId -> (Random.nextInt(Int.MaxValue).toLong + 100) val idx = i % tokensDistribution.size