Skip to content

Commit

Permalink
rename version consts, use assertExceptionThrown
Browse files Browse the repository at this point in the history
  • Loading branch information
ross-weir committed Dec 28, 2023
1 parent 9e1a5e1 commit 0f76431
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions core/shared/src/main/scala/sigma/VersionContext.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sigma

import VersionContext.{EvolutionVersion, JitActivationVersion}
import VersionContext.{V6SoftForkVersion, JitActivationVersion}

import scala.util.DynamicVariable

Expand All @@ -24,7 +24,7 @@ case class VersionContext(activatedVersion: Byte, ergoTreeVersion: Byte) {

/** @return true, if the activated script version of Ergo protocol on the network is
* including Evolution update. */
def isEvolutionActivated: Boolean = activatedVersion >= EvolutionVersion
def isV6SoftForkActivated: Boolean = activatedVersion >= V6SoftForkVersion
}

object VersionContext {
Expand All @@ -46,7 +46,7 @@ object VersionContext {
/**
* The version of ErgoTree corresponding to "evolution" (6.0) soft-fork
*/
val EvolutionVersion: Byte = 3
val V6SoftForkVersion: Byte = 3

private val _defaultContext = VersionContext(
activatedVersion = 1/* v4.x */,
Expand Down
4 changes: 2 additions & 2 deletions core/shared/src/test/scala/sigma/VersionTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import scala.util.DynamicVariable

trait VersionTesting {

/** Tests run for both version 2 & version 3 */
/** Tests run for all supported versions starting from 0. */
protected val activatedVersions: Seq[Byte] =
(0 to VersionContext.MaxSupportedScriptVersion).map(_.toByte).toArray[Byte]

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

/** Current activated version used in tests. */
def activatedVersionInTests: Byte = _currActivatedVersion.value
Expand Down
2 changes: 1 addition & 1 deletion interpreter/shared/src/main/scala/sigmastate/types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ case object SBoolean extends SPrimType with SEmbeddable with SLogical with SProd
.withInfo(PropertyCall, "Convert true to 1 and false to 0")

protected override def getMethods(): Seq[SMethod] = {
if (VersionContext.current.isEvolutionActivated) {
if (VersionContext.current.isV6SoftForkActivated) {
super.getMethods() ++ Seq(ToByteMethod)
} else {
super.getMethods()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ trait GraphBuilding extends SigmaLibrary { IR: IRContext =>
else
error(s"The type of $obj is expected to be Collection to select 'size' property", obj.sourceContext.toOption)

case Select(obj, SBoolean.ToByte, _) if obj.tpe.isBoolean && VersionContext.current.isEvolutionActivated =>
case Select(obj, SBoolean.ToByte, _) if obj.tpe.isBoolean && VersionContext.current.isV6SoftForkActivated =>
val bool = eval(obj.asBoolValue)
bool.toByte

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class ErgoTreeSpecification extends SigmaDslTesting with ContractsTestkit {

{
import SBoolean._
if (VersionContext.current.isEvolutionActivated) {
if (VersionContext.current.isV6SoftForkActivated) {
(SBoolean.typeId, Seq(MInfo(1, ToByteMethod)), true)
} else {
(SBoolean.typeId, Seq.empty[MInfo], true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import sigmastate.lang.Terms._
import org.ergoplatform._
import org.scalatest.BeforeAndAfterAll
import scorex.util.encode.Base58
import sigma.VersionContext.EvolutionVersion
import sigma.VersionContext.V6SoftForkVersion
import sigma.util.Extensions.IntOps
import sigmastate.crypto.CryptoConstants
import sigmastate.helpers.{CompilerTestingCommons, ErgoLikeContextTesting, ErgoLikeTestInterpreter, ErgoLikeTestProvingInterpreter}
Expand Down Expand Up @@ -211,8 +211,8 @@ class TestingInterpreterSpecification extends CompilerTestingCommons
| bool.toByte == 1.toByte && false.toByte == 0.toByte
|}
|""".stripMargin
if (activatedVersionInTests < EvolutionVersion) {
an [sigmastate.exceptions.MethodNotFound] should be thrownBy testEval(source)
if (activatedVersionInTests < V6SoftForkVersion) {
assertExceptionThrown(testEval(source), rootCauseLike[sigmastate.exceptions.MethodNotFound]("Cannot find method 'toByte'"))
} else {
testEval(source)
}
Expand Down

0 comments on commit 0f76431

Please sign in to comment.