Skip to content

Commit

Permalink
versioning and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed May 17, 2024
1 parent 12a958c commit 4f2fb23
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class CoreDataSerializer {
i += 1
}

case SOption(elemType) =>
case SOption(elemType) if VersionContext.current.isV6SoftForkActivated =>
val o = v.asInstanceOf[Option[elemType.WrappedType]]
w.putOption(o){case (w, v) =>
serialize(v, elemType, w)
Expand Down Expand Up @@ -124,7 +124,7 @@ class CoreDataSerializer {
}.toArray[Any]
val coll = Colls.fromArray(arr)(sigma.AnyType)
Evaluation.toDslTuple(coll, tuple)
case tOption: SOption[_] =>
case tOption: SOption[_] if VersionContext.current.isV6SoftForkActivated =>
r.getOption[tOption.ElemWrappedType] {
deserialize(tOption.elemType, r).asInstanceOf[tOption.ElemWrappedType]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.scalacheck.Arbitrary._
import sigma.data.{DataValueComparer, OptionType, RType, SigmaBoolean, TupleColl}
import sigma.ast.SCollection.SByteArray
import sigmastate.eval._
import sigma.{AvlTree, Colls, Evaluation}
import sigma.{AvlTree, Colls, Evaluation, VersionContext}
import sigma.ast.SType.AnyOps
import sigma.ast._
import org.scalacheck.Gen
Expand Down Expand Up @@ -95,13 +95,24 @@ class DataSerializerSpecification extends SerializationSpecification {
def testOption[T <: SType](tpe: T) = {
implicit val wWrapped: Gen[T#WrappedType] = wrappedTypeGen(tpe)
val tT = Evaluation.stypeToRType(tpe)
forAll { in: T#WrappedType =>
roundtrip[SType](Some(in).asWrappedType, SOption(tpe))
roundtrip[SOption[T]](None, SOption(tpe))
roundtrip[SOption[T]](Some(in), SOption(tpe))
roundtrip[SOption[SCollection[T]]](Some(Colls.fromItems(in)(tT)), SOption(SCollectionType(tpe)))
roundtrip[SCollection[SOption[T]]](Colls.fromItems(Option(in), None.asInstanceOf[Option[T#WrappedType]])(OptionType(tT)), SCollectionType(SOption(tpe)))
roundtrip[SOption[SOption[T]]](Some(Some(in)), SOption(SOption(tpe)))

an[Exception] should be thrownBy (
VersionContext.withVersions((VersionContext.V6SoftForkVersion - 1).toByte, 1) {
forAll { in: T#WrappedType =>
roundtrip[SType](Some(in).asWrappedType, SOption(tpe))
roundtrip[SOption[SCollection[T]]](Some(Colls.fromItems(in)(tT)), SOption(SCollectionType(tpe)))
}
})

VersionContext.withVersions(VersionContext.V6SoftForkVersion, 1) {
forAll { in: T#WrappedType =>
roundtrip[SType](Some(in).asWrappedType, SOption(tpe))
roundtrip[SOption[T]](None, SOption(tpe))
roundtrip[SOption[T]](Some(in), SOption(tpe))
roundtrip[SOption[SCollection[T]]](Some(Colls.fromItems(in)(tT)), SOption(SCollectionType(tpe)))
roundtrip[SCollection[SOption[T]]](Colls.fromItems(Option(in), None.asInstanceOf[Option[T#WrappedType]])(OptionType(tT)), SCollectionType(SOption(tpe)))
roundtrip[SOption[SOption[T]]](Some(Some(in)), SOption(SOption(tpe)))
}
}
}

Expand Down

0 comments on commit 4f2fb23

Please sign in to comment.