From 1ca2932419798fa8f39c0d331ba3d00024e148d0 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Sun, 20 Oct 2024 22:06:58 +0300 Subject: [PATCH 1/2] more scripts in test --- .../mempool/ErgoNodeTransactionSpec.scala | 50 +++++++++++-------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/src/test/scala/org/ergoplatform/modifiers/mempool/ErgoNodeTransactionSpec.scala b/src/test/scala/org/ergoplatform/modifiers/mempool/ErgoNodeTransactionSpec.scala index 4e7969b4cc..db1cc3da43 100644 --- a/src/test/scala/org/ergoplatform/modifiers/mempool/ErgoNodeTransactionSpec.scala +++ b/src/test/scala/org/ergoplatform/modifiers/mempool/ErgoNodeTransactionSpec.scala @@ -494,35 +494,45 @@ class ErgoNodeTransactionSpec extends ErgoCorePropertyTest { * not recognizing it. */ property("Soft-forked execution of Ergoscript containing unknown methods") { + val trees = Array( + "1b130206022edf0580fcf622d193db060873007301", // contains SBigInt.nbits + "19110204040400d191b1dc6a03dd0173007301", // sigmaProp(Global.serialize(2).size > 0) + "1916030601ff090105090100d192dc061473000173017302" // { val b = bigInt("-1"); val m = unsignedBigInt("5"); val ub = b.toUnsignedMod(m); ub >= 0 } + // todo: scripts with optional / Header values + ) - val activatedVersion = 3.toByte - val params = new Parameters(0, LaunchParameters.parametersTable.updated(123, activatedVersion + 1), ErgoValidationSettingsUpdate.empty) + trees.foreach { tree => + val activatedVersion = 3.toByte + val params = new Parameters(0, LaunchParameters.parametersTable.updated(123, activatedVersion + 1), ErgoValidationSettingsUpdate.empty) - // for next version, rule 1011 should be replaced , otherwise transaction validation will fail - // in this test, the rule is replaced with self, but for real activation this choice should be revised - val ruleId = CheckAndGetMethod.id - val updVs = ErgoValidationSettings.initial.updated(ErgoValidationSettingsUpdate(Seq(), Seq(ruleId -> ReplacedRule(ruleId)))) + // for next version, rule 1011 should be replaced , otherwise transaction validation will fail + // in this test, the rule is replaced with self, but for real activation this choice should be revised + val ruleId = CheckAndGetMethod.id + val updVs = ErgoValidationSettings.initial.updated(ErgoValidationSettingsUpdate(Seq(), Seq(ruleId -> ReplacedRule(ruleId), 1007.toShort -> ReplacedRule(ruleId)))) - val stateContext = emptyStateContext.copy(currentParameters = params, validationSettings = updVs)(chainSettings) - stateContext.blockVersion shouldBe activatedVersion + 1 + val stateContext = emptyStateContext.copy(currentParameters = params, validationSettings = updVs)(chainSettings) + stateContext.blockVersion shouldBe activatedVersion + 1 - // the following ergo tree contains SBigInt.nbits method which is not supported by this client (as of 5.x version) - // ergo tree version is 3, less value (e.g. version = 2 which gives 1a130206022edf0580fcf622d193db060873007301) - // also works - val ergoTree = DefaultSerializer.deserializeErgoTree(Base16.decode("1b130206022edf0580fcf622d193db060873007301").get) + // the following ergo tree contains a method or a type which is not supported by this client (as of 5.x version) + val ergoTree = DefaultSerializer.deserializeErgoTree(Base16.decode(tree).get) - ergoTree.root.isLeft shouldBe true // unparsed + ergoTree.root.isLeft shouldBe true // unparsed - val b = new ErgoBox(1000000000L, ergoTree, Colls.emptyColl, - Map.empty, ModifierId @@ "c95c2ccf55e03cac6659f71ca4df832d28e2375569cec178dcb17f3e2e5f7742", - 0, 0) - val input = Input(b.id, ProverResult(Array.emptyByteArray, ContextExtension.empty)) + val b = new ErgoBox(1000000000L, ergoTree, Colls.emptyColl, + Map.empty, ModifierId @@ "c95c2ccf55e03cac6659f71ca4df832d28e2375569cec178dcb17f3e2e5f7742", + 0, 0) + val input = Input(b.id, ProverResult(Array.emptyByteArray, ContextExtension.empty)) - val oc = new ErgoBoxCandidate(b.value, b.ergoTree, b.creationHeight) + val oc = new ErgoBoxCandidate(b.value, b.ergoTree, b.creationHeight) - val utx = new ErgoTransaction(IndexedSeq(input), IndexedSeq.empty, IndexedSeq(oc)) + val utx = new ErgoTransaction(IndexedSeq(input), IndexedSeq.empty, IndexedSeq(oc)) - utx.statefulValidity(IndexedSeq(b), IndexedSeq.empty, stateContext, 0)(defaultProver).isSuccess shouldBe true + utx.statefulValidity(IndexedSeq(b), IndexedSeq.empty, stateContext, 0)(defaultProver).isSuccess shouldBe true + } } + // todo: make script for + // "190b010d0880d1937300850880", // { val b = 1.toByte; b.toBits == Coll(false, false, false, false, false, false, false, true) } + // which is successfully parsed + } From 6a89b135f936d387ba3a2b07f8aebc691e30f96f Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Mon, 21 Oct 2024 18:42:14 +0300 Subject: [PATCH 2/2] tree w. toBits added --- .../modifiers/mempool/ErgoNodeTransactionSpec.scala | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/test/scala/org/ergoplatform/modifiers/mempool/ErgoNodeTransactionSpec.scala b/src/test/scala/org/ergoplatform/modifiers/mempool/ErgoNodeTransactionSpec.scala index db1cc3da43..0284724618 100644 --- a/src/test/scala/org/ergoplatform/modifiers/mempool/ErgoNodeTransactionSpec.scala +++ b/src/test/scala/org/ergoplatform/modifiers/mempool/ErgoNodeTransactionSpec.scala @@ -497,7 +497,8 @@ class ErgoNodeTransactionSpec extends ErgoCorePropertyTest { val trees = Array( "1b130206022edf0580fcf622d193db060873007301", // contains SBigInt.nbits "19110204040400d191b1dc6a03dd0173007301", // sigmaProp(Global.serialize(2).size > 0) - "1916030601ff090105090100d192dc061473000173017302" // { val b = bigInt("-1"); val m = unsignedBigInt("5"); val ub = b.toUnsignedMod(m); ub >= 0 } + "1916030601ff090105090100d192dc061473000173017302", // { val b = bigInt("-1"); val m = unsignedBigInt("5"); val ub = b.toUnsignedMod(m); ub >= 0 } + "190d00d193db0207e4e30102850880" // { val b = getVar[Byte](1).get; b.toBits == Coll(false, false, false, false, false, false, false, true) } // todo: scripts with optional / Header values ) @@ -530,9 +531,5 @@ class ErgoNodeTransactionSpec extends ErgoCorePropertyTest { utx.statefulValidity(IndexedSeq(b), IndexedSeq.empty, stateContext, 0)(defaultProver).isSuccess shouldBe true } } - - // todo: make script for - // "190b010d0880d1937300850880", // { val b = 1.toByte; b.toBits == Coll(false, false, false, false, false, false, false, true) } - // which is successfully parsed - + }