Skip to content

Commit

Permalink
v6.0-serialize: all new features move to LanguageSpecificationV6
Browse files Browse the repository at this point in the history
  • Loading branch information
aslesarenko committed May 19, 2024
1 parent cfd6e7b commit 4fb3daa
Show file tree
Hide file tree
Showing 5 changed files with 343 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ trait CrossVersionProps extends AnyPropSpecLike with TestsBase {
System.gc()
}
forEachScriptAndErgoTreeVersion(activatedVersions, ergoTreeVersions) {
VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) {
testFun_Run(testName, testFun)
}
}
}
}
Expand Down
225 changes: 0 additions & 225 deletions sc/shared/src/test/scala/sigma/LanguageSpecificationV5.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,6 @@ class LanguageSpecificationV5 extends LanguageSpecificationBase { suite =>
/// Boolean type operations
///-----------------------------------------------------

property("Boolean methods equivalence") {
val toByte = newFeature((x: Boolean) => x.toByte, "{ (x: Boolean) => x.toByte }")

val cases = Seq(
(true, Success(1.toByte)),
(false, Success(0.toByte))
)

testCases(cases, toByte)
}

property("BinXor(logical XOR) equivalence") {
val binXor = existingFeature((x: (Boolean, Boolean)) => x._1 ^ x._2,
"{ (x: (Boolean, Boolean)) => x._1 ^ x._2 }",
Expand Down Expand Up @@ -950,31 +939,6 @@ class LanguageSpecificationV5 extends LanguageSpecificationBase { suite =>
swapArgs(LE_cases, cost = 1768, newCostDetails = binaryRelationCostDetails(GE, SByte)),
">=", GE.apply)(_ >= _)
}

property("Byte methods equivalence (new features)") {
lazy val toBytes = newFeature((x: Byte) => x.toBytes, "{ (x: Byte) => x.toBytes }")
lazy val toAbs = newFeature((x: Byte) => x.toAbs, "{ (x: Byte) => x.toAbs }")
lazy val compareTo = newFeature(
(x: (Byte, Byte)) => x._1.compareTo(x._2),
"{ (x: (Byte, Byte)) => x._1.compareTo(x._2) }")

lazy val bitOr = newFeature(
{ (x: (Byte, Byte)) => (x._1 | x._2).toByteExact },
"{ (x: (Byte, Byte)) => (x._1 | x._2).toByteExact }")

lazy val bitAnd = newFeature(
{ (x: (Byte, Byte)) => (x._1 & x._2).toByteExact },
"{ (x: (Byte, Byte)) => (x._1 & x._2).toByteExact }")

forAll { x: Byte =>
Seq(toBytes, toAbs).foreach(f => f.checkEquality(x))
}

forAll { x: (Byte, Byte) =>
Seq(compareTo, bitOr, bitAnd).foreach(_.checkEquality(x))
}
}

property("Short methods equivalence") {
SShort.upcast(0.toShort) shouldBe 0.toShort // boundary test case
SShort.downcast(0.toShort) shouldBe 0.toShort // boundary test case
Expand Down Expand Up @@ -1255,29 +1219,6 @@ class LanguageSpecificationV5 extends LanguageSpecificationBase { suite =>
">=", GE.apply)(_ >= _)
}

property("Short methods equivalence (new features)") {
lazy val toBytes = newFeature((x: Short) => x.toBytes, "{ (x: Short) => x.toBytes }")
lazy val toAbs = newFeature((x: Short) => x.toAbs, "{ (x: Short) => x.toAbs }")

lazy val compareTo = newFeature((x: (Short, Short)) => x._1.compareTo(x._2),
"{ (x: (Short, Short)) => x._1.compareTo(x._2) }")

lazy val bitOr = newFeature(
{ (x: (Short, Short)) => (x._1 | x._2).toShortExact },
"{ (x: (Short, Short)) => x._1 | x._2 }")

lazy val bitAnd = newFeature(
{ (x: (Short, Short)) => (x._1 & x._2).toShortExact },
"{ (x: (Short, Short)) => x._1 & x._2 }")

forAll { x: Short =>
Seq(toBytes, toAbs).foreach(_.checkEquality(x))
}
forAll { x: (Short, Short) =>
Seq(compareTo, bitOr, bitAnd).foreach(_.checkEquality(x))
}
}

property("Int methods equivalence") {
SInt.upcast(0) shouldBe 0 // boundary test case
SInt.downcast(0) shouldBe 0 // boundary test case
Expand Down Expand Up @@ -1558,28 +1499,6 @@ class LanguageSpecificationV5 extends LanguageSpecificationBase { suite =>
">=", GE.apply)(_ >= _)
}

property("Int methods equivalence (new features)") {
lazy val toBytes = newFeature((x: Int) => x.toBytes, "{ (x: Int) => x.toBytes }")
lazy val toAbs = newFeature((x: Int) => x.toAbs, "{ (x: Int) => x.toAbs }")
lazy val compareTo = newFeature((x: (Int, Int)) => x._1.compareTo(x._2),
"{ (x: (Int, Int)) => x._1.compareTo(x._2) }")

lazy val bitOr = newFeature(
{ (x: (Int, Int)) => x._1 | x._2 },
"{ (x: (Int, Int)) => x._1 | x._2 }")

lazy val bitAnd = newFeature(
{ (x: (Int, Int)) => x._1 & x._2 },
"{ (x: (Int, Int)) => x._1 & x._2 }")

forAll { x: Int =>
Seq(toBytes, toAbs).foreach(_.checkEquality(x))
}
forAll { x: (Int, Int) =>
Seq(compareTo, bitOr, bitAnd).foreach(_.checkEquality(x))
}
}

property("Long downcast and upcast identity") {
forAll { x: Long =>
SLong.upcast(x) shouldBe x // boundary test case
Expand Down Expand Up @@ -1877,28 +1796,6 @@ class LanguageSpecificationV5 extends LanguageSpecificationBase { suite =>
">=", GE.apply)(_ >= _)
}

property("Long methods equivalence (new features)") {
lazy val toBytes = newFeature((x: Long) => x.toBytes, "{ (x: Long) => x.toBytes }")
lazy val toAbs = newFeature((x: Long) => x.toAbs, "{ (x: Long) => x.toAbs }")
lazy val compareTo = newFeature((x: (Long, Long)) => x._1.compareTo(x._2),
"{ (x: (Long, Long)) => x._1.compareTo(x._2) }")

lazy val bitOr = newFeature(
{ (x: (Long, Long)) => x._1 | x._2 },
"{ (x: (Long, Long)) => x._1 | x._2 }")

lazy val bitAnd = newFeature(
{ (x: (Long, Long)) => x._1 & x._2 },
"{ (x: (Long, Long)) => x._1 & x._2 }")

forAll { x: Long =>
Seq(toBytes, toAbs).foreach(_.checkEquality(x))
}
forAll { x: (Long, Long) =>
Seq(compareTo, bitOr, bitAnd).foreach(_.checkEquality(x))
}
}

property("BigInt methods equivalence") {
verifyCases(
{
Expand Down Expand Up @@ -2157,59 +2054,6 @@ class LanguageSpecificationV5 extends LanguageSpecificationBase { suite =>
">=", GE.apply)(o.gteq(_, _))
}

property("BigInt methods equivalence (new features)") {
// TODO v6.0: the behavior of `upcast` for BigInt is different from all other Numeric types (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/877)
// The `Upcast(bigInt, SBigInt)` node is never produced by ErgoScript compiler, but is still valid ErgoTree.
// It makes sense to fix this inconsistency as part of upcoming forks
assertExceptionThrown(
SBigInt.upcast(CBigInt(new BigInteger("0", 16)).asInstanceOf[AnyVal]),
_.getMessage.contains("Cannot upcast value")
)

// TODO v6.0: the behavior of `downcast` for BigInt is different from all other Numeric types (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/877)
// The `Downcast(bigInt, SBigInt)` node is never produced by ErgoScript compiler, but is still valid ErgoTree.
// It makes sense to fix this inconsistency as part of HF
assertExceptionThrown(
SBigInt.downcast(CBigInt(new BigInteger("0", 16)).asInstanceOf[AnyVal]),
_.getMessage.contains("Cannot downcast value")
)

val toByte = newFeature((x: BigInt) => x.toByte,
"{ (x: BigInt) => x.toByte }",
FuncValue(Vector((1, SBigInt)), Downcast(ValUse(1, SBigInt), SByte)))

val toShort = newFeature((x: BigInt) => x.toShort,
"{ (x: BigInt) => x.toShort }",
FuncValue(Vector((1, SBigInt)), Downcast(ValUse(1, SBigInt), SShort)))

val toInt = newFeature((x: BigInt) => x.toInt,
"{ (x: BigInt) => x.toInt }",
FuncValue(Vector((1, SBigInt)), Downcast(ValUse(1, SBigInt), SInt)))

val toLong = newFeature((x: BigInt) => x.toLong,
"{ (x: BigInt) => x.toLong }",
FuncValue(Vector((1, SBigInt)), Downcast(ValUse(1, SBigInt), SLong)))

lazy val toBytes = newFeature((x: BigInt) => x.toBytes, "{ (x: BigInt) => x.toBytes }")
lazy val toAbs = newFeature((x: BigInt) => x.toAbs, "{ (x: BigInt) => x.toAbs }")

lazy val compareTo = newFeature((x: (BigInt, BigInt)) => x._1.compareTo(x._2),
"{ (x: (BigInt, BigInt)) => x._1.compareTo(x._2) }")

lazy val bitOr = newFeature({ (x: (BigInt, BigInt)) => x._1 | x._2 },
"{ (x: (BigInt, BigInt)) => x._1 | x._2 }")

lazy val bitAnd = newFeature({ (x: (BigInt, BigInt)) => x._1 & x._2 },
"{ (x: (BigInt, BigInt)) => x._1 & x._2 }")

forAll { x: BigInt =>
Seq(toByte, toShort, toInt, toLong, toBytes, toAbs).foreach(_.checkEquality(x))
}
forAll { x: (BigInt, BigInt) =>
Seq(compareTo, bitOr, bitAnd).foreach(_.checkEquality(x))
}
}

/** Executed a series of test cases of NEQ operation verify using two _different_
* data instances `x` and `y`.
* @param cost the expected cost of `verify` (the same for all cases)
Expand Down Expand Up @@ -3944,16 +3788,6 @@ class LanguageSpecificationV5 extends LanguageSpecificationBase { suite =>
)))
}

property("Box properties equivalence (new features)") {
// TODO v6.0: related to https://github.com/ScorexFoundation/sigmastate-interpreter/issues/416
val getReg = newFeature((x: Box) => x.getReg[Int](1).get,
"{ (x: Box) => x.getReg[Int](1).get }")

forAll { box: Box =>
Seq(getReg).foreach(_.checkEquality(box))
}
}

property("Conditional access to registers") {
def boxWithRegisters(regs: AdditionalRegisters): Box = {
SigmaDsl.Box(testBox(20, TrueTree, 0, Seq(), regs))
Expand Down Expand Up @@ -7531,36 +7365,6 @@ class LanguageSpecificationV5 extends LanguageSpecificationBase { suite =>
preGeneratedSamples = Some(samples))
}

// TODO v6.0 (3h): https://github.com/ScorexFoundation/sigmastate-interpreter/issues/479
property("Coll find method equivalence") {
val find = newFeature((x: Coll[Int]) => x.find({ (v: Int) => v > 0 }),
"{ (x: Coll[Int]) => x.find({ (v: Int) => v > 0} ) }")
forAll { x: Coll[Int] =>
find.checkEquality(x)
}
}

// TODO v6.0 (3h): https://github.com/ScorexFoundation/sigmastate-interpreter/issues/418
property("Coll bitwise methods equivalence") {
val shiftRight = newFeature(
{ (x: Coll[Boolean]) =>
if (x.size > 2) x.slice(0, x.size - 2) else Colls.emptyColl[Boolean]
},
"{ (x: Coll[Boolean]) => x >> 2 }")
forAll { x: Array[Boolean] =>
shiftRight.checkEquality(Colls.fromArray(x))
}
}

// TODO v6.0 (3h): https://github.com/ScorexFoundation/sigmastate-interpreter/issues/479
property("Coll diff methods equivalence") {
val diff = newFeature((x: (Coll[Int], Coll[Int])) => x._1.diff(x._2),
"{ (x: (Coll[Int], Coll[Int])) => x._1.diff(x._2) }")
forAll { (x: Coll[Int], y: Coll[Int]) =>
diff.checkEquality((x, y))
}
}

property("Coll fold method equivalence") {
val n = ExactNumeric.IntIsExactNumeric
val costDetails1 = TracedCost(
Expand Down Expand Up @@ -8972,17 +8776,6 @@ class LanguageSpecificationV5 extends LanguageSpecificationBase { suite =>
) ))
}

// TODO v6.0: implement Option.fold (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/479)
property("Option new methods") {
val n = ExactNumeric.LongIsExactNumeric
val fold = newFeature({ (x: Option[Long]) => x.fold(5.toLong)( (v: Long) => n.plus(v, 1) ) },
"{ (x: Option[Long]) => x.fold(5, { (v: Long) => v + 1 }) }")

forAll { x: Option[Long] =>
Seq(fold).map(_.checkEquality(x))
}
}

property("Option fold workaround method") {
val costDetails1 = TracedCost(
traceBase ++ Array(
Expand Down Expand Up @@ -9418,24 +9211,6 @@ class LanguageSpecificationV5 extends LanguageSpecificationBase { suite =>
preGeneratedSamples = Some(Seq()))
}

// TODO v6.0 (3h): implement allZK func https://github.com/ScorexFoundation/sigmastate-interpreter/issues/543
property("allZK equivalence") {
lazy val allZK = newFeature((x: Coll[SigmaProp]) => SigmaDsl.allZK(x),
"{ (x: Coll[SigmaProp]) => allZK(x) }")
forAll { x: Coll[SigmaProp] =>
allZK.checkEquality(x)
}
}

// TODO v6.0 (3h): implement anyZK func https://github.com/ScorexFoundation/sigmastate-interpreter/issues/543
property("anyZK equivalence") {
lazy val anyZK = newFeature((x: Coll[SigmaProp]) => SigmaDsl.anyZK(x),
"{ (x: Coll[SigmaProp]) => anyZK(x) }")
forAll { x: Coll[SigmaProp] =>
anyZK.checkEquality(x)
}
}

property("allOf equivalence") {
def costDetails(i: Int) = TracedCost(traceBase :+ ast.SeqCostItem(CompanionDesc(AND), PerItemCost(JitCost(10), JitCost(5), 32), i))
verifyCases(
Expand Down
Loading

0 comments on commit 4fb3daa

Please sign in to comment.