Skip to content

Commit

Permalink
v3 interpreter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ross-weir committed Nov 23, 2023
1 parent 399363d commit 12e2a3e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
11 changes: 5 additions & 6 deletions core/shared/src/test/scala/sigma/VersionTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import scala.util.DynamicVariable

trait VersionTesting {

/** In v5.x we run test for only one activated version on the network (== 2).
* In the branch for v6.0 the new version 3 should be added so that the tests run for both.
*/
/** Tests run for both version 2 & version 3 */
protected val activatedVersions: Seq[Byte] =
(0 to VersionContext.MaxSupportedScriptVersion).map(_.toByte).toArray[Byte]

private[sigma] val _currActivatedVersion = new DynamicVariable[Byte](2) // v5.x by default
private[sigma] val _currActivatedVersion = new DynamicVariable[Byte](3) // v6.x by default

/** Current activated version used in tests. */
def activatedVersionInTests: Byte = _currActivatedVersion.value
Expand Down Expand Up @@ -41,9 +39,10 @@ trait VersionTesting {
_ + 1) { j =>
val treeVersion = ergoTreeVers(j)
// for each tree version up to currently activated, set it up and execute block
_currErgoTreeVersion.withValue(treeVersion)(block)
_currErgoTreeVersion.withValue(treeVersion) {
VersionContext.withVersions(activatedVersion, treeVersion)(block)
}
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import sigmastate.lang.Terms._
import org.ergoplatform._
import org.scalatest.BeforeAndAfterAll
import scorex.util.encode.Base58
import sigma.VersionContext.EvolutionVersion
import sigma.util.Extensions.IntOps
import sigmastate.crypto.CryptoConstants
import sigmastate.helpers.{CompilerTestingCommons, ErgoLikeContextTesting, ErgoLikeTestInterpreter, ErgoLikeTestProvingInterpreter}
Expand Down Expand Up @@ -203,11 +204,18 @@ class TestingInterpreterSpecification extends CompilerTestingCommons
}

property("Evaluate boolean casting ops") {
testEval(
"""{
val source =
"""
|{
| val bool: Boolean = true
| bool.toByte == 1.toByte && false.toByte == 0.toByte
}""".stripMargin)
|}
|""".stripMargin
if (activatedVersionInTests < EvolutionVersion) {
an [sigmastate.exceptions.MethodNotFound] should be thrownBy testEval(source)
} else {
testEval(source)
}
}

property("Evaluate numeric casting ops") {
Expand Down

0 comments on commit 12e2a3e

Please sign in to comment.