Skip to content

Commit

Permalink
polishing, LSV6 test
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Jul 26, 2024
1 parent b677b18 commit e501a8b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
19 changes: 10 additions & 9 deletions data/shared/src/main/scala/sigma/ast/methods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1467,18 +1467,19 @@ case object SHeaderMethods extends MonoTypeMethods {
E.checkPow_eval(mc, header)
}

private lazy val v5Methods = super.getMethods() ++ Seq(
idMethod, versionMethod, parentIdMethod, ADProofsRootMethod, stateRootMethod, transactionsRootMethod,
timestampMethod, nBitsMethod, heightMethod, extensionRootMethod, minerPkMethod, powOnetimePkMethod,
powNonceMethod, powDistanceMethod, votesMethod)

// 6.0 : checkPow method added
private lazy val v6Methods = v5Methods ++ Seq(checkPowMethod)

protected override def getMethods() = {
if (VersionContext.current.isV6SoftForkActivated) {
// 6.0 : checkPow method added
super.getMethods() ++ Seq(
idMethod, versionMethod, parentIdMethod, ADProofsRootMethod, stateRootMethod, transactionsRootMethod,
timestampMethod, nBitsMethod, heightMethod, extensionRootMethod, minerPkMethod, powOnetimePkMethod,
powNonceMethod, powDistanceMethod, votesMethod, checkPowMethod)
v6Methods
} else {
super.getMethods() ++ Seq(
idMethod, versionMethod, parentIdMethod, ADProofsRootMethod, stateRootMethod, transactionsRootMethod,
timestampMethod, nBitsMethod, heightMethod, extensionRootMethod, minerPkMethod, powOnetimePkMethod,
powNonceMethod, powDistanceMethod, votesMethod)
v5Methods
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ abstract class ErgoTreeEvaluator {
mc: MethodCall, tree: AvlTree,
operations: Coll[Coll[Byte]], proof: Coll[Byte]): Option[AvlTree]

/** Implements evaluation of Header.checkPow method call ErgoTree node. */
def checkPow_eval(mc: MethodCall, header: Header): Boolean

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class CErgoTreeEvaluator(
}
}

/** Implements evaluation of Header.checkPow method call ErgoTree node. */
override def checkPow_eval(mc: MethodCall, header: Header): Boolean = {
val checkPowCostInfo = OperationCostInfo(checkPowMethod.costKind.asInstanceOf[FixedCost], NamedDesc("Header.checkPow"))
fixedCostOp(checkPowCostInfo){
Expand Down
30 changes: 29 additions & 1 deletion sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sigma

import sigma.ast.{Apply, Downcast, FixedCost, FixedCostItem, FuncValue, GetVar, JitCost, OptionGet, SBigInt, SByte, SInt, SLong, SShort, ValUse}
import sigma.ast.{Apply, Downcast, FixedCost, FixedCostItem, FuncValue, GetVar, JitCost, MethodCall, OptionGet, SBigInt, SBoolean, SByte, SHeader, SHeaderMethods, SInt, SLong, SShort, ValUse, Value}
import sigma.data.{CBigInt, ExactNumeric}
import sigma.eval.SigmaDsl
import sigma.util.Extensions.{BooleanOps, ByteOps, IntOps, LongOps}
Expand Down Expand Up @@ -338,6 +338,34 @@ class LanguageSpecificationV6 extends LanguageSpecificationBase { suite =>
}
}

property("Header new methods") {
def checkPoW = newFeature({ (x: Header) => x.checkPow},
"{ (x: Header) => x.checkPow }",
FuncValue(
Array((1, SHeader)),
MethodCall.typed[Value[SBoolean.type]](
ValUse(1, SHeader),
SHeaderMethods.getMethodByName("checkPow"),
IndexedSeq(),
Map()
)
),
sinceVersion = VersionContext.V6SoftForkVersion)

if (VersionContext.current.isV6SoftForkActivated) {
forAll { x: Header =>
Seq(checkPoW).map(_.checkEquality(x))
}
} else {
an[Exception] shouldBe thrownBy {
forAll { x: Header =>
Seq(checkPoW).map(_.checkEquality(x))
}
}
}

}

// TODO v6.0: implement Option.fold (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/479)
property("Option new methods") {
val n = ExactNumeric.LongIsExactNumeric
Expand Down

0 comments on commit e501a8b

Please sign in to comment.