Skip to content

Commit

Permalink
first failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Jun 19, 2024
1 parent 11777ef commit b7e2a38
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
21 changes: 20 additions & 1 deletion data/shared/src/main/scala/sigma/ast/methods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1418,16 +1418,35 @@ case object SContextMethods extends MonoTypeMethods {
lazy val selfBoxIndexMethod = propertyCall("selfBoxIndex", SInt, 8, FixedCost(JitCost(20)))
lazy val lastBlockUtxoRootHashMethod = property("LastBlockUtxoRootHash", SAvlTree, 9, LastBlockUtxoRootHash)
lazy val minerPubKeyMethod = property("minerPubKey", SByteArray, 10, MinerPubkey)

lazy val getVarMethod = SMethod(
this, "getVar", SFunc(ContextFuncDom, SOption(tT), Array(paramT)), 11, GetVar.costKind)
.withInfo(GetVar, "Get context variable with given \\lst{varId} and type.",
ArgInfo("varId", "\\lst{Byte} identifier of context variable"))

protected override def getMethods() = super.getMethods() ++ Seq(
lazy val getVarFromInputMethod = SMethod(
this, "getVarFromInput", SFunc(Array(SContext, SShort, SByte), SOption(tT), Array(paramT)), 12, GetVar.costKind, Seq(tT))
.withInfo(GetVar, "Get context variable with given \\lst{varId} and type.",
ArgInfo("varId", "\\lst{Byte} identifier of context variable"))

private lazy val v5Methods = super.getMethods() ++ Seq(
dataInputsMethod, headersMethod, preHeaderMethod, inputsMethod, outputsMethod, heightMethod, selfMethod,
selfBoxIndexMethod, lastBlockUtxoRootHashMethod, minerPubKeyMethod, getVarMethod
)

private lazy val v6Methods = super.getMethods() ++ Seq(
dataInputsMethod, headersMethod, preHeaderMethod, inputsMethod, outputsMethod, heightMethod, selfMethod,
selfBoxIndexMethod, lastBlockUtxoRootHashMethod, minerPubKeyMethod, getVarMethod, getVarFromInputMethod
)

protected override def getMethods(): Seq[SMethod] = {
if(VersionContext.current.isV6SoftForkActivated) {
v6Methods
} else {
v5Methods
}
}

/** Names of methods which provide blockchain context.
* This value can be reused where necessary to avoid allocations. */
val BlockchainContextMethodNames: IndexedSeq[String] = Array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ class SigmaTyper(val builder: SigmaBuilder,
case (Ident(GetVarFunc.name | ExecuteFromVarFunc.name, _), Seq(id: Constant[SNumericType]@unchecked))
if id.tpe.isNumType =>
Seq(ByteConstant(SByte.downcast(id.value.asInstanceOf[AnyVal])).withSrcCtx(id.sourceContext))
case (Ident(SContextMethods.getVarFromInputMethod.name, _),
Seq(inputId: Constant[SNumericType]@unchecked, varId: Constant[SNumericType]@unchecked))
if inputId.tpe.isNumType && varId.tpe.isNumType =>
Seq(ShortConstant(SShort.downcast(inputId.value.asInstanceOf[AnyVal])).withSrcCtx(inputId.sourceContext),
ByteConstant(SByte.downcast(varId.value.asInstanceOf[AnyVal])).withSrcCtx(varId.sourceContext))
case _ => typedArgs
}
val actualTypes = adaptedTypedArgs.map(_.tpe)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sigmastate.utxo
import org.ergoplatform.ErgoBox.{AdditionalRegisters, R6, R8}
import org.ergoplatform._
import sigma.Extensions.ArrayOps
import sigma.VersionContext
import sigma.ast.SCollection.SByteArray
import sigma.ast.SType.AnyOps
import sigma.data.{AvlTreeData, CAnyValue, CSigmaDslBuilder}
Expand Down Expand Up @@ -157,6 +158,24 @@ class BasicOpsSpecification extends CompilerTestingCommons
)
}

property("getVarFromInput") {
def getVarTest() = {
val customExt = Map(
1.toByte -> IntConstant(5)
).toSeq
test("R1", env, customExt,
"{ CONTEXT.getVarFromInput[Int](0, 1) == 5 }",
null
)
}

if(VersionContext.current.isV6SoftForkActivated) {
getVarTest()
} else {
an[Exception] should be thrownBy getVarTest()
}
}

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

0 comments on commit b7e2a38

Please sign in to comment.