Skip to content

Commit

Permalink
SigmaTyperTest fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Oct 31, 2024
1 parent dde7f6e commit a18967c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ class DataSerializerSpecification extends SerializationSpecification {
implicit val tAny = sigma.AnyType

val withVersion = if (tpe == SHeader || tpe == SUnsignedBigInt) {
Some(VersionContext.V6SoftForkVersion)
None // Some(VersionContext.V6SoftForkVersion)
} else {
None
}

forAll { xs: Array[T#WrappedType] =>
roundtrip[SCollection[T]](xs.toColl, SCollection(tpe), withVersion)
roundtrip[SType](xs.toColl.map(x => (x, x)).asWrappedType, SCollection(STuple(tpe, tpe)), withVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sigma.serialization.generators

import org.scalacheck.{Arbitrary, Gen}
import org.scalacheck.Arbitrary.arbString
import sigma.VersionContext
import sigma.ast._

trait TypeGenerators {
Expand All @@ -22,8 +23,13 @@ trait TypeGenerators {
implicit val primTypeGen: Gen[SPrimType] =
Gen.oneOf[SPrimType](SBoolean, SByte, SShort, SInt, SLong, SBigInt, SUnsignedBigInt, SGroupElement, SSigmaProp, SUnit)
implicit val arbPrimType: Arbitrary[SPrimType] = Arbitrary(primTypeGen)
implicit val predefTypeGen: Gen[SPredefType] =
Gen.oneOf[SPredefType](SBoolean, SByte, SShort, SInt, SLong, SBigInt, SUnsignedBigInt, SGroupElement, SSigmaProp, SUnit, SBox, SAvlTree, SHeader)
implicit val predefTypeGen: Gen[SPredefType] = {
if(VersionContext.current.isV6SoftForkActivated){
Gen.oneOf[SPredefType](SBoolean, SByte, SShort, SInt, SLong, SBigInt, SUnsignedBigInt, SGroupElement, SSigmaProp, SUnit, SBox, SAvlTree, SHeader)
} else {
Gen.oneOf[SPredefType](SBoolean, SByte, SShort, SInt, SLong, SBigInt, SGroupElement, SSigmaProp, SUnit, SBox, SAvlTree)
}
}
implicit val arbPredefType: Arbitrary[SPredefType] = Arbitrary(predefTypeGen)

implicit def genToArbitrary[T: Gen]: Arbitrary[T] = Arbitrary(implicitly[Gen[T]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,20 @@ class DataJsonEncoderSpecification extends SerializationSpecification {
implicit val tT = Evaluation.stypeToRType(tpe)
implicit val tagT = tT.classTag

val withVersion = if (tpe == SHeader || tpe == SUnsignedBigInt) {
Some(VersionContext.V6SoftForkVersion)
} else {
None
}

forAll { xs: Array[T#WrappedType] =>
roundtrip[SCollection[T]](xs.toColl, SCollection(tpe), withVersion)
roundtrip[SType](xs.toColl.map(x => (x, x)).asWrappedType, SCollection(STuple(tpe, tpe)), withVersion)
roundtrip[SCollection[T]](xs.toColl, SCollection(tpe))
roundtrip[SType](xs.toColl.map(x => (x, x)).asWrappedType, SCollection(STuple(tpe, tpe)))

val nested = xs.toColl.map(x => Colls.fromItems[T#WrappedType](x, x))
roundtrip[SCollection[SCollection[T]]](nested, SCollection(SCollection(tpe)), withVersion)
roundtrip[SCollection[SCollection[T]]](nested, SCollection(SCollection(tpe)))

roundtrip[SType](
xs.toColl.map { x =>
val arr = Colls.fromItems[T#WrappedType](x, x)
(arr, arr)
}.asWrappedType,
SCollection(STuple(SCollection(tpe), SCollection(tpe))),
withVersion
SCollection(STuple(SCollection(tpe), SCollection(tpe)))
)
}
}
Expand All @@ -74,17 +68,11 @@ class DataJsonEncoderSpecification extends SerializationSpecification {
@nowarn implicit val tag : ClassTag[T#WrappedType] = tT.classTag
@nowarn implicit val tAny : RType[Any] = sigma.AnyType

val withVersion = if (tpe == SHeader) {
Some(VersionContext.V6SoftForkVersion)
} else {
None
}

forAll { in: (T#WrappedType, T#WrappedType) =>
val (x,y) = (in._1, in._2)
roundtrip[SType]((x, y).asWrappedType, STuple(tpe, tpe), withVersion)
roundtrip[SType](((x, y), (x, y)).asWrappedType, STuple(STuple(tpe, tpe), STuple(tpe, tpe)), withVersion)
roundtrip[SType](((x, y), ((x, y), (x, y))).asWrappedType, STuple(STuple(tpe, tpe), STuple(STuple(tpe, tpe), STuple(tpe, tpe))), withVersion)
roundtrip[SType]((x, y).asWrappedType, STuple(tpe, tpe))
roundtrip[SType](((x, y), (x, y)).asWrappedType, STuple(STuple(tpe, tpe), STuple(tpe, tpe)))
roundtrip[SType](((x, y), ((x, y), (x, y))).asWrappedType, STuple(STuple(tpe, tpe), STuple(STuple(tpe, tpe), STuple(tpe, tpe))))
}
}

Expand Down

0 comments on commit a18967c

Please sign in to comment.