Skip to content

Commit

Permalink
Merge pull request #2135 from ccellado/improve-ci
Browse files Browse the repository at this point in the history
Fix ergo-core publishing in build.sbt
  • Loading branch information
kushti authored Mar 9, 2024
2 parents bd9db19 + 11ec4f3 commit 26f7271
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 25 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: [[email protected]]
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions ergo-core/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}

}
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand All @@ -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())
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 26f7271

Please sign in to comment.