From 8993b3afab938da9be4f0fbbe1a02a9d8a0b9598 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Fri, 6 Dec 2024 20:00:51 +0300 Subject: [PATCH] ergo tree version removed from withVersions --- .../src/main/scala/sigma/VersionContext.scala | 3 +-- .../src/test/scala/sigma/CollsTests.scala | 4 ++-- .../scala/sigma/VersionTestingProperty.scala | 2 +- .../serialization/ErgoTreeSerializer.scala | 6 ++++- .../sigmastate/interpreter/Interpreter.scala | 8 +++---- .../interpreter/ProverInterpreter.scala | 2 +- .../DataSerializerSpecification.scala | 12 +++++----- .../MethodCallSerializerSpecification.scala | 24 +++++++++---------- .../SerializationSpecification.scala | 2 +- .../scala/sigmastate/CrossVersionProps.scala | 2 +- .../scala/sigmastate/eval/BasicOpsTests.scala | 4 ++-- .../scala/sigmastate/lang/LangTests.scala | 2 +- .../ErgoAddressSpecification.scala | 2 +- .../sigma/LanguageSpecificationBase.scala | 2 +- .../test/scala/sigma/SigmaDslTesting.scala | 18 +++++++------- .../sigmastate/ErgoTreeSpecification.scala | 18 +++++++------- .../sigmastate/eval/ErgoScriptTestkit.scala | 2 +- .../utxo/BasicOpsSpecification.scala | 4 ++-- .../sdk/AppkitProvingInterpreter.scala | 2 +- .../sdk/DataJsonEncoderSpecification.scala | 6 ++--- 20 files changed, 64 insertions(+), 61 deletions(-) diff --git a/core/shared/src/main/scala/sigma/VersionContext.scala b/core/shared/src/main/scala/sigma/VersionContext.scala index 053b1b086e..d7110edc93 100644 --- a/core/shared/src/main/scala/sigma/VersionContext.scala +++ b/core/shared/src/main/scala/sigma/VersionContext.scala @@ -83,11 +83,10 @@ object VersionContext { * necessary versions of Ergo protocol and ErgoTree. * * @param activatedVersion Currently activated script version == Block.headerVersion - 1 - * @param ergoTreeVersion ErgoTree version to be set on the current thread * @param block block of code to execute * @return result of block execution */ - def withVersions[T](activatedVersion: Byte, ergoTreeVersion: Byte)(block: => T): T = + def withScriptVersion[T](activatedVersion: Byte)(block: => T): T = _versionContext.withValue(VersionContext(activatedVersion))(block) /** Checks the version context has the given versions*/ diff --git a/core/shared/src/test/scala/sigma/CollsTests.scala b/core/shared/src/test/scala/sigma/CollsTests.scala index da427ba576..612a1ea0b0 100644 --- a/core/shared/src/test/scala/sigma/CollsTests.scala +++ b/core/shared/src/test/scala/sigma/CollsTests.scala @@ -63,7 +63,7 @@ class CollsTests extends AnyPropSpec with ScalaCheckPropertyChecks with Matchers equalLengthMapped(pairs, squared(inc)) // due to problem with append } } - VersionContext.withVersions(VersionContext.JitActivationVersion, VersionContext.JitActivationVersion) { + VersionContext.withScriptVersion(VersionContext.JitActivationVersion) { // TODO v5.0: make it work // equalLengthMapped(pairs, squared(inc)) // problem fixed in v5.0 } @@ -75,7 +75,7 @@ class CollsTests extends AnyPropSpec with ScalaCheckPropertyChecks with Matchers equalLengthMapped(pairs.append(pairs), squared(inc)) // due to problem with append } } - VersionContext.withVersions(VersionContext.JitActivationVersion, VersionContext.JitActivationVersion) { + VersionContext.withScriptVersion(VersionContext.JitActivationVersion) { // TODO v5.0: make it work // equalLengthMapped(pairs.append(pairs), squared(inc)) // problem fixed in v5.0 } diff --git a/core/shared/src/test/scala/sigma/VersionTestingProperty.scala b/core/shared/src/test/scala/sigma/VersionTestingProperty.scala index 2c25359a89..b4c6e60465 100644 --- a/core/shared/src/test/scala/sigma/VersionTestingProperty.scala +++ b/core/shared/src/test/scala/sigma/VersionTestingProperty.scala @@ -17,7 +17,7 @@ trait VersionTestingProperty extends AnyPropSpec with VersionTesting { (implicit pos: Position): Unit = { super.property(testName, testTags:_*) { forEachScriptAndErgoTreeVersion(activatedVersions, ergoTreeVersions) { - VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + VersionContext.withScriptVersion(activatedVersionInTests) { testFun_Run(testName, testFun) } } diff --git a/data/shared/src/main/scala/sigma/serialization/ErgoTreeSerializer.scala b/data/shared/src/main/scala/sigma/serialization/ErgoTreeSerializer.scala index 357ad4eb5a..1d14fcdc6b 100644 --- a/data/shared/src/main/scala/sigma/serialization/ErgoTreeSerializer.scala +++ b/data/shared/src/main/scala/sigma/serialization/ErgoTreeSerializer.scala @@ -127,7 +127,7 @@ class ErgoTreeSerializer(protocolVersion: Byte = VersionContext.V6SoftForkVersio val r = SigmaSerializer.startReader(bytes) deserializeErgoTree(r, SigmaSerializer.MaxPropositionSize) } - + def deserializeErgoTree(r: SigmaByteReader, maxTreeSizeBytes: Int): ErgoTree = { val startPos = r.position val previousPositionLimit = r.positionLimit @@ -385,4 +385,8 @@ class ErgoTreeSerializer(protocolVersion: Byte = VersionContext.V6SoftForkVersio (resBytes, nConstants) } +} + +object ErgoTreeSerializer { + val DefaultSerializer = new ErgoTreeSerializer } \ No newline at end of file diff --git a/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala b/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala index 92f749e136..a9474d0c6b 100644 --- a/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala +++ b/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala @@ -204,7 +204,7 @@ trait Interpreter { ctx: CTX, env: ScriptEnv): ReductionResult = { val context = ctx.withErgoTreeVersion(ergoTree.version).asInstanceOf[CTX] - VersionContext.withVersions(context.activatedScriptVersion, ergoTree.version) { + VersionContext.withScriptVersion(context.activatedScriptVersion) { val prop = propositionFromErgoTree(ergoTree, context) val res = prop match { @@ -217,7 +217,7 @@ trait Interpreter { ReductionResult(sb, resCost) case _ if !ergoTree.hasDeserialize => val ctx = context.asInstanceOf[ErgoLikeContext] - val res = VersionContext.withVersions(ctx.activatedScriptVersion, ergoTree.version) { + val res = VersionContext.withScriptVersion(ctx.activatedScriptVersion) { CErgoTreeEvaluator.evalToCrypto(ctx, ergoTree, evalSettings) } res @@ -242,7 +242,7 @@ trait Interpreter { context: CTX, env: ScriptEnv): ReductionResult = { implicit val vs: SigmaValidationSettings = context.validationSettings - val res = VersionContext.withVersions(context.activatedScriptVersion, ergoTree.version) { + val res = VersionContext.withScriptVersion(context.activatedScriptVersion) { val deserializeSubstitutionCost = java7.compat.Math.multiplyExact(ergoTree.bytes.length, CostPerTreeByte) val currCost = addCostChecked(context.initCost, deserializeSubstitutionCost, context.costLimit) val context1 = context.withInitCost(currCost).asInstanceOf[CTX] @@ -359,7 +359,7 @@ trait Interpreter { case Some(resWhenSoftFork) => return Success(resWhenSoftFork) case None => // proceed normally } - VersionContext.withVersions(context.activatedScriptVersion, ergoTree.version) { + VersionContext.withScriptVersion(context.activatedScriptVersion) { // NOTE, ergoTree.complexity is not acrued to the cost in v5.0 val reduced = fullReduction(ergoTree, context, env) reduced.value match { diff --git a/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverInterpreter.scala b/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverInterpreter.scala index ed2349eb0f..d06287a8d3 100644 --- a/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverInterpreter.scala +++ b/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverInterpreter.scala @@ -134,7 +134,7 @@ trait ProverInterpreter extends Interpreter with ProverUtils { case None => // proceed normally } - VersionContext.withVersions(context.activatedScriptVersion, ergoTree.version) { + VersionContext.withScriptVersion(context.activatedScriptVersion) { val (resValue, resCost) = { val reduced = fullReduction(ergoTree, context, env) val fullCost = addCryptoCost(reduced.value, reduced.cost, context.costLimit) diff --git a/interpreter/shared/src/test/scala/sigma/serialization/DataSerializerSpecification.scala b/interpreter/shared/src/test/scala/sigma/serialization/DataSerializerSpecification.scala index 9201214e4f..500cdf02fb 100644 --- a/interpreter/shared/src/test/scala/sigma/serialization/DataSerializerSpecification.scala +++ b/interpreter/shared/src/test/scala/sigma/serialization/DataSerializerSpecification.scala @@ -52,7 +52,7 @@ class DataSerializerSpecification extends SerializationSpecification { withVersion match { case Some(ver) => - VersionContext.withVersions(ver, 1) { + VersionContext.withScriptVersion(ver) { test() } case None => @@ -122,14 +122,14 @@ class DataSerializerSpecification extends SerializationSpecification { val tT = Evaluation.stypeToRType(tpe) an[Exception] should be thrownBy ( - VersionContext.withVersions((VersionContext.V6SoftForkVersion - 1).toByte, 1) { + VersionContext.withScriptVersion((VersionContext.V6SoftForkVersion - 1).toByte) { forAll { in: T#WrappedType => roundtrip[SType](Some(in).asWrappedType, SOption(tpe)) roundtrip[SOption[SCollection[T]]](Some(Colls.fromItems(in)(tT)), SOption(SCollectionType(tpe))) } }) - VersionContext.withVersions(VersionContext.V6SoftForkVersion, 1) { + VersionContext.withScriptVersion(VersionContext.V6SoftForkVersion) { forAll { in: T#WrappedType => roundtrip[SType](Some(in).asWrappedType, SOption(tpe)) roundtrip[SOption[T]](None, SOption(tpe)) @@ -189,12 +189,12 @@ class DataSerializerSpecification extends SerializationSpecification { } property("nuanced versioned test for header roundtrip") { - VersionContext.withVersions(VersionContext.V6SoftForkVersion, 1) { + VersionContext.withScriptVersion(VersionContext.V6SoftForkVersion) { forAll { x: Header => roundtrip[SHeader.type](x, SHeader) } } an[SerializerException] should be thrownBy ( - VersionContext.withVersions((VersionContext.V6SoftForkVersion - 1).toByte, 1) { + VersionContext.withScriptVersion((VersionContext.V6SoftForkVersion - 1).toByte) { val h = headerGen.sample.get roundtrip[SHeader.type](h, SHeader) }) @@ -219,7 +219,7 @@ class DataSerializerSpecification extends SerializationSpecification { Colls.emptyColl ) - VersionContext.withVersions(VersionContext.V6SoftForkVersion, 1) { + VersionContext.withScriptVersion(VersionContext.V6SoftForkVersion) { roundtrip[SHeader.type](header, SHeader) } } diff --git a/interpreter/shared/src/test/scala/sigma/serialization/MethodCallSerializerSpecification.scala b/interpreter/shared/src/test/scala/sigma/serialization/MethodCallSerializerSpecification.scala index 4bfe3c6a25..abbf539727 100644 --- a/interpreter/shared/src/test/scala/sigma/serialization/MethodCallSerializerSpecification.scala +++ b/interpreter/shared/src/test/scala/sigma/serialization/MethodCallSerializerSpecification.scala @@ -38,12 +38,12 @@ class MethodCallSerializerSpecification extends SerializationSpecification { roundTripTest(expr) } - VersionContext.withVersions(VersionContext.V6SoftForkVersion, 1) { + VersionContext.withScriptVersion(VersionContext.V6SoftForkVersion) { code } a[SerializerException] should be thrownBy ( - VersionContext.withVersions((VersionContext.V6SoftForkVersion - 1).toByte, 1) { + VersionContext.withScriptVersion((VersionContext.V6SoftForkVersion - 1).toByte) { code } ) @@ -65,12 +65,12 @@ class MethodCallSerializerSpecification extends SerializationSpecification { roundTripTest(expr) } - VersionContext.withVersions(VersionContext.V6SoftForkVersion, 1) { + VersionContext.withScriptVersion(VersionContext.V6SoftForkVersion) { code } an[ValidationException] should be thrownBy ( - VersionContext.withVersions((VersionContext.V6SoftForkVersion - 1).toByte, 1) { + VersionContext.withScriptVersion((VersionContext.V6SoftForkVersion - 1).toByte) { code } ) @@ -87,12 +87,12 @@ class MethodCallSerializerSpecification extends SerializationSpecification { roundTripTest(expr) } - VersionContext.withVersions(VersionContext.V6SoftForkVersion, 1) { + VersionContext.withScriptVersion(VersionContext.V6SoftForkVersion) { code } an[ValidationException] should be thrownBy ( - VersionContext.withVersions((VersionContext.V6SoftForkVersion - 1).toByte, 1) { + VersionContext.withScriptVersion((VersionContext.V6SoftForkVersion - 1).toByte) { code } ) @@ -111,12 +111,12 @@ class MethodCallSerializerSpecification extends SerializationSpecification { println(SGlobalMethods.deserializeToMethod.hasExplicitTypeArgs) - VersionContext.withVersions(VersionContext.V6SoftForkVersion, 1) { + VersionContext.withScriptVersion(VersionContext.V6SoftForkVersion) { code } an[Exception] should be thrownBy ( - VersionContext.withVersions((VersionContext.V6SoftForkVersion - 1).toByte, 1) { + VersionContext.withScriptVersion((VersionContext.V6SoftForkVersion - 1).toByte) { code }) } @@ -133,12 +133,12 @@ class MethodCallSerializerSpecification extends SerializationSpecification { } // should be ok - VersionContext.withVersions(VersionContext.V6SoftForkVersion, 1) { + VersionContext.withScriptVersion(VersionContext.V6SoftForkVersion) { code } an[ValidationException] should be thrownBy ( - VersionContext.withVersions((VersionContext.V6SoftForkVersion - 1).toByte, 1) { + VersionContext.withScriptVersion((VersionContext.V6SoftForkVersion - 1).toByte) { code }) } @@ -154,12 +154,12 @@ class MethodCallSerializerSpecification extends SerializationSpecification { roundTripTest(expr) } - VersionContext.withVersions(VersionContext.V6SoftForkVersion, 1) { + VersionContext.withScriptVersion(VersionContext.V6SoftForkVersion) { code } an[ValidationException] should be thrownBy ( - VersionContext.withVersions((VersionContext.V6SoftForkVersion - 1).toByte, 1) { + VersionContext.withScriptVersion((VersionContext.V6SoftForkVersion - 1).toByte) { code } ) diff --git a/interpreter/shared/src/test/scala/sigma/serialization/SerializationSpecification.scala b/interpreter/shared/src/test/scala/sigma/serialization/SerializationSpecification.scala index aa7a8722ba..ae23712170 100644 --- a/interpreter/shared/src/test/scala/sigma/serialization/SerializationSpecification.scala +++ b/interpreter/shared/src/test/scala/sigma/serialization/SerializationSpecification.scala @@ -35,7 +35,7 @@ trait SerializationSpecification extends AnyPropSpec } withVersion match { case Some(ver) => - VersionContext.withVersions(ver, 0) { + VersionContext.withScriptVersion(ver) { test() } case None => diff --git a/interpreter/shared/src/test/scala/sigmastate/CrossVersionProps.scala b/interpreter/shared/src/test/scala/sigmastate/CrossVersionProps.scala index 87101a1f71..84600b0620 100644 --- a/interpreter/shared/src/test/scala/sigmastate/CrossVersionProps.scala +++ b/interpreter/shared/src/test/scala/sigmastate/CrossVersionProps.scala @@ -31,7 +31,7 @@ trait CrossVersionProps extends AnyPropSpecLike with TestsBase { System.gc() } forEachScriptAndErgoTreeVersion(activatedVersions, ergoTreeVersions) { - VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + VersionContext.withScriptVersion(activatedVersionInTests) { testFun_Run(testName, testFun) } } diff --git a/interpreter/shared/src/test/scala/sigmastate/eval/BasicOpsTests.scala b/interpreter/shared/src/test/scala/sigmastate/eval/BasicOpsTests.scala index 52cc6af66c..5ebf82d953 100644 --- a/interpreter/shared/src/test/scala/sigmastate/eval/BasicOpsTests.scala +++ b/interpreter/shared/src/test/scala/sigmastate/eval/BasicOpsTests.scala @@ -89,7 +89,7 @@ class BasicOpsTests extends AnyFunSuite with ContractsTestkit with Matchers { coster = accumulator, DefaultProfiler, es) val msg = Colls.fromArray(Base16.decode("0a101b8c6a4f2e").get) - VersionContext.withVersions(VersionContext.V6SoftForkVersion, VersionContext.V6SoftForkVersion) { + VersionContext.withScriptVersion(VersionContext.V6SoftForkVersion) { val res = MethodCall(Global, SGlobalMethods.xorMethod, IndexedSeq(ByteArrayConstant(msg), ByteArrayConstant(msg)), Map.empty) .evalTo[sigma.Coll[Byte]](Map.empty)(evaluator) @@ -125,7 +125,7 @@ class BasicOpsTests extends AnyFunSuite with ContractsTestkit with Matchers { constants = ErgoTree.EmptyConstants, coster = accumulator, DefaultProfiler, es) - VersionContext.withVersions(VersionContext.V6SoftForkVersion, VersionContext.V6SoftForkVersion) { + VersionContext.withScriptVersion(VersionContext.V6SoftForkVersion) { val res = MethodCall(Global, SGlobalMethods.powHitMethod, IndexedSeq(IntConstant(k), ByteArrayConstant(msg), ByteArrayConstant(nonce), ByteArrayConstant(hbs), IntConstant(N)), Map.empty) diff --git a/parsers/shared/src/test/scala/sigmastate/lang/LangTests.scala b/parsers/shared/src/test/scala/sigmastate/lang/LangTests.scala index de83070ac3..2aae13d13b 100644 --- a/parsers/shared/src/test/scala/sigmastate/lang/LangTests.scala +++ b/parsers/shared/src/test/scala/sigmastate/lang/LangTests.scala @@ -82,7 +82,7 @@ trait LangTests extends Matchers with NegativeTesting { /** Execute the given `block` having `version` as both activated and ErgoTree version. */ def runWithVersion[T](version: Byte)(block: => T): T = { - VersionContext.withVersions(version, version)(block) + VersionContext.withScriptVersion(version)(block) } } diff --git a/sc/shared/src/test/scala/org/ergoplatform/ErgoAddressSpecification.scala b/sc/shared/src/test/scala/org/ergoplatform/ErgoAddressSpecification.scala index d8ee6e3707..fca280cd9f 100644 --- a/sc/shared/src/test/scala/org/ergoplatform/ErgoAddressSpecification.scala +++ b/sc/shared/src/test/scala/org/ergoplatform/ErgoAddressSpecification.scala @@ -272,7 +272,7 @@ class ErgoAddressSpecification extends SigmaDslTesting property("Pay2SHAddress.script should create ErgoTree v0") { val (prop, _) = createPropAndScriptBytes() - val address = VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + val address = VersionContext.withScriptVersion(activatedVersionInTests) { Pay2SHAddress(prop) } address.script.version shouldBe 0 diff --git a/sc/shared/src/test/scala/sigma/LanguageSpecificationBase.scala b/sc/shared/src/test/scala/sigma/LanguageSpecificationBase.scala index 7be79546e7..20475e8e09 100644 --- a/sc/shared/src/test/scala/sigma/LanguageSpecificationBase.scala +++ b/sc/shared/src/test/scala/sigma/LanguageSpecificationBase.scala @@ -47,7 +47,7 @@ abstract class LanguageSpecificationBase extends SigmaDslTesting * parameters. */ protected override def testFun_Run(testName: String, testFun: => Any): Unit = { - VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + VersionContext.withScriptVersion(activatedVersionInTests) { super.testFun_Run(testName, testFun) } } diff --git a/sc/shared/src/test/scala/sigma/SigmaDslTesting.scala b/sc/shared/src/test/scala/sigma/SigmaDslTesting.scala index 7f3f28b791..488071a700 100644 --- a/sc/shared/src/test/scala/sigma/SigmaDslTesting.scala +++ b/sc/shared/src/test/scala/sigma/SigmaDslTesting.scala @@ -527,11 +527,11 @@ class SigmaDslTesting extends AnyPropSpec */ def checkEquality(input: A, logInputOutput: Boolean = false): Try[(B, CostDetails)] = { // check the old implementation against Scala semantic function - val oldRes = VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + val oldRes = VersionContext.withScriptVersion(activatedVersionInTests) { checkEq(scalaFunc)(oldF)(input) } - val newRes = VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + val newRes = VersionContext.withScriptVersion(activatedVersionInTests) { checkEq(scalaFunc)({ x => var y: (B, CostDetails) = null val N = nBenchmarkIters + 1 @@ -588,13 +588,13 @@ class SigmaDslTesting extends AnyPropSpec */ override def checkExpected(input: A, expected: Expected[B]): Unit = { // check the old implementation with Scala semantic - val (oldRes, _) = VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + val (oldRes, _) = VersionContext.withScriptVersion(activatedVersionInTests) { checkEq(scalaFunc)(oldF)(input).get } oldRes shouldBe expected.value.get // check the new implementation with Scala semantic - val (newRes, newDetails) = VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + val (newRes, newDetails) = VersionContext.withScriptVersion(activatedVersionInTests) { checkEq(scalaFunc)(newF)(input).get } newRes shouldBe expected.value.get @@ -716,7 +716,7 @@ class SigmaDslTesting extends AnyPropSpec override def checkEquality(input: A, logInputOutput: Boolean = false): Try[(B, CostDetails)] = { // check the old implementation against Scala semantic function var oldRes: Try[(B, CostDetails)] = null - oldRes = VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + oldRes = VersionContext.withScriptVersion(activatedVersionInTests) { try checkEq(scalaFunc)(oldF)(input) catch { case e: TestFailedException => @@ -734,7 +734,7 @@ class SigmaDslTesting extends AnyPropSpec val newRes = { // check the new implementation against Scala semantic function - val newRes = VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + val newRes = VersionContext.withScriptVersion(activatedVersionInTests) { checkEq(scalaFuncNew)(newF)(input) } if (ergoTreeVersionInTests < VersionContext.JitActivationVersion) { @@ -770,7 +770,7 @@ class SigmaDslTesting extends AnyPropSpec */ override def checkExpected(input: A, expected: Expected[B]): Unit = { // check the new implementation with Scala semantic function - val newRes = VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + val newRes = VersionContext.withScriptVersion(activatedVersionInTests) { checkEq(scalaFuncNew)(newF)(input) } @@ -910,7 +910,7 @@ class SigmaDslTesting extends AnyPropSpec override def checkExpected(input: A, expected: Expected[B]): Unit = { Try(oldF(input)).isFailure shouldBe true if (!(newImpl eq oldImpl)) { - val (newRes, _) = VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + val (newRes, _) = VersionContext.withScriptVersion(activatedVersionInTests) { checkEq(scalaFuncNew)(newF)(input).get } val newExpectedRes = expected.newResults(ergoTreeVersionInTests) @@ -1264,7 +1264,7 @@ class SigmaDslTesting extends AnyPropSpec val funcNoTrace = funcJit[A, B](f.script)(tA, tB, IR, noTraceSettings, cs) var iCase = 0 val (res, total) = BenchmarkUtil.measureTimeNano { - VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + VersionContext.withScriptVersion(activatedVersionInTests) { cases.map { x => assert(func(x)._1 == f.newF(x)._1) iCase += 1 diff --git a/sc/shared/src/test/scala/sigmastate/ErgoTreeSpecification.scala b/sc/shared/src/test/scala/sigmastate/ErgoTreeSpecification.scala index 0504a79c65..985826879a 100644 --- a/sc/shared/src/test/scala/sigmastate/ErgoTreeSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/ErgoTreeSpecification.scala @@ -696,12 +696,12 @@ class ErgoTreeSpecification extends SigmaDslTesting with ContractsTestkit with C val expr = Apply(FuncValue(Vector(), IntConstant(1)), IndexedSeq()) forEachScriptAndErgoTreeVersion(activatedVersions, ergoTreeVersions) { - VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + VersionContext.withScriptVersion(activatedVersionInTests) { val newF = funcJitFromExpr[Int, Int]("({ (x: Int) => 1 })()", expr) assertExceptionThrown( { val x = 100 // any value which is not used anyway - val _ = VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + val _ = VersionContext.withScriptVersion(activatedVersionInTests) { newF.apply(x) } }, @@ -721,9 +721,9 @@ class ErgoTreeSpecification extends SigmaDslTesting with ContractsTestkit with C val x = 1 forEachScriptAndErgoTreeVersion(activatedVersions, ergoTreeVersions) { - VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + VersionContext.withScriptVersion(activatedVersionInTests) { val newF = funcJitFromExpr[Int, Int](script, expr) - val (y, _) = VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + val (y, _) = VersionContext.withScriptVersion(activatedVersionInTests) { newF.apply(x) } y shouldBe -1 @@ -739,11 +739,11 @@ class ErgoTreeSpecification extends SigmaDslTesting with ContractsTestkit with C val script = "{ (x: Int, y: Int) => x + y }" forEachScriptAndErgoTreeVersion(activatedVersions, ergoTreeVersions) { - VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + VersionContext.withScriptVersion(activatedVersionInTests) { val newF = funcJitFromExpr[(Int, Int), Int](script, expr) assertExceptionThrown( { - val _ = VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + val _ = VersionContext.withScriptVersion(activatedVersionInTests) { newF.apply((1, 1)) } }, @@ -840,7 +840,7 @@ class ErgoTreeSpecification extends SigmaDslTesting with ContractsTestkit with C forEachScriptAndErgoTreeVersion( activatedVers = Array(JitActivationVersion), ergoTreeVers = ergoTreeVersions) { - VersionContext.withVersions(activatedVersionInTests, ergoTreeVersionInTests) { + VersionContext.withScriptVersion(activatedVersionInTests) { { // depth 3 val cf = mkCompiledFunc(3) @@ -950,13 +950,13 @@ class ErgoTreeSpecification extends SigmaDslTesting with ContractsTestkit with C .dummy(fakeSelf, VersionContext.current.activatedVersion) .withErgoTreeVersion(tree.version) - VersionContext.withVersions(activatedVersion = 1, tree.version) { + VersionContext.withScriptVersion(activatedVersion = 1) { // v4.x behavior val res = CErgoTreeEvaluator.evalToCrypto(createCtx, tree, evalSettings) res shouldBe ReductionResult(TrivialProp(true), 3) } - VersionContext.withVersions(activatedVersion = 2, tree.version) { + VersionContext.withScriptVersion(activatedVersion = 2) { // v5.0 behavior assertExceptionThrown( CErgoTreeEvaluator.evalToCrypto(createCtx, tree, evalSettings), diff --git a/sc/shared/src/test/scala/sigmastate/eval/ErgoScriptTestkit.scala b/sc/shared/src/test/scala/sigmastate/eval/ErgoScriptTestkit.scala index da9ed70efd..c36ccaa852 100644 --- a/sc/shared/src/test/scala/sigmastate/eval/ErgoScriptTestkit.scala +++ b/sc/shared/src/test/scala/sigmastate/eval/ErgoScriptTestkit.scala @@ -188,7 +188,7 @@ trait ErgoScriptTestkit extends ContractsTestkit with LangTests if (ergoCtx.isDefined) { val ectx = ergoCtx.get.withErgoTreeVersion(ergoTreeVersionInTests) - VersionContext.withVersions(ectx.activatedScriptVersion, ergoTreeVersionInTests) { + VersionContext.withScriptVersion(ectx.activatedScriptVersion) { val calcCtx = ectx.toSigmaContext() val testContractRes = testContract.map(_(calcCtx)) testContractRes.foreach { res => diff --git a/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala index 2194414ab0..ea4d64c2c1 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala @@ -16,7 +16,7 @@ import scorex.utils.Longs import sigma.{Colls, SigmaTestingData} import sigma.Extensions.ArrayOps import sigma.{SigmaTestingData, VersionContext} -import sigma.VersionContext.{V6SoftForkVersion, withVersions} +import sigma.VersionContext.{V6SoftForkVersion, withScriptVersion} import sigma.VersionContext.V6SoftForkVersion import sigma.VersionContext import sigma.GroupElement @@ -127,7 +127,7 @@ class BasicOpsSpecification extends CompilerTestingCommons propExp.asSigmaProp } else { // compile with the latest compiler version, to get validation exception during execution, not compilation error - withVersions(VersionContext.MaxSupportedScriptVersion, ergoTreeVersionInTests) { + withScriptVersion(VersionContext.MaxSupportedScriptVersion) { compile(env, script).asBoolValue.toSigmaProp } } diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/AppkitProvingInterpreter.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/AppkitProvingInterpreter.scala index c0dc075a9b..b2931d1eba 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/AppkitProvingInterpreter.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/AppkitProvingInterpreter.scala @@ -340,7 +340,7 @@ object ReducedErgoLikeTransactionSerializer extends SigmaSerializer[ReducedErgoL */ def parse(r: SigmaByteReader, blockVersion: Byte): ReducedErgoLikeTransaction = { val scriptVersion = (blockVersion - 1).toByte - VersionContext.withVersions(scriptVersion, scriptVersion) { + VersionContext.withScriptVersion(scriptVersion) { parse(r) } } diff --git a/sdk/shared/src/test/scala/org/ergoplatform/sdk/DataJsonEncoderSpecification.scala b/sdk/shared/src/test/scala/org/ergoplatform/sdk/DataJsonEncoderSpecification.scala index 7e73b6c93d..1eebc9c1ba 100644 --- a/sdk/shared/src/test/scala/org/ergoplatform/sdk/DataJsonEncoderSpecification.scala +++ b/sdk/shared/src/test/scala/org/ergoplatform/sdk/DataJsonEncoderSpecification.scala @@ -31,7 +31,7 @@ class DataJsonEncoderSpecification extends SerializationSpecification { withVersion match { case Some(ver) => - VersionContext.withVersions(ver, 0) { + VersionContext.withScriptVersion(ver) { test() } case None => @@ -221,7 +221,7 @@ class DataJsonEncoderSpecification extends SerializationSpecification { } if (tpe == SHeader) { - VersionContext.withVersions(VersionContext.V6SoftForkVersion, 0) { + VersionContext.withScriptVersion(VersionContext.V6SoftForkVersion) { test() } } else { @@ -232,7 +232,7 @@ class DataJsonEncoderSpecification extends SerializationSpecification { property("AnyValue") { forAll { t: SPredefType => if (t == SHeader) { - VersionContext.withVersions(VersionContext.V6SoftForkVersion, 1) { + VersionContext.withScriptVersion(VersionContext.V6SoftForkVersion) { testAnyValue(t) testAnyValue(SOption(t)) }