From cb9e9eb01d51cede18146c126d134b5f5f882526 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Wed, 25 Sep 2024 00:35:12 +0300 Subject: [PATCH] fixing JS tests --- core/shared/src/main/scala/sigma/SigmaDsl.scala | 2 +- .../src/main/scala/sigma/reflection/ReflectionData.scala | 4 ++-- data/shared/src/main/scala/sigma/SigmaDataReflection.scala | 5 +++++ data/shared/src/main/scala/sigma/ast/methods.scala | 7 +++---- .../src/main/scala/sigma/data/CSigmaDslBuilder.scala | 4 +++- .../main/scala/sigma/compiler/ir/GraphIRReflection.scala | 5 +++++ .../compiler/ir/wrappers/sigma/impl/SigmaDslImpl.scala | 6 +++--- .../src/test/scala/sigma/LanguageSpecificationV6.scala | 6 +++--- sdk/js/src/main/scala/org/ergoplatform/sdk/js/Isos.scala | 2 +- 9 files changed, 26 insertions(+), 15 deletions(-) diff --git a/core/shared/src/main/scala/sigma/SigmaDsl.scala b/core/shared/src/main/scala/sigma/SigmaDsl.scala index 8731a61b16..0d0cdd57eb 100644 --- a/core/shared/src/main/scala/sigma/SigmaDsl.scala +++ b/core/shared/src/main/scala/sigma/SigmaDsl.scala @@ -765,6 +765,6 @@ trait SigmaDslBuilder { def xor(l: Coll[Byte], r: Coll[Byte]): Coll[Byte] /** Deserializes provided `bytes` into a value of type `T`. **/ - def deserializeTo[T](tpe: SType, bytes: Coll[Byte])(implicit cT: RType[T]): T + def deserializeTo[T](bytes: Coll[Byte])(implicit cT: RType[T]): T } diff --git a/core/shared/src/main/scala/sigma/reflection/ReflectionData.scala b/core/shared/src/main/scala/sigma/reflection/ReflectionData.scala index cb351a4932..13ee0bc79e 100644 --- a/core/shared/src/main/scala/sigma/reflection/ReflectionData.scala +++ b/core/shared/src/main/scala/sigma/reflection/ReflectionData.scala @@ -451,8 +451,8 @@ object ReflectionData { mkMethod(clazz, "decodePoint", Array[Class[_]](cColl)) { (obj, args) => obj.asInstanceOf[SigmaDslBuilder].decodePoint(args(0).asInstanceOf[Coll[Byte]]) }, - mkMethod(clazz, "deserializeTo", Array[Class[_]](classOf[SType], cColl, classOf[RType[_]])) { (obj, args) => - obj.asInstanceOf[SigmaDslBuilder].deserializeTo(args(0).asInstanceOf[SType], args(1).asInstanceOf[Coll[Byte]])(args(2).asInstanceOf[RType[_]]) + mkMethod(clazz, "deserializeTo", Array[Class[_]](cColl, classOf[RType[_]])) { (obj, args) => + obj.asInstanceOf[SigmaDslBuilder].deserializeTo(args(0).asInstanceOf[Coll[Byte]])(args(1).asInstanceOf[RType[_]]) } ) ) diff --git a/data/shared/src/main/scala/sigma/SigmaDataReflection.scala b/data/shared/src/main/scala/sigma/SigmaDataReflection.scala index c64bdee877..73babfbdc2 100644 --- a/data/shared/src/main/scala/sigma/SigmaDataReflection.scala +++ b/data/shared/src/main/scala/sigma/SigmaDataReflection.scala @@ -335,6 +335,11 @@ object SigmaDataReflection { obj.asInstanceOf[SGlobalMethods.type].serialize_eval(args(0).asInstanceOf[MethodCall], args(1).asInstanceOf[SigmaDslBuilder], args(2).asInstanceOf[SType#WrappedType])(args(3).asInstanceOf[ErgoTreeEvaluator]) + }, + mkMethod(clazz, "deserializeTo_eval", Array[Class[_]](classOf[MethodCall], classOf[SigmaDslBuilder], classOf[Coll[_]], classOf[ErgoTreeEvaluator])) { (obj, args) => + obj.asInstanceOf[SGlobalMethods.type].deserializeTo_eval(args(0).asInstanceOf[MethodCall], + args(1).asInstanceOf[SigmaDslBuilder], + args(2).asInstanceOf[Coll[Byte]])(args(3).asInstanceOf[ErgoTreeEvaluator]) } ) ) diff --git a/data/shared/src/main/scala/sigma/ast/methods.scala b/data/shared/src/main/scala/sigma/ast/methods.scala index dd174e2f3e..43cda702d0 100644 --- a/data/shared/src/main/scala/sigma/ast/methods.scala +++ b/data/shared/src/main/scala/sigma/ast/methods.scala @@ -1687,11 +1687,10 @@ case object SGlobalMethods extends MonoTypeMethods { private val deserializeCostKind = PerItemCost( baseCost = JitCost(20), perChunkCost = JitCost(7), chunkSize = 128) - lazy val desJava = ownerType.reprClass.getMethod("deserializeTo", classOf[SType], classOf[Coll[Byte]], classOf[RType[_]]) - lazy val deserializeToMethod = SMethod( this, "deserializeTo", SFunc(Array(SGlobal, SByteArray), tT, Array(paramT)), 4, deserializeCostKind, Seq(tT)) - .withIRInfo(MethodCallIrBuilder, desJava) + .withIRInfo(MethodCallIrBuilder, + javaMethodOf[SigmaDslBuilder, Coll[Byte], RType[_]]("deserializeTo")) .withInfo(MethodCall, "Deserialize provided bytes into an object of requested type", ArgInfo("first", "Bytes to deserialize")) @@ -1709,7 +1708,7 @@ case object SGlobalMethods extends MonoTypeMethods { val tpe = mc.tpe val cT = stypeToRType(tpe) E.addSeqCost(deserializeCostKind, bytes.length, deserializeToMethod.opDesc) { () => - G.deserializeTo(tpe, bytes)(cT) + G.deserializeTo(bytes)(cT) } } diff --git a/data/shared/src/main/scala/sigma/data/CSigmaDslBuilder.scala b/data/shared/src/main/scala/sigma/data/CSigmaDslBuilder.scala index bdb470782b..cdd7d66cee 100644 --- a/data/shared/src/main/scala/sigma/data/CSigmaDslBuilder.scala +++ b/data/shared/src/main/scala/sigma/data/CSigmaDslBuilder.scala @@ -6,6 +6,7 @@ import org.ergoplatform.validation.ValidationRules import scorex.crypto.hash.{Blake2b256, Sha256} import scorex.util.serialization.VLQByteBufferReader import scorex.utils.Longs +import sigma.Evaluation.rtypeToSType import sigma.ast.{AtLeast, SType, SubstConstants} import sigma.crypto.{CryptoConstants, EcPointType, Ecp} import sigma.eval.Extensions.EvalCollOps @@ -211,7 +212,8 @@ class CSigmaDslBuilder extends SigmaDslBuilder { dsl => Colls.fromArray(w.toBytes) } - def deserializeTo[T](tpe: SType, bytes: Coll[Byte])(implicit cT: RType[T]): T = { + def deserializeTo[T](bytes: Coll[Byte])(implicit cT: RType[T]): T = { + val tpe = rtypeToSType(cT) val reader = new SigmaByteReader(new VLQByteBufferReader(ByteBuffer.wrap(bytes.toArray)), new ConstantStore(), false) val res = DataSerializer.deserialize(tpe, reader) res.asInstanceOf[T] diff --git a/sc/shared/src/main/scala/sigma/compiler/ir/GraphIRReflection.scala b/sc/shared/src/main/scala/sigma/compiler/ir/GraphIRReflection.scala index dcdce623ac..658fb4693b 100644 --- a/sc/shared/src/main/scala/sigma/compiler/ir/GraphIRReflection.scala +++ b/sc/shared/src/main/scala/sigma/compiler/ir/GraphIRReflection.scala @@ -1,5 +1,7 @@ package sigma.compiler.ir +import sigma.Coll +import sigma.ast.SType import sigma.compiler.ir.primitives.Thunks import sigma.data.RType import sigma.reflection.ReflectionData.registerClassEntry @@ -510,6 +512,9 @@ object GraphIRReflection { }, mkMethod(clazz, "serialize", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) => obj.asInstanceOf[ctx.SigmaDslBuilder].serialize(args(0).asInstanceOf[ctx.Ref[Any]]) + }, + mkMethod(clazz, "deserializeTo", Array[Class[_]](classOf[Base#Ref[_]], classOf[TypeDescs#Elem[_]])) { (obj, args) => + obj.asInstanceOf[ctx.SigmaDslBuilder].deserializeTo(args(0).asInstanceOf[ctx.Ref[ctx.Coll[Byte]]])(args(1).asInstanceOf[ctx.Elem[SType]]) } ) ) diff --git a/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/impl/SigmaDslImpl.scala b/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/impl/SigmaDslImpl.scala index 2c64e09691..4988e425ad 100644 --- a/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/impl/SigmaDslImpl.scala +++ b/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/impl/SigmaDslImpl.scala @@ -1976,7 +1976,7 @@ object SigmaDslBuilder extends EntityObject("SigmaDslBuilder") { asRep[T](mkMethodCall(self, SigmaDslBuilderClass.getMethod("deserializeTo", classOf[Sym], classOf[Elem[T]]), Array[AnyRef](l, cT), - true, false, element[T])) + true, false, element[T](cT), Map(tT -> Evaluation.rtypeToSType(cT.sourceType)))) } } @@ -2147,9 +2147,9 @@ object SigmaDslBuilder extends EntityObject("SigmaDslBuilder") { def deserializeTo[T](bytes: Ref[Coll[Byte]])(implicit cT: Elem[T]): Ref[T] = { asRep[T](mkMethodCall(source, - SigmaDslBuilderClass.getMethod("deserializeTo", classOf[Sym], classOf[Elem[T]]), + SigmaDslBuilderClass.getMethod("deserializeTo", classOf[Sym], classOf[Elem[_]]), Array[AnyRef](bytes, cT), - true, true, element[T])) + true, true, element[T](cT), Map(tT -> Evaluation.rtypeToSType(cT.sourceType)))) } } diff --git a/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala b/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala index 2f2a2aa522..22487c0a33 100644 --- a/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala +++ b/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala @@ -1525,7 +1525,7 @@ class LanguageSpecificationV6 extends LanguageSpecificationBase { suite => property("Global.deserializeTo - group element") { def deserializeTo: Feature[GroupElement, Boolean] = { newFeature( - { (x: GroupElement) => CSigmaDslBuilder.deserializeTo[GroupElement](SGroupElement, x.getEncoded) == x}, + { (x: GroupElement) => CSigmaDslBuilder.deserializeTo[GroupElement](x.getEncoded) == x}, "{ (x: GroupElement) => Global.deserializeTo[GroupElement](x.getEncoded) == x }", FuncValue( Array((1, SGroupElement)), @@ -1568,7 +1568,7 @@ class LanguageSpecificationV6 extends LanguageSpecificationBase { suite => def deserializeTo: Feature[Header, Boolean] = { newFeature( - { (x: Header) => CSigmaDslBuilder.deserializeTo[Header](SHeader, CSigmaDslBuilder.serialize(x)) == x}, + { (x: Header) => CSigmaDslBuilder.deserializeTo[Header](CSigmaDslBuilder.serialize(x)) == x}, "{ (x: Header) => Global.deserializeTo[Header](serialize(x)) == x }", sinceVersion = VersionContext.V6SoftForkVersion ) @@ -1588,7 +1588,7 @@ class LanguageSpecificationV6 extends LanguageSpecificationBase { suite => def deserializeTo: Feature[BigInt, Boolean] = { newFeature( - { (x: BigInt) => CSigmaDslBuilder.deserializeTo[BigInt](SBigInt, CSigmaDslBuilder.serialize(x)) == x}, + { (x: BigInt) => CSigmaDslBuilder.deserializeTo[BigInt](CSigmaDslBuilder.serialize(x)) == x}, "{ (x: BigInt) => Global.deserializeTo[BigInt](serialize(x)) == x }", sinceVersion = VersionContext.V6SoftForkVersion ) diff --git a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Isos.scala b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Isos.scala index 6ab6017894..84f2b21da8 100644 --- a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Isos.scala +++ b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Isos.scala @@ -10,7 +10,7 @@ import sigma.data.js.{Isos => DataIsos} import sigma.data.CHeader import sigma.interpreter.{ContextExtension, ProverResult} import sigma.js.AvlTree -import sigmastate.eval.{CHeader, CPreHeader} +import sigmastate.eval.CPreHeader import sigmastate.fleetSdkCommon.distEsmTypesBoxesMod.Box import sigmastate.fleetSdkCommon.distEsmTypesRegistersMod.NonMandatoryRegisters import sigmastate.fleetSdkCommon.distEsmTypesTokenMod.TokenAmount