From 19c752da1ff6cb2054846641d097238ccfdd58ee Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Thu, 3 Oct 2024 11:44:28 +0300 Subject: [PATCH] fixing most of tests --- data/js/src/main/scala/sigma/Platform.scala | 1 + .../org/ergoplatform/ErgoScriptPredef.scala | 3 +- .../org/ergoplatform/ErgoTreePredefSpec.scala | 24 +++++------ .../TestingInterpreterSpecification.scala | 16 +++++--- .../utxo/AVLTreeScriptsSpecification.scala | 10 ++--- .../utxo/ContextEnrichingSpecification.scala | 14 +++---- .../ErgoLikeInterpreterSpecification.scala | 41 ++++++++++++------- .../AtomicSwapExampleSpecification.scala | 1 - ...alletAdvContractExampleSpecification.scala | 7 +--- ...ldWalletContractExampleSpecification.scala | 1 - .../DHTupleExampleSpecification.scala | 1 - .../DemurrageExampleSpecification.scala | 1 - .../sigmastate/utxo/examples/IcoExample.scala | 7 ++-- .../utxo/examples/LetsSpecification.scala | 4 +- .../examples/MixExampleSpecification.scala | 5 +-- .../RPSGameExampleSpecification.scala | 7 ++-- .../ReversibleTxExampleSpecification.scala | 11 +++-- .../TimedPaymentExampleSpecification.scala | 1 - .../XorGameExampleSpecification.scala | 7 ++-- 19 files changed, 82 insertions(+), 80 deletions(-) diff --git a/data/js/src/main/scala/sigma/Platform.scala b/data/js/src/main/scala/sigma/Platform.scala index 29c761c3f1..45d74ea2b2 100644 --- a/data/js/src/main/scala/sigma/Platform.scala +++ b/data/js/src/main/scala/sigma/Platform.scala @@ -31,6 +31,7 @@ object Platform { case ge: GroupElement => Nullable(mkConstant[SGroupElement.type](ge, SGroupElement)) case b: Boolean => Nullable(if (b) TrueLeaf else FalseLeaf) case v: String => Nullable(mkConstant[SString.type](v, SString)) + case h: Header if VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SHeader.type](h, SHeader)) // The Box lifting was broken in v4.x. `SigmaDsl.Box(b)` was missing which means the // isCorrectType requirement would fail in ConstantNode constructor. diff --git a/sc/shared/src/main/scala/org/ergoplatform/ErgoScriptPredef.scala b/sc/shared/src/main/scala/org/ergoplatform/ErgoScriptPredef.scala index 9eec42a4fb..7bcf10d593 100644 --- a/sc/shared/src/main/scala/org/ergoplatform/ErgoScriptPredef.scala +++ b/sc/shared/src/main/scala/org/ergoplatform/ErgoScriptPredef.scala @@ -1,6 +1,7 @@ package org.ergoplatform import org.ergoplatform.ErgoAddressEncoder.NetworkPrefix +import sigma.Colls import sigma.ast.SType import sigma.ast.syntax.SigmaPropValue import sigma.ast.Value @@ -32,7 +33,7 @@ object ErgoScriptPredef { networkPrefix: NetworkPrefix) (implicit IR: IRContext): SigmaPropValue = { val env = emptyEnv + - ("tokenId" -> tokenId, "thresholdAmount" -> thresholdAmount) + ("tokenId" -> Colls.fromArray(tokenId), "thresholdAmount" -> thresholdAmount) val res = compileWithCosting(env, """{ | val sumValues = { (xs: Coll[Long]) => xs.fold(0L, { (acc: Long, amt: Long) => acc + amt }) } diff --git a/sc/shared/src/test/scala/org/ergoplatform/ErgoTreePredefSpec.scala b/sc/shared/src/test/scala/org/ergoplatform/ErgoTreePredefSpec.scala index eb086e88c8..40012c2806 100644 --- a/sc/shared/src/test/scala/org/ergoplatform/ErgoTreePredefSpec.scala +++ b/sc/shared/src/test/scala/org/ergoplatform/ErgoTreePredefSpec.scala @@ -58,8 +58,8 @@ class ErgoTreePredefSpec extends CompilerTestingCommons with CompilerCrossVersio boxesToSpend = inputBoxes, spendingTransaction, self = inputBox, activatedVersionInTests) - val pr = prover.prove(emptyEnv + (ScriptNameProp -> "boxCreationHeight_prove"), propTree, ctx, fakeMessage).get - verifier.verify(emptyEnv + (ScriptNameProp -> "boxCreationHeight_verify"), propTree, ctx, pr, fakeMessage).get._1 shouldBe true + val pr = prover.prove(emptyEnv, propTree, ctx, fakeMessage).get + verifier.verify(emptyEnv, propTree, ctx, pr, fakeMessage).get._1 shouldBe true } property("collect coins from the founders' box") { @@ -118,8 +118,8 @@ class ErgoTreePredefSpec extends CompilerTestingCommons with CompilerCrossVersio boxesToSpend = inputBoxes, spendingTransaction, self = inputBoxes.head, activatedVersionInTests) - val pr = prover.prove(emptyEnv + (ScriptNameProp -> "checkSpending_prove"), prop, ctx, fakeMessage).get - verifier.verify(emptyEnv + (ScriptNameProp -> "checkSpending_verify"), prop, ctx, pr, fakeMessage).get._1 shouldBe true + val pr = prover.prove(emptyEnv, prop, ctx, fakeMessage).get + verifier.verify(emptyEnv, prop, ctx, pr, fakeMessage).get._1 shouldBe true } } @@ -148,13 +148,13 @@ class ErgoTreePredefSpec extends CompilerTestingCommons with CompilerCrossVersio self = inputBoxes.head, activatedVersionInTests) // should not be able to collect before minerRewardDelay - val prove = prover.prove(emptyEnv + (ScriptNameProp -> "rewardOutputScript_prove"), prop, ctx, fakeMessage).get - verifier.verify(emptyEnv + (ScriptNameProp -> "rewardOutputScript_verify"), prop, prevBlockCtx, prove, fakeMessage) + val prove = prover.prove(emptyEnv, prop, ctx, fakeMessage).get + verifier.verify(emptyEnv, prop, prevBlockCtx, prove, fakeMessage) .getOrThrow should matchPattern { case (false,_) => } // should be able to collect after minerRewardDelay - val pr = prover.prove(emptyEnv + (ScriptNameProp -> "prove"), prop, ctx, fakeMessage).getOrThrow - verifier.verify(emptyEnv + (ScriptNameProp -> "verify"), prop, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true + val pr = prover.prove(emptyEnv, prop, ctx, fakeMessage).getOrThrow + verifier.verify(emptyEnv, prop, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true } property("create transaction collecting the emission box") { @@ -232,8 +232,8 @@ class ErgoTreePredefSpec extends CompilerTestingCommons with CompilerCrossVersio self = inputBoxes.head, activatedVersionInTests).withCostLimit(scriptCostLimitInTests * 10) - val pr = prover.prove(emptyEnv + (ScriptNameProp -> "tokenThresholdScript_prove"), prop, ctx, fakeMessage).getOrThrow - verifier.verify(emptyEnv + (ScriptNameProp -> "tokenThresholdScript_verify"), prop, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true + val pr = prover.prove(emptyEnv, prop, ctx, fakeMessage).getOrThrow + verifier.verify(emptyEnv, prop, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true } @@ -308,8 +308,8 @@ class ErgoTreePredefSpec extends CompilerTestingCommons with CompilerCrossVersio boxesToSpend = inputBoxes, spendingTransaction, self = inputBoxes.head, activatedVersionInTests) - val pr = prover.prove(emptyEnv + (ScriptNameProp -> "checkRewardTx_prove"), prop, ctx, fakeMessage).getOrThrow - verifier.verify(emptyEnv + (ScriptNameProp -> "checkRewardTx_verify"), prop, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true + val pr = prover.prove(emptyEnv, prop, ctx, fakeMessage).getOrThrow + verifier.verify(emptyEnv, prop, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true spendingTransaction } diff --git a/sc/shared/src/test/scala/sigmastate/TestingInterpreterSpecification.scala b/sc/shared/src/test/scala/sigmastate/TestingInterpreterSpecification.scala index 4ba6b1a9f7..42d424994d 100644 --- a/sc/shared/src/test/scala/sigmastate/TestingInterpreterSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/TestingInterpreterSpecification.scala @@ -12,7 +12,7 @@ import scorex.util.encode.{Base16, Base58} import sigma.Colls import sigma.VersionContext.V6SoftForkVersion import sigma.VersionContext -import sigma.data.{CAND, CAvlTree, CHeader, ProveDlog, SigmaBoolean, TrivialProp} +import sigma.data.{CAND, CAvlTree, CBox, CHeader, ProveDlog, SigmaBoolean, TrivialProp} import sigma.interpreter.ContextExtension import sigma.util.Extensions.IntOps import sigmastate.helpers.{CompilerTestingCommons, ErgoLikeContextTesting, ErgoLikeTestInterpreter, ErgoLikeTestProvingInterpreter} @@ -143,12 +143,18 @@ class TestingInterpreterSpecification extends CompilerTestingCommons val env = Map( "dk1" -> dk1, "dk2" -> dk2, - "bytes1" -> Array[Byte](1, 2, 3), - "bytes2" -> Array[Byte](4, 5, 6), - "box1" -> testBox(10, TrueTree, 0, Seq(), Map( + "bytes1" -> Colls.fromArray(Array[Byte](1, 2, 3)), + "bytes2" -> Colls.fromArray(Array[Byte](4, 5, 6)), + "box1" -> (if(VersionContext.current.isJitActivated) { + CBox(testBox(10, TrueTree, 0, Seq(), Map( + reg1 -> IntArrayConstant(Array[Int](1, 2, 3)), + reg2 -> BoolArrayConstant(Array[Boolean](true, false, true)) + )))} else { + testBox(10, TrueTree, 0, Seq(), Map( reg1 -> IntArrayConstant(Array[Int](1, 2, 3)), reg2 -> BoolArrayConstant(Array[Boolean](true, false, true)) - )) + )) + }) ) val prop = mkTestErgoTree(compile(env, code)(IR).asBoolValue.toSigmaProp) val challenge = Array.fill(32)(Random.nextInt(100).toByte) diff --git a/sc/shared/src/test/scala/sigmastate/utxo/AVLTreeScriptsSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/AVLTreeScriptsSpecification.scala index 6b0c0080c9..ca7f9dd7c7 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/AVLTreeScriptsSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/AVLTreeScriptsSpecification.scala @@ -15,14 +15,13 @@ import sigmastate.helpers.{CompilerTestingCommons, ContextEnrichingTestProvingIn import sigmastate.helpers.TestingHelpers._ import sigmastate.interpreter.Interpreter.ScriptNameProp import sigma.ast.syntax._ -import sigma.Coll +import sigma.{AvlTree, Coll, Colls, Context} import sigma.ast.SAvlTree import sigma.ast.syntax.{GetVarByteArray, OptionValueOps} import sigma.compiler.ir.IRContext import sigma.data.{AvlTreeData, AvlTreeFlags, CSigmaProp, TrivialProp} import sigma.eval.SigmaDsl import sigma.interpreter.ProverResult -import sigma.{AvlTree, Context} import sigmastate.eval.Extensions.AvlTreeOps @@ -39,9 +38,6 @@ class AVLTreeScriptsSpecification extends CompilerTestingCommons def genKey(str: String): ADKey = ADKey @@@ Blake2b256("key: " + str) def genValue(str: String): ADValue = ADValue @@@ Blake2b256("val: " + str) - val inKey = genKey("init key") - val inValue = genValue("init value") - property("avl tree - removals") { case class AvlTreeContract[Spec <: ContractSpec] (ops: Coll[Coll[Byte]], proof: Coll[Byte], prover: Spec#ProvingParty) @@ -204,7 +200,7 @@ class AVLTreeScriptsSpecification extends CompilerTestingCommons val treeData = new AvlTreeData(digest.toColl, AvlTreeFlags.ReadOnly, 32, None) - val env = Map("key" -> key, "proof" -> proof) + val env = Map("key" -> Colls.fromArray(key), "proof" -> Colls.fromArray(proof)) val prop = compile(env, """SELF.R4[AvlTree].get.contains(key, proof)""").asBoolValue.toSigmaProp val propExp = IR.builder.mkMethodCall( @@ -374,7 +370,7 @@ class AVLTreeScriptsSpecification extends CompilerTestingCommons val treeData = SigmaDsl.avlTree(new AvlTreeData(digest.toColl, AvlTreeFlags.ReadOnly, 32, None)) val env = Map("proofId" -> proofId.toLong, - "keys" -> ConcreteCollection.fromItems(genKey("3"), genKey("4"), genKey("5"))) + "keys" -> Colls.fromItems(Colls.fromArray(genKey("3")), Colls.fromArray(genKey("4")), Colls.fromArray(genKey("5")))) val prop = compile(env, """{ | val tree = SELF.R4[AvlTree].get diff --git a/sc/shared/src/test/scala/sigmastate/utxo/ContextEnrichingSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/ContextEnrichingSpecification.scala index fe3dac68b3..3b2baa62fe 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/ContextEnrichingSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/ContextEnrichingSpecification.scala @@ -5,8 +5,8 @@ import scorex.crypto.hash.Blake2b256 import sigma.ast._ import sigma.ast.syntax._ import sigmastate._ -import sigmastate.helpers.{ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestInterpreter, CompilerTestingCommons} -import sigma.Coll +import sigmastate.helpers.{CompilerTestingCommons, ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestInterpreter} +import sigma.{Coll, Colls} class ContextEnrichingSpecification extends CompilerTestingCommons @@ -19,7 +19,7 @@ class ContextEnrichingSpecification extends CompilerTestingCommons val preimage = prover.contextExtenders(1).value.asInstanceOf[Coll[Byte]] val pubkey = prover.dlogSecrets.head.publicImage - val env = Map("blake" -> Blake2b256(preimage.toArray), "pubkey" -> pubkey) + val env = Map("blake" -> Colls.fromArray(Blake2b256(preimage.toArray)), "pubkey" -> pubkey) val prop = compile(env, """{ | pubkey && blake2b256(getVar[Coll[Byte]](1).get) == blake @@ -49,7 +49,7 @@ class ContextEnrichingSpecification extends CompilerTestingCommons val preimage2 = prover.contextExtenders(2).value.asInstanceOf[Coll[Byte]] val pubkey = prover.dlogSecrets.head.publicImage - val env = Map("blake" -> Blake2b256(preimage1.append(preimage2).toArray), "pubkey" -> pubkey) + val env = Map("blake" -> Colls.fromArray(Blake2b256(preimage1.append(preimage2).toArray)), "pubkey" -> pubkey) val prop = compile(env, """{ | pubkey && blake2b256(getVar[Coll[Byte]](1).get ++ getVar[Coll[Byte]](2).get) == blake @@ -89,7 +89,7 @@ class ContextEnrichingSpecification extends CompilerTestingCommons .withContextExtender(k1, ByteArrayConstant(v1)) .withContextExtender(k2, ByteArrayConstant(v2)) - val env = Map("k1" -> k1.toInt, "k2" -> k2.toInt, "r" -> r) + val env = Map("k1" -> k1.toInt, "k2" -> k2.toInt, "r" -> Colls.fromArray(r)) val prop = compile(env, "{ xor(getVar[Coll[Byte]](k1).get, getVar[Coll[Byte]](k2).get) == r }").asBoolValue.toSigmaProp val propTree = mkTestErgoTree(prop) @@ -119,7 +119,7 @@ class ContextEnrichingSpecification extends CompilerTestingCommons val prover = new ContextEnrichingTestProvingInterpreter val preimage = prover.contextExtenders(1).value.asInstanceOf[Coll[Byte]] - val env = Map("blake" -> Blake2b256(preimage.toArray)) + val env = Map("blake" -> Colls.fromArray(Blake2b256(preimage.toArray))) val prop = compile(env, """{ | blake2b256(getVar[Coll[Byte]](1).get) == blake @@ -149,7 +149,7 @@ class ContextEnrichingSpecification extends CompilerTestingCommons val preimage1 = prover.contextExtenders(1).value.asInstanceOf[Coll[Byte]] val preimage2 = prover.contextExtenders(2).value.asInstanceOf[Coll[Byte]] - val env = Map("blake" -> Blake2b256(preimage2.append(preimage1).toArray)) + val env = Map("blake" -> Colls.fromArray(Blake2b256(preimage2.append(preimage1).toArray))) val prop = compile(env, """{ | blake2b256(getVar[Coll[Byte]](2).get ++ getVar[Coll[Byte]](1).get) == blake diff --git a/sc/shared/src/test/scala/sigmastate/utxo/ErgoLikeInterpreterSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/ErgoLikeInterpreterSpecification.scala index 615a826649..f7adc194b5 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/ErgoLikeInterpreterSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/ErgoLikeInterpreterSpecification.scala @@ -5,11 +5,12 @@ import org.ergoplatform.ErgoBox.R4 import org.ergoplatform._ import org.scalatest.TryValues._ import scorex.crypto.hash.Blake2b256 +import sigma.{Colls, VersionContext} import sigma.ast.SCollection.SByteArray import sigma.ast._ import sigmastate._ import sigma.ast.syntax._ -import sigma.data.{AvlTreeData, ProveDHTuple, ProveDlog, TrivialProp} +import sigma.data.{AvlTreeData, CBox, ProveDHTuple, ProveDlog, TrivialProp} import sigma.util.Extensions.EcpOps import sigma.validation.ValidationException import sigmastate.eval._ @@ -51,8 +52,8 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons .withErgoTreeVersion(ergoTreeVersionInTests) val e = compile(Map( - "h1" -> ErgoTree.withSegregation(ergoTreeHeaderInTests, h1).bytes, - "h2" -> ErgoTree.withSegregation(ergoTreeHeaderInTests, h2).bytes), + "h1" -> Colls.fromArray(ErgoTree.withSegregation(ergoTreeHeaderInTests, h1).bytes), + "h2" -> Colls.fromArray(ErgoTree.withSegregation(ergoTreeHeaderInTests, h2).bytes)), "h1 == h1") val exp = TrueLeaf e shouldBe exp @@ -192,7 +193,7 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons val spendingTransaction = createTransaction(newBoxes) def mixingRequestProp(sender: ProveDlog, timeout: Int): ErgoTree = { - val env = Map("sender" -> sender, "timeout" -> timeout, "properHash" -> properHash) + val env = Map("sender" -> sender, "timeout" -> timeout, "properHash" -> Colls.fromArray(properHash)) val compiledProp = compile(env, """{ | val notTimePassed = HEIGHT <= timeout @@ -459,9 +460,14 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons val pubkey1 = prover.dlogSecrets.head.publicImage val pubkey2 = prover.dlogSecrets(1).publicImage + val tb = testBox(value = 10, ergoTree = mkTestErgoTree(pubkey1), creationHeight = 0) + val brother = if(VersionContext.current.isJitActivated) { + CBox(tb) + } else { + tb + } - val brother = testBox(value = 10, ergoTree = mkTestErgoTree(pubkey1), creationHeight = 0) - val brotherWithWrongId = testBox(value = 10, + val tbWithWrongId = testBox(value = 10, ergoTree = mkTestErgoTree(pubkey1), creationHeight = 0, boxIndex = 120: Short) @@ -482,7 +488,7 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons val propExpected = BinAnd( EQ(SizeOf(Inputs), IntConstant(2)), - EQ(ExtractId(ByIndex(Inputs, 0)), ExtractId(BoxConstant(brother)))).toSigmaProp + EQ(ExtractId(ByIndex(Inputs, 0)), ExtractId(BoxConstant(tb)))).toSigmaProp prop shouldBe propExpected // try a version of the script that matches the white paper @@ -496,18 +502,18 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons currentHeight = 50, lastBlockUtxoRoot = AvlTreeData.dummy, minerPubkey = ErgoLikeContextTesting.dummyPubkey, - boxesToSpend = IndexedSeq(brother, s), + boxesToSpend = IndexedSeq(tb, s), spendingTransaction, self = s, activatedVersionInTests) - val pr = prover.prove(emptyEnv + (ScriptNameProp -> "prove_prop"), propTree, ctx, fakeMessage).getOrThrow - verifier.verify(emptyEnv + (ScriptNameProp -> "verify_prop"), propTree, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true + val pr = prover.prove(emptyEnv, propTree, ctx, fakeMessage).getOrThrow + verifier.verify(emptyEnv, propTree, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true val wrongCtx = ErgoLikeContextTesting( currentHeight = 50, lastBlockUtxoRoot = AvlTreeData.dummy, minerPubkey = ErgoLikeContextTesting.dummyPubkey, - boxesToSpend = IndexedSeq(brotherWithWrongId, s), + boxesToSpend = IndexedSeq(tbWithWrongId, s), spendingTransaction, self = s, activatedVersionInTests) @@ -522,9 +528,9 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons }""".stripMargin).asBoolValue.toSigmaProp val prop2Tree = mkTestErgoTree(prop2) - prover.prove(emptyEnv + (ScriptNameProp -> "prove_prop2"), prop2Tree, ctx, fakeMessage).isFailure shouldBe true + prover.prove(emptyEnv, prop2Tree, ctx, fakeMessage).isFailure shouldBe true verifier - .verify(emptyEnv + (ScriptNameProp -> "verify_prop2"), prop2Tree, ctx, pr, fakeMessage) + .verify(emptyEnv, prop2Tree, ctx, pr, fakeMessage) .getOrThrow._1 shouldBe false } @@ -547,7 +553,12 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons val newBoxes = IndexedSeq(newBox) val spendingTransaction = createTransaction(newBoxes) - val env = Map("friend" -> friend) + val friendVar = if(VersionContext.current.isJitActivated){ + CBox(friend) + } else { + friend + } + val env = Map("friend" -> friendVar) val prop = compile(env, """{ | @@ -623,7 +634,7 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons val helloHash = Blake2b256.hash(preimageHello) - val env = Map("helloHash" -> helloHash) + val env = Map("helloHash" -> Colls.fromArray(helloHash)) val prop = compile(env, """{ | val cond = INPUTS(0).value > 10 diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/AtomicSwapExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/AtomicSwapExampleSpecification.scala index 131aba22d0..7323dc6118 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/AtomicSwapExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/AtomicSwapExampleSpecification.scala @@ -39,7 +39,6 @@ class AtomicSwapExampleSpecification extends CompilerTestingCommons with Compile val deadlineB = 500 val env = Map( - ScriptNameProp -> "atomic", "height1" -> height1, "height2" -> height2, "deadlineBob" -> deadlineB, "deadlineAlice" -> deadlineA, "pubkeyA" -> pubkeyA, "pubkeyB" -> pubkeyB, "hx" -> hx) diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/ColdWalletAdvContractExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/ColdWalletAdvContractExampleSpecification.scala index 9bcfd81ecf..ef100a36a5 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/ColdWalletAdvContractExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/ColdWalletAdvContractExampleSpecification.scala @@ -9,6 +9,7 @@ import sigmastate.helpers.{CompilerTestingCommons, ContextEnrichingTestProvingIn import sigmastate.helpers.TestingHelpers._ import sigmastate.interpreter.Interpreter.ScriptNameProp import sigma.ast.syntax._ +import sigmastate.interpreter.Interpreter class ColdWalletAdvContractExampleSpecification extends CompilerTestingCommons @@ -35,7 +36,6 @@ class ColdWalletAdvContractExampleSpecification extends CompilerTestingCommons val minSpend = 100 val env = Map( - ScriptNameProp -> "env", "user1" -> alicePubKey, "user2" -> bobPubKey, "user3" -> carolPubKey, @@ -109,12 +109,9 @@ class ColdWalletAdvContractExampleSpecification extends CompilerTestingCommons ) ) - val dave = new ErgoLikeTestProvingInterpreter // paying to dave, some arbitrary user - val davePubKey = dave.dlogSecrets.head.publicImage - val firstWithdrawHeight = depositHeight + 1 // - val spendEnv = Map(ScriptNameProp -> "spendEnv") + val spendEnv = Interpreter.emptyEnv // One of Alice, Bob or Carol withdraws val firstWithdrawAmount1Key = depositAmount * percent1Key / 100 // less than or equal to percent diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/ColdWalletContractExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/ColdWalletContractExampleSpecification.scala index 1948bc16d9..bfeb9732a8 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/ColdWalletContractExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/ColdWalletContractExampleSpecification.scala @@ -31,7 +31,6 @@ class ColdWalletContractExampleSpecification extends CompilerTestingCommons val minSpend = 100 val env = Map( - ScriptNameProp -> "env", "alice" -> alicePubKey, "bob" -> bobPubKey, "blocksIn24h" -> IntConstant(blocksIn24h), diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/DHTupleExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/DHTupleExampleSpecification.scala index 9246cc1c8e..60569d061e 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/DHTupleExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/DHTupleExampleSpecification.scala @@ -38,7 +38,6 @@ class DHTupleExampleSpecification extends CompilerTestingCommons val g_x = alicePubKey.value // g_x is Alice's public key (g_x = g^x) val env = Map( - ScriptNameProp -> "env", "g" -> g.toGroupElement, "g_x" -> g_x.toGroupElement ) diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/DemurrageExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/DemurrageExampleSpecification.scala index 4ec6922c38..6d4ff117d3 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/DemurrageExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/DemurrageExampleSpecification.scala @@ -49,7 +49,6 @@ class DemurrageExampleSpecification extends CompilerTestingCommons val regScript = userProver.dlogSecrets.head.publicImage val env = Map( - ScriptNameProp -> "Demurrage", "demurragePeriod" -> demurragePeriod, "demurrageCoeff" -> demurrageCoeff, "regScript" -> regScript diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/IcoExample.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/IcoExample.scala index 556c56bc03..9c81e4539d 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/IcoExample.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/IcoExample.scala @@ -252,8 +252,7 @@ class IcoExample extends CompilerTestingCommons private val feeBytes = feeProp.bytes val env = Map( - ScriptNameProp -> "withdrawalScriptEnv", - "feeBytes" -> feeBytes, + "feeBytes" -> Colls.fromArray(feeBytes), "projectPubKey" -> project.secrets.head.publicImage ) lazy val withdrawalScript: SigmaPropValue = compile(env, @@ -313,7 +312,7 @@ class IcoExample extends CompilerTestingCommons Blake2b256(ErgoTreeSerializer.DefaultSerializer.serializeErgoTree(withdrawalTree)) } - def issuanceScript: SigmaPropValue = compile(env.updated("nextStageScriptHash", wsHash), + def issuanceScript: SigmaPropValue = compile(env.updated("nextStageScriptHash", Colls.fromArray(wsHash)), """{ | val openTree = SELF.R5[AvlTree].get | @@ -349,7 +348,7 @@ class IcoExample extends CompilerTestingCommons Blake2b256(ErgoTreeSerializer.DefaultSerializer.serializeErgoTree(tree)) } - def fundingScript: SigmaPropValue = compile(env.updated("nextStageScriptHash", issuanceHash), + def fundingScript: SigmaPropValue = compile(env.updated("nextStageScriptHash", Colls.fromArray(issuanceHash)), """{ | | val selfIndexIsZero = INPUTS(0).id == SELF.id diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/LetsSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/LetsSpecification.scala index 556fbf9c06..609a127bec 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/LetsSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/LetsSpecification.scala @@ -178,7 +178,7 @@ class LetsSpecification extends CompilerTestingCommons with CompilerCrossVersion val letsTokenId = Digest32Coll @@ Colls.fromArray(Array.fill(32)(Random.nextInt(100).toByte)) - val env = Map(ScriptNameProp -> "withdrawalScriptEnv", "letsToken" -> ByteArrayConstant(letsTokenId)) + val env = Map("letsToken" -> ByteArrayConstant(letsTokenId)) private val miningRewardsDelay = 720 private val feeProp = ErgoTreePredef.feeProposition(miningRewardsDelay) // create ErgoTree v0 @@ -235,7 +235,7 @@ class LetsSpecification extends CompilerTestingCommons with CompilerCrossVersion def userContractHash = Blake2b256(ErgoTreeSerializer.DefaultSerializer.serializeErgoTree(exchangeTree)) - def managementScript = compile(env.updated("userContractHash", userContractHash), + def managementScript = compile(env.updated("userContractHash", Colls.fromArray(userContractHash)), """{ | | val selfOut = OUTPUTS(0) diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/MixExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/MixExampleSpecification.scala index fc19a485ee..fdb241a908 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/MixExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/MixExampleSpecification.scala @@ -3,6 +3,7 @@ package sigmastate.utxo.examples import java.math.BigInteger import org.ergoplatform.ErgoBox.{R4, R5} import scorex.crypto.hash.Blake2b256 +import sigma.Colls import sigma.data.{AvlTreeData, ProveDHTuple, ProveDlog} import sigma.util.Extensions.EcpOps import sigmastate.CompilerCrossVersionProps @@ -41,7 +42,6 @@ class MixExampleSpecification extends CompilerTestingCommons // val alicePubKey:ProveDlog = ProveDlog(g_x) val fullMixEnv = Map( - ScriptNameProp -> "fullMixEnv", "g" -> g.toGroupElement, "gX" -> gX.toGroupElement ) @@ -60,10 +60,9 @@ class MixExampleSpecification extends CompilerTestingCommons ).asSigmaProp) val halfMixEnv = Map( - ScriptNameProp -> "halfMixEnv", "g" -> g.toGroupElement, "gX" -> gX.toGroupElement, - "fullMixScriptHash" -> Blake2b256(fullMixScript.bytes) + "fullMixScriptHash" -> Colls.fromArray(Blake2b256(fullMixScript.bytes)) ) // Note that below script allows Alice to spend the half-mix output anytime before Bob spends it. diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/RPSGameExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/RPSGameExampleSpecification.scala index c695b8e07d..3ca85e892b 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/RPSGameExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/RPSGameExampleSpecification.scala @@ -4,6 +4,7 @@ package sigmastate.utxo.examples import org.ergoplatform.ErgoBox.{R4, R5, R6, R7} import scorex.crypto.hash.Blake2b256 import scorex.utils.Random +import sigma.Colls import sigma.data.{AvlTreeData, ProveDlog} import sigma.ast.{ByteArrayConstant, ByteConstant, ErgoTree, IntConstant, SigmaPropConstant} import sigmastate._ @@ -51,9 +52,8 @@ class RPSGameExampleSpecification extends CompilerTestingCommons val h = Blake2b256(s :+ a) // Alice's commitment val fullGameEnv = Map( - ScriptNameProp -> "fullGameScriptEnv", "alice" -> alicePubKey, - "k" -> h + "k" -> Colls.fromArray(h) ) val fullGameScript = mkTestErgoTree(compile(fullGameEnv, @@ -78,9 +78,8 @@ class RPSGameExampleSpecification extends CompilerTestingCommons ).asSigmaProp) val halfGameEnv = Map( - ScriptNameProp -> "halfGameScript", "alice" -> alicePubKey, - "fullGameScriptHash" -> Blake2b256(fullGameScript.bytes) + "fullGameScriptHash" -> Colls.fromArray(Blake2b256(fullGameScript.bytes)) ) // Note that below script allows Alice to spend the half-game output anytime before Bob spends it. diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/ReversibleTxExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/ReversibleTxExampleSpecification.scala index 4294dc5b4b..fad547460f 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/ReversibleTxExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/ReversibleTxExampleSpecification.scala @@ -3,13 +3,14 @@ package sigmastate.utxo.examples import org.ergoplatform.ErgoBox.{R4, R5} import org.ergoplatform._ import scorex.crypto.hash.Blake2b256 +import sigma.Colls import sigma.data.AvlTreeData import sigma.ast.{ErgoTree, IntConstant, SigmaPropConstant} import sigmastate._ import sigmastate.helpers.{CompilerTestingCommons, ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestInterpreter} import sigmastate.helpers.TestingHelpers._ -import sigmastate.interpreter.Interpreter.ScriptNameProp import sigma.ast.syntax._ +import sigmastate.interpreter.Interpreter class ReversibleTxExampleSpecification extends CompilerTestingCommons @@ -79,7 +80,6 @@ class ReversibleTxExampleSpecification extends CompilerTestingCommons val carolPubKey = carol.dlogSecrets.head.publicImage val withdrawEnv = Map( - ScriptNameProp -> "withdrawEnv", "carol" -> carolPubKey // this pub key can reverse payments ) @@ -94,12 +94,11 @@ class ReversibleTxExampleSpecification extends CompilerTestingCommons val blocksIn24h = 500 val feeProposition = ErgoTreePredef.feeProposition() val depositEnv = Map( - ScriptNameProp -> "depositEnv", "alice" -> alicePubKey, "blocksIn24h" -> blocksIn24h, "maxFee" -> 10L, - "feePropositionBytes" -> feeProposition.bytes, - "withdrawScriptHash" -> Blake2b256(withdrawScript.bytes) + "feePropositionBytes" -> Colls.fromArray(feeProposition.bytes), + "withdrawScriptHash" -> Colls.fromArray(Blake2b256(withdrawScript.bytes)) ) val depositScript = mkTestErgoTree(compile(depositEnv, @@ -189,7 +188,7 @@ class ReversibleTxExampleSpecification extends CompilerTestingCommons self = reversibleWithdrawOutput, activatedVersionInTests ) - val spendEnv = Map(ScriptNameProp -> "spendEnv") + val spendEnv = Interpreter.emptyEnv val proofBobSpend = bob.prove(spendEnv, withdrawScript, bobSpendContext, fakeMessage).get.proof diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/TimedPaymentExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/TimedPaymentExampleSpecification.scala index 2657a49eb0..fb1c275fb8 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/TimedPaymentExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/TimedPaymentExampleSpecification.scala @@ -27,7 +27,6 @@ class TimedPaymentExampleSpecification extends CompilerTestingCommons val bobPubKey = bob.dlogSecrets.head.publicImage val env = Map( - ScriptNameProp -> "env", "alice" -> alicePubKey ) diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/XorGameExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/XorGameExampleSpecification.scala index b3d6d4eff8..8821ccb72e 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/XorGameExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/XorGameExampleSpecification.scala @@ -4,6 +4,7 @@ package sigmastate.utxo.examples import org.ergoplatform.ErgoBox.{R4, R5, R6} import scorex.crypto.hash.Blake2b256 import scorex.utils.Random +import sigma.Colls import sigma.data.{AvlTreeData, ProveDlog} import sigma.ast.{ByteArrayConstant, ByteConstant, IntConstant, SigmaPropConstant} import sigmastate._ @@ -51,9 +52,8 @@ class XorGameExampleSpecification extends CompilerTestingCommons val h = Blake2b256(s :+ a) // Alice's commitment val fullGameEnv = Map( - ScriptNameProp -> "fullGameScriptEnv", "alice" -> alicePubKey, - "h" -> h + "h" -> Colls.fromArray(h) ) val fullGameScript = mkTestErgoTree(compile(fullGameEnv, @@ -73,9 +73,8 @@ class XorGameExampleSpecification extends CompilerTestingCommons ).asSigmaProp) val halfGameEnv = Map( - ScriptNameProp -> "halfGameScript", "alice" -> alicePubKey, - "fullGameScriptHash" -> Blake2b256(fullGameScript.bytes) + "fullGameScriptHash" -> Colls.fromArray(Blake2b256(fullGameScript.bytes)) ) // Note that below script allows Alice to spend the half-game output anytime before Bob spends it.