Skip to content

Commit

Permalink
improving tests in BasicOpsSpecification, type test for getVarFromInput
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Oct 21, 2024
1 parent 35fe87a commit 9036aec
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 101 deletions.
4 changes: 2 additions & 2 deletions core/shared/src/main/scala/sigma/SigmaDsl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -592,13 +592,13 @@ trait Context {
/**
* A variant of `getVar` to extract a context variable by id and type from any input
*
* @param inputId - input index
* @param inputIndex - input index
* @param id - context variable id
* @tparam T - expected type of the variable
* @return Some(value) if the variable is defined in the context AND has the given type.
* None otherwise
*/
def getVarFromInput[T](inputId: Short, id: Byte)(implicit cT: RType[T]): Option[T]
def getVarFromInput[T](inputIndex: Short, id: Byte)(implicit cT: RType[T]): Option[T]

def vars: Coll[AnyValue]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ case class CContext(
} else None
}

override def getVarFromInput[T](inputId: Short, id: Byte)(implicit tT: RType[T]): Option[T] = {
spendingTransaction.inputs.lift(inputId).flatMap(_.extension.get(id)) match {
override def getVarFromInput[T](inputIndex: Short, id: Byte)(implicit tT: RType[T]): Option[T] = {
spendingTransaction.inputs.lift(inputIndex).flatMap(_.extension.get(id)) match {
case Some(v) if stypeToRType[SType](v.tpe) == tT => Some(v.value.asInstanceOf[T])
case _ =>
None
Expand Down
6 changes: 6 additions & 0 deletions sc/shared/src/test/scala/sigmastate/lang/SigmaTyperTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,12 @@ class SigmaTyperTest extends AnyPropSpec
typecheck(env, "CONTEXT.getVar[Int](1.toByte).get") shouldBe SInt
}

property("SContext.getVarFromInput") {
runWithVersion(VersionContext.V6SoftForkVersion) {
typecheck(env, "CONTEXT.getVarFromInput[Int](1.toShort, 1.toByte).get") shouldBe SInt
}
}

property("SAvlTree.digest") {
typecheck(env, "getVar[AvlTree](1).get.digest") shouldBe SByteArray
}
Expand Down
Loading

0 comments on commit 9036aec

Please sign in to comment.