From 472f06d448afed3d5e5149254abd2fc9b740d1c8 Mon Sep 17 00:00:00 2001 From: Alexandr Makoed Date: Mon, 26 Nov 2018 12:25:12 +0300 Subject: [PATCH 1/3] NODE-1131: Make order type in script inputType optional --- lang/js/src/main/scala/JsAPI.scala | 4 +- .../com/wavesplatform/lang/JavaAdapter.scala | 2 +- .../com/wavesplatform/utils/DocExport.scala | 3 +- .../wavesplatform/lang/EvaluatorV1Test.scala | 2 +- .../v1/evaluator/ctx/impl/waves/Types.scala | 43 +++++++++--------- .../ctx/impl/waves/WavesContext.scala | 12 ++--- .../matcher/model/OrderValidator.scala | 2 +- .../transaction/smart/BlockchainContext.scala | 3 +- .../transaction/smart/Verifier.scala | 2 +- .../smart/script/ScriptRunner.scala | 6 ++- .../com/wavesplatform/utils/package.scala | 2 +- .../smart/predef/ScriptVersionsTest.scala | 2 +- .../predef/TransactionBindingsTest.scala | 44 ++++++++++++++----- .../state/diffs/smart/predef/package.scala | 4 +- 14 files changed, 78 insertions(+), 53 deletions(-) diff --git a/lang/js/src/main/scala/JsAPI.scala b/lang/js/src/main/scala/JsAPI.scala index a70a04e1ff..cc8b0018b3 100644 --- a/lang/js/src/main/scala/JsAPI.scala +++ b/lang/js/src/main/scala/JsAPI.scala @@ -56,7 +56,9 @@ object JsAPI { override def data(addressOrAlias: Recipient, key: String, dataType: DataType): Option[Any] = ??? override def accountBalanceOf(addressOrAlias: Recipient, assetId: Option[Array[Byte]]): Either[String, Long] = ??? override def resolveAlias(name: String): Either[String, Recipient.Address] = ??? - } + }, + proofsEnabled = true, + orderEnabled = true ) val cryptoContext = CryptoContext.build(Global) diff --git a/lang/jvm/src/main/scala/com/wavesplatform/lang/JavaAdapter.scala b/lang/jvm/src/main/scala/com/wavesplatform/lang/JavaAdapter.scala index 5cd1b0add8..80e5ba5579 100644 --- a/lang/jvm/src/main/scala/com/wavesplatform/lang/JavaAdapter.scala +++ b/lang/jvm/src/main/scala/com/wavesplatform/lang/JavaAdapter.scala @@ -14,7 +14,7 @@ object JavaAdapter { new CompilerV1( Monoid.combineAll(Seq( CryptoContext.compilerContext(com.wavesplatform.lang.Global), - WavesContext.build(version, null, true).compilerContext, + WavesContext.build(version, null, true, true).compilerContext, PureContext.build(version).compilerContext ))) diff --git a/lang/jvm/src/main/scala/com/wavesplatform/utils/DocExport.scala b/lang/jvm/src/main/scala/com/wavesplatform/utils/DocExport.scala index 664e712778..2821ee6f55 100644 --- a/lang/jvm/src/main/scala/com/wavesplatform/utils/DocExport.scala +++ b/lang/jvm/src/main/scala/com/wavesplatform/utils/DocExport.scala @@ -31,7 +31,8 @@ object DocExport { override def accountBalanceOf(addressOrAlias: Recipient, assetId: Option[Array[Byte]]): Either[String, Long] = ??? override def resolveAlias(name: String): Either[String, Recipient.Address] = ??? }, - proofsEnabled = true + proofsEnabled = true, + orderEnabled = true ) val cryptoContext = CryptoContext.build(Global) diff --git a/lang/jvm/src/test/scala/com/wavesplatform/lang/EvaluatorV1Test.scala b/lang/jvm/src/test/scala/com/wavesplatform/lang/EvaluatorV1Test.scala index 9819db5dc8..cbf0fa2251 100644 --- a/lang/jvm/src/test/scala/com/wavesplatform/lang/EvaluatorV1Test.scala +++ b/lang/jvm/src/test/scala/com/wavesplatform/lang/EvaluatorV1Test.scala @@ -41,7 +41,7 @@ class EvaluatorV1Test extends PropSpec with PropertyChecks with Matchers with Sc Seq( defaultCryptoContext, pureContext, - WavesContext.build(V1, environment, true) + WavesContext.build(V1, environment, true, true) ) ) diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/Types.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/Types.scala index 322be1ae1b..fd18843954 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/Types.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/Types.scala @@ -258,11 +258,13 @@ object Types { ) } - val scriptInputTypeWithProofs = - UNION.create((buildOrderType(true) :: buildActiveTransactionTypes(true)).map(_.typeRef)) - - val scriptInputTypeWithoutProofs = - UNION.create((buildOrderType(false) :: buildActiveTransactionTypes(false)).map(_.typeRef)) + def scriptInputType(proofsEnabled: Boolean, orderEnabled: Boolean) = { + val txstpe = buildActiveTransactionTypes(proofsEnabled) + if (orderEnabled) + UNION.create((buildOrderType(proofsEnabled) :: txstpe).map(_.typeRef)) + else + UNION.create(txstpe.map(_.typeRef)) + } val anyTransactionTypeWithProofs = { val activeTxTypes = buildActiveTransactionTypes(proofsEnabled = true) @@ -280,25 +282,26 @@ object Types { .create((activeTxTypes ++ obsoleteTxTypes).map(_.typeRef)) } - val wavesTypesWithProofs: Seq[DefinedType] = { - val activeTxTypes = buildActiveTransactionTypes(proofsEnabled = true) - val obsoleteTxTypes = buildObsoleteTransactionTypes(proofsEnabled = true) - - val transactionsCommonType = UnionType("Transaction", activeTxTypes.map(_.typeRef)) - - val transactionTypes: List[CaseType] = obsoleteTxTypes ++ activeTxTypes - - Seq(addressType, aliasType, transfer, buildOrderType(true), assetPairType, dataEntryType, transactionsCommonType) ++ transactionTypes - } - - val wavesTypesWithoutProofs: Seq[DefinedType] = { - val activeTxTypes = buildActiveTransactionTypes(proofsEnabled = false) - val obsoleteTxTypes = buildObsoleteTransactionTypes(proofsEnabled = false) + def buildWavesTypes(orderEnabled: Boolean, proofsEnabled: Boolean): Seq[DefinedType] = { + val activeTxTypes = buildActiveTransactionTypes(proofsEnabled) + val obsoleteTxTypes = buildObsoleteTransactionTypes(proofsEnabled) val transactionsCommonType = UnionType("Transaction", activeTxTypes.map(_.typeRef)) val transactionTypes: List[CaseType] = obsoleteTxTypes ++ activeTxTypes - Seq(addressType, aliasType, transfer, buildOrderType(false), assetPairType, dataEntryType, transactionsCommonType) ++ transactionTypes + val wavesTypesWithoutOrder = + Seq( + addressType, + aliasType, + transfer, + assetPairType, + dataEntryType, + transactionsCommonType + ) ++ transactionTypes + + if (orderEnabled) + wavesTypesWithoutOrder :+ buildOrderType(proofsEnabled) + else wavesTypesWithoutOrder } } diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/WavesContext.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/WavesContext.scala index f5dc422c6b..9728da9a0f 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/WavesContext.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/WavesContext.scala @@ -20,9 +20,7 @@ object WavesContext { import Types._ import com.wavesplatform.lang.v1.evaluator.ctx.impl.converters._ - def build(version: ScriptVersion, - env: Environment, - proofsEnabled: Boolean): CTX = { + def build(version: ScriptVersion, env: Environment, orderEnabled: Boolean, proofsEnabled: Boolean): CTX = { val environmentFunctions = new EnvironmentFunctions(env) def getDataFromStateF(name: String, internalName: Short, dataType: DataType): BaseFunction = @@ -320,9 +318,7 @@ object WavesContext { val sellOrdTypeCoeval: Coeval[Either[String, CaseObj]] = Coeval(Right(ordType(OrdType.Sell))) val buyOrdTypeCoeval: Coeval[Either[String, CaseObj]] = Coeval(Right(ordType(OrdType.Buy))) - val scriptInputType = - if (proofsEnabled) scriptInputTypeWithProofs - else scriptInputTypeWithoutProofs + val scriptInputType = Types.scriptInputType(proofsEnabled, orderEnabled) val commonVars = Map( ("height", ((com.wavesplatform.lang.v1.compiler.Types.LONG, "Current blockchain height"), LazyVal(EitherT(heightCoeval)))), @@ -359,9 +355,7 @@ object WavesContext { wavesBalanceF ) - val types = - if (proofsEnabled) wavesTypesWithProofs - else wavesTypesWithoutProofs + val types = buildWavesTypes(orderEnabled, proofsEnabled) CTX(types, commonVars ++ vars(version.value), functions) } diff --git a/src/main/scala/com/wavesplatform/matcher/model/OrderValidator.scala b/src/main/scala/com/wavesplatform/matcher/model/OrderValidator.scala index 32952d1536..f70b80f635 100644 --- a/src/main/scala/com/wavesplatform/matcher/model/OrderValidator.scala +++ b/src/main/scala/com/wavesplatform/matcher/model/OrderValidator.scala @@ -70,7 +70,7 @@ class OrderValidator(db: DB, if (!blockchain.isFeatureActivated(BlockchainFeatures.SmartAssets, blockchain.height)) Left("Trading of scripted asset isn't allowed yet") else { - try ScriptRunner[EVALUATED](blockchain.height, Coproduct(tx), blockchain, script, proofsEnabled = false) match { + try ScriptRunner[EVALUATED](blockchain.height, Coproduct(tx), blockchain, script, proofsEnabled = false, orderEnabled = false) match { case (_, Left(execError)) => Left(s"Error executing script of asset $assetId: $execError") case (_, Right(FALSE)) => Left(s"Order rejected by script of asset $assetId") case (_, Right(TRUE)) => Right(()) diff --git a/src/main/scala/com/wavesplatform/transaction/smart/BlockchainContext.scala b/src/main/scala/com/wavesplatform/transaction/smart/BlockchainContext.scala index 7aa80ac134..d8b47ad39b 100644 --- a/src/main/scala/com/wavesplatform/transaction/smart/BlockchainContext.scala +++ b/src/main/scala/com/wavesplatform/transaction/smart/BlockchainContext.scala @@ -19,13 +19,14 @@ object BlockchainContext { in: Coeval[In], h: Coeval[Int], blockchain: Blockchain, + orderEnabled: Boolean, proofsEnabled: Boolean): EvaluationContext = { Monoid .combineAll( Seq( PureContext.build(version), CryptoContext.build(Global), - WavesContext.build(version, new WavesEnvironment(nByte, in, h, blockchain), proofsEnabled) + WavesContext.build(version, new WavesEnvironment(nByte, in, h, blockchain), orderEnabled, proofsEnabled) )) .evaluationContext } diff --git a/src/main/scala/com/wavesplatform/transaction/smart/Verifier.scala b/src/main/scala/com/wavesplatform/transaction/smart/Verifier.scala index 6c4d501c6a..ec9ff95cfc 100644 --- a/src/main/scala/com/wavesplatform/transaction/smart/Verifier.scala +++ b/src/main/scala/com/wavesplatform/transaction/smart/Verifier.scala @@ -59,7 +59,7 @@ object Verifier extends Instrumented with ScorexLogging { Try { logged( s"transaction ${transaction.id()}", - ScriptRunner[EVALUATED](height, Coproduct[TxOrd](transaction), blockchain, script, !isTokenScript) + ScriptRunner[EVALUATED](height, Coproduct[TxOrd](transaction), blockchain, script, !isTokenScript, !isTokenScript) ) match { case (log, Left(execError)) => Left(ScriptExecutionError(execError, script.text, log, isTokenScript)) case (log, Right(FALSE)) => diff --git a/src/main/scala/com/wavesplatform/transaction/smart/script/ScriptRunner.scala b/src/main/scala/com/wavesplatform/transaction/smart/script/ScriptRunner.scala index 5a57f0169d..7b14e4aca9 100644 --- a/src/main/scala/com/wavesplatform/transaction/smart/script/ScriptRunner.scala +++ b/src/main/scala/com/wavesplatform/transaction/smart/script/ScriptRunner.scala @@ -18,7 +18,8 @@ object ScriptRunner { in: Transaction :+: Order :+: CNil, blockchain: Blockchain, script: Script, - proofsEnabled: Boolean): (ExprEvaluator.Log, Either[ExecutionError, A]) = { + proofsEnabled: Boolean, + orderEnabled: Boolean): (ExprEvaluator.Log, Either[ExecutionError, A]) = { script match { case Script.Expr(expr) => val ctx = BlockchainContext.build( @@ -27,7 +28,8 @@ object ScriptRunner { Coeval.evalOnce(in), Coeval.evalOnce(height), blockchain, - proofsEnabled + proofsEnabled, + orderEnabled ) EvaluatorV1.applywithLogging[A](ctx, expr) diff --git a/src/main/scala/com/wavesplatform/utils/package.scala b/src/main/scala/com/wavesplatform/utils/package.scala index b3a9cd53b9..d72a73c77b 100644 --- a/src/main/scala/com/wavesplatform/utils/package.scala +++ b/src/main/scala/com/wavesplatform/utils/package.scala @@ -94,7 +94,7 @@ package object utils extends ScorexLogging { .combineAll(Seq( PureContext.build(version), CryptoContext.build(Global), - WavesContext.build(version, new WavesEnvironment(AddressScheme.current.chainId, Coeval(???), Coeval(???), EmptyBlockchain), true) + WavesContext.build(version, new WavesEnvironment(AddressScheme.current.chainId, Coeval(???), Coeval(???), EmptyBlockchain), true, true) ))) } .toMap diff --git a/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ScriptVersionsTest.scala b/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ScriptVersionsTest.scala index 1cb86ca0f6..02a1a33c7e 100644 --- a/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ScriptVersionsTest.scala +++ b/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ScriptVersionsTest.scala @@ -31,7 +31,7 @@ class ScriptVersionsTest extends FreeSpec with PropertyChecks with Matchers with compileResult <- CompilerV1(compilerContext(version), expr) (typedExpr, _) = compileResult s <- ScriptV1(version, typedExpr, checkSize = false) - r <- ScriptRunner[T](blockchain.height, Coproduct(tx), blockchain, s, true)._2 + r <- ScriptRunner[T](blockchain.height, Coproduct(tx), blockchain, s, true, true)._2 } yield r } diff --git a/src/test/scala/com/wavesplatform/state/diffs/smart/predef/TransactionBindingsTest.scala b/src/test/scala/com/wavesplatform/state/diffs/smart/predef/TransactionBindingsTest.scala index 0d81769718..710c59728e 100644 --- a/src/test/scala/com/wavesplatform/state/diffs/smart/predef/TransactionBindingsTest.scala +++ b/src/test/scala/com/wavesplatform/state/diffs/smart/predef/TransactionBindingsTest.scala @@ -5,7 +5,7 @@ import com.wavesplatform.lang.Global import com.wavesplatform.lang.ScriptVersion.Versions.V2 import com.wavesplatform.lang.Testing.evaluated import com.wavesplatform.lang.v1.compiler.CompilerV1 -import com.wavesplatform.lang.v1.compiler.Terms.{CONST_BOOLEAN, EVALUATED} +import com.wavesplatform.lang.v1.compiler.Terms.{CONST_BOOLEAN, CONST_LONG, EVALUATED} import com.wavesplatform.lang.v1.evaluator.EvaluatorV1 import com.wavesplatform.lang.v1.evaluator.ctx.impl.waves.WavesContext import com.wavesplatform.lang.v1.evaluator.ctx.impl.{CryptoContext, PureContext} @@ -489,7 +489,7 @@ class TransactionBindingsTest extends PropSpec with PropertyChecks with Matchers } } - property("Bindings without proofs") { + property("Bindings w/wo proofs/order") { val txTypeGen: Gen[String] = Gen.oneOf( List( "TransferTransaction", @@ -504,8 +504,8 @@ class TransactionBindingsTest extends PropSpec with PropertyChecks with Matchers ) ) - forAll(txTypeGen, orderGen) { (txType, ord) => - val src = + forAll(txTypeGen, orderGen) { (txType, in) => + val src1 = s""" |let expectedProof = base58'satoshi' |match tx { @@ -514,24 +514,46 @@ class TransactionBindingsTest extends PropSpec with PropertyChecks with Matchers |} """.stripMargin - val expectedError = s"Compilation failed: Undefined field `proofs` of variable of type `Union(List($txType))`" + val src2 = + s""" + |match tx { + | case o: Order => 1 + | case t: $txType => 2 + | case _ => 3 + |} + """.stripMargin - runWithoutProofs(src, Coproduct[In](ord)) should produce(expectedError) - runScript[EVALUATED](src, Coproduct[In](ord)) shouldBe Right(CONST_BOOLEAN(true)) + val noProofsError = s"Compilation failed: Undefined field `proofs` of variable of type `Union(List($txType))`" + + runCustom( + src1, + proofs = false, + order = true + ) should produce(noProofsError) + + runCustom( + src2, + proofs = true, + order = false + ) shouldBe 'left + + runScript[EVALUATED](src1, Coproduct[In](in)) shouldBe Right(CONST_BOOLEAN(true)) + runScript[EVALUATED](src2, Coproduct[In](in)) shouldBe Right(CONST_LONG(1)) } } - def runWithoutProofs(script: String, t: In, networkByte: Byte = networkByte): Either[String, EVALUATED] = { + def runCustom(script: String, proofs: Boolean, order: Boolean): Either[String, EVALUATED] = { import cats.syntax.monoid._ import com.wavesplatform.lang.v1.CTX._ val Success(expr, _) = Parser(script) val ctx = - PureContext.build(V2) |+| + PureContext + .build(V2) |+| CryptoContext .build(Global) |+| WavesContext - .build(V2, new WavesEnvironment(networkByte, Coeval(t), null, EmptyBlockchain), false) + .build(V2, new WavesEnvironment(networkByte, Coeval(null), null, EmptyBlockchain), proofsEnabled = proofs, orderEnabled = order) for { compileResult <- CompilerV1(ctx.compilerContext, expr) @@ -550,7 +572,7 @@ class TransactionBindingsTest extends PropSpec with PropertyChecks with Matchers CryptoContext .build(Global) |+| WavesContext - .build(V2, new WavesEnvironment(networkByte, Coeval(t), null, EmptyBlockchain), true) + .build(V2, new WavesEnvironment(networkByte, Coeval(t), null, EmptyBlockchain), true, true) for { compileResult <- CompilerV1(ctx.compilerContext, expr) diff --git a/src/test/scala/com/wavesplatform/state/diffs/smart/predef/package.scala b/src/test/scala/com/wavesplatform/state/diffs/smart/predef/package.scala index 5c6ab138dc..75c991635c 100644 --- a/src/test/scala/com/wavesplatform/state/diffs/smart/predef/package.scala +++ b/src/test/scala/com/wavesplatform/state/diffs/smart/predef/package.scala @@ -7,10 +7,10 @@ import com.wavesplatform.lang.v1.compiler.Terms.EVALUATED import com.wavesplatform.lang.v1.evaluator.EvaluatorV1 import com.wavesplatform.lang.v1.parser.Parser import com.wavesplatform.state.{Blockchain, ByteStr} -import com.wavesplatform.transaction.{DataTransaction, Transaction} import com.wavesplatform.transaction.smart.BlockchainContext import com.wavesplatform.transaction.smart.BlockchainContext.In import com.wavesplatform.transaction.transfer.TransferTransaction +import com.wavesplatform.transaction.{DataTransaction, Transaction} import com.wavesplatform.utils.{EmptyBlockchain, compilerContext} import fastparse.core.Parsed.Success import monix.eval.Coeval @@ -24,7 +24,7 @@ package object predef { for { compileResult <- CompilerV1(compilerContext(version), expr) (typedExpr, _) = compileResult - evalContext = BlockchainContext.build(version, networkByte, Coeval.evalOnce(t), Coeval.evalOnce(blockchain.height), blockchain, true) + evalContext = BlockchainContext.build(version, networkByte, Coeval.evalOnce(t), Coeval.evalOnce(blockchain.height), blockchain, true, true) r <- EvaluatorV1[T](evalContext, typedExpr) } yield r } From 87c5df0140a8c6939dca23e53ce6bd743f35f5cc Mon Sep 17 00:00:00 2001 From: Alexandr Makoed Date: Tue, 27 Nov 2018 11:17:40 +0300 Subject: [PATCH 2/3] NODE-1311: Fix all tests --- .../lang/v1/CompilerBenchmark.scala | 2 +- .../state/StateSyntheticBenchmark.scala | 2 +- .../utils/Gen.scala | 6 +- .../IntegrationSuiteWithThreeAddresses.scala | 2 +- .../com/wavesplatform/it/MatcherNode.scala | 4 +- .../smartcontracts/ExtraFeeTestSuite.scala | 2 +- .../OrdersFromScriptedAccTestSuite.scala | 12 +- .../OrdersFromScriptedAssetTestSuite.scala | 2 +- .../com/wavesplatform/it/sync/package.scala | 2 +- .../AtomicSwapSmartContractSuite.scala | 2 +- .../it/sync/smartcontract/BigString.scala | 2 +- .../LeaseSmartContractsTestSuite.scala | 2 +- .../MassTransferSmartContractSuite.scala | 2 +- .../ScriptExecutionErrorSuite.scala | 2 +- .../SetScriptTransactionSuite.scala | 2 +- .../it/sync/smartcontract/UTXAllowance.scala | 2 +- .../AssetSupportedTransactionsSuite.scala | 111 ++++++++++++------ .../smartasset/ExchangeSmartAssetsSuite.scala | 30 +++-- .../SetAssetScriptTransactionSuite.scala | 38 ++++-- .../v1/evaluator/ctx/impl/waves/Types.scala | 24 ++-- .../ctx/impl/waves/WavesContext.scala | 2 +- .../api/http/UtilsApiRoute.scala | 24 ++-- .../smart/script/ScriptCompiler.scala | 8 +- .../com/wavesplatform/utils/package.scala | 46 +++++--- .../wavesplatform/db/ScriptCacheTest.scala | 3 +- .../market/OrderValidatorSpecification.scala | 2 +- .../diffs/AssetTransactionsDiffTest.scala | 2 +- .../diffs/ExchangeTransactionDiffTest.scala | 12 +- .../SigVerifyPerformanceTest.scala | 2 +- .../smart/predef/ContextFunctionsTest.scala | 2 +- .../ObsoleteTransactionBindingsTest.scala | 2 +- .../smart/predef/ScriptVersionsTest.scala | 4 +- .../predef/SerContextFunctionsTest.scala | 2 +- .../state/diffs/smart/predef/package.scala | 2 +- .../smart/scenarios/MultiSig2of3Test.scala | 2 +- ...NotaryControlledTransferScenarioTest.scala | 4 +- .../scenarios/OnlyTransferIsAllowedTest.scala | 2 +- .../smart/scenarios/OracleDataTest.scala | 2 +- .../smart/scenarios/ScriptedSponsorTest.scala | 4 +- .../TransactionFieldAccessTest.scala | 2 +- .../smart/script/ScriptCompilerV1Test.scala | 8 +- 41 files changed, 238 insertions(+), 150 deletions(-) diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/CompilerBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/CompilerBenchmark.scala index a5e8521d19..ba674ddf0f 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/CompilerBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/CompilerBenchmark.scala @@ -16,7 +16,7 @@ import com.wavesplatform.transaction.smart.script.ScriptCompiler class CompilerBenchmark { @Benchmark - def serialize_test(st: St, bh: Blackhole): Unit = bh.consume(ScriptCompiler(st.scriptString).explicitGet()._1) + def serialize_test(st: St, bh: Blackhole): Unit = bh.consume(ScriptCompiler(st.scriptString, isAssetScript = false).explicitGet()._1) } object CompilerBenchmark { diff --git a/benchmark/src/test/scala/com/wavesplatform/state/StateSyntheticBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/state/StateSyntheticBenchmark.scala index 4e0cd2ee4f..ed3a69f3eb 100644 --- a/benchmark/src/test/scala/com/wavesplatform/state/StateSyntheticBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/state/StateSyntheticBenchmark.scala @@ -75,7 +75,7 @@ object StateSyntheticBenchmark { val textScript = "sigVerify(tx.bodyBytes,tx.proofs[0],tx.senderPk)" val untypedScript = Parser(textScript).get.value - val typedScript = CompilerV1(compilerContext(V1), untypedScript).explicitGet()._1 + val typedScript = CompilerV1(compilerContext(V1, isAssetScript = false), untypedScript).explicitGet()._1 val setScriptBlock = nextBlock( Seq( diff --git a/generator/src/main/scala/com.wavesplatform.generator/utils/Gen.scala b/generator/src/main/scala/com.wavesplatform.generator/utils/Gen.scala index 934ba7c8ef..4a066e364b 100644 --- a/generator/src/main/scala/com.wavesplatform.generator/utils/Gen.scala +++ b/generator/src/main/scala/com.wavesplatform.generator/utils/Gen.scala @@ -31,7 +31,7 @@ object Gen { |${recString(10)} || true """.stripMargin - val script = ScriptCompiler(s).explicitGet() + val script = ScriptCompiler(s, isAssetScript = false).explicitGet() script._1 } @@ -60,7 +60,7 @@ object Gen { |} """.stripMargin - val script = ScriptCompiler(src).explicitGet() + val script = ScriptCompiler(src, isAssetScript = false).explicitGet() script._1 } @@ -97,7 +97,7 @@ object Gen { |$finalStatement """.stripMargin - val (script, _) = ScriptCompiler(src) + val (script, _) = ScriptCompiler(src, isAssetScript = false) .explicitGet() log.info(s"${script.text}") script diff --git a/it/src/main/scala/com/wavesplatform/it/IntegrationSuiteWithThreeAddresses.scala b/it/src/main/scala/com/wavesplatform/it/IntegrationSuiteWithThreeAddresses.scala index f8decca2d3..b9a6090263 100644 --- a/it/src/main/scala/com/wavesplatform/it/IntegrationSuiteWithThreeAddresses.scala +++ b/it/src/main/scala/com/wavesplatform/it/IntegrationSuiteWithThreeAddresses.scala @@ -88,7 +88,7 @@ trait IntegrationSuiteWithThreeAddresses def setContract(contractText: Option[String], acc: PrivateKeyAccount): String = { val script = contractText.map { x => val scriptText = x.stripMargin - ScriptCompiler(scriptText).explicitGet()._1 + ScriptCompiler(scriptText, isAssetScript = false).explicitGet()._1 } val setScriptTransaction = SetScriptTransaction .selfSigned(SetScriptTransaction.supportedVersions.head, acc, script, 0.014.waves, System.currentTimeMillis()) diff --git a/it/src/main/scala/com/wavesplatform/it/MatcherNode.scala b/it/src/main/scala/com/wavesplatform/it/MatcherNode.scala index dbb52f8564..1f3aa7da40 100644 --- a/it/src/main/scala/com/wavesplatform/it/MatcherNode.scala +++ b/it/src/main/scala/com/wavesplatform/it/MatcherNode.scala @@ -40,7 +40,7 @@ trait MatcherNode extends BeforeAndAfterAll with Nodes with ScorexLogging { def initialScripts(): Unit = { for (i <- List(matcherNode, aliceNode, bobNode).indices) { - val script = ScriptCompiler("true").explicitGet()._1 + val script = ScriptCompiler("true", isAssetScript = false).explicitGet()._1 val pk = PrivateKeyAccount.fromSeed(nodes(i).seed(addresses(i))).right.get val setScriptTransaction = SetScriptTransaction .selfSigned(SetScriptTransaction.supportedVersions.head, pk, Some(script), 0.01.waves, System.currentTimeMillis()) @@ -58,7 +58,7 @@ trait MatcherNode extends BeforeAndAfterAll with Nodes with ScorexLogging { def setContract(contractText: Option[String], acc: PrivateKeyAccount): TransactionInfo = { val script = contractText.map { x => val scriptText = x.stripMargin - ScriptCompiler(scriptText).explicitGet()._1 + ScriptCompiler(scriptText, isAssetScript = false).explicitGet()._1 } val setScriptTransaction = SetScriptTransaction .selfSigned(SetScriptTransaction.supportedVersions.head, acc, script, 0.014.waves, System.currentTimeMillis()) diff --git a/it/src/test/scala/com/wavesplatform/it/sync/matcher/smartcontracts/ExtraFeeTestSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/matcher/smartcontracts/ExtraFeeTestSuite.scala index 478efcc17d..9465145c84 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/matcher/smartcontracts/ExtraFeeTestSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/matcher/smartcontracts/ExtraFeeTestSuite.scala @@ -16,7 +16,7 @@ class ExtraFeeTestSuite extends MatcherSuiteBase { override protected def nodeConfigs: Seq[Config] = Configs - val trueScript = Some(ScriptCompiler("true").explicitGet()._1.bytes().base64) //TODO добавить типовые проверки в скрипт + val trueScript = Some(ScriptCompiler("true", isAssetScript = false).explicitGet()._1.bytes().base64) //TODO добавить типовые проверки в скрипт val amount = 1L val price = 100000000L diff --git a/it/src/test/scala/com/wavesplatform/it/sync/matcher/smartcontracts/OrdersFromScriptedAccTestSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/matcher/smartcontracts/OrdersFromScriptedAccTestSuite.scala index 983f57cad4..aba5d2cfcf 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/matcher/smartcontracts/OrdersFromScriptedAccTestSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/matcher/smartcontracts/OrdersFromScriptedAccTestSuite.scala @@ -39,11 +39,13 @@ class OrdersFromScriptedAccTestSuite extends MatcherSuiteBase { withClue("duplicate names in contracts are denied") { val setScriptTransaction = SetScriptTransaction - .selfSigned(SetScriptTransaction.supportedVersions.head, - bobAcc, - Some(ScriptCompiler(sDupNames).explicitGet()._1), - 0.014.waves, - System.currentTimeMillis()) + .selfSigned( + SetScriptTransaction.supportedVersions.head, + bobAcc, + Some(ScriptCompiler(sDupNames, isAssetScript = false).explicitGet()._1), + 0.014.waves, + System.currentTimeMillis() + ) .right .get diff --git a/it/src/test/scala/com/wavesplatform/it/sync/matcher/smartcontracts/OrdersFromScriptedAssetTestSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/matcher/smartcontracts/OrdersFromScriptedAssetTestSuite.scala index e8e1971ffb..a4819a2a17 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/matcher/smartcontracts/OrdersFromScriptedAssetTestSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/matcher/smartcontracts/OrdersFromScriptedAssetTestSuite.scala @@ -219,7 +219,7 @@ object OrdersFromScriptedAssetTestSuite { | case other => true |} |""".stripMargin - ScriptCompiler(scriptText).explicitGet()._1 + ScriptCompiler(scriptText, isAssetScript = true).explicitGet()._1 } private val commonConfig = ConfigFactory.parseString(s""" diff --git a/it/src/test/scala/com/wavesplatform/it/sync/package.scala b/it/src/test/scala/com/wavesplatform/it/sync/package.scala index 219659ff44..0c9baf58b6 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/package.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/package.scala @@ -38,7 +38,7 @@ package object sync { val supportedVersions = List(null, "2") //sign and broadcast use default for V1 - val script = ScriptCompiler(s"""true""".stripMargin).explicitGet()._1 + val script = ScriptCompiler(s"""true""".stripMargin, isAssetScript = false).explicitGet()._1 val scriptBase64 = script.bytes.value.base64 val errNotAllowedByToken = "Transaction is not allowed by token-script" diff --git a/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/AtomicSwapSmartContractSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/AtomicSwapSmartContractSuite.scala index b7812135a7..dfd34ac254 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/AtomicSwapSmartContractSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/AtomicSwapSmartContractSuite.scala @@ -72,7 +72,7 @@ class AtomicSwapSmartContractSuite extends BaseTransactionSuite with CancelAfter }""".stripMargin val pkSwapBC1 = pkByAddress(swapBC1) - val script = ScriptCompiler(scriptText).explicitGet()._1 + val script = ScriptCompiler(scriptText, isAssetScript = false).explicitGet()._1 val sc1SetTx = SetScriptTransaction .selfSigned(version = SetScriptTransaction.supportedVersions.head, sender = pkSwapBC1, diff --git a/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/BigString.scala b/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/BigString.scala index bcb3fca928..fc043706ef 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/BigString.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/BigString.scala @@ -43,7 +43,7 @@ class BigString extends BaseTransactionSuite with CancelAfterFailure { } """.stripMargin - val script = ScriptCompiler(scriptText).explicitGet()._1 + val script = ScriptCompiler(scriptText, isAssetScript = false).explicitGet()._1 val setScriptTransaction = SetScriptTransaction .selfSigned(SetScriptTransaction.supportedVersions.head, acc0, Some(script), setScriptFee, System.currentTimeMillis()) .explicitGet() diff --git a/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/LeaseSmartContractsTestSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/LeaseSmartContractsTestSuite.scala index 3138cd472a..e19fddd0d7 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/LeaseSmartContractsTestSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/LeaseSmartContractsTestSuite.scala @@ -40,7 +40,7 @@ class LeaseSmartContractsTestSuite extends BaseTransactionSuite with CancelAfter } """.stripMargin - val script = ScriptCompiler(scriptText).explicitGet()._1 + val script = ScriptCompiler(scriptText, isAssetScript = false).explicitGet()._1 val setScriptTransaction = SetScriptTransaction .selfSigned(SetScriptTransaction.supportedVersions.head, acc0, Some(script), setScriptFee, System.currentTimeMillis()) .explicitGet() diff --git a/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/MassTransferSmartContractSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/MassTransferSmartContractSuite.scala index 496ed1bfde..a738a142f9 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/MassTransferSmartContractSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/MassTransferSmartContractSuite.scala @@ -58,7 +58,7 @@ class MassTransferSmartContractSuite extends BaseTransactionSuite with CancelAft """.stripMargin // set script - val script = ScriptCompiler(scriptText).explicitGet()._1 + val script = ScriptCompiler(scriptText, isAssetScript = false).explicitGet()._1 val setScriptTransaction = SetScriptTransaction .selfSigned(SetScriptTransaction.supportedVersions.head, sender.privateKey, Some(script), setScriptFee, System.currentTimeMillis()) .explicitGet() diff --git a/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/ScriptExecutionErrorSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/ScriptExecutionErrorSuite.scala index 875d98ca71..2dd176715b 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/ScriptExecutionErrorSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/ScriptExecutionErrorSuite.scala @@ -33,7 +33,7 @@ class ScriptExecutionErrorSuite extends BaseTransactionSuite with CancelAfterFai |} """.stripMargin - val compiled = ScriptCompiler(scriptSrc).explicitGet()._1 + val compiled = ScriptCompiler(scriptSrc, isAssetScript = false).explicitGet()._1 val tx = sender.signedBroadcast( SetScriptTransaction.selfSigned(1, acc2, Some(compiled), setScriptFee, ts).explicitGet().json() + diff --git a/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/SetScriptTransactionSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/SetScriptTransactionSuite.scala index 2198862ae7..145ab29866 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/SetScriptTransactionSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/SetScriptTransactionSuite.scala @@ -57,7 +57,7 @@ class SetScriptTransactionSuite extends BaseTransactionSuite with CancelAfterFai } """.stripMargin - val script = ScriptCompiler(scriptText).explicitGet()._1 + val script = ScriptCompiler(scriptText, isAssetScript = false).explicitGet()._1 val setScriptTransaction = SetScriptTransaction .selfSigned(SetScriptTransaction.supportedVersions.head, acc0, Some(script), setScriptFee, System.currentTimeMillis()) .explicitGet() diff --git a/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/UTXAllowance.scala b/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/UTXAllowance.scala index 8b90551bc4..1455579481 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/UTXAllowance.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/UTXAllowance.scala @@ -32,7 +32,7 @@ class UTXAllowance extends FreeSpec with Matchers with WaitForHeight2 with Cance val scriptText = s"""true""".stripMargin - val script = ScriptCompiler(scriptText).explicitGet()._1 + val script = ScriptCompiler(scriptText, isAssetScript = false).explicitGet()._1 val setScriptTransaction = SetScriptTransaction .selfSigned(SetScriptTransaction.supportedVersions.head, acc, Some(script), setScriptFee, System.currentTimeMillis()) .right diff --git a/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/smartasset/AssetSupportedTransactionsSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/smartasset/AssetSupportedTransactionsSuite.scala index 30e59136b2..ad2075689c 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/smartasset/AssetSupportedTransactionsSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/smartasset/AssetSupportedTransactionsSuite.scala @@ -48,13 +48,16 @@ class AssetSupportedTransactionsSuite extends BaseTransactionSuite { nodes.waitForHeightAriseAndTxPresent(tTxId1) //deprecate transfers with amount > 99 - val scr = ScriptCompiler(s""" + val scr = ScriptCompiler( + s""" |match tx { | case s : SetAssetScriptTransaction => true | case t: TransferTransaction => t.amount <= 99 | case _ => false |} - """.stripMargin).explicitGet()._1.bytes.value.base64 + """.stripMargin, + isAssetScript = true + ).explicitGet()._1.bytes.value.base64 val setScriptId = sender.setAssetScript(asset, firstAddress, setAssetScriptFee + smartExtraFee, Some(scr)).id nodes.waitForHeightAriseAndTxPresent(setScriptId) @@ -70,14 +73,17 @@ class AssetSupportedTransactionsSuite extends BaseTransactionSuite { } test("transfer goes only to addresses from list (white or black)") { - val scr = ScriptCompiler(s""" + val scr = ScriptCompiler( + s""" |match tx { | case s : SetAssetScriptTransaction => true | case t: TransferTransaction => t.recipient == addressFromPublicKey(base58'${ByteStr( - pkByAddress(secondAddress).publicKey).base58}') + pkByAddress(secondAddress).publicKey).base58}') | case _ => false |} - """.stripMargin).explicitGet()._1.bytes.value.base64 + """.stripMargin, + isAssetScript = true + ).explicitGet()._1.bytes.value.base64 val setScriptId = sender.setAssetScript(asset, firstAddress, setAssetScriptFee + smartExtraFee, Some(scr)).id nodes.waitForHeightAriseAndTxPresent(setScriptId) @@ -88,15 +94,18 @@ class AssetSupportedTransactionsSuite extends BaseTransactionSuite { assertBadRequestAndMessage(sender.transfer(firstAddress, firstAddress, 1, smartMinFee, Some(asset)), errNotAllowedByToken) - val scr1 = ScriptCompiler(s""" + val scr1 = ScriptCompiler( + s""" |match tx { | case s : SetAssetScriptTransaction => true | case t: TransferTransaction => t.recipient != addressFromPublicKey(base58'${ByteStr( - pkByAddress(secondAddress).publicKey).base58}') && t.recipient != addressFromPublicKey(base58'${ByteStr( - pkByAddress(firstAddress).publicKey).base58}') + pkByAddress(secondAddress).publicKey).base58}') && t.recipient != addressFromPublicKey(base58'${ByteStr( + pkByAddress(firstAddress).publicKey).base58}') | case _ => false |} - """.stripMargin).explicitGet()._1.bytes.value.base64 + """.stripMargin, + isAssetScript = true + ).explicitGet()._1.bytes.value.base64 val setScriptId1 = sender.setAssetScript(asset, firstAddress, setAssetScriptFee + smartExtraFee, Some(scr1)).id nodes.waitForHeightAriseAndTxPresent(setScriptId1) @@ -117,13 +126,16 @@ class AssetSupportedTransactionsSuite extends BaseTransactionSuite { val sponsorId = sender.sponsorAsset(firstAddress, feeAsset, baseFee = 2, fee = sponsorFee + smartExtraFee).id nodes.waitForHeightAriseAndTxPresent(sponsorId) - val scr = ScriptCompiler(s""" + val scr = ScriptCompiler( + s""" |match tx { | case s : SetAssetScriptTransaction => true | case t: TransferTransaction => t.feeAssetId == base58'$feeAsset' | case _ => false |} - """.stripMargin).explicitGet()._1.bytes.value.base64 + """.stripMargin, + isAssetScript = true + ).explicitGet()._1.bytes.value.base64 val setScriptId = sender.setAssetScript(asset, firstAddress, setAssetScriptFee + smartExtraFee, Some(scr)).id nodes.waitForHeightAriseAndTxPresent(setScriptId) @@ -156,14 +168,17 @@ class AssetSupportedTransactionsSuite extends BaseTransactionSuite { val tTxId = sender.transfer(firstAddress, secondAddress, 100, smartMinFee, Some(blackAsset)).id nodes.waitForHeightAriseAndTxPresent(tTxId) - val scr = ScriptCompiler(s""" + val scr = ScriptCompiler( + s""" |match tx { | case s : SetAssetScriptTransaction => true | case t: TransferTransaction => let issuer = extract(addressFromString("${firstAddress}")) | isDefined(getInteger(issuer,toBase58String(t.id))) == true | case _ => false |} - """.stripMargin).explicitGet()._1.bytes.value.base64 + """.stripMargin, + isAssetScript = true + ).explicitGet()._1.bytes.value.base64 val setScriptId = sender.setAssetScript(blackAsset, firstAddress, setAssetScriptFee + smartExtraFee, Some(scr)).id nodes.waitForHeightAriseAndTxPresent(setScriptId) @@ -217,13 +232,16 @@ class AssetSupportedTransactionsSuite extends BaseTransactionSuite { val toThird = sender.transfer(firstAddress, thirdAddress, 100, smartMinFee, Some(asset)).id nodes.waitForHeightAriseAndTxPresent(toThird) - val scr = ScriptCompiler(s""" + val scr = ScriptCompiler( + s""" |match tx { | case s : SetAssetScriptTransaction => true | case b: BurnTransaction => b.sender == addressFromPublicKey(base58'${ByteStr(pkByAddress(secondAddress).publicKey).base58}') | case _ => false |} - """.stripMargin).explicitGet()._1.bytes.value.base64 + """.stripMargin, + isAssetScript = true + ).explicitGet()._1.bytes.value.base64 val setScriptId = sender.setAssetScript(asset, firstAddress, setAssetScriptFee + smartExtraFee, Some(scr)).id nodes.waitForHeightAriseAndTxPresent(setScriptId) @@ -232,14 +250,17 @@ class AssetSupportedTransactionsSuite extends BaseTransactionSuite { assertBadRequestAndMessage(sender.burn(firstAddress, asset, 10, smartMinFee).id, errNotAllowedByToken) - val scr1 = ScriptCompiler(s""" + val scr1 = ScriptCompiler( + s""" |match tx { | case s : SetAssetScriptTransaction => true | case b: BurnTransaction => b.sender != addressFromPublicKey(base58'${ByteStr( - pkByAddress(secondAddress).publicKey).base58}') + pkByAddress(secondAddress).publicKey).base58}') | case _ => false |} - """.stripMargin).explicitGet()._1.bytes.value.base64 + """.stripMargin, + isAssetScript = true + ).explicitGet()._1.bytes.value.base64 val setScriptId1 = sender.setAssetScript(asset, firstAddress, setAssetScriptFee + smartExtraFee, Some(scr1)).id nodes.waitForHeightAriseAndTxPresent(setScriptId1) @@ -253,13 +274,16 @@ class AssetSupportedTransactionsSuite extends BaseTransactionSuite { } ignore("burn by some height") { - val scr = ScriptCompiler(s""" + val scr = ScriptCompiler( + s""" |match tx { | case s : SetAssetScriptTransaction => true | case b: BurnTransaction => height % 2 == 0 | case _ => false |} - """.stripMargin).explicitGet()._1.bytes.value.base64 + """.stripMargin, + isAssetScript = true + ).explicitGet()._1.bytes.value.base64 val setScriptId = sender.setAssetScript(asset, firstAddress, setAssetScriptFee + smartExtraFee, Some(scr)).id nodes.waitForHeightAriseAndTxPresent(setScriptId) @@ -286,12 +310,16 @@ class AssetSupportedTransactionsSuite extends BaseTransactionSuite { reissuable = false, issueFee, 2, - Some(ScriptCompiler(s""" + Some( + ScriptCompiler( + s""" |match tx { | case b : BurnTransaction => false | case _ => true |} - """.stripMargin).explicitGet()._1.bytes.value.base64) + """.stripMargin, + isAssetScript = true + ).explicitGet()._1.bytes.value.base64) ) .id @@ -301,7 +329,8 @@ class AssetSupportedTransactionsSuite extends BaseTransactionSuite { } test("masstransfer - taxation") { - val scr = ScriptCompiler(s""" + val scr = ScriptCompiler( + s""" |match tx { | case s : SetAssetScriptTransaction => true | case m: MassTransferTransaction => @@ -311,7 +340,9 @@ class AssetSupportedTransactionsSuite extends BaseTransactionSuite { | twoTransfers && issuerIsRecipient && taxesPaid | case _ => false |} - """.stripMargin).explicitGet()._1.bytes.value.base64 + """.stripMargin, + isAssetScript = true + ).explicitGet()._1.bytes.value.base64 val setScriptId = sender.setAssetScript(asset, firstAddress, setAssetScriptFee + smartExtraFee, Some(scr)).id nodes.waitForHeightAriseAndTxPresent(setScriptId) @@ -325,14 +356,17 @@ class AssetSupportedTransactionsSuite extends BaseTransactionSuite { } test("masstransfer - transferCount <=2") { - val scr = ScriptCompiler(s""" + val scr = ScriptCompiler( + s""" |match tx { | case s : SetAssetScriptTransaction => true | case m: MassTransferTransaction => | m.transferCount <= 2 | case _ => false |} - """.stripMargin).explicitGet()._1.bytes.value.base64 + """.stripMargin, + isAssetScript = true + ).explicitGet()._1.bytes.value.base64 val setScriptId = sender.setAssetScript(asset, firstAddress, setAssetScriptFee + smartExtraFee, Some(scr)).id nodes.waitForHeightAriseAndTxPresent(setScriptId) @@ -349,13 +383,16 @@ class AssetSupportedTransactionsSuite extends BaseTransactionSuite { assertBadRequestAndMessage(sender.reissue(secondAddress, asset, someAssetAmount, reissuable = true, fee = issueFee + smartExtraFee).id, "Reason: Asset was issued by other address") - val scr = ScriptCompiler(s""" + val scr = ScriptCompiler( + s""" |match tx { | case s : SetAssetScriptTransaction => true | case r: ReissueTransaction => r.sender == addressFromPublicKey(base58'${ByteStr(pkByAddress(secondAddress).publicKey).base58}') | case _ => false |} - """.stripMargin).explicitGet()._1.bytes.value.base64 + """.stripMargin, + isAssetScript = true + ).explicitGet()._1.bytes.value.base64 val setScriptId = sender.setAssetScript(asset, firstAddress, setAssetScriptFee + smartExtraFee, Some(scr)).id nodes.waitForHeightAriseAndTxPresent(setScriptId) @@ -380,13 +417,16 @@ class AssetSupportedTransactionsSuite extends BaseTransactionSuite { nodes.waitForHeightAriseAndTxPresent(assetNonReissue) - val scr = ScriptCompiler(s""" + val scr = ScriptCompiler( + s""" |match tx { | case s : SetAssetScriptTransaction => true | case r: ReissueTransaction => r.sender == addressFromPublicKey(base58'${ByteStr(pkByAddress(secondAddress).publicKey).base58}') | case _ => false |} - """.stripMargin).explicitGet()._1.bytes.value.base64 + """.stripMargin, + isAssetScript = true + ).explicitGet()._1.bytes.value.base64 val setScriptId = sender.setAssetScript(assetNonReissue, firstAddress, setAssetScriptFee + smartExtraFee, Some(scr)).id nodes.waitForHeightAriseAndTxPresent(setScriptId) @@ -400,14 +440,17 @@ class AssetSupportedTransactionsSuite extends BaseTransactionSuite { test("sponsorship of smart asset") { assertBadRequestAndMessage(sender.sponsorAsset(firstAddress, asset, baseFee = 2, fee = sponsorFee + smartExtraFee).id, errNotAllowedByToken) - val scr = ScriptCompiler(s""" + val scr = ScriptCompiler( + s""" |match tx { | case s : SetAssetScriptTransaction => true | case ss: SponsorFeeTransaction => ss.sender == addressFromPublicKey(base58'${ByteStr( - pkByAddress(firstAddress).publicKey).base58}') + pkByAddress(firstAddress).publicKey).base58}') | case _ => false |} - """.stripMargin).explicitGet()._1.bytes.value.base64 + """.stripMargin, + isAssetScript = true + ).explicitGet()._1.bytes.value.base64 val setScriptId = sender.setAssetScript(asset, firstAddress, setAssetScriptFee + smartExtraFee, Some(scr)).id nodes.waitForHeightAriseAndTxPresent(setScriptId) @@ -427,7 +470,7 @@ class AssetSupportedTransactionsSuite extends BaseTransactionSuite { reissuable = false, issueFee, 2, - script = Some(ScriptCompiler(s"""false""".stripMargin).explicitGet()._1.bytes.value.base64) + script = Some(ScriptCompiler(s"""false""".stripMargin, isAssetScript = true).explicitGet()._1.bytes.value.base64) ) .id nodes.waitForHeightAriseAndTxPresent(assetWOSupport) diff --git a/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/smartasset/ExchangeSmartAssetsSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/smartasset/ExchangeSmartAssetsSuite.scala index 91d52e6a19..6711c6f97e 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/smartasset/ExchangeSmartAssetsSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/smartcontract/smartasset/ExchangeSmartAssetsSuite.scala @@ -39,11 +39,15 @@ class ExchangeSmartAssetsSuite extends BaseTransactionSuite with CancelAfterFail /* combination of smart accounts and smart assets */ - val script = Some(ScriptCompiler(s""" + val script = Some( + ScriptCompiler( + s""" |match tx { |case s : SetAssetScriptTransaction => true |case e: ExchangeTransaction => e.sender == addressFromPublicKey(base58'${ByteStr(acc2.publicKey).base58}') - |case _ => false}""".stripMargin).explicitGet()._1.bytes.value.base64) + |case _ => false}""".stripMargin, + isAssetScript = true + ).explicitGet()._1.bytes.value.base64) val smartAsset = sender .issue(firstAddress, "SmartAsset", "TestCoin", someAssetAmount, 0, reissuable = false, issueFee, 2, script, true) @@ -61,11 +65,15 @@ class ExchangeSmartAssetsSuite extends BaseTransactionSuite with CancelAfterFail sender.signedBroadcast(exchangeTx(smartPair), waitForTx = true) } - val scriptUpdated = Some(ScriptCompiler(s""" + val scriptUpdated = Some( + ScriptCompiler( + s""" |match tx { |case s : SetAssetScriptTransaction => true |case e: ExchangeTransaction => e.sender == addressFromPublicKey(base58'${ByteStr(acc1.publicKey).base58}') - |case _ => false}""".stripMargin).explicitGet()._1.bytes.value.base64) + |case _ => false}""".stripMargin, + isAssetScript = true + ).explicitGet()._1.bytes.value.base64) sender.setAssetScript(smartAsset, firstAddress, setAssetScriptFee, scriptUpdated, waitForTx = true) @@ -86,13 +94,17 @@ class ExchangeSmartAssetsSuite extends BaseTransactionSuite with CancelAfterFail sender.transfer(secondAddress, firstAddress, 1000, minFee + smartExtraFee, Some(assetB), waitForTx = true) sender.transfer(firstAddress, secondAddress, 1000, minFee + smartExtraFee, Some(assetA), waitForTx = true) - val script = Some(ScriptCompiler(s""" + val script = Some( + ScriptCompiler( + s""" |let assetA = base58'$assetA' |let assetB = base58'$assetB' |match tx { |case s : SetAssetScriptTransaction => true |case e: ExchangeTransaction => (e.sellOrder.assetPair.priceAsset == assetA || e.sellOrder.assetPair.amountAsset == assetA) && (e.sellOrder.assetPair.priceAsset == assetB || e.sellOrder.assetPair.amountAsset == assetB) - |case _ => false}""".stripMargin).explicitGet()._1.bytes.value.base64) + |case _ => false}""".stripMargin, + isAssetScript = true + ).explicitGet()._1.bytes.value.base64) sender.setAssetScript(assetA, firstAddress, setAssetScriptFee, script, waitForTx = true) sender.setAssetScript(assetB, secondAddress, setAssetScriptFee, script, waitForTx = true) @@ -127,9 +139,9 @@ class ExchangeSmartAssetsSuite extends BaseTransactionSuite with CancelAfterFail } test("use all functions from RIDE for asset script") { - val script1 = Some(ScriptCompiler(cryptoContextScript).explicitGet()._1.bytes.value.base64) - val script2 = Some(ScriptCompiler(pureContextScript(dtx)).explicitGet()._1.bytes.value.base64) - val script3 = Some(ScriptCompiler(wavesContextScript(dtx)).explicitGet()._1.bytes.value.base64) + val script1 = Some(ScriptCompiler(cryptoContextScript, isAssetScript = true).explicitGet()._1.bytes.value.base64) + val script2 = Some(ScriptCompiler(pureContextScript(dtx), isAssetScript = true).explicitGet()._1.bytes.value.base64) + val script3 = Some(ScriptCompiler(wavesContextScript(dtx), isAssetScript = true).explicitGet()._1.bytes.value.base64) List(script1, script2, script3) .map { i => diff --git a/it/src/test/scala/com/wavesplatform/it/sync/transactions/SetAssetScriptTransactionSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/transactions/SetAssetScriptTransactionSuite.scala index 01bed23eb6..e8ced5cf05 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/transactions/SetAssetScriptTransactionSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/transactions/SetAssetScriptTransactionSuite.scala @@ -18,13 +18,16 @@ import scala.concurrent.duration._ import scala.util.Random class SetAssetScriptTransactionSuite extends BaseTransactionSuite { - var assetWOScript = "" - var assetWScript = "" - private val accountB = pkByAddress(secondAddress) - private val unchangeableScript = ScriptCompiler(s""" + var assetWOScript = "" + var assetWScript = "" + private val accountB = pkByAddress(secondAddress) + private val unchangeableScript = ScriptCompiler( + s""" |match tx { |case s : SetAssetScriptTransaction => false - |case _ => true}""".stripMargin).explicitGet()._1 + |case _ => true}""".stripMargin, + isAssetScript = true + ).explicitGet()._1 protected override def beforeAll(): Unit = { super.beforeAll() @@ -79,11 +82,15 @@ class SetAssetScriptTransactionSuite extends BaseTransactionSuite { reissuable = false, issueFee, 2, - script = Some(ScriptCompiler(s""" + script = Some( + ScriptCompiler( + s""" |match tx { |case s : SetAssetScriptTransaction => s.sender == addressFromPublicKey(base58'${ByteStr( - pkByAddress(secondAddress).publicKey).base58}') - |case _ => false}""".stripMargin).explicitGet()._1.bytes.value.base64) + pkByAddress(secondAddress).publicKey).base58}') + |case _ => false}""".stripMargin, + isAssetScript = true + ).explicitGet()._1.bytes.value.base64) ) .id nodes.waitForHeightAriseAndTxPresent(assetWAnotherOwner) @@ -110,12 +117,15 @@ class SetAssetScriptTransactionSuite extends BaseTransactionSuite { } test("sender's waves balance is decreased by fee") { - val script2 = ScriptCompiler(s""" + val script2 = ScriptCompiler( + s""" |match tx { | case s : SetAssetScriptTransaction => true | case _ => false |} - """.stripMargin).explicitGet()._1.bytes.value.base64 + """.stripMargin, + isAssetScript = true + ).explicitGet()._1.bytes.value.base64 val (balance, eff) = notMiner.accountBalances(firstAddress) val details = notMiner.assetsDetails(assetWScript, true).scriptDetails.getOrElse(fail("Expecting to get asset details")) @@ -243,10 +253,14 @@ class SetAssetScriptTransactionSuite extends BaseTransactionSuite { .selfSigned( SetScriptTransaction.supportedVersions.head, accountA, - Some(ScriptCompiler(s"""|let pkB = base58'${ByteStr(accountB.publicKey)}' + Some( + ScriptCompiler( + s"""|let pkB = base58'${ByteStr(accountB.publicKey)}' |match tx { |case s : SetAssetScriptTransaction => sigVerify(s.bodyBytes,s.proofs[0],pkB) - |case _ => true}""".stripMargin).explicitGet()._1), + |case _ => true}""".stripMargin, + isAssetScript = true + ).explicitGet()._1), setScriptFee, System.currentTimeMillis() ) diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/Types.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/Types.scala index fd18843954..832dff3f7b 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/Types.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/Types.scala @@ -282,7 +282,7 @@ object Types { .create((activeTxTypes ++ obsoleteTxTypes).map(_.typeRef)) } - def buildWavesTypes(orderEnabled: Boolean, proofsEnabled: Boolean): Seq[DefinedType] = { + def buildWavesTypes(proofsEnabled: Boolean): Seq[DefinedType] = { val activeTxTypes = buildActiveTransactionTypes(proofsEnabled) val obsoleteTxTypes = buildObsoleteTransactionTypes(proofsEnabled) @@ -290,18 +290,14 @@ object Types { val transactionTypes: List[CaseType] = obsoleteTxTypes ++ activeTxTypes - val wavesTypesWithoutOrder = - Seq( - addressType, - aliasType, - transfer, - assetPairType, - dataEntryType, - transactionsCommonType - ) ++ transactionTypes - - if (orderEnabled) - wavesTypesWithoutOrder :+ buildOrderType(proofsEnabled) - else wavesTypesWithoutOrder + Seq( + addressType, + aliasType, + transfer, + assetPairType, + dataEntryType, + buildOrderType(proofsEnabled), + transactionsCommonType + ) ++ transactionTypes } } diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/WavesContext.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/WavesContext.scala index 9728da9a0f..5ea9fb788d 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/WavesContext.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/waves/WavesContext.scala @@ -355,7 +355,7 @@ object WavesContext { wavesBalanceF ) - val types = buildWavesTypes(orderEnabled, proofsEnabled) + val types = buildWavesTypes(proofsEnabled) CTX(types, commonVars ++ vars(version.value), functions) } diff --git a/src/main/scala/com/wavesplatform/api/http/UtilsApiRoute.scala b/src/main/scala/com/wavesplatform/api/http/UtilsApiRoute.scala index f2e7865de7..85beb9230a 100644 --- a/src/main/scala/com/wavesplatform/api/http/UtilsApiRoute.scala +++ b/src/main/scala/com/wavesplatform/api/http/UtilsApiRoute.scala @@ -47,18 +47,20 @@ case class UtilsApiRoute(timeService: Time, settings: RestAPISettings) extends A )) def compile: Route = path("script" / "compile") { (post & entity(as[String])) { code => - complete( - ScriptCompiler(code).fold( - e => ScriptCompilerError(e), { - case (script, complexity) => - Json.obj( - "script" -> script.bytes().base64, - "complexity" -> complexity, - "extraFee" -> CommonValidation.ScriptExtraFee - ) - } + parameter('assetScript.as[Boolean] ? false) { isAssetScript => + complete( + ScriptCompiler(code, isAssetScript).fold( + e => ScriptCompilerError(e), { + case (script, complexity) => + Json.obj( + "script" -> script.bytes().base64, + "complexity" -> complexity, + "extraFee" -> CommonValidation.ScriptExtraFee + ) + } + ) ) - ) + } } } diff --git a/src/main/scala/com/wavesplatform/transaction/smart/script/ScriptCompiler.scala b/src/main/scala/com/wavesplatform/transaction/smart/script/ScriptCompiler.scala index 0844893c42..be49f7fa51 100644 --- a/src/main/scala/com/wavesplatform/transaction/smart/script/ScriptCompiler.scala +++ b/src/main/scala/com/wavesplatform/transaction/smart/script/ScriptCompiler.scala @@ -14,7 +14,7 @@ import scala.util.{Failure, Success, Try} object ScriptCompiler extends ScorexLogging { - def apply(scriptText: String): Either[String, (Script, Long)] = { + def apply(scriptText: String, isAssetScript: Boolean): Either[String, (Script, Long)] = { val directives = DirectiveParser(scriptText) val scriptWithoutDirectives = @@ -24,14 +24,14 @@ object ScriptCompiler extends ScorexLogging { for { ver <- extractVersion(directives) - expr <- tryCompile(scriptWithoutDirectives, ver, directives) + expr <- tryCompile(scriptWithoutDirectives, ver, isAssetScript, directives) script <- ScriptV1(ver, expr) complexity <- ScriptEstimator(varNames(ver), functionCosts(ver), expr) } yield (script, complexity) } - def tryCompile(src: String, version: ScriptVersion, directives: List[Directive]): Either[String, EXPR] = { - val compiler = new CompilerV1(compilerContext(version)) + def tryCompile(src: String, version: ScriptVersion, isAssetScript: Boolean, directives: List[Directive]): Either[String, EXPR] = { + val compiler = new CompilerV1(compilerContext(version, isAssetScript)) try { compiler.compile(src, directives) } catch { diff --git a/src/main/scala/com/wavesplatform/utils/package.scala b/src/main/scala/com/wavesplatform/utils/package.scala index d72a73c77b..ee25c49b1e 100644 --- a/src/main/scala/com/wavesplatform/utils/package.scala +++ b/src/main/scala/com/wavesplatform/utils/package.scala @@ -86,18 +86,34 @@ package object utils extends ScorexLogging { } } - private val lazyContexts: Map[ScriptVersion, Coeval[CTX]] = Seq - .tabulate(2) { v => - val version = ScriptVersion.fromInt(v + 1).get - version -> Coeval.evalOnce( - Monoid - .combineAll(Seq( - PureContext.build(version), - CryptoContext.build(Global), - WavesContext.build(version, new WavesEnvironment(AddressScheme.current.chainId, Coeval(???), Coeval(???), EmptyBlockchain), true, true) - ))) - } - .toMap + private val lazyAssetContexts: Map[ScriptVersion, Coeval[CTX]] = + Seq + .tabulate(2) { v => + val version = ScriptVersion.fromInt(v + 1).get + version -> Coeval.evalOnce( + Monoid + .combineAll(Seq( + PureContext.build(version), + CryptoContext.build(Global), + WavesContext + .build(version, new WavesEnvironment(AddressScheme.current.chainId, Coeval(???), Coeval(???), EmptyBlockchain), false, false) + ))) + } + .toMap + + private val lazyContexts: Map[ScriptVersion, Coeval[CTX]] = + Seq + .tabulate(2) { v => + val version = ScriptVersion.fromInt(v + 1).get + version -> Coeval.evalOnce( + Monoid + .combineAll(Seq( + PureContext.build(version), + CryptoContext.build(Global), + WavesContext.build(version, new WavesEnvironment(AddressScheme.current.chainId, Coeval(???), Coeval(???), EmptyBlockchain), true, true) + ))) + } + .toMap def dummyEvalContext(version: ScriptVersion): EvaluationContext = lazyContexts(version)().evaluationContext @@ -124,9 +140,11 @@ package object utils extends ScorexLogging { costs.toMap } - def compilerContext(version: ScriptVersion): CompilerContext = lazyContexts(version)().compilerContext + def compilerContext(version: ScriptVersion, isAssetScript: Boolean): CompilerContext = + if (isAssetScript) lazyAssetContexts(version)().compilerContext + else lazyContexts(version)().compilerContext - def varNames(version: ScriptVersion): Set[String] = compilerContext(version).varDefs.keySet + def varNames(version: ScriptVersion): Set[String] = compilerContext(version, isAssetScript = false).varDefs.keySet @tailrec final def untilTimeout[T](timeout: FiniteDuration, delay: FiniteDuration = 100.milliseconds, onFailure: => Unit = {})(fn: => T): T = { diff --git a/src/test/scala/com/wavesplatform/db/ScriptCacheTest.scala b/src/test/scala/com/wavesplatform/db/ScriptCacheTest.scala index b25b3b7ae8..1284c1dcc3 100644 --- a/src/test/scala/com/wavesplatform/db/ScriptCacheTest.scala +++ b/src/test/scala/com/wavesplatform/db/ScriptCacheTest.scala @@ -27,7 +27,8 @@ class ScriptCacheTest extends FreeSpec with Matchers with WithDB with Transactio s""" |let ind = $ind |true - """.stripMargin + """.stripMargin, + isAssetScript = false ).explicitGet() script diff --git a/src/test/scala/com/wavesplatform/matcher/market/OrderValidatorSpecification.scala b/src/test/scala/com/wavesplatform/matcher/market/OrderValidatorSpecification.scala index 7e8a2044fe..53e11825ee 100644 --- a/src/test/scala/com/wavesplatform/matcher/market/OrderValidatorSpecification.scala +++ b/src/test/scala/com/wavesplatform/matcher/market/OrderValidatorSpecification.scala @@ -184,7 +184,7 @@ class OrderValidatorSpecification val pk = PrivateKeyAccount(randomBytes()) val o = newBuyOrder(pk, version = 2) - val script = ScriptCompiler("true && (height > 0)").explicitGet()._1 + val script = ScriptCompiler("true && (height > 0)", isAssetScript = false).explicitGet()._1 (bc.accountScript _).when(pk.toAddress).returns(Some(script)) ov.validateNewOrder(o) should produce("height is inaccessible when running script on matcher") } diff --git a/src/test/scala/com/wavesplatform/state/diffs/AssetTransactionsDiffTest.scala b/src/test/scala/com/wavesplatform/state/diffs/AssetTransactionsDiffTest.scala index db63e54e36..9398a07d67 100644 --- a/src/test/scala/com/wavesplatform/state/diffs/AssetTransactionsDiffTest.scala +++ b/src/test/scala/com/wavesplatform/state/diffs/AssetTransactionsDiffTest.scala @@ -219,7 +219,7 @@ class AssetTransactionsDiffTest extends PropSpec with PropertyChecks with Matche private def createScript(code: String) = { val Parsed.Success(expr, _) = Parser(code).get - ScriptV1(CompilerV1(compilerContext(V1), expr).explicitGet()._1).explicitGet() + ScriptV1(CompilerV1(compilerContext(V1, isAssetScript = false), expr).explicitGet()._1).explicitGet() } def genesisIssueTransferReissue(code: String): Gen[(Seq[GenesisTransaction], IssueTransactionV2, TransferTransactionV1, ReissueTransactionV1)] = diff --git a/src/test/scala/com/wavesplatform/state/diffs/ExchangeTransactionDiffTest.scala b/src/test/scala/com/wavesplatform/state/diffs/ExchangeTransactionDiffTest.scala index b11389842e..e9c2796af6 100644 --- a/src/test/scala/com/wavesplatform/state/diffs/ExchangeTransactionDiffTest.scala +++ b/src/test/scala/com/wavesplatform/state/diffs/ExchangeTransactionDiffTest.scala @@ -392,10 +392,10 @@ class ExchangeTransactionDiffTest extends PropSpec with PropertyChecks with Matc property("Disable use OrderV1 on SmartAccount") { val enoughFee = 100000000 val script = "true" - val txScriptCompiled = ScriptCompiler(script).explicitGet()._1 + val txScriptCompiled = ScriptCompiler(script, isAssetScript = false).explicitGet()._1 - val sellerScript = Some(ScriptCompiler(script).explicitGet()._1) - val buyerScript = Some(ScriptCompiler(script).explicitGet()._1) + val sellerScript = Some(ScriptCompiler(script, isAssetScript = false).explicitGet()._1) + val buyerScript = Some(ScriptCompiler(script, isAssetScript = false).explicitGet()._1) val chainId = AddressScheme.current.chainId @@ -507,10 +507,10 @@ class ExchangeTransactionDiffTest extends PropSpec with PropertyChecks with Matc txScript: String): Gen[(GenesisTransaction, List[TransferTransaction], List[Transaction], ExchangeTransaction)] = { val enoughFee = 100000000 - val txScriptCompiled = ScriptCompiler(txScript).explicitGet()._1 + val txScriptCompiled = ScriptCompiler(txScript, isAssetScript = false).explicitGet()._1 - val sellerScript = Some(ScriptCompiler(sellerScriptSrc).explicitGet()._1) - val buyerScript = Some(ScriptCompiler(buyerScriptSrc).explicitGet()._1) + val sellerScript = Some(ScriptCompiler(sellerScriptSrc, isAssetScript = false).explicitGet()._1) + val buyerScript = Some(ScriptCompiler(buyerScriptSrc, isAssetScript = false).explicitGet()._1) val chainId = AddressScheme.current.chainId diff --git a/src/test/scala/com/wavesplatform/state/diffs/smart/performance/SigVerifyPerformanceTest.scala b/src/test/scala/com/wavesplatform/state/diffs/smart/performance/SigVerifyPerformanceTest.scala index 33fe6e7e99..d70dcefcfc 100644 --- a/src/test/scala/com/wavesplatform/state/diffs/smart/performance/SigVerifyPerformanceTest.scala +++ b/src/test/scala/com/wavesplatform/state/diffs/smart/performance/SigVerifyPerformanceTest.scala @@ -54,7 +54,7 @@ class SigVerifyPerformanceTest extends PropSpec with PropertyChecks with Matcher ignore("parallel native signature verification vs sequential scripted signature verification") { val textScript = "sigVerify(tx.bodyBytes,tx.proofs[0],tx.senderPk)" val untypedScript = Parser(textScript).get.value - val typedScript = CompilerV1(compilerContext(V1), untypedScript).explicitGet()._1 + val typedScript = CompilerV1(compilerContext(V1, isAssetScript = false), untypedScript).explicitGet()._1 forAll(differentTransfers(typedScript)) { case (gen, setScript, transfers, scriptTransfers) => diff --git a/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ContextFunctionsTest.scala b/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ContextFunctionsTest.scala index 11e0f9803d..1456ee0ba9 100644 --- a/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ContextFunctionsTest.scala +++ b/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ContextFunctionsTest.scala @@ -52,7 +52,7 @@ class ContextFunctionsTest extends PropSpec with PropertyChecks with Matchers wi .map(x => Parser(x).get.value) typedScript = { - val compilerScript = CompilerV1(compilerContext(V1), untypedScript).explicitGet()._1 + val compilerScript = CompilerV1(compilerContext(V1, isAssetScript = false), untypedScript).explicitGet()._1 ScriptV1(compilerScript).explicitGet() } setScriptTransaction: SetScriptTransaction = SetScriptTransaction.selfSigned(1, recipient, Some(typedScript), 100000000L, ts).explicitGet() diff --git a/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ObsoleteTransactionBindingsTest.scala b/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ObsoleteTransactionBindingsTest.scala index abff1116e0..0271202d13 100644 --- a/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ObsoleteTransactionBindingsTest.scala +++ b/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ObsoleteTransactionBindingsTest.scala @@ -75,7 +75,7 @@ class ObsoleteTransactionBindingsTest extends PropSpec with PropertyChecks with genesis: GenesisTransaction = GenesisTransaction.create(master, ENOUGH_AMT * 3, ts).explicitGet() payment = PaymentTransaction.create(master, recipient, ENOUGH_AMT * 2, fee, ts).explicitGet() untypedScript = Parser(script(genesis, payment)).get.value - typedScript = ScriptV1(CompilerV1(compilerContext(V1), untypedScript).explicitGet()._1).explicitGet() + typedScript = ScriptV1(CompilerV1(compilerContext(V1, isAssetScript = false), untypedScript).explicitGet()._1).explicitGet() setScriptTransaction: SetScriptTransaction = SetScriptTransaction .selfSigned(1, recipient, Some(typedScript), 100000000L, ts) .explicitGet() diff --git a/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ScriptVersionsTest.scala b/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ScriptVersionsTest.scala index 02a1a33c7e..7d32e64eaf 100644 --- a/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ScriptVersionsTest.scala +++ b/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ScriptVersionsTest.scala @@ -28,7 +28,7 @@ class ScriptVersionsTest extends FreeSpec with PropertyChecks with Matchers with blockchain: Blockchain = EmptyBlockchain): Either[String, T] = { val Success(expr, _) = Parser(script) for { - compileResult <- CompilerV1(compilerContext(version), expr) + compileResult <- CompilerV1(compilerContext(version, isAssetScript = false), expr) (typedExpr, _) = compileResult s <- ScriptV1(version, typedExpr, checkSize = false) r <- ScriptRunner[T](blockchain.height, Coproduct(tx), blockchain, s, true, true)._2 @@ -51,7 +51,7 @@ class ScriptVersionsTest extends FreeSpec with PropertyChecks with Matchers with import com.wavesplatform.lagonaki.mocks.TestBlock.{create => block} val Success(expr, _) = Parser(duplicateNames) - val Right((typedExpr, _)) = CompilerV1(compilerContext(V1), expr) + val Right((typedExpr, _)) = CompilerV1(compilerContext(V1, isAssetScript = false), expr) val settings = TestFunctionalitySettings.Enabled.copy( preActivatedFeatures = Map(BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.SmartAccountTrading.id -> 3)) val setup = for { diff --git a/src/test/scala/com/wavesplatform/state/diffs/smart/predef/SerContextFunctionsTest.scala b/src/test/scala/com/wavesplatform/state/diffs/smart/predef/SerContextFunctionsTest.scala index 0893edc7fb..711f5d76c6 100644 --- a/src/test/scala/com/wavesplatform/state/diffs/smart/predef/SerContextFunctionsTest.scala +++ b/src/test/scala/com/wavesplatform/state/diffs/smart/predef/SerContextFunctionsTest.scala @@ -50,7 +50,7 @@ class SerContextFunctionsTest extends PropSpec with PropertyChecks with Matchers .get val untypedScript = Parser(scriptWithAllFunctions(dtx, ttx)).get.value - val compiledScript = CompilerV1(compilerContext(V1), untypedScript).explicitGet()._1 + val compiledScript = CompilerV1(compilerContext(V1, isAssetScript = false), untypedScript).explicitGet()._1 val bytes = Array[Byte](4, 0, 0, 0, 3, 114, 110, 100, 9, 0, 0, 0, 0, 0, 0, 2, 9, 0, 0, 106, 0, 0, 0, 2, 8, 5, 0, 0, 0, 2, 116, 120, 0, 0, 0, 9, 116, 105, 109, 101, 115, 116, 97, 109, 112, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 7, 108, 111, 110, 103, 65, 108, 108, 3, 3, 3, 3, 9, 0, 0, 0, 0, 0, 0, 2, 9, 0, 0, 104, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, -24, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, diff --git a/src/test/scala/com/wavesplatform/state/diffs/smart/predef/package.scala b/src/test/scala/com/wavesplatform/state/diffs/smart/predef/package.scala index 75c991635c..8ded9d5da8 100644 --- a/src/test/scala/com/wavesplatform/state/diffs/smart/predef/package.scala +++ b/src/test/scala/com/wavesplatform/state/diffs/smart/predef/package.scala @@ -22,7 +22,7 @@ package object predef { def runScript[T <: EVALUATED](script: String, version: ScriptVersion, t: In, blockchain: Blockchain, networkByte: Byte): Either[String, T] = { val Success(expr, _) = Parser(script) for { - compileResult <- CompilerV1(compilerContext(version), expr) + compileResult <- CompilerV1(compilerContext(version, isAssetScript = false), expr) (typedExpr, _) = compileResult evalContext = BlockchainContext.build(version, networkByte, Coeval.evalOnce(t), Coeval.evalOnce(blockchain.height), blockchain, true, true) r <- EvaluatorV1[T](evalContext, typedExpr) diff --git a/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/MultiSig2of3Test.scala b/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/MultiSig2of3Test.scala index 2bc68bbfc0..3ae212fff5 100644 --- a/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/MultiSig2of3Test.scala +++ b/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/MultiSig2of3Test.scala @@ -38,7 +38,7 @@ class MultiSig2of3Test extends PropSpec with PropertyChecks with Matchers with T | """.stripMargin val untyped = Parser(script).get.value - CompilerV1(compilerContext(V1), untyped).explicitGet()._1 + CompilerV1(compilerContext(V1, isAssetScript = false), untyped).explicitGet()._1 } val preconditionsAndTransfer: Gen[(GenesisTransaction, SetScriptTransaction, TransferTransactionV2, Seq[ByteStr])] = for { diff --git a/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/NotaryControlledTransferScenarioTest.scala b/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/NotaryControlledTransferScenarioTest.scala index 2912a69c5c..ef250d7295 100644 --- a/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/NotaryControlledTransferScenarioTest.scala +++ b/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/NotaryControlledTransferScenarioTest.scala @@ -61,7 +61,7 @@ class NotaryControlledTransferScenarioTest extends PropSpec with PropertyChecks untypedScript = Parser(assetScript).get.value - typedScript = ScriptV1(CompilerV1(compilerContext(V1), untypedScript).explicitGet()._1).explicitGet() + typedScript = ScriptV1(CompilerV1(compilerContext(V1, isAssetScript = false), untypedScript).explicitGet()._1).explicitGet() issueTransaction = IssueTransactionV2 .selfSigned( @@ -111,7 +111,7 @@ class NotaryControlledTransferScenarioTest extends PropSpec with PropertyChecks private def eval(code: String) = { val untyped = Parser(code).get.value - val typed = CompilerV1(compilerContext(V1), untyped).map(_._1) + val typed = CompilerV1(compilerContext(V1, isAssetScript = false), untyped).map(_._1) typed.flatMap(EvaluatorV1[EVALUATED](dummyEvalContext(V1), _)) } diff --git a/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OnlyTransferIsAllowedTest.scala b/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OnlyTransferIsAllowedTest.scala index 286a328c41..49a7c99130 100644 --- a/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OnlyTransferIsAllowedTest.scala +++ b/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OnlyTransferIsAllowedTest.scala @@ -27,7 +27,7 @@ class OnlyTransferIsAllowedTest extends PropSpec with PropertyChecks with Matche | } """.stripMargin val untyped = Parser(scriptText).get.value - val transferAllowed = CompilerV1(compilerContext(V1), untyped).explicitGet()._1 + val transferAllowed = CompilerV1(compilerContext(V1, isAssetScript = false), untyped).explicitGet()._1 forAll(preconditionsTransferAndLease(transferAllowed)) { case (genesis, script, lease, transfer) => diff --git a/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OracleDataTest.scala b/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OracleDataTest.scala index 33cb621d2a..da8a0a0326 100644 --- a/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OracleDataTest.scala +++ b/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/OracleDataTest.scala @@ -56,7 +56,7 @@ class OracleDataTest extends PropSpec with PropertyChecks with Matchers with Tra |}""".stripMargin setScript <- { val untypedAllFieldsRequiredScript = Parser(allFieldsRequiredScript).get.value - val typedAllFieldsRequiredScript = CompilerV1(compilerContext(V1), untypedAllFieldsRequiredScript).explicitGet()._1 + val typedAllFieldsRequiredScript = CompilerV1(compilerContext(V1, isAssetScript = false), untypedAllFieldsRequiredScript).explicitGet()._1 selfSignedSetScriptTransactionGenP(master, ScriptV1(typedAllFieldsRequiredScript).explicitGet()) } transferFromScripted <- versionedTransferGenP(master, alice, Proofs.empty) diff --git a/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/ScriptedSponsorTest.scala b/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/ScriptedSponsorTest.scala index 2261779e47..00cf1d8521 100644 --- a/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/ScriptedSponsorTest.scala +++ b/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/ScriptedSponsorTest.scala @@ -102,7 +102,7 @@ class ScriptedSponsorTest extends PropSpec with PropertyChecks with Matchers wit gen2 = GenesisTransaction .create(recipient, ENOUGH_AMT, timestamp) .explicitGet() - (script, _) = ScriptCompiler(s"false").explicitGet() + (script, _) = ScriptCompiler(s"false", isAssetScript = false).explicitGet() issueTx = IssueTransactionV1 .selfSigned( sender = contract, @@ -174,7 +174,7 @@ class ScriptedSponsorTest extends PropSpec with PropertyChecks with Matchers wit gen2 = GenesisTransaction .create(sponsor, ENOUGH_AMT, timestamp) .explicitGet() - (script, _) = ScriptCompiler(s"true").explicitGet() + (script, _) = ScriptCompiler(s"true", isAssetScript = false).explicitGet() issueTx = IssueTransactionV1 .selfSigned( sender = sponsor, diff --git a/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/TransactionFieldAccessTest.scala b/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/TransactionFieldAccessTest.scala index c235af43ad..439d8b3bd9 100644 --- a/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/TransactionFieldAccessTest.scala +++ b/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/TransactionFieldAccessTest.scala @@ -22,7 +22,7 @@ class TransactionFieldAccessTest extends PropSpec with PropertyChecks with Match private def preconditionsTransferAndLease( code: String): Gen[(GenesisTransaction, SetScriptTransaction, LeaseTransaction, TransferTransactionV2)] = { val untyped = Parser(code).get.value - val typed = CompilerV1(compilerContext(V1), untyped).explicitGet()._1 + val typed = CompilerV1(compilerContext(V1, isAssetScript = false), untyped).explicitGet()._1 preconditionsTransferAndLease(typed) } diff --git a/src/test/scala/com/wavesplatform/transaction/smart/script/ScriptCompilerV1Test.scala b/src/test/scala/com/wavesplatform/transaction/smart/script/ScriptCompilerV1Test.scala index af4380bf34..07a3b4ce98 100644 --- a/src/test/scala/com/wavesplatform/transaction/smart/script/ScriptCompilerV1Test.scala +++ b/src/test/scala/com/wavesplatform/transaction/smart/script/ScriptCompilerV1Test.scala @@ -14,22 +14,22 @@ class ScriptCompilerV1Test extends PropSpec with PropertyChecks with Matchers { property("compile script with specified version") { val script = scriptWithVersion("1".some) - ScriptCompiler(script) shouldBe Right((expectedScript, 13)) + ScriptCompiler(script, isAssetScript = false) shouldBe Right((expectedScript, 13)) } property("use version 1 if not specified") { val script = scriptWithVersion(none) - ScriptCompiler(script) shouldBe Right((expectedScript, 13)) + ScriptCompiler(script, isAssetScript = false) shouldBe Right((expectedScript, 13)) } property("fails on unsupported version") { val script = scriptWithVersion("8".some) - ScriptCompiler(script) shouldBe Left("Unsupported language version") + ScriptCompiler(script, isAssetScript = false) shouldBe Left("Unsupported language version") } property("fails on incorrect version value") { val script = scriptWithVersion("oOooOps".some) - ScriptCompiler(script) shouldBe Left("Can't parse language version") + ScriptCompiler(script, isAssetScript = false) shouldBe Left("Can't parse language version") } private val expectedExpr = BLOCK( From 38a2229f00136e60473252b21981529d15275ced Mon Sep 17 00:00:00 2001 From: Alexandr Makoed Date: Wed, 28 Nov 2018 12:55:45 +0300 Subject: [PATCH 3/3] NODE-1311: Fix IT --- .../it/sync/transactions/SetAssetScriptTransactionSuite.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/it/src/test/scala/com/wavesplatform/it/sync/transactions/SetAssetScriptTransactionSuite.scala b/it/src/test/scala/com/wavesplatform/it/sync/transactions/SetAssetScriptTransactionSuite.scala index e8ced5cf05..b56581c961 100644 --- a/it/src/test/scala/com/wavesplatform/it/sync/transactions/SetAssetScriptTransactionSuite.scala +++ b/it/src/test/scala/com/wavesplatform/it/sync/transactions/SetAssetScriptTransactionSuite.scala @@ -259,7 +259,7 @@ class SetAssetScriptTransactionSuite extends BaseTransactionSuite { |match tx { |case s : SetAssetScriptTransaction => sigVerify(s.bodyBytes,s.proofs[0],pkB) |case _ => true}""".stripMargin, - isAssetScript = true + isAssetScript = false ).explicitGet()._1), setScriptFee, System.currentTimeMillis()