Skip to content

Commit

Permalink
v5.0-unit-register-test: added test for Unit registers
Browse files Browse the repository at this point in the history
  • Loading branch information
aslesarenko committed Jul 5, 2022
1 parent 85336ec commit 4f2579b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@ trait RuntimeCosting extends CostingRules { IR: IRContext =>
case SInt => IntElement
case SLong => LongElement
case SString => StringElement
case SUnit => UnitElement
case SAny => AnyElement
case SBigInt => bigIntElement
case SBox => boxElement
Expand All @@ -829,6 +830,7 @@ trait RuntimeCosting extends CostingRules { IR: IRContext =>
case IntElement => SInt
case LongElement => SLong
case StringElement => SString
case UnitElement => SUnit
case AnyElement => SAny
case _: BigIntElem[_] => SBigInt
case _: GroupElementElem[_] => SGroupElement
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package sigmastate.utxo

import java.math.BigInteger

import org.ergoplatform.ErgoBox.{R6, R8}
import org.ergoplatform.ErgoBox.{AdditionalRegisters, R6, R8}
import org.ergoplatform._
import scalan.RType
import sigmastate.SCollection.SByteArray
Expand Down Expand Up @@ -61,7 +60,8 @@ class BasicOpsSpecification extends SigmaTestingCommons
ext: Seq[VarBinding],
script: String, propExp: SValue,
onlyPositive: Boolean = true,
testExceededCost: Boolean = true) = {
testExceededCost: Boolean = true,
additionalRegistersOpt: Option[AdditionalRegisters] = None) = {
val prover = new ContextEnrichingTestProvingInterpreter() {
override lazy val contextExtenders: Map[Byte, EvaluatedValue[_ <: SType]] = {
val p1 = dlogSecrets(0).publicImage
Expand All @@ -80,9 +80,11 @@ class BasicOpsSpecification extends SigmaTestingCommons

val tree = ErgoTree.fromProposition(ergoTreeHeaderInTests, prop)
val p3 = prover.dlogSecrets(2).publicImage
val boxToSpend = testBox(10, tree, additionalRegisters = Map(
reg1 -> SigmaPropConstant(p3),
reg2 -> IntConstant(1)),
val boxToSpend = testBox(10, tree,
additionalRegisters = additionalRegistersOpt.getOrElse(Map(
reg1 -> SigmaPropConstant(p3),
reg2 -> IntConstant(1))
),
creationHeight = 5)

val newBox1 = testBox(10, tree, creationHeight = 0, boxIndex = 0, additionalRegisters = Map(
Expand Down Expand Up @@ -122,6 +124,41 @@ class BasicOpsSpecification extends SigmaTestingCommons
flexVerifier.verify(verifyEnv, tree, ctxExt, pr.proof, fakeMessage).get._1 shouldBe true
}

property("Unit register") {
val unitConstant = Constant[SUnit.type]((), SUnit)
VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) {
if (VersionContext.current.isJitActivated) {
test("R1", env, ext,
"{ SELF.R4[Unit].isDefined }",
ExtractRegisterAs[SUnit.type](Self, reg1)(SUnit).isDefined.toSigmaProp,
additionalRegistersOpt = Some(Map(
reg1 -> unitConstant,
))
)

// test("R2", env, ext,
// "{ SELF.R4[Unit].get == () }",
// EQ(ExtractRegisterAs[SUnit.type](Self, reg1)(SUnit).get, unitConstant).toSigmaProp,
// additionalRegistersOpt = Some(Map(
// reg1 -> unitConstant,
// ))
// )
} else {
assertExceptionThrown(
test("R1", env, ext,
"{ SELF.R4[Unit].isDefined }",
ExtractRegisterAs[SUnit.type](Self, reg1)(SUnit).isDefined.toSigmaProp,
additionalRegistersOpt = Some(Map(
reg1 -> unitConstant,
))
),
rootCauseLike[RuntimeException]("Don't know how to compute Sized for type PrimitiveType(Unit,")
)
}
}

}

property("Relation operations") {
test("R1", env, ext,
"{ allOf(Coll(getVar[Boolean](trueVar).get, true, true)) }",
Expand Down

0 comments on commit 4f2579b

Please sign in to comment.