diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/EvaluatorV2Benchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/EvaluatorV2Benchmark.scala index bbd723a1c56..ddeb86bbd97 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/EvaluatorV2Benchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/EvaluatorV2Benchmark.scala @@ -17,7 +17,7 @@ import org.openjdk.jmh.infra.Blackhole import scala.annotation.tailrec object EvaluatorV2Benchmark { - val pureContext: CTX[Environment] = PureContext.build(V1, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] + val pureContext: CTX[Environment] = PureContext.build(V1, useNewPowPrecision = true).withEnvironment[Environment] val pureEvalContext: EvaluationContext[Environment, Id] = pureContext.evaluationContext(Common.emptyBlockchainEnvironment()) } diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/ScriptEvaluatorBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/ScriptEvaluatorBenchmark.scala index 25c77a4e9f4..65f936fa2d3 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/ScriptEvaluatorBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/ScriptEvaluatorBenchmark.scala @@ -27,7 +27,7 @@ import scala.util.Random object ScriptEvaluatorBenchmark { val version = V1 val pureEvalContext: EvaluationContext[NoContext, Id] = - PureContext.build(V1, fixUnicodeFunctions = true, useNewPowPrecision = true).evaluationContext + PureContext.build(V1, useNewPowPrecision = true).evaluationContext val evaluatorV1: EvaluatorV1[Id, NoContext] = new EvaluatorV1[Id, NoContext]() } @@ -218,7 +218,7 @@ class Concat { @State(Scope.Benchmark) class Median { - val context: EvaluationContext[NoContext, Id] = PureContext.build(V4, fixUnicodeFunctions = true, useNewPowPrecision = true).evaluationContext + val context: EvaluationContext[NoContext, Id] = PureContext.build(V4, useNewPowPrecision = true).evaluationContext val randomElements: Array[EXPR] = (1 to 10000).map { _ => @@ -261,7 +261,7 @@ class Median { @State(Scope.Benchmark) class SigVerify32Kb { val context: EvaluationContext[NoContext, Id] = - Monoid.combine(PureContext.build(V4, fixUnicodeFunctions = true, useNewPowPrecision = true).evaluationContext, + Monoid.combine(PureContext.build(V4, useNewPowPrecision = true).evaluationContext, CryptoContext.build(Global, V4).evaluationContext) val expr: EXPR = { @@ -284,7 +284,7 @@ class SigVerify32Kb { class ListRemoveByIndex { val context: EvaluationContext[NoContext, Id] = Monoid.combine( - PureContext.build(V4, fixUnicodeFunctions = true, useNewPowPrecision = true).evaluationContext, + PureContext.build(V4, useNewPowPrecision = true).evaluationContext, CryptoContext.build(Global, V4).evaluationContext ) diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/package.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/package.scala index e2ad4a537d8..586b8c9a9a1 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/package.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/package.scala @@ -30,5 +30,5 @@ package object v1 { expr: EXPR, stdLibVersion: StdLibVersion ): (Log[Id], Int, Either[ExecutionError, Terms.EVALUATED]) = - EvaluatorV2.applyCompleted(ctx, expr, stdLibVersion, newMode = true) + EvaluatorV2.applyCompleted(ctx, expr, stdLibVersion, newMode = true, correctFunctionCallScope = true) } diff --git a/benchmark/src/test/scala/com/wavesplatform/state/BloomFilterBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/state/BloomFilterBenchmark.scala index 74b4ed77ea9..c855e2b68d6 100644 --- a/benchmark/src/test/scala/com/wavesplatform/state/BloomFilterBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/state/BloomFilterBenchmark.scala @@ -32,7 +32,7 @@ class BloomFilterBenchmark { @Benchmark def verifyExchangeTxSign(bh: Blackhole, st: St): Unit = { - bh.consume(Verifier.verifyAsEllipticCurveSignature(st.exchangeTransactions(Random.nextInt(1000)))) + bh.consume(Verifier.verifyAsEllipticCurveSignature(st.exchangeTransactions(Random.nextInt(1000)), checkWeakPk = false)) } } diff --git a/lang/doc/src/main/scala/com/wavesplatform/utils/doc/RideFullContext.scala b/lang/doc/src/main/scala/com/wavesplatform/utils/doc/RideFullContext.scala index 0f1a813d6b7..19564796fa2 100644 --- a/lang/doc/src/main/scala/com/wavesplatform/utils/doc/RideFullContext.scala +++ b/lang/doc/src/main/scala/com/wavesplatform/utils/doc/RideFullContext.scala @@ -12,7 +12,7 @@ object RideFullContext { def build(ds: DirectiveSet): CTX[Environment] = { val wavesCtx = WavesContext.build(Global,ds) val cryptoCtx = CryptoContext.build(Global, ds.stdLibVersion).withEnvironment[Environment] - val pureCtx = PureContext.build(ds.stdLibVersion).withEnvironment[Environment] + val pureCtx = PureContext.build().withEnvironment[Environment] pureCtx |+| cryptoCtx |+| wavesCtx } } diff --git a/lang/js/src/main/scala/JsAPI.scala b/lang/js/src/main/scala/JsAPI.scala index 9eed31a812f..4c8805cebaa 100644 --- a/lang/js/src/main/scala/JsAPI.scala +++ b/lang/js/src/main/scala/JsAPI.scala @@ -33,7 +33,7 @@ object JsAPI { ) private def cryptoContext(version: StdLibVersion) = CryptoContext.build(Global, version).withEnvironment[Environment] - private def pureContext(version: StdLibVersion) = PureContext.build(version, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] + private def pureContext(version: StdLibVersion) = PureContext.build(version, useNewPowPrecision = true).withEnvironment[Environment] private val fullDAppContext: Map[StdLibVersion, CTX[Environment]] = DirectiveDictionary[StdLibVersion].all 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 52c050f437d..7b677c88af4 100644 --- a/lang/jvm/src/main/scala/com/wavesplatform/lang/JavaAdapter.scala +++ b/lang/jvm/src/main/scala/com/wavesplatform/lang/JavaAdapter.scala @@ -15,7 +15,7 @@ object JavaAdapter { Seq( CryptoContext.compilerContext(Global, version), WavesContext.build(Global, ???).compilerContext, - PureContext.build(version, fixUnicodeFunctions = true, useNewPowPrecision = true).compilerContext + PureContext.build(version, useNewPowPrecision = true).compilerContext )) def compile(input: String): EXPR = { diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/utils/package.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/utils/package.scala index 24ffca9d317..ee3902294df 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/utils/package.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/utils/package.scala @@ -76,7 +76,7 @@ package object utils { val ctx = Coeval.evalOnce( Monoid.combineAll( Seq( - PureContext.build(version, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(version, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(Global, version).withEnvironment[Environment], WavesContext.build(Global, ds) ) diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/EvaluatorV2.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/EvaluatorV2.scala index 8a08d1ba2ec..d39c9df11a5 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/EvaluatorV2.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/EvaluatorV2.scala @@ -306,12 +306,12 @@ class EvaluatorV2( case _ => Coeval.now(unused) } } - .onErrorHandle { e => - val error = if (e.getMessage != null) e.getMessage else e.toString + .onErrorHandle { throwable => + val error = if (throwable.getMessage != null) throwable.getMessage else throwable.toString ctx.log(let, Left(error)) - throw e match { - case _: EvaluationException | _: RejectException => e - case _ => EvaluationException(e.getMessage, limit) + throw throwable match { + case evalExc: EvaluationException => evalExc + case other => EvaluationException(other.getMessage, limit) } } } diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/RejectException.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/RejectException.scala deleted file mode 100644 index 3a62544ab43..00000000000 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/RejectException.scala +++ /dev/null @@ -1,3 +0,0 @@ -package com.wavesplatform.lang.v1.evaluator - -case class RejectException(error: String) extends RuntimeException(error) diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ScriptResult.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ScriptResult.scala index 54af999c869..a4ae0635a87 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ScriptResult.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ScriptResult.scala @@ -20,6 +20,7 @@ import com.wavesplatform.lang.v1.traits.domain._ sealed trait ScriptResult { def returnedValue: EVALUATED = unit def invokes: Seq[(Address, String, Seq[EVALUATED], Seq[CaseObj], ScriptResult)] = Nil + def unusedComplexity: Int } case class ScriptResultV3(ds: List[DataItem[_]], ts: List[AssetTransfer], unusedComplexity: Int) extends ScriptResult case class ScriptResultV4( diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/PureContext.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/PureContext.scala index ae09c5c5ba9..d8c4c0b6b4a 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/PureContext.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/PureContext.scala @@ -561,9 +561,9 @@ object PureContext { } private val dropBytesBeforeV6 = dropBytes(checkLimits = false) - private val dropBytesFromV6 = dropBytes(checkLimits = true) + private val dropBytesFromV6 = dropBytes(checkLimits = true) private val takeBytesBeforeV6 = takeBytes(checkLimits = false) - private val takeBytesFromV6 = takeBytes(checkLimits = true) + private val takeBytesFromV6 = takeBytes(checkLimits = true) private val dropRightBytesBeforeV6: BaseFunction[NoContext] = UserFunction( @@ -839,14 +839,14 @@ object PureContext { ) { case CONST_STRING(xs) :: CONST_LONG(number) :: Nil => val limit = Terms.DataEntryValueMax - if (number < 0) - Left(s"Unexpected negative number = $number passed to takeRight()") - else if (number > limit) - Left(s"Number = $number passed to takeRight() exceeds String limit = $limit") - else { - val correctedNumber = number.max(0).min(xs.codePointCount(0, xs.length)) - CONST_STRING(xs.takeRight(xs.offsetByCodePoints(0, trimLongToInt(correctedNumber)))) - } + if (number < 0) + Left(s"Unexpected negative number = $number passed to takeRight()") + else if (number > limit) + Left(s"Number = $number passed to takeRight() exceeds String limit = $limit") + else { + val correctedNumber = number.max(0).min(xs.codePointCount(0, xs.length)) + CONST_STRING(xs.takeRight(xs.offsetByCodePoints(0, trimLongToInt(correctedNumber)))) + } case xs => notImplemented[Id, EVALUATED]("takeRight(xs: String, number: Int)", xs) } @@ -920,7 +920,6 @@ object PureContext { notImplemented[Id, EVALUATED]("dropRight(xs: String, number: Int)", xs) } - val UTF8Decoder = UTF_8.newDecoder def toUtf8String(reduceLimit: Boolean): BaseFunction[NoContext] = @@ -1492,7 +1491,7 @@ object PureContext { 1, (CREATE_TUPLE + resultSize - 2).toShort, PARAMETERIZEDTUPLE(typeParams), - typeParams.mapWithIndex { case (typeParam, i) => (s"element${i + 1}", typeParam) }* + typeParams.mapWithIndex { case (typeParam, i) => (s"element${i + 1}", typeParam) } * ) { case elements if elements.length == resultSize => val fields = elements.mapWithIndex { case (element, i) => (s"_${i + 1}", element) }.toMap @@ -1513,16 +1512,18 @@ object PureContext { } def pow(roundTypes: UNION, useNewPrecision: Boolean): BaseFunction[NoContext] = { - NativeFunction("pow", - Map(V3 -> 100L, V4 -> 100L, V5 -> 100L, V6 -> 28L), - POW, - LONG, - ("base", LONG), - ("bp", LONG), - ("exponent", LONG), - ("ep", LONG), - ("rp", LONG), - ("round", roundTypes)) { + NativeFunction( + "pow", + Map(V3 -> 100L, V4 -> 100L, V5 -> 100L, V6 -> 28L), + POW, + LONG, + ("base", LONG), + ("bp", LONG), + ("exponent", LONG), + ("ep", LONG), + ("rp", LONG), + ("round", roundTypes) + ) { case CONST_LONG(b) :: CONST_LONG(bp) :: CONST_LONG(e) :: CONST_LONG(ep) :: CONST_LONG(rp) :: round :: Nil => if (bp < 0 || bp > 8 @@ -1716,7 +1717,7 @@ object PureContext { m.flatMap(result) { case (Right(value), complexity) => evaluateUserFunction(function, List(value, element), complexity) case (error, complexity) => Coeval((error, complexity).pure[F]) - } + } ) case xs => val err = notImplemented[F, EVALUATED](s"fold_$limit(list: List[A], accumulator: B, function: String)", xs) @@ -1834,7 +1835,7 @@ object PureContext { Array( extract, fraction(fixLimitCheck = false), - sizeStringFixed, + sizeStringFixed ) private val v1V2V3CommonFunctionsUnfixed = @@ -1884,14 +1885,14 @@ object PureContext { splitStrFixed ) - private def v3Functions(fixUnicodeFunctions: Boolean, useNewPowPrecision: Boolean) = - v1V2V3CommonFunctions(fixUnicodeFunctions) ++ + private def v3Functions(useNewPowPrecision: Boolean) = + v1V2V3CommonFunctions(useNewPowPrecision) ++ fromV3Functions ++ v3V4Functions(useNewPowPrecision) ++ Array( toUtf8String(reduceLimit = false), listConstructor(checkSize = false) - ) ++ (if (fixUnicodeFunctions) v3FunctionFixed else v3FunctionsUnfixed) + ) ++ (if (useNewPowPrecision) v3FunctionFixed else v3FunctionsUnfixed) private val fromV4Functions = commonFunctions ++ @@ -1913,11 +1914,11 @@ object PureContext { makeString ) ++ (MinTupleSize to MaxTupleSize).map(i => createTupleN(i)) - private def v4FunctionsUnfixed(useNewPowPrecision: Boolean) = + private def v4FunctionsUnfixed = fromV4Functions ++ takeDropBytesBeforeV6 ++ takeDropStringUnfixedBeforeV6 ++ - v3V4Functions(useNewPowPrecision) ++ + v3V4Functions(useNewPowPrecision = false) ++ Array( indexOf, indexOfN, @@ -1928,11 +1929,11 @@ object PureContext { fraction(fixLimitCheck = false) ) - private def v4FunctionsFixed(useNewPowPrecision: Boolean) = + private def v4FunctionsFixed = fromV4Functions ++ takeDropBytesBeforeV6 ++ takeDropStringFixedBeforeV6 ++ - v3V4Functions(useNewPowPrecision) ++ + v3V4Functions(useNewPowPrecision = true) ++ Array( indexOfFixed, indexOfNFixed, @@ -1943,8 +1944,8 @@ object PureContext { fraction(fixLimitCheck = false) ) - private def v4Functions(fixUnicodeFunctions: Boolean, useNewPowPrecision: Boolean) = - if (fixUnicodeFunctions) v4FunctionsFixed(useNewPowPrecision) else v4FunctionsUnfixed(useNewPowPrecision) + private def v4Functions(useNewPowPrecision: Boolean) = + if (useNewPowPrecision) v4FunctionsFixed else v4FunctionsUnfixed private def fromV5Functions(useNewPowPrecision: Boolean) = fromV4Functions ++ @@ -1980,7 +1981,7 @@ object PureContext { logBigInt(UNION(fromV5RoundTypes)), pow(UNION(fromV5RoundTypes), useNewPowPrecision), log(UNION(fromV5RoundTypes)), - fraction(fixLimitCheck = true), + fraction(fixLimitCheck = true) ) private def v5Functions(useNewPowPrecision: Boolean) = @@ -2015,28 +2016,20 @@ object PureContext { v1V2V3CommonFunctions(fixUnicodeFunctions) ) - private def v3Ctx(fixUnicodeFunctions: Boolean, useNewPowPrecision: Boolean) = + private def v3Ctx(useNewPowPrecision: Boolean) = CTX[NoContext]( v1v2v3v4Types, v3V4Vars, - v3Functions(fixUnicodeFunctions, useNewPowPrecision) + v3Functions(useNewPowPrecision) ) - private def v4Ctx(fixUnicodeFunctions: Boolean, useNewPowPrecision: Boolean) = + private def v4Ctx(useNewPowPrecision: Boolean) = CTX[NoContext]( v1v2v3v4Types, v3V4Vars, - v4Functions(fixUnicodeFunctions, useNewPowPrecision) + v4Functions(useNewPowPrecision) ) - private val v1V2CtxFixed = v1V2Ctx(true) - private def v3CtxFixed(useNewPowPrecision: Boolean) = v3Ctx(true, useNewPowPrecision) - private def v4CtxFixed(useNewPowPrecision: Boolean) = v4Ctx(true, useNewPowPrecision) - - private val v1V2CtxUnfixed = v1V2Ctx(false) - private def v3CtxUnfixed(useNewPowPrecision: Boolean) = v3Ctx(false, useNewPowPrecision) - private def v4CtxUnfixed(useNewPowPrecision: Boolean) = v4Ctx(false, useNewPowPrecision) - private def v5Ctx(useNewPowPrecision: Boolean) = CTX[NoContext]( v5Types, @@ -2044,22 +2037,19 @@ object PureContext { v5Functions(useNewPowPrecision) ) - private val v6Ctx = + private[this] val v6Ctx = CTX[NoContext]( v5Types, v5Vars, v6Functions ) - def build(version: StdLibVersion, fixUnicodeFunctions: Boolean, useNewPowPrecision: Boolean): CTX[NoContext] = + def build(version: StdLibVersion, useNewPowPrecision: Boolean): CTX[NoContext] = version match { - case V1 | V2 if fixUnicodeFunctions => v1V2CtxFixed - case V3 if fixUnicodeFunctions => v3CtxFixed(useNewPowPrecision) - case V4 if fixUnicodeFunctions => v4CtxFixed(useNewPowPrecision) - case V1 | V2 => v1V2CtxUnfixed - case V3 => v3CtxUnfixed(useNewPowPrecision) - case V4 => v4CtxUnfixed(useNewPowPrecision) - case V5 => v5Ctx(useNewPowPrecision) - case V6 => v6Ctx + case V1 | V2 => v1V2Ctx(useNewPowPrecision) + case V3 => v3Ctx(useNewPowPrecision) + case V4 => v4Ctx(useNewPowPrecision) + case V5 => v5Ctx(useNewPowPrecision) + case V6 => v6Ctx } } diff --git a/lang/testkit/src/main/scala/com/wavesplatform/lang/Common.scala b/lang/testkit/src/main/scala/com/wavesplatform/lang/Common.scala index 20114f3c5c6..80281a88e26 100644 --- a/lang/testkit/src/main/scala/com/wavesplatform/lang/Common.scala +++ b/lang/testkit/src/main/scala/com/wavesplatform/lang/Common.scala @@ -30,7 +30,7 @@ object Common { def ev[T <: EVALUATED]( context: EvaluationContext[NoContext, Id] = - Monoid.combine(PureContext.build(V1, fixUnicodeFunctions = true, useNewPowPrecision = true).evaluationContext, addCtx.evaluationContext), + Monoid.combine(PureContext.build(V1, useNewPowPrecision = true).evaluationContext, addCtx.evaluationContext), expr: EXPR ): Either[ExecutionError, T] = new EvaluatorV1[Id, NoContext]().apply[T](context, expr) diff --git a/lang/testkit/src/main/scala/com/wavesplatform/lang/v1/compiler/TestCompiler.scala b/lang/testkit/src/main/scala/com/wavesplatform/lang/v1/compiler/TestCompiler.scala index 4234f2bbb33..31220370515 100644 --- a/lang/testkit/src/main/scala/com/wavesplatform/lang/v1/compiler/TestCompiler.scala +++ b/lang/testkit/src/main/scala/com/wavesplatform/lang/v1/compiler/TestCompiler.scala @@ -17,7 +17,7 @@ import scala.collection.mutable class TestCompiler(version: StdLibVersion) { private lazy val baseCompilerContext = - PureContext.build(version, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(version, useNewPowPrecision = true).withEnvironment[Environment] |+| CryptoContext.build(Global, version).withEnvironment[Environment] private lazy val compilerContext = @@ -39,7 +39,7 @@ class TestCompiler(version: StdLibVersion) { def compileContract(script: String, allowIllFormedStrings: Boolean = false): Script = ContractScript(version, compile(script, allowIllFormedStrings).explicitGet()).explicitGet() - def compileExpression(script: String, allowIllFormedStrings: Boolean = false, checkSize: Boolean = true): Script = + def compileExpression(script: String, allowIllFormedStrings: Boolean = false, checkSize: Boolean = true): ExprScript = ExprScript( version, ExpressionCompiler.compile(script, expressionCompilerContext, allowIllFormedStrings).explicitGet()._1, diff --git a/lang/tests/src/test/scala/com/wavesplatform/lang/ContractIntegrationTest.scala b/lang/tests/src/test/scala/com/wavesplatform/lang/ContractIntegrationTest.scala index 685760c3725..ffd89879e87 100644 --- a/lang/tests/src/test/scala/com/wavesplatform/lang/ContractIntegrationTest.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/lang/ContractIntegrationTest.scala @@ -24,7 +24,7 @@ import org.scalatest.Inside class ContractIntegrationTest extends PropSpec with Inside { private val ctx: CTX[Environment] = - PureContext.build(V3, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(V3, useNewPowPrecision = true).withEnvironment[Environment] |+| CTX[Environment](sampleTypes, Map.empty, Array.empty) |+| WavesContext.build( Global, diff --git a/lang/tests/src/test/scala/com/wavesplatform/lang/EvaluatorV1CaseObjField.scala b/lang/tests/src/test/scala/com/wavesplatform/lang/EvaluatorV1CaseObjField.scala index 3957fb025a0..0e1eb1116be 100644 --- a/lang/tests/src/test/scala/com/wavesplatform/lang/EvaluatorV1CaseObjField.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/lang/EvaluatorV1CaseObjField.scala @@ -16,7 +16,7 @@ import com.wavesplatform.test.PropSpec class EvaluatorV1CaseObjField extends PropSpec { def context(p: CaseObj): EvaluationContext[NoContext, Id] = - Monoid.combine(PureContext.build(V1, fixUnicodeFunctions = true, useNewPowPrecision = true).evaluationContext, sampleUnionContext(p)) + Monoid.combine(PureContext.build(V1, useNewPowPrecision = true).evaluationContext, sampleUnionContext(p)) property("case custom type field access") { ev[CONST_LONG]( diff --git a/lang/tests/src/test/scala/com/wavesplatform/lang/IntegrationTest.scala b/lang/tests/src/test/scala/com/wavesplatform/lang/IntegrationTest.scala index dba4dee4871..6fbec65d896 100755 --- a/lang/tests/src/test/scala/com/wavesplatform/lang/IntegrationTest.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/lang/IntegrationTest.scala @@ -83,7 +83,7 @@ class IntegrationTest extends PropSpec with Inside { val ctx: CTX[C] = Monoid.combineAll( Seq( - PureContext.build(version, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[C], + PureContext.build(version, useNewPowPrecision = true).withEnvironment[C], CryptoContext.build(Global, version).withEnvironment[C], addCtx.withEnvironment[C], CTX[C](sampleTypes, stringToTuple, Array(f, f2)), @@ -430,7 +430,7 @@ class IntegrationTest extends PropSpec with Inside { } val context = Monoid.combine( - PureContext.build(V1, fixUnicodeFunctions = true, useNewPowPrecision = true).evaluationContext[Id], + PureContext.build(V1, useNewPowPrecision = true).evaluationContext[Id], EvaluationContext.build( typeDefs = Map.empty, letDefs = Map("x" -> LazyVal.fromEvaluated[Id](CONST_LONG(3L))), @@ -444,7 +444,7 @@ class IntegrationTest extends PropSpec with Inside { property("context won't change after execution of an inner block") { val context = Monoid.combine( - PureContext.build(V1, fixUnicodeFunctions = true, useNewPowPrecision = true).evaluationContext[Id], + PureContext.build(V1, useNewPowPrecision = true).evaluationContext[Id], EvaluationContext.build( typeDefs = Map.empty, letDefs = Map("x" -> LazyVal.fromEvaluated[Id](CONST_LONG(3L))), diff --git a/lang/tests/src/test/scala/com/wavesplatform/lang/ScriptPreprocessorTest.scala b/lang/tests/src/test/scala/com/wavesplatform/lang/ScriptPreprocessorTest.scala index 4b87622959b..59ae65d494a 100644 --- a/lang/tests/src/test/scala/com/wavesplatform/lang/ScriptPreprocessorTest.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/lang/ScriptPreprocessorTest.scala @@ -29,7 +29,7 @@ class ScriptPreprocessorTest extends PropSpec with ScriptGenParser { private def eval(code: String): Either[String, EVALUATED] = { val untyped = Parser.parseExpr(code).get.value - val ctx: CTX[NoContext] = Monoid.combineAll(Seq(PureContext.build(V3, fixUnicodeFunctions = true, useNewPowPrecision = true))) + val ctx: CTX[NoContext] = Monoid.combineAll(Seq(PureContext.build(V3, useNewPowPrecision = true))) val typed = ExpressionCompiler(ctx.compilerContext, untyped) typed.flatMap(v => evaluator.apply[EVALUATED](ctx.evaluationContext, v._1)) } diff --git a/lang/tests/src/test/scala/com/wavesplatform/lang/SerdeTest.scala b/lang/tests/src/test/scala/com/wavesplatform/lang/SerdeTest.scala index 61ba4f004ea..787600309c7 100644 --- a/lang/tests/src/test/scala/com/wavesplatform/lang/SerdeTest.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/lang/SerdeTest.scala @@ -176,7 +176,7 @@ class SerdeTest extends FreeSpec { } private def roundTripTest(untypedExpr: Expressions.EXPR): Assertion = { - val typedExpr = ExpressionCompiler(PureContext.build(V1, fixUnicodeFunctions = true, useNewPowPrecision = true).compilerContext, untypedExpr).map(_._1).explicitGet() + val typedExpr = ExpressionCompiler(PureContext.build(V1, useNewPowPrecision = true).compilerContext, untypedExpr).map(_._1).explicitGet() roundTripTest(typedExpr) } diff --git a/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/ContractCompilerCompactorTest.scala b/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/ContractCompilerCompactorTest.scala index 775371e2f76..acfd09c3343 100644 --- a/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/ContractCompilerCompactorTest.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/ContractCompilerCompactorTest.scala @@ -53,11 +53,11 @@ class ContractCompilerCompactorTest extends PropSpec { } val ctxV4 = - PureContext.build(V4, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(V4, useNewPowPrecision = true).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet(V4, Account, DAppType).explicitGet()) val ctxV5 = - PureContext.build(V5, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(V5, useNewPowPrecision = true).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet(V5, Account, DAppType).explicitGet()) def expectedScript(stdLibVersion: StdLibVersion): String = @@ -104,7 +104,7 @@ class ContractCompilerCompactorTest extends PropSpec { val stdLibVer = V3 val ctx = - PureContext.build(stdLibVer, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(stdLibVer, useNewPowPrecision = true).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet(stdLibVer, Account, DAppType).explicitGet()) val compilationResult = @@ -153,7 +153,7 @@ class ContractCompilerCompactorTest extends PropSpec { } val ctx = - PureContext.build(V5, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(V5, useNewPowPrecision = true).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet(V5, Account, DAppType).explicitGet()) val compilationResult = compiler.ContractCompiler(ctx.compilerContext, expr, V5, needCompaction = true).explicitGet().compactedSource(V5) @@ -198,7 +198,7 @@ class ContractCompilerCompactorTest extends PropSpec { } val ctx = - PureContext.build(V5, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(V5, useNewPowPrecision = true).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet(V5, Account, DAppType).explicitGet()) val compilationResult = compiler.ContractCompiler(ctx.compilerContext, expr, V5, needCompaction = true).explicitGet().compactedSource(V5) @@ -241,7 +241,7 @@ class ContractCompilerCompactorTest extends PropSpec { } val ctx = - PureContext.build(V5, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(V5, useNewPowPrecision = true).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet(V5, Account, DAppType).explicitGet()) val compilationCompactedResult = compiler.ContractCompiler(ctx.compilerContext, expr, V5, needCompaction = true) @@ -284,7 +284,7 @@ class ContractCompilerCompactorTest extends PropSpec { } val ctx = - PureContext.build(V5, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(V5, useNewPowPrecision = true).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet(V5, Account, DAppType).explicitGet()) val compilationResult = @@ -344,7 +344,7 @@ class ContractCompilerCompactorTest extends PropSpec { """.stripMargin val ctx = - PureContext.build(V5, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(V5, useNewPowPrecision = true).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet(V5, Account, DAppType).explicitGet()) //noinspection RedundantDefaultArgument @@ -390,7 +390,7 @@ class ContractCompilerCompactorTest extends PropSpec { } val ctx = - PureContext.build(V5, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(V5, useNewPowPrecision = true).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet(V5, Account, DAppType).explicitGet()) val compilationCompactedResult = compiler.ContractCompiler(ctx.compilerContext, expr, V5, needCompaction = true).explicitGet().compactedSource() @@ -428,7 +428,7 @@ class ContractCompilerCompactorTest extends PropSpec { } val ctx = - PureContext.build(V5, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(V5, useNewPowPrecision = true).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet(V5, Account, DAppType).explicitGet()) val compilationCompactedResult = compiler.ContractCompiler(ctx.compilerContext, expr, V5, needCompaction = true).explicitGet().compactedSource() diff --git a/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/ContractCompilerTest.scala b/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/ContractCompilerTest.scala index 46246da3dad..f8c4341e4e0 100644 --- a/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/ContractCompilerTest.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/ContractCompilerTest.scala @@ -29,7 +29,7 @@ class ContractCompilerTest extends PropSpec { Monoid .combineAll( Seq( - PureContext.build(V3, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(V3, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(com.wavesplatform.lang.Global, V3).withEnvironment[Environment], WavesContext.build( Global, @@ -43,7 +43,7 @@ class ContractCompilerTest extends PropSpec { Monoid .combineAll( Seq( - PureContext.build(V4, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(V4, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(com.wavesplatform.lang.Global, V4).withEnvironment[Environment], WavesContext.build( Global, @@ -429,7 +429,7 @@ class ContractCompilerTest extends PropSpec { val ctx = Monoid .combineAll( Seq( - PureContext.build(V3, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(V3, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(com.wavesplatform.lang.Global, V3).withEnvironment[Environment], WavesContext.build( Global, @@ -566,7 +566,7 @@ class ContractCompilerTest extends PropSpec { val ctx = Monoid .combineAll( Seq( - PureContext.build(V3, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(V3, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(com.wavesplatform.lang.Global, V3).withEnvironment[Environment], WavesContext.build( Global, @@ -1000,7 +1000,7 @@ class ContractCompilerTest extends PropSpec { Parser.parseContract(script).get.value } val ctx = - PureContext.build(V4, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(V4, useNewPowPrecision = true).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet(V4, Account, DAppType).explicitGet()) compiler.ContractCompiler(ctx.compilerContext, expr, V4) shouldBe Symbol("right") @@ -1010,7 +1010,7 @@ class ContractCompilerTest extends PropSpec { val ctx = Monoid .combineAll( Seq( - PureContext.build(V3, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(V3, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(com.wavesplatform.lang.Global, V3).withEnvironment[Environment], WavesContext.build( Global, @@ -1092,7 +1092,7 @@ class ContractCompilerTest extends PropSpec { Parser.parseContract(script).get.value } val ctx = - PureContext.build(V5, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(V5, useNewPowPrecision = true).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet(V5, Account, DAppType).explicitGet()) compiler.ContractCompiler(ctx.compilerContext, expr, V5) shouldBe Symbol("right") @@ -1130,7 +1130,7 @@ class ContractCompilerTest extends PropSpec { Parser.parseContract(script).get.value } val ctx = - PureContext.build(V4, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(V4, useNewPowPrecision = true).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet(V4, Account, DAppType).explicitGet()) compiler.ContractCompiler(ctx.compilerContext, expr, V4) shouldBe Symbol("left") @@ -1153,7 +1153,7 @@ class ContractCompilerTest extends PropSpec { Parser.parseContract(script).get.value } val ctx = - PureContext.build(V4, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(V4, useNewPowPrecision = true).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet(V4, Account, DAppType).explicitGet()) val result = compiler.ContractCompiler(ctx.compilerContext, expr, V4) diff --git a/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/DecompilerTest.scala b/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/DecompilerTest.scala index 9bfdff38be1..d2398c38397 100644 --- a/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/DecompilerTest.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/DecompilerTest.scala @@ -806,7 +806,7 @@ class DecompilerTest extends PropSpec { val ctx = Monoid.combine( - PureContext.build(V4, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(V4, useNewPowPrecision = true).withEnvironment[Environment], WavesContext.build(Global, DirectiveSet(V4, Account, DAppType).explicitGet()) ) @@ -867,7 +867,7 @@ class DecompilerTest extends PropSpec { val ctx = Monoid.combineAll( Seq( - PureContext.build(V4, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(V4, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(Global, V4).withEnvironment[Environment], WavesContext.build(Global, DirectiveSet(V4, Account, DAppType).explicitGet()) ) @@ -908,7 +908,7 @@ class DecompilerTest extends PropSpec { val ctx = Monoid.combineAll( Seq( - PureContext.build(V4, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(V4, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(Global, V4).withEnvironment[Environment], WavesContext.build(Global, DirectiveSet(V4, Account, DAppType).explicitGet()) ) @@ -940,7 +940,7 @@ class DecompilerTest extends PropSpec { val ctx = Monoid.combineAll( Seq( - PureContext.build(V5, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(V5, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(Global, V5).withEnvironment[Environment], WavesContext.build(Global, DirectiveSet(V5, Account, DAppType).explicitGet()) ) @@ -974,7 +974,7 @@ class DecompilerTest extends PropSpec { val ctx = Monoid.combineAll( Seq( - PureContext.build(V5, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(V5, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(Global, V5).withEnvironment[Environment], WavesContext.build(Global, DirectiveSet(V5, Account, DAppType).explicitGet()) ) @@ -1019,7 +1019,7 @@ class DecompilerTest extends PropSpec { val ctx = Monoid.combineAll( Seq( - PureContext.build(V5, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(V5, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(Global, V5).withEnvironment[Environment], WavesContext.build(Global, DirectiveSet(V5, Account, DAppType).explicitGet()) ) diff --git a/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/ExpressionCompilerV1Test.scala b/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/ExpressionCompilerV1Test.scala index 34effd21e50..47db301b16b 100644 --- a/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/ExpressionCompilerV1Test.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/ExpressionCompilerV1Test.scala @@ -307,7 +307,7 @@ class ExpressionCompilerV1Test extends PropSpec { val ctx = Monoid .combineAll( Seq( - PureContext.build(V4, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(V4, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(com.wavesplatform.lang.Global, V4).withEnvironment[Environment], WavesContext.build( Global, diff --git a/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/package.scala b/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/package.scala index 0e48fe5ef79..f88231054b0 100644 --- a/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/package.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/package.scala @@ -37,7 +37,7 @@ package object compiler { def getTestContext(v: StdLibVersion, t: ScriptType = Account): CTX[Environment] = { Monoid .combineAll(Seq( - PureContext.build(v, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(v, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(Global, v).withEnvironment[Environment], WavesContext.build(Global, DirectiveSet(v, t, Expression).explicitGet()), CTX[NoContext]( diff --git a/lang/tests/src/test/scala/com/wavesplatform/lang/doc/DocExportTest.scala b/lang/tests/src/test/scala/com/wavesplatform/lang/doc/DocExportTest.scala index bcc8ae54928..42ed074ea96 100644 --- a/lang/tests/src/test/scala/com/wavesplatform/lang/doc/DocExportTest.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/lang/doc/DocExportTest.scala @@ -17,7 +17,7 @@ class DocExportTest extends PropSpec { def buildFullContext(ds: DirectiveSet): CTX[Environment] = { val wavesCtx = WavesContext.build(Global, ds) val cryptoCtx = CryptoContext.build(Global, ds.stdLibVersion).withEnvironment[Environment] - val pureCtx = PureContext.build(ds.stdLibVersion, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] + val pureCtx = PureContext.build(ds.stdLibVersion, useNewPowPrecision = true).withEnvironment[Environment] pureCtx |+| cryptoCtx |+| wavesCtx } diff --git a/lang/tests/src/test/scala/com/wavesplatform/lang/evaluator/EvaluatorV1V2Test.scala b/lang/tests/src/test/scala/com/wavesplatform/lang/evaluator/EvaluatorV1V2Test.scala index 3b9a8fcbe2d..0938743b0a4 100644 --- a/lang/tests/src/test/scala/com/wavesplatform/lang/evaluator/EvaluatorV1V2Test.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/lang/evaluator/EvaluatorV1V2Test.scala @@ -38,7 +38,7 @@ class EvaluatorV1V2Test extends PropSpec with EitherValues { implicit val version: StdLibVersion = V4 - private def pureContext(implicit version: StdLibVersion) = PureContext.build(version, fixUnicodeFunctions = true, useNewPowPrecision = true) + private def pureContext(implicit version: StdLibVersion) = PureContext.build(version, useNewPowPrecision = true) private def defaultCryptoContext(implicit version: StdLibVersion) = CryptoContext.build(Global, version) @@ -57,7 +57,7 @@ class EvaluatorV1V2Test extends PropSpec with EitherValues { ) private def pureEvalContext(implicit version: StdLibVersion): EvaluationContext[NoContext, Id] = - PureContext.build(version, fixUnicodeFunctions = true, useNewPowPrecision = true).evaluationContext + PureContext.build(version, useNewPowPrecision = true).evaluationContext private val defaultEvaluator = new EvaluatorV1[Id, Environment]() diff --git a/lang/tests/src/test/scala/com/wavesplatform/lang/evaluator/EvaluatorV2Test.scala b/lang/tests/src/test/scala/com/wavesplatform/lang/evaluator/EvaluatorV2Test.scala index 59f71f9901a..55ff61a0006 100644 --- a/lang/tests/src/test/scala/com/wavesplatform/lang/evaluator/EvaluatorV2Test.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/lang/evaluator/EvaluatorV2Test.scala @@ -25,7 +25,7 @@ import scala.util.Random class EvaluatorV2Test extends PropSpec with Inside { private val version = V4 private val ctx = - PureContext.build(version, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(version, useNewPowPrecision = true).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet(version, Account, DApp).explicitGet()) private val environment = Common.emptyBlockchainEnvironment() diff --git a/lang/tests/src/test/scala/com/wavesplatform/lang/evaluator/ScriptResultTest.scala b/lang/tests/src/test/scala/com/wavesplatform/lang/evaluator/ScriptResultTest.scala index c90595ff2ca..7361d91ddca 100644 --- a/lang/tests/src/test/scala/com/wavesplatform/lang/evaluator/ScriptResultTest.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/lang/evaluator/ScriptResultTest.scala @@ -19,7 +19,7 @@ import com.wavesplatform.test._ class ScriptResultTest extends PropSpec { val pureEvalContext: EvaluationContext[Environment, Id] = - PureContext.build(V3, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment].evaluationContext(utils.environment) + PureContext.build(V3, useNewPowPrecision = true).withEnvironment[Environment].evaluationContext(utils.environment) val el = List.empty[(String, FINAL)] val address1 = ByteStr.fromBytes(19: Byte) diff --git a/lang/tests/src/test/scala/com/wavesplatform/lang/v1/estimator/ScriptEstimatorTestBase.scala b/lang/tests/src/test/scala/com/wavesplatform/lang/v1/estimator/ScriptEstimatorTestBase.scala index 997f4248730..f3dc08efe29 100644 --- a/lang/tests/src/test/scala/com/wavesplatform/lang/v1/estimator/ScriptEstimatorTestBase.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/lang/v1/estimator/ScriptEstimatorTestBase.scala @@ -38,7 +38,7 @@ class ScriptEstimatorTestBase(estimators: ScriptEstimator*) extends PropSpec { Monoid .combineAll( Seq( - PureContext.build(version, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(version, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(Global, version).withEnvironment[Environment], WavesContext.build(Global, DirectiveSet(version, Account, DApp).explicitGet()), CTX[NoContext]( diff --git a/lang/tests/src/test/scala/com/wavesplatform/lang/v1/estimator/package.scala b/lang/tests/src/test/scala/com/wavesplatform/lang/v1/estimator/package.scala index f36d57d86c0..aefc1bc94ce 100644 --- a/lang/tests/src/test/scala/com/wavesplatform/lang/v1/estimator/package.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/lang/v1/estimator/package.scala @@ -15,7 +15,7 @@ import monix.eval.Coeval package object estimator { private val version = V3 private val ctx = - PureContext.build(version, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(version, useNewPowPrecision = true).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet.contractDirectiveSet) private val environment = Common.emptyBlockchainEnvironment() diff --git a/lang/tests/src/test/scala/com/wavesplatform/utils/MerkleTest.scala b/lang/tests/src/test/scala/com/wavesplatform/utils/MerkleTest.scala index 1d7d82e0f07..11414a10b28 100644 --- a/lang/tests/src/test/scala/com/wavesplatform/utils/MerkleTest.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/utils/MerkleTest.scala @@ -112,7 +112,7 @@ class MerkleTest extends PropSpec { private def eval[T <: EVALUATED](code: String, version: StdLibVersion = V3): Either[String, T] = { val untyped = Parser.parseExpr(code).get.value - val ctx = PureContext.build(version, fixUnicodeFunctions = true, useNewPowPrecision = true) |+| CryptoContext.build(Global, version) + val ctx = PureContext.build(version, useNewPowPrecision = true) |+| CryptoContext.build(Global, version) val typed = ExpressionCompiler(ctx.compilerContext, untyped) typed.flatMap(v => evaluator.apply[T](ctx.evaluationContext, v._1)) } diff --git a/lang/tests/src/test/scala/com/wavesplatform/utils/RSATest.scala b/lang/tests/src/test/scala/com/wavesplatform/utils/RSATest.scala index ef48f552a71..e81b7681d79 100644 --- a/lang/tests/src/test/scala/com/wavesplatform/utils/RSATest.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/utils/RSATest.scala @@ -138,7 +138,7 @@ class RSATest extends PropSpec with BeforeAndAfterAll { val signature = privateSignature.sign - eval(scriptSrc(alg, message, signature, xpub.getEncoded), PureContext.build(V3, fixUnicodeFunctions = true, useNewPowPrecision = true) |+| CryptoContext.build(Global, V3)) shouldBe Right(CONST_BOOLEAN(true)) + eval(scriptSrc(alg, message, signature, xpub.getEncoded), PureContext.build(V3, useNewPowPrecision = true) |+| CryptoContext.build(Global, V3)) shouldBe Right(CONST_BOOLEAN(true)) } } } @@ -157,7 +157,7 @@ class RSATest extends PropSpec with BeforeAndAfterAll { val signature = privateSignature.sign - eval(scriptSrc(alg, message, signature, xpub.getEncoded), PureContext.build(V4, fixUnicodeFunctions = true, useNewPowPrecision = true) |+| CryptoContext.build(Global, V4)) should produce(s"Can't find a function '${algToType(alg)}'()") + eval(scriptSrc(alg, message, signature, xpub.getEncoded), PureContext.build(V4, useNewPowPrecision = true) |+| CryptoContext.build(Global, V4)) should produce(s"Can't find a function '${algToType(alg)}'()") } } } @@ -180,7 +180,7 @@ class RSATest extends PropSpec with BeforeAndAfterAll { val vars: Map[String, (FINAL, ContextfulVal[NoContext])] = Map( ("msg", (BYTESTR, ContextfulVal.pure[NoContext](CONST_BYTESTR(ByteStr(message), limit = CONST_BYTESTR.DataTxSize).explicitGet()))), ) - val ctx: CTX[NoContext] = PureContext.build(V4, fixUnicodeFunctions = true, useNewPowPrecision = true) |+| CryptoContext.build(Global, V4) |+| CTX[NoContext](Seq(), vars, Array.empty[BaseFunction[NoContext]]) + val ctx: CTX[NoContext] = PureContext.build(V4, useNewPowPrecision = true) |+| CryptoContext.build(Global, V4) |+| CTX[NoContext](Seq(), vars, Array.empty[BaseFunction[NoContext]]) eval(limScriptSrc(lim, alg, signature, xpub.getEncoded), ctx) shouldBe Right(CONST_BOOLEAN(true)) } @@ -206,7 +206,7 @@ class RSATest extends PropSpec with BeforeAndAfterAll { val vars: Map[String, (FINAL, ContextfulVal[NoContext])] = Map( ("msg", (BYTESTR, ContextfulVal.pure[NoContext](CONST_BYTESTR(ByteStr(message), limit = CONST_BYTESTR.DataTxSize).explicitGet()))), ) - val ctx: CTX[NoContext] = PureContext.build(V4, fixUnicodeFunctions = true, useNewPowPrecision = true) |+| CryptoContext.build(Global, V4) |+| CTX[NoContext](Seq(), vars, Array.empty[BaseFunction[NoContext]]) + val ctx: CTX[NoContext] = PureContext.build(V4, useNewPowPrecision = true) |+| CryptoContext.build(Global, V4) |+| CTX[NoContext](Seq(), vars, Array.empty[BaseFunction[NoContext]]) eval(limScriptSrc(lim, alg, signature, xpub.getEncoded), ctx) shouldBe Left(s"Invalid message size = ${lim * 1024 + 1} bytes, must be not greater than ${lim} KB") } @@ -231,7 +231,7 @@ class RSATest extends PropSpec with BeforeAndAfterAll { val vars: Map[String, (FINAL, ContextfulVal[NoContext])] = Map( ("msg", (BYTESTR, ContextfulVal.pure[NoContext](CONST_BYTESTR(ByteStr(message), limit = CONST_BYTESTR.DataTxSize).explicitGet()))), ) - val ctx: CTX[NoContext] = PureContext.build(V4, fixUnicodeFunctions = true, useNewPowPrecision = true) |+| CryptoContext.build(Global, V4) |+| CTX[NoContext](Seq(), vars, Array.empty[BaseFunction[NoContext]]) + val ctx: CTX[NoContext] = PureContext.build(V4, useNewPowPrecision = true) |+| CryptoContext.build(Global, V4) |+| CTX[NoContext](Seq(), vars, Array.empty[BaseFunction[NoContext]]) eval(maxScriptSrcV4(alg, signature, xpub.getEncoded), ctx) shouldBe Right(CONST_BOOLEAN(true)) } @@ -255,7 +255,7 @@ class RSATest extends PropSpec with BeforeAndAfterAll { val vars: Map[String, (FINAL, ContextfulVal[NoContext])] = Map( ("msg", (BYTESTR, ContextfulVal.pure[NoContext](CONST_BYTESTR(ByteStr(message), limit = CONST_BYTESTR.DataTxSize).explicitGet()))), ) - val ctx: CTX[NoContext] = PureContext.build(V3, fixUnicodeFunctions = true, useNewPowPrecision = true) |+| CryptoContext.build(Global, V3) |+| CTX[NoContext](Seq(), vars, Array.empty[BaseFunction[NoContext]]) + val ctx: CTX[NoContext] = PureContext.build(V3, useNewPowPrecision = true) |+| CryptoContext.build(Global, V3) |+| CTX[NoContext](Seq(), vars, Array.empty[BaseFunction[NoContext]]) eval(maxScriptSrc(alg, signature, xpub.getEncoded), ctx) shouldBe Right(CONST_BOOLEAN(true)) } @@ -279,7 +279,7 @@ class RSATest extends PropSpec with BeforeAndAfterAll { val vars: Map[String, (FINAL, ContextfulVal[NoContext])] = Map( ("msg", (BYTESTR, ContextfulVal.pure[NoContext](CONST_BYTESTR(ByteStr(message), limit = CONST_BYTESTR.DataTxSize).explicitGet()))), ) - val ctx: CTX[NoContext] = PureContext.build(V3, fixUnicodeFunctions = true, useNewPowPrecision = true) |+| CryptoContext.build(Global, V3) |+| CTX[NoContext](Seq(), vars, Array.empty[BaseFunction[NoContext]]) + val ctx: CTX[NoContext] = PureContext.build(V3, useNewPowPrecision = true) |+| CryptoContext.build(Global, V3) |+| CTX[NoContext](Seq(), vars, Array.empty[BaseFunction[NoContext]]) eval(maxScriptSrc(alg, signature, xpub.getEncoded), ctx) shouldBe Left(s"Invalid message size = ${32 * 1024 + 1} bytes, must be not greater than 32 KB") } @@ -295,7 +295,7 @@ class RSATest extends PropSpec with BeforeAndAfterAll { Random.nextBytes(signature) algs foreach { alg => - eval(scriptSrc(alg, message, signature, xpub.getEncoded), PureContext.build(V3, fixUnicodeFunctions = true, useNewPowPrecision = true) |+| CryptoContext.build(Global, V3)) shouldBe Right(CONST_BOOLEAN(false)) + eval(scriptSrc(alg, message, signature, xpub.getEncoded), PureContext.build(V3, useNewPowPrecision = true) |+| CryptoContext.build(Global, V3)) shouldBe Right(CONST_BOOLEAN(false)) } } } @@ -325,7 +325,7 @@ class RSATest extends PropSpec with BeforeAndAfterAll { privateSignature.update(message) val signature = privateSignature.sign - val ctx = PureContext.build(V3, fixUnicodeFunctions = true, useNewPowPrecision = true) |+| CryptoContext.build(Global, V3) + val ctx = PureContext.build(V3, useNewPowPrecision = true) |+| CryptoContext.build(Global, V3) val invalidKey = Array[Byte](1, 2, 3) eval(scriptSrc(alg, message, signature, invalidKey), ctx) should produce(s"Invalid key base58'${ByteStr(invalidKey)}'") @@ -335,7 +335,7 @@ class RSATest extends PropSpec with BeforeAndAfterAll { private val evaluator = new EvaluatorV1[Id, NoContext]() - private def eval[T <: EVALUATED](code: String, ctx: CTX[NoContext] = PureContext.build(V4, fixUnicodeFunctions = true, useNewPowPrecision = true) |+| CryptoContext.build(Global, V4)): Either[String, T] = { + private def eval[T <: EVALUATED](code: String, ctx: CTX[NoContext] = PureContext.build(V4, useNewPowPrecision = true) |+| CryptoContext.build(Global, V4)): Either[String, T] = { val untyped = Parser.parseExpr(code).get.value val typed = ExpressionCompiler(ctx.compilerContext, untyped) typed.flatMap(v => evaluator.apply[T](ctx.evaluationContext, v._1)) diff --git a/node-generator/src/main/scala/com/wavesplatform/generator/NarrowTransactionGenerator.scala b/node-generator/src/main/scala/com/wavesplatform/generator/NarrowTransactionGenerator.scala index 4313c34c4e9..c1f2e27439e 100644 --- a/node-generator/src/main/scala/com/wavesplatform/generator/NarrowTransactionGenerator.scala +++ b/node-generator/src/main/scala/com/wavesplatform/generator/NarrowTransactionGenerator.scala @@ -226,7 +226,7 @@ class NarrowTransactionGenerator( val sender = randomFrom(accounts).get val aliasString = NarrowTransactionGenerator.generateAlias() logOption( - CreateAliasTransaction.selfSigned(correctVersion(TxVersion.V2), sender, Alias.create(aliasString).explicitGet(), 500000L, timestamp) + CreateAliasTransaction.selfSigned(correctVersion(TxVersion.V2), sender, aliasString, 500000L, timestamp) ) case TransactionType.MassTransfer => diff --git a/node-it/src/test/scala/com/wavesplatform/it/asset/GrpcSponsorFeeActionSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/asset/GrpcSponsorFeeActionSuite.scala index c85dc2d0602..40e31dce813 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/asset/GrpcSponsorFeeActionSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/asset/GrpcSponsorFeeActionSuite.scala @@ -441,7 +441,7 @@ class GrpcSponsorFeeActionSuite extends AnyFreeSpec with GrpcBaseTransactionSuit assertBadRequestAndMessage( miner.invokeScript(miner.keyPair, dApp.toAddress.toString, Some("sponsorAsset"), waitForTx = true, fee = smartMinFee), - "Negative sponsor amount = -1" + "NegativeMinFee(-1,asset)" ) } diff --git a/node-it/src/test/scala/com/wavesplatform/it/asset/SponsorFeeActionSuite.scala b/node-it/src/test/scala/com/wavesplatform/it/asset/SponsorFeeActionSuite.scala index f5878cae3b7..d1b1cfbbdba 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/asset/SponsorFeeActionSuite.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/asset/SponsorFeeActionSuite.scala @@ -433,7 +433,7 @@ class SponsorFeeActionSuite extends BaseFreeSpec { dApp ) - assertBadRequestAndMessage(miner.invokeScript(miner.keyPair, dAppAddress, Some("sponsorAsset"), fee = smartMinFee), "Negative sponsor amount = -1") + assertBadRequestAndMessage(miner.invokeScript(miner.keyPair, dAppAddress, Some("sponsorAsset"), fee = smartMinFee), "NegativeMinFee(-1,asset)") } "SponsorFee is available only for assets issuing from current address" in { diff --git a/node/src/main/scala/com/wavesplatform/GenesisBlockGenerator.scala b/node/src/main/scala/com/wavesplatform/GenesisBlockGenerator.scala index 3b4b5c0fcd4..c66d6529258 100644 --- a/node/src/main/scala/com/wavesplatform/GenesisBlockGenerator.scala +++ b/node/src/main/scala/com/wavesplatform/GenesisBlockGenerator.scala @@ -48,14 +48,7 @@ object GenesisBlockGenerator extends App { val features: Map[Short, Int] = preActivatedFeatures.map(_.toShort -> 0).toMap - val functionalitySettings: FunctionalitySettings = FunctionalitySettings( - Int.MaxValue, - Int.MaxValue, - preActivatedFeatures = features, - doubleFeaturesPeriodsAfterHeight = Int.MaxValue, - minBlockTime = minBlockTime.getOrElse(15.seconds), - delayDelta = delayDelta.getOrElse(8) - ) + val functionalitySettings: FunctionalitySettings = FunctionalitySettings(Int.MaxValue, Int.MaxValue, preActivatedFeatures = features, doubleFeaturesPeriodsAfterHeight = Int.MaxValue, minBlockTime = minBlockTime.getOrElse(15.seconds), delayDelta = delayDelta.getOrElse(8)) def preActivated(feature: BlockchainFeature): Boolean = features.contains(feature.id) } diff --git a/node/src/main/scala/com/wavesplatform/api/http/UtilsApiRoute.scala b/node/src/main/scala/com/wavesplatform/api/http/UtilsApiRoute.scala index 61d42858878..2091835316a 100644 --- a/node/src/main/scala/com/wavesplatform/api/http/UtilsApiRoute.scala +++ b/node/src/main/scala/com/wavesplatform/api/http/UtilsApiRoute.scala @@ -314,7 +314,7 @@ object UtilsApiRoute { private object ScriptCallEvaluator { def compile(stdLibVersion: StdLibVersion)(str: String): Either[GenericError, EXPR] = { val ctx = - PureContext.build(stdLibVersion, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(stdLibVersion, useNewPowPrecision = true).withEnvironment[Environment] |+| CryptoContext.build(Global, stdLibVersion).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet(stdLibVersion, Account, Expression).explicitGet()) diff --git a/node/src/main/scala/com/wavesplatform/settings/BlockchainSettings.scala b/node/src/main/scala/com/wavesplatform/settings/BlockchainSettings.scala index 3ca1cc31ca8..d2ba711386f 100644 --- a/node/src/main/scala/com/wavesplatform/settings/BlockchainSettings.scala +++ b/node/src/main/scala/com/wavesplatform/settings/BlockchainSettings.scala @@ -36,21 +36,21 @@ case class RewardsSettings( } object RewardsSettings { - val MAINNET = apply( + val MAINNET: RewardsSettings = apply( 100000, 6 * Constants.UnitsInWave, 50000000, 10000 ) - val TESTNET = apply( + val TESTNET: RewardsSettings = apply( 100000, 6 * Constants.UnitsInWave, 50000000, 10000 ) - val STAGENET = apply( + val STAGENET: RewardsSettings = apply( 100000, 6 * Constants.UnitsInWave, 50000000, @@ -73,19 +73,16 @@ case class FunctionalitySettings( minAssetInfoUpdateInterval: Int = 100000, minBlockTime: FiniteDuration = 15.seconds, delayDelta: Int = 8, - syncDAppCheckPaymentsHeight: Int = 0, - checkTotalDataEntriesBytesHeight: Int = 0, - syncDAppCheckTransfersHeight: Int = 0, estimationOverflowFixHeight: Int = 0, estimatorSumOverflowFixHeight: Int = 0 ) { - val allowLeasedBalanceTransferUntilHeight: Int = blockVersion3AfterHeight - val allowTemporaryNegativeUntil = lastTimeBasedForkParameter - val minimalGeneratingBalanceAfter = lastTimeBasedForkParameter - val allowTransactionsFromFutureUntil = lastTimeBasedForkParameter - val allowUnissuedAssetsUntil = lastTimeBasedForkParameter - val allowInvalidReissueInSameBlockUntilTimestamp = lastTimeBasedForkParameter - val allowMultipleLeaseCancelTransactionUntilTimestamp = lastTimeBasedForkParameter + val allowLeasedBalanceTransferUntilHeight: Int = blockVersion3AfterHeight + val allowTemporaryNegativeUntil: Long = lastTimeBasedForkParameter + val minimalGeneratingBalanceAfter: Long = lastTimeBasedForkParameter + val allowTransactionsFromFutureUntil: Long = lastTimeBasedForkParameter + val allowUnissuedAssetsUntil: Long = lastTimeBasedForkParameter + val allowInvalidReissueInSameBlockUntilTimestamp: Long = lastTimeBasedForkParameter + val allowMultipleLeaseCancelTransactionUntilTimestamp: Long = lastTimeBasedForkParameter require(featureCheckBlocksPeriod > 0, "featureCheckBlocksPeriod must be greater than 0") require( @@ -112,44 +109,35 @@ case class FunctionalitySettings( } object FunctionalitySettings { - val MAINNET = apply( + val MAINNET: FunctionalitySettings = apply( featureCheckBlocksPeriod = 5000, blocksForFeatureActivation = 4000, generationBalanceDepthFrom50To1000AfterHeight = 232000, - lastTimeBasedForkParameter = 1530161445559L, blockVersion3AfterHeight = 795000, doubleFeaturesPeriodsAfterHeight = 810000, + lastTimeBasedForkParameter = 1530161445559L, estimatorPreCheckHeight = 1847610, - syncDAppCheckPaymentsHeight = 2746200, - checkTotalDataEntriesBytesHeight = 2771954, - syncDAppCheckTransfersHeight = 2792473, estimationOverflowFixHeight = 2858710, estimatorSumOverflowFixHeight = 2897510 ) - val TESTNET = apply( + val TESTNET: FunctionalitySettings = apply( featureCheckBlocksPeriod = 3000, blocksForFeatureActivation = 2700, blockVersion3AfterHeight = 161700, doubleFeaturesPeriodsAfterHeight = Int.MaxValue, lastTimeBasedForkParameter = 1492560000000L, estimatorPreCheckHeight = 817380, - syncDAppCheckPaymentsHeight = 1698800, - checkTotalDataEntriesBytesHeight = 1711600, - syncDAppCheckTransfersHeight = 1727461, estimationOverflowFixHeight = 1793770, estimatorSumOverflowFixHeight = 1832520 ) - val STAGENET = apply( + val STAGENET: FunctionalitySettings = apply( featureCheckBlocksPeriod = 100, blocksForFeatureActivation = 40, - doubleFeaturesPeriodsAfterHeight = 1000000000, preActivatedFeatures = (1 to 13).map(_.toShort -> 0).toMap, + doubleFeaturesPeriodsAfterHeight = 1000000000, minAssetInfoUpdateInterval = 10, - syncDAppCheckPaymentsHeight = 967300, - checkTotalDataEntriesBytesHeight = 991912, - syncDAppCheckTransfersHeight = 1012439, estimationOverflowFixHeight = 1078680, estimatorSumOverflowFixHeight = 1097419 ) @@ -170,7 +158,7 @@ case class GenesisSettings( ) object GenesisSettings { // TODO: Move to network-defaults.conf - val MAINNET = GenesisSettings( + val MAINNET: GenesisSettings = GenesisSettings( 1460678400000L, 1465742577614L, Constants.UnitsInWave * Constants.TotalWaves, @@ -187,7 +175,7 @@ object GenesisSettings { // TODO: Move to network-defaults.conf 60.seconds ) - val TESTNET = GenesisSettings( + val TESTNET: GenesisSettings = GenesisSettings( 1460678400000L, 1478000000000L, Constants.UnitsInWave * Constants.TotalWaves, @@ -206,7 +194,7 @@ object GenesisSettings { // TODO: Move to network-defaults.conf 60.seconds ) - val STAGENET = GenesisSettings( + val STAGENET: GenesisSettings = GenesisSettings( 1561705836768L, 1561705836768L, Constants.UnitsInWave * Constants.TotalWaves, diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/BalanceDiffValidation.scala b/node/src/main/scala/com/wavesplatform/state/diffs/BalanceDiffValidation.scala index 94a832d1443..cb46b299dd2 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/BalanceDiffValidation.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/BalanceDiffValidation.scala @@ -1,5 +1,7 @@ package com.wavesplatform.state.diffs +import scala.util.{Left, Right} + import com.wavesplatform.account.Address import com.wavesplatform.common.state.ByteStr import com.wavesplatform.state.{Blockchain, Diff, Portfolio} @@ -7,9 +9,11 @@ import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.TxValidationError.AccountBalanceError import com.wavesplatform.utils.ScorexLogging -import scala.util.{Left, Right} - object BalanceDiffValidation extends ScorexLogging { + def cond(b: Blockchain, cond: Blockchain => Boolean)(d: Diff): Either[AccountBalanceError, Diff] = { + if (cond(b)) apply(b)(d) + else Right(d) + } def apply(b: Blockchain)(d: Diff): Either[AccountBalanceError, Diff] = { val changedAccounts = d.portfolios.keySet diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/TransactionDiffer.scala b/node/src/main/scala/com/wavesplatform/state/diffs/TransactionDiffer.scala index 082990e0445..24cb6ba5639 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/TransactionDiffer.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/TransactionDiffer.scala @@ -68,15 +68,15 @@ object TransactionDiffer { blockchain: Blockchain, tx: Transaction ): TracedResult[ValidationError, Diff] = { - val verifyAssets = verify || (transactionMayFail(tx) && acceptFailed(blockchain)) + val runVerifiers = verify || (transactionMayFail(tx) && acceptFailed(blockchain)) val result = for { _ <- validateCommon(blockchain, tx, prevBlockTimestamp, currentBlockTimestamp, verify).traced _ <- validateFunds(blockchain, tx).traced - verifierDiff <- if (verify) verifierDiff(blockchain, tx) else Right(Diff.empty).traced + verifierDiff <- if (runVerifiers) verifierDiff(blockchain, tx) else Right(Diff.empty).traced transactionDiff <- transactionDiff(blockchain, tx, verifierDiff, currentBlockTimestamp, limitedExecution) remainingComplexity = if (limitedExecution) ContractLimits.FailFreeInvokeComplexity - transactionDiff.scriptsComplexity.toInt else Int.MaxValue _ <- validateBalance(blockchain, tx.tpe, transactionDiff).traced.leftMap { err => - def acceptFailedByBalance() = + def acceptFailedByBalance(): Boolean = acceptFailed(blockchain) && blockchain.isFeatureActivated(BlockchainFeatures.SynchronousCalls) if (transactionDiff.scriptsComplexity > ContractLimits.FailFreeInvokeComplexity && transactionMayFail(tx) && acceptFailedByBalance()) @@ -84,9 +84,17 @@ object TransactionDiffer { else err } - diff <- assetsVerifierDiff(blockchain, tx, verifyAssets, transactionDiff, remainingComplexity) + diff <- assetsVerifierDiff(blockchain, tx, runVerifiers, transactionDiff, remainingComplexity) } yield diff - result.leftMap(TransactionValidationError(_, tx)) + + result.leftMap { + // Force reject + case fte: FailedTransactionError + if fte.spentComplexity <= ContractLimits.FailFreeInvokeComplexity && blockchain.isFeatureActivated(BlockchainFeatures.RideV6) => + TransactionValidationError(ScriptExecutionError(fte.message, fte.log, fte.assetId), tx) + + case err => TransactionValidationError(err, tx) + } } // validation related @@ -134,7 +142,7 @@ object TransactionDiffer { } } yield () - private def verifierDiff(blockchain: Blockchain, tx: Transaction) = + private[this] def verifierDiff(blockchain: Blockchain, tx: Transaction): TracedResult[ValidationError, Diff] = Verifier(blockchain)(tx).map(complexity => Diff.empty.copy(scriptsComplexity = complexity)) def assetsVerifierDiff( diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/invoke/CachedDAppCTX.scala b/node/src/main/scala/com/wavesplatform/state/diffs/invoke/CachedDAppCTX.scala index c7c3911d08b..6b0611704bb 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/invoke/CachedDAppCTX.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/invoke/CachedDAppCTX.scala @@ -13,18 +13,22 @@ import com.wavesplatform.lang.v1.traits.Environment import com.wavesplatform.state.Blockchain object CachedDAppCTX { - private val cache: Map[(StdLibVersion, Boolean, Boolean), InvariableContext] = + private val cache: Map[(StdLibVersion, Boolean), InvariableContext] = (for { version <- DirectiveDictionary[StdLibVersion].all.filter(_ >= V3) - fixUnicodeFunctions <- Seq(true, false) useNewPowPrecision <- Seq(true, false) } yield { - val ctx = PureContext.build(version, fixUnicodeFunctions, useNewPowPrecision).withEnvironment[Environment] |+| + val ctx = PureContext.build(version, useNewPowPrecision).withEnvironment[Environment] |+| CryptoContext.build(Global, version).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet(version, Account, DApp).explicitGet()) - ((version, fixUnicodeFunctions, useNewPowPrecision), InvariableContext(ctx)) + ((version, useNewPowPrecision), InvariableContext(ctx)) }).toMap def get(version: StdLibVersion, blockchain: Blockchain): InvariableContext = - cache((version, blockchain.isFeatureActivated(BlockchainFeatures.SynchronousCalls), blockchain.height >= blockchain.settings.functionalitySettings.syncDAppCheckPaymentsHeight)) + cache( + ( + version, + blockchain.isFeatureActivated(BlockchainFeatures.SynchronousCalls), // fixUnicodeFunctions + useNewPowPrecision + ) + ) } diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeDiffsCommon.scala b/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeDiffsCommon.scala index 4c5f73ccaf8..0f533192588 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeDiffsCommon.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeDiffsCommon.scala @@ -3,11 +3,12 @@ package com.wavesplatform.state.diffs.invoke import scala.util.{Failure, Right, Success, Try} import cats.Id -import cats.instances.list._ -import cats.instances.map._ -import cats.syntax.either._ -import cats.syntax.semigroup._ -import cats.syntax.traverse._ +import cats.instances.either.* +import cats.instances.list.* +import cats.instances.map.* +import cats.syntax.either.* +import cats.syntax.semigroup.* +import cats.syntax.traverse.* import com.google.common.base.Throwables import com.google.protobuf.ByteString import com.wavesplatform.account.{Address, AddressOrAlias, PublicKey} @@ -15,34 +16,34 @@ import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.features.BlockchainFeatures.{BlockV5, SynchronousCalls} -import com.wavesplatform.features.EstimatorProvider._ -import com.wavesplatform.features.InvokeScriptSelfPaymentPolicyProvider._ -import com.wavesplatform.features.ScriptTransferValidationProvider._ -import com.wavesplatform.lang._ -import com.wavesplatform.lang.directives.values._ +import com.wavesplatform.features.EstimatorProvider.* +import com.wavesplatform.features.InvokeScriptSelfPaymentPolicyProvider.* +import com.wavesplatform.features.ScriptTransferValidationProvider.* +import com.wavesplatform.lang.* +import com.wavesplatform.lang.directives.values.* import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.v1.ContractLimits -import com.wavesplatform.lang.v1.compiler.Terms.{FUNCTION_CALL, _} -import com.wavesplatform.lang.v1.evaluator.{Log, RejectException, ScriptResult, ScriptResultV4} +import com.wavesplatform.lang.v1.compiler.Terms.{FUNCTION_CALL, *} +import com.wavesplatform.lang.v1.evaluator.{Log, ScriptResult, ScriptResultV4} import com.wavesplatform.lang.v1.traits.Environment -import com.wavesplatform.lang.v1.traits.domain._ +import com.wavesplatform.lang.v1.traits.domain.* import com.wavesplatform.lang.v1.traits.domain.Tx.{BurnPseudoTx, ReissuePseudoTx, ScriptTransfer, SponsorFeePseudoTx} -import com.wavesplatform.state._ -import com.wavesplatform.state.diffs.DiffsCommon -import com.wavesplatform.state.diffs.FeeValidation._ +import com.wavesplatform.state.* +import com.wavesplatform.state.diffs.{BalanceDiffValidation, DiffsCommon} +import com.wavesplatform.state.diffs.FeeValidation.* import com.wavesplatform.state.reader.CompositeBlockchain import com.wavesplatform.transaction.{Asset, AssetIdLength, ERC20Address, PBSince, TransactionType} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} -import com.wavesplatform.transaction.TxValidationError._ +import com.wavesplatform.transaction.TxValidationError.* import com.wavesplatform.transaction.assets.IssueTransaction -import com.wavesplatform.transaction.smart._ +import com.wavesplatform.transaction.smart.* import com.wavesplatform.transaction.smart.script.ScriptRunner import com.wavesplatform.transaction.smart.script.ScriptRunner.TxOrd import com.wavesplatform.transaction.smart.script.trace.{AssetVerifierTrace, TracedResult} import com.wavesplatform.transaction.smart.script.trace.AssetVerifierTrace.AssetContext import com.wavesplatform.transaction.smart.script.trace.TracedResult.Attribute import com.wavesplatform.transaction.validation.impl.{DataTxValidator, LeaseCancelTxValidator, LeaseTxValidator, SponsorFeeTxValidator} -import com.wavesplatform.utils._ +import com.wavesplatform.utils.* import shapeless.Coproduct object InvokeDiffsCommon { @@ -490,10 +491,7 @@ object InvokeDiffsCommon { } else if (issue.description.length > IssueTransaction.MaxAssetDescriptionLength) { TracedResult(Left(FailedTransactionError.dAppExecution("Invalid asset description", 0L)), List()) } else if (blockchain.assetDescription(asset).isDefined || blockchain.resolveERC20Address(ERC20Address(asset)).isDefined) { - if (blockchain.height >= blockchain.settings.functionalitySettings.syncDAppCheckTransfersHeight) - throw RejectException(s"Asset ${issue.id} is already issued") - else - TracedResult(Left(FailedTransactionError.dAppExecution(s"Asset $asset is already issued", 0L)), List()) + TracedResult(Left(FailedTransactionError.dAppExecution(s"Asset $asset is already issued", 0L)), List()) } else { val staticInfo = AssetStaticInfo(TransactionId @@ itx.txId, pk, issue.decimals, blockchain.isNFT(issue)) val volumeInfo = AssetVolumeInfo(issue.isReissuable, BigInt(issue.quantity)) @@ -584,7 +582,7 @@ object InvokeDiffsCommon { ) } - val diff = action match { + val baseDiffTraced = action match { case t: AssetTransfer => applyTransfer(t, if (blockchain.isFeatureActivated(BlockV5)) { pk @@ -599,6 +597,13 @@ object InvokeDiffsCommon { case l: Lease => applyLease(l).leftMap(FailedTransactionError.asFailedScriptError) case lc: LeaseCancel => applyLeaseCancel(lc).leftMap(FailedTransactionError.asFailedScriptError) } + + val diff = baseDiffTraced.flatMap(baseDiff => TracedResult( + BalanceDiffValidation + .cond(blockchain, _.isFeatureActivated(BlockchainFeatures.RideV6))(baseDiff) + .leftMap(FailedTransactionError.asFailedScriptError(_).addComplexity(baseDiff.scriptsComplexity)) + )) + diffAcc |+| diff.leftMap(_.addComplexity(curDiff.scriptsComplexity)) case _ => diffAcc @@ -653,19 +658,14 @@ object InvokeDiffsCommon { availableDataSize: Int ): TracedResult[ValidationError, Unit] = { def error(message: String) = TracedResult(Left(FailedTransactionError.dAppExecution(message, usedComplexity, log))) - val checkSizeHeight = blockchain.settings.functionalitySettings.checkTotalDataEntriesBytesHeight - val checkSizeRejectHeight = blockchain.settings.functionalitySettings.syncDAppCheckTransfersHeight if (dataCount > availableData) error("Stored data count limit is exceeded") else if (dataSize > availableDataSize) { - val limit = ContractLimits.MaxTotalWriteSetSizeInBytes - val actual = limit + dataSize - availableDataSize - val message = s"Storing data size should not exceed $limit, actual: $actual bytes" - if (blockchain.height >= checkSizeRejectHeight) { - throw RejectException(message) - } else if (blockchain.height >= checkSizeHeight) - error(message) + val limit = ContractLimits.MaxTotalWriteSetSizeInBytes + val actual = limit + dataSize - availableDataSize + if (blockchain.isFeatureActivated(BlockchainFeatures.SynchronousCalls)) + error(s"Storing data size should not exceed $limit, actual: $actual bytes") else TracedResult(Right(())) } else if (actionsCount > availableActions) @@ -674,25 +674,35 @@ object InvokeDiffsCommon { TracedResult(Right(())) } - def checkScriptResultFields(blockchain: Blockchain, r: ScriptResult): Unit = - r match { - case ScriptResultV4(actions, _, _) if blockchain.height >= blockchain.settings.functionalitySettings.syncDAppCheckTransfersHeight => - actions.foreach { - case Reissue(_, _, quantity) => if (quantity < 0) throw RejectException(s"Negative reissue quantity = $quantity") - case Burn(_, quantity) => if (quantity < 0) throw RejectException(s"Negative burn quantity = $quantity") - case t: AssetTransfer => if (t.amount < 0) throw RejectException(s"Negative transfer amount = ${t.amount}") - case l: Lease => if (l.amount < 0) throw RejectException(s"Negative lease amount = ${l.amount}") - case s: SponsorFee => - if (s.minSponsoredAssetFee.exists(_ < 0)) throw RejectException(s"Negative sponsor amount = ${s.minSponsoredAssetFee.get}") - case i: Issue => - val length = i.name.getBytes("UTF-8").length - if (length < IssueTransaction.MinAssetNameLength || length > IssueTransaction.MaxAssetNameLength) { - throw RejectException("Invalid asset name") - } else if (i.description.length > IssueTransaction.MaxAssetDescriptionLength) { - throw RejectException("Invalid asset description") - } - case _ => - } - case _ => + /** + * Checks invoke script callable function result for negative numbers in issue, burn, transfers, etc. + Should produce failed transactions if the spent complexity went over the fail-free limit, and should reject them if not. + * @note Ignores all checks before the SynchronousCalls feature activation + * @note Caller should calculate spent complexity and transform the error into a FailedTransactionError + */ + private[invoke] def checkScriptResultFields(blockchain: Blockchain, result: ScriptResult): Either[ValidationError, Unit] = + result match { + case ScriptResultV4(actions, _, _) if blockchain.isFeatureActivated(BlockchainFeatures.SynchronousCalls) => + actions + .map { + case Reissue(_, _, quantity) if quantity < 0 => Left(GenericError(s"Negative reissue quantity = $quantity")) + case Burn(_, quantity) if quantity < 0 => Left(GenericError(s"Negative burn quantity = $quantity")) + case t: AssetTransfer if t.amount < 0 => Left(GenericError(s"Negative transfer amount = ${t.amount}")) + case l: Lease if l.amount < 0 => Left(GenericError(s"Negative lease amount = ${l.amount}")) + case s: SponsorFee if s.minSponsoredAssetFee.exists(_ < 0) => + Left(GenericError(s"Negative sponsor amount = ${s.minSponsoredAssetFee.get}")) + case i: Issue => + val length = i.name.getBytes("UTF-8").length + if (length < IssueTransaction.MinAssetNameLength || length > IssueTransaction.MaxAssetNameLength) { + Left(GenericError("Invalid asset name")) + } else if (i.description.length > IssueTransaction.MaxAssetDescriptionLength) { + Left(GenericError("Invalid asset description")) + } else Right(()) + case _ => Right(()) + } + .sequence + .map(_ => ()) + + case _ => Right(()) } } diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScriptDiff.scala b/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScriptDiff.scala index 43938df4994..7d1669de60e 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScriptDiff.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScriptDiff.scala @@ -9,6 +9,7 @@ import cats.syntax.semigroup.* import cats.syntax.traverseFilter.* import com.wavesplatform.account.* import com.wavesplatform.common.state.ByteStr +import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.features.EstimatorProvider.EstimatorBlockchainExt import com.wavesplatform.features.EvaluatorFixProvider.* import com.wavesplatform.features.FunctionCallPolicyProvider.* @@ -19,7 +20,7 @@ import com.wavesplatform.lang.directives.values.{DApp as DAppType, *} import com.wavesplatform.lang.script.ContractScript.ContractScriptImpl import com.wavesplatform.lang.v1.ContractLimits import com.wavesplatform.lang.v1.compiler.Terms.* -import com.wavesplatform.lang.v1.evaluator.{ContractEvaluator, IncompleteResult, Log, RejectException, ScriptResult, ScriptResultV3, ScriptResultV4} +import com.wavesplatform.lang.v1.evaluator.{ContractEvaluator, IncompleteResult, Log, ScriptResult, ScriptResultV3, ScriptResultV4} import com.wavesplatform.lang.v1.evaluator.ctx.impl.unit import com.wavesplatform.lang.v1.traits.Environment import com.wavesplatform.lang.v1.traits.domain.{Recipient as RideRecipient, *} @@ -27,9 +28,10 @@ import com.wavesplatform.lang.v1.traits.domain.Tx.ScriptTransfer import com.wavesplatform.metrics.* import com.wavesplatform.state.* import com.wavesplatform.state.diffs.invoke.CallArgumentPolicy.* +import com.wavesplatform.state.diffs.BalanceDiffValidation import com.wavesplatform.state.reader.CompositeBlockchain -import com.wavesplatform.transaction.{Asset, TransactionType, TxValidationError} -import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} +import com.wavesplatform.transaction.{TransactionType, TxValidationError} +import com.wavesplatform.transaction.Asset.IssuedAsset import com.wavesplatform.transaction.TxValidationError.* import com.wavesplatform.transaction.smart.{DApp as DAppTarget, *} import com.wavesplatform.transaction.smart.script.ScriptRunner @@ -216,20 +218,13 @@ object InvokeScriptDiff { }) } _ = invocationRoot.setLog(log) + spentComplexity = remainingComplexity - scriptResult.unusedComplexity.max(0) - _ = if (blockchain.height >= blockchain.settings.functionalitySettings.syncDAppCheckTransfersHeight) - checkDiffBalances(diff, blockchain) - - newBlockchain = CompositeBlockchain(blockchain, diff) - - _ <- traced { - val newBalance = newBlockchain.balance(invoker) - Either.cond( - blockchain.height < blockchain.settings.functionalitySettings.syncDAppCheckPaymentsHeight || newBalance >= 0, - (), - GenericError(balanceError(invoker, newBalance, Waves)) - ) - } + _ <- traced( + BalanceDiffValidation + .cond(blockchain, _.isFeatureActivated(BlockchainFeatures.SynchronousCalls))(diff) + .leftMap(be => FailedTransactionError.dAppExecution(be.toString, spentComplexity, log)) + ) doProcessActions = (actions: List[CallableAction], unusedComplexity: Int) => { val storingComplexity = if (blockchain.storeEvaluatedComplexity) complexityAfterPayments - unusedComplexity else invocationComplexity @@ -242,7 +237,7 @@ object InvokeScriptDiff { pk, storingComplexity.toInt, tx, - newBlockchain, + CompositeBlockchain(blockchain, diff), blockTime, isSyncCall = true, limitedExecution, @@ -296,8 +291,11 @@ object InvokeScriptDiff { } resultDiff = diff.copy(scriptsComplexity = 0) |+| actionsDiff |+| Diff.empty.copy(scriptsComplexity = paymentsComplexity) - _ = if (blockchain.height >= blockchain.settings.functionalitySettings.syncDAppCheckTransfersHeight) - checkDiffBalances(resultDiff, blockchain) + _ <- traced( + BalanceDiffValidation + .cond(blockchain, _.isFeatureActivated(BlockchainFeatures.SynchronousCalls))(resultDiff) + .leftMap(be => FailedTransactionError.dAppExecution(be.toString, resultDiff.scriptsComplexity, log)) + ) _ = invocationRoot.setResult(scriptResult) } yield (resultDiff, evaluated, remainingActions1, remainingData1, remainingDataSize1) @@ -312,34 +310,6 @@ object InvokeScriptDiff { } } - private def checkDiffBalances(diff: Diff, blockchain: Blockchain): Unit = { - val newBlockchain = CompositeBlockchain(blockchain, diff) - diff.portfolios.toList.foreach { - case (address, portfolio) => - if (portfolio.balance < 0) { - val newBalance = newBlockchain.balance(address) - if (newBalance < 0) - throw RejectException(balanceError(address, newBalance, Waves)) - } - portfolio.assets.foreach { - case (asset, amount) => - if (amount < 0) { - val newBalance = newBlockchain.balance(address, asset) - if (newBalance < 0) - throw RejectException(balanceError(address, newBalance, asset)) - } - } - } - } - - private def balanceError(address: Address, balance: Long, asset: Asset) = { - val assetInfo = asset match { - case IssuedAsset(id) => s" asset $id" - case Waves => "" - } - s"Sync call leads to temporary negative$assetInfo balance = $balance for address $address" - } - private def evaluateV2( version: StdLibVersion, blockchain: Blockchain, @@ -347,7 +317,7 @@ object InvokeScriptDiff { invocation: ContractEvaluator.Invocation, environment: Environment[Id], limit: Int, - startComplexity: Int + startComplexityLimit: Int ): Coeval[Either[ValidationError, (ScriptResult, Log[Id])]] = { val evaluationCtx = CachedDAppCTX.get(version, blockchain).completeContext(environment) ContractEvaluator @@ -356,12 +326,16 @@ object InvokeScriptDiff { _.leftMap( { case (error, unusedComplexity, log) => - val usedComplexity = startComplexity - unusedComplexity + val usedComplexity = startComplexityLimit - unusedComplexity FailedTransactionError.dAppExecution(error, usedComplexity, log) } - ).map { r => - InvokeDiffsCommon.checkScriptResultFields(blockchain, r._1); r - } + ).flatMap { + case (result, log) => + val usedComplexity = startComplexityLimit - result.unusedComplexity.max(0) + (for (_ <- + InvokeDiffsCommon.checkScriptResultFields(blockchain, result)) yield (result, log)) + .leftMap(err => FailedTransactionError.dAppExecution(err.toString, usedComplexity, log)) + } ) } } diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScriptTransactionDiff.scala b/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScriptTransactionDiff.scala index c81b44a5439..50146de9865 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScriptTransactionDiff.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/invoke/InvokeScriptTransactionDiff.scala @@ -35,10 +35,10 @@ import com.wavesplatform.state.diffs.invoke.CallArgumentPolicy.* import com.wavesplatform.state.reader.CompositeBlockchain import com.wavesplatform.transaction.TransactionBase import com.wavesplatform.transaction.TxValidationError.* +import com.wavesplatform.transaction.smart.{DApp as DAppTarget, *} import com.wavesplatform.transaction.smart.InvokeTransaction.DefaultCall import com.wavesplatform.transaction.smart.script.ScriptRunner.TxOrd import com.wavesplatform.transaction.smart.script.trace.{InvokeScriptTrace, TracedResult} -import com.wavesplatform.transaction.smart.{DApp as DAppTarget, *} import com.wavesplatform.transaction.validation.impl.DataTxValidator import monix.eval.Coeval import shapeless.Coproduct @@ -336,8 +336,12 @@ object InvokeScriptTransactionDiff { } else ScriptExecutionError.dAppExecution(error, log) } - .map { r => - InvokeDiffsCommon.checkScriptResultFields(blockchain, r._1); r + .flatMap { + case (result, log) => + val usedComplexity = startLimit - result.unusedComplexity.max(0) + (for (_ <- + InvokeDiffsCommon.checkScriptResultFields(blockchain, result)) yield (result, log)) + .leftMap(err => FailedTransactionError.dAppExecution(err.toString, usedComplexity, log)) } } diff --git a/node/src/main/scala/com/wavesplatform/transaction/smart/BlockchainContext.scala b/node/src/main/scala/com/wavesplatform/transaction/smart/BlockchainContext.scala index b343d42bfba..c01c42c32f2 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/smart/BlockchainContext.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/smart/BlockchainContext.scala @@ -41,7 +41,7 @@ object BlockchainContext { ).map { ds => val environment = new WavesEnvironment(nByte, in, h, blockchain, address, ds, txId) val fixUnicodeFunctions = blockchain.isFeatureActivated(BlockchainFeatures.SynchronousCalls) - val useNewPowPrecision = blockchain.height >= blockchain.settings.functionalitySettings.syncDAppCheckPaymentsHeight + val useNewPowPrecision = blockchain.isFeatureActivated(BlockchainFeatures.SynchronousCalls) build(ds, environment, fixUnicodeFunctions, useNewPowPrecision) } @@ -55,7 +55,7 @@ object BlockchainContext { .synchronized( cache.computeIfAbsent( (ds.stdLibVersion, fixUnicodeFunctions, ds), { _ => - PureContext.build(ds.stdLibVersion, fixUnicodeFunctions, useNewPowPrecision).withEnvironment[Environment] |+| + PureContext.build(ds.stdLibVersion, useNewPowPrecision).withEnvironment[Environment] |+| CryptoContext.build(Global, ds.stdLibVersion).withEnvironment[Environment] |+| WavesContext.build(Global, ds) } diff --git a/node/src/test/scala/com/wavesplatform/TestHelpers.scala b/node/src/test/scala/com/wavesplatform/TestHelpers.scala index b6b12f47df8..e9b1b338702 100644 --- a/node/src/test/scala/com/wavesplatform/TestHelpers.scala +++ b/node/src/test/scala/com/wavesplatform/TestHelpers.scala @@ -22,10 +22,7 @@ object TestHelpers { } def enableNG(settings: FunctionalitySettings): FunctionalitySettings = - settings.copy( - blockVersion3AfterHeight = 0, - preActivatedFeatures = settings.preActivatedFeatures ++ Map(BlockchainFeatures.NG.id -> 0) - ) + settings.copy(blockVersion3AfterHeight = 0, preActivatedFeatures = settings.preActivatedFeatures ++ Map(BlockchainFeatures.NG.id -> 0)) def enableNG(settings: WavesSettings): WavesSettings = settings.copy( diff --git a/node/src/test/scala/com/wavesplatform/consensus/FPPoSSelectorTest.scala b/node/src/test/scala/com/wavesplatform/consensus/FPPoSSelectorTest.scala index 93430e81b5d..d4678b49eb4 100644 --- a/node/src/test/scala/com/wavesplatform/consensus/FPPoSSelectorTest.scala +++ b/node/src/test/scala/com/wavesplatform/consensus/FPPoSSelectorTest.scala @@ -247,9 +247,7 @@ class FPPoSSelectorTest extends FreeSpec with WithDB with DBCacheSettings { val defaultWriter = TestLevelDB.withFunctionalitySettings( db, ignoreSpendableBalanceChanged, - TestFunctionalitySettings.Stub.copy( - preActivatedFeatures = Map(BlockchainFeatures.FairPoS.id -> 0) ++ (if (VRFActivated) Map(BlockchainFeatures.BlockV5.id -> 0) else Map()) - ) + TestFunctionalitySettings.Stub.copy(preActivatedFeatures = Map(BlockchainFeatures.FairPoS.id -> 0) ++ (if (VRFActivated) Map(BlockchainFeatures.BlockV5.id -> 0) else Map())) ) val settings0 = WavesSettings.fromRootConfig(loadConfig(ConfigFactory.load())) val settings = settings0.copy(featuresSettings = settings0.featuresSettings.copy(autoShutdownOnUnsupportedFeature = false)) diff --git a/node/src/test/scala/com/wavesplatform/history/BlockRewardSpec.scala b/node/src/test/scala/com/wavesplatform/history/BlockRewardSpec.scala index d8f57ee7d56..c2706e85454 100644 --- a/node/src/test/scala/com/wavesplatform/history/BlockRewardSpec.scala +++ b/node/src/test/scala/com/wavesplatform/history/BlockRewardSpec.scala @@ -28,16 +28,11 @@ class BlockRewardSpec extends FreeSpec with WithDomain { private val InitialReward = 6 * Constants.UnitsInWave private val rewardSettings = settings.copy( blockchainSettings = DefaultBlockchainSettings.copy( - functionalitySettings = FunctionalitySettings( - featureCheckBlocksPeriod = 10, - blocksForFeatureActivation = 1, - doubleFeaturesPeriodsAfterHeight = Int.MaxValue, - preActivatedFeatures = Map( + functionalitySettings = FunctionalitySettings(featureCheckBlocksPeriod = 10, blocksForFeatureActivation = 1, preActivatedFeatures = Map( BlockchainFeatures.BlockReward.id -> BlockRewardActivationHeight, BlockchainFeatures.NG.id -> NGActivationHeight, BlockchainFeatures.FeeSponsorship.id -> -10 - ) - ), + ), doubleFeaturesPeriodsAfterHeight = Int.MaxValue), rewardsSettings = RewardsSettings( 10, InitialReward, @@ -430,16 +425,11 @@ class BlockRewardSpec extends FreeSpec with WithDomain { private val calcRewardSettings = rewardSettings.copy( blockchainSettings = rewardSettings.blockchainSettings.copy( - functionalitySettings = FunctionalitySettings( - featureCheckBlocksPeriod = 10, - blocksForFeatureActivation = 1, - doubleFeaturesPeriodsAfterHeight = Int.MaxValue, - preActivatedFeatures = Map( + functionalitySettings = FunctionalitySettings(featureCheckBlocksPeriod = 10, blocksForFeatureActivation = 1, preActivatedFeatures = Map( BlockchainFeatures.BlockReward.id -> 4, BlockchainFeatures.NG.id -> NGActivationHeight, BlockchainFeatures.FeeSponsorship.id -> -10 - ) - ), + ), doubleFeaturesPeriodsAfterHeight = Int.MaxValue), rewardsSettings = RewardsSettings(12, 6 * Constants.UnitsInWave, 1 * Constants.UnitsInWave, 6) ) ) @@ -494,16 +484,11 @@ class BlockRewardSpec extends FreeSpec with WithDomain { private val smallPeriodRewardSettings = rewardSettings.copy( blockchainSettings = rewardSettings.blockchainSettings.copy( - functionalitySettings = FunctionalitySettings( - featureCheckBlocksPeriod = 10, - blocksForFeatureActivation = 1, - doubleFeaturesPeriodsAfterHeight = Int.MaxValue, - preActivatedFeatures = Map( + functionalitySettings = FunctionalitySettings(featureCheckBlocksPeriod = 10, blocksForFeatureActivation = 1, preActivatedFeatures = Map( BlockchainFeatures.BlockReward.id -> 4, BlockchainFeatures.NG.id -> NGActivationHeight, BlockchainFeatures.FeeSponsorship.id -> -10 - ) - ), + ), doubleFeaturesPeriodsAfterHeight = Int.MaxValue), rewardsSettings = RewardsSettings(3, 6 * Constants.UnitsInWave, 1 * Constants.UnitsInWave, 2) ) ) diff --git a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBurnTest.scala b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBurnTest.scala index 8bae5d5df82..cd846c411a8 100644 --- a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBurnTest.scala +++ b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterBurnTest.scala @@ -48,11 +48,7 @@ class BlockchainUpdaterBurnTest extends PropSpec with DomainScenarioDrivenProper val localBlockchainSettings: BlockchainSettings = DefaultBlockchainSettings.copy( functionalitySettings = DefaultBlockchainSettings.functionalitySettings - .copy( - featureCheckBlocksPeriod = 1, - blocksForFeatureActivation = 1, - preActivatedFeatures = Map(BlockchainFeatures.NG.id -> 0, BlockchainFeatures.DataTransaction.id -> 0) - ) + .copy(featureCheckBlocksPeriod = 1, blocksForFeatureActivation = 1, preActivatedFeatures = Map(BlockchainFeatures.NG.id -> 0, BlockchainFeatures.DataTransaction.id -> 0)) ) val localWavesSettings: WavesSettings = settings.copy(blockchainSettings = localBlockchainSettings) diff --git a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterSponsoredFeeBlockTest.scala b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterSponsoredFeeBlockTest.scala index f2309eaee4d..ab4047ffbe8 100644 --- a/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterSponsoredFeeBlockTest.scala +++ b/node/src/test/scala/com/wavesplatform/history/BlockchainUpdaterSponsoredFeeBlockTest.scala @@ -90,15 +90,11 @@ class BlockchainUpdaterSponsoredFeeBlockTest extends PropSpec with DomainScenari val SponsoredFeeActivatedAt0BlockchainSettings: BlockchainSettings = DefaultBlockchainSettings.copy( functionalitySettings = DefaultBlockchainSettings.functionalitySettings - .copy( - featureCheckBlocksPeriod = 1, - blocksForFeatureActivation = 1, - preActivatedFeatures = Map( + .copy(featureCheckBlocksPeriod = 1, blocksForFeatureActivation = 1, preActivatedFeatures = Map( BlockchainFeatures.FeeSponsorship.id -> 0, BlockchainFeatures.NG.id -> 0, BlockchainFeatures.BlockV5.id -> 0 - ) - ) + )) ) val SponsoredActivatedAt0WavesSettings: WavesSettings = settings.copy(blockchainSettings = SponsoredFeeActivatedAt0BlockchainSettings) diff --git a/node/src/test/scala/com/wavesplatform/history/Domain.scala b/node/src/test/scala/com/wavesplatform/history/Domain.scala index c32f608ecb1..1833017e064 100644 --- a/node/src/test/scala/com/wavesplatform/history/Domain.scala +++ b/node/src/test/scala/com/wavesplatform/history/Domain.scala @@ -2,15 +2,15 @@ package com.wavesplatform.history import scala.collection.immutable.SortedMap import scala.concurrent.Future -import scala.concurrent.duration._ +import scala.concurrent.duration.* import scala.util.control.NonFatal import scala.util.Try -import cats.syntax.option._ -import com.wavesplatform.{database, Application} +import cats.syntax.option.* +import com.wavesplatform.{database, Application, TestValues} import com.wavesplatform.account.{Address, KeyPair} import com.wavesplatform.api.BlockMeta -import com.wavesplatform.api.common._ +import com.wavesplatform.api.common.* import com.wavesplatform.block.{Block, MicroBlock} import com.wavesplatform.block.Block.BlockId import com.wavesplatform.common.state.ByteStr @@ -23,9 +23,9 @@ import com.wavesplatform.lagonaki.mocks.TestBlock import com.wavesplatform.lang.ValidationError import com.wavesplatform.lang.script.Script import com.wavesplatform.settings.WavesSettings -import com.wavesplatform.state._ +import com.wavesplatform.state.* import com.wavesplatform.state.diffs.TransactionDiffer -import com.wavesplatform.transaction.{BlockchainUpdater, _} +import com.wavesplatform.transaction.{BlockchainUpdater, *} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.smart.script.trace.TracedResult import com.wavesplatform.utils.{EthEncoding, SystemTime} @@ -36,7 +36,7 @@ import org.iq80.leveldb.DB import play.api.libs.json.{JsNull, Json, JsValue} case class Domain(db: DB, blockchainUpdater: BlockchainUpdaterImpl, levelDBWriter: LevelDBWriter, settings: WavesSettings) { - import Domain._ + import Domain.* val blockchain: BlockchainUpdaterImpl = blockchainUpdater @@ -185,11 +185,25 @@ case class Domain(db: DB, blockchainUpdater: BlockchainUpdaterImpl, levelDBWrite lastBlock } + def appendAndCatchError(txs: Transaction*): ValidationError = { + val block = createBlock(Block.PlainBlockVersion, txs) + val result = appendBlockE(block) + txs.foreach { tx => + require(blockchain.transactionInfo(tx.id()).isEmpty, s"should not pass: $tx") + } + result.left.getOrElse(throw new RuntimeException(s"Block appended successfully: $txs")) + } + def appendAndAssertFailed(txs: Transaction*): Block = { val block = createBlock(Block.PlainBlockVersion, txs) - appendBlock(block) - txs.foreach(tx => require(!blockchain.transactionSucceeded(tx.id()), s"should fail: $tx")) - lastBlock + appendBlockE(block) match { + case Left(err) => + throw new RuntimeException(s"Should be success: $err") + + case Right(_) => + txs.foreach(tx => require(!blockchain.transactionSucceeded(tx.id()), s"should fail: $tx")) + lastBlock + } } def appendBlockE(txs: Transaction*): Either[ValidationError, Seq[Diff]] = @@ -312,7 +326,7 @@ case class Domain(db: DB, blockchainUpdater: BlockchainUpdaterImpl, levelDBWrite //noinspection ScalaStyle object helpers { def creditWavesToDefaultSigner(amount: Long = 10_0000_0000): Unit = { - import com.wavesplatform.transaction.utils.EthConverters._ + import com.wavesplatform.transaction.utils.EthConverters.* appendBlock(TxHelpers.genesis(TxHelpers.defaultAddress, amount), TxHelpers.genesis(TxHelpers.defaultSigner.toEthWavesAddress, amount)) } @@ -329,6 +343,22 @@ case class Domain(db: DB, blockchainUpdater: BlockchainUpdaterImpl, levelDBWrite def setScript(account: KeyPair, script: Script): Unit = { appendBlock(TxHelpers.setScript(account, script)) } + + def setData(account: KeyPair, entries: DataEntry[_]*): Unit = { + appendBlock(entries.map(TxHelpers.dataEntry(account, _)): _*) + } + + def transfer(account: KeyPair, to: Address, amount: TxAmount, asset: Asset): Unit = { + appendBlock(TxHelpers.transfer(account, to, amount, asset)) + } + + def transferAll(account: KeyPair, to: Address, asset: Asset): Unit = { + val balanceMinusFee = { + val balance = blockchain.balance(account.toAddress, asset) + if (asset == Waves) balance - TestValues.fee else balance + } + transfer(account, to, balanceMinusFee, asset) + } } val transactionsApi: CommonTransactionsApi = CommonTransactionsApi( diff --git a/node/src/test/scala/com/wavesplatform/history/LeasingExpirySpec.scala b/node/src/test/scala/com/wavesplatform/history/LeasingExpirySpec.scala index f5498ea0870..1b674bcc8a5 100644 --- a/node/src/test/scala/com/wavesplatform/history/LeasingExpirySpec.scala +++ b/node/src/test/scala/com/wavesplatform/history/LeasingExpirySpec.scala @@ -22,16 +22,10 @@ class LeasingExpirySpec extends FreeSpec with WithDomain { private val leasingSettings = settings.copy( blockchainSettings = DefaultBlockchainSettings.copy( - functionalitySettings = FunctionalitySettings( - featureCheckBlocksPeriod = 100, - blocksForFeatureActivation = 80, - doubleFeaturesPeriodsAfterHeight = Int.MaxValue, - leaseExpiration = LeasingValidity, - preActivatedFeatures = Map( + functionalitySettings = FunctionalitySettings(featureCheckBlocksPeriod = 100, blocksForFeatureActivation = 80, preActivatedFeatures = Map( BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.LeaseExpiration.id -> LeasingExpiryActivationHeight - ) - ) + ), doubleFeaturesPeriodsAfterHeight = Int.MaxValue, leaseExpiration = LeasingValidity) ) ) diff --git a/node/src/test/scala/com/wavesplatform/http/DebugApiRouteSpec.scala b/node/src/test/scala/com/wavesplatform/http/DebugApiRouteSpec.scala index 825adff51e8..29304a303d3 100644 --- a/node/src/test/scala/com/wavesplatform/http/DebugApiRouteSpec.scala +++ b/node/src/test/scala/com/wavesplatform/http/DebugApiRouteSpec.scala @@ -961,8 +961,7 @@ class DebugApiRouteSpec "txs with empty and small verifier" in { val blockchain = createBlockchainStub { blockchain => - val settings = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + val settings = TestFunctionalitySettings.Enabled.copy(featureCheckBlocksPeriod = 1, blocksForFeatureActivation = 1, preActivatedFeatures = Map( BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.SmartAssets.id -> 0, BlockchainFeatures.Ride4DApps.id -> 0, @@ -971,10 +970,7 @@ class DebugApiRouteSpec BlockchainFeatures.BlockReward.id -> 0, BlockchainFeatures.BlockV5.id -> 0, BlockchainFeatures.SynchronousCalls.id -> 0 - ), - featureCheckBlocksPeriod = 1, - blocksForFeatureActivation = 1 - ) + )) (() => blockchain.settings).when().returns(WavesSettings.default().blockchainSettings.copy(functionalitySettings = settings)) (() => blockchain.activatedFeatures).when().returns(settings.preActivatedFeatures) (blockchain.balance _).when(*, *).returns(ENOUGH_AMT) diff --git a/node/src/test/scala/com/wavesplatform/http/UtilsRouteSpec.scala b/node/src/test/scala/com/wavesplatform/http/UtilsRouteSpec.scala index 632707f2798..1a67540179e 100644 --- a/node/src/test/scala/com/wavesplatform/http/UtilsRouteSpec.scala +++ b/node/src/test/scala/com/wavesplatform/http/UtilsRouteSpec.scala @@ -1,5 +1,7 @@ package com.wavesplatform.http +import scala.concurrent.duration._ + import akka.http.scaladsl.testkit.RouteTestTimeout import com.google.protobuf.ByteString import com.wavesplatform.account.Address @@ -9,25 +11,24 @@ import com.wavesplatform.api.http.requests.ScriptWithImportsRequest import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.{Base58, EitherExt2} import com.wavesplatform.crypto +import com.wavesplatform.db.WithDomain import com.wavesplatform.features.BlockchainFeatures -import com.wavesplatform.history.DefaultBlockchainSettings +import com.wavesplatform.lang.{contract, Global} import com.wavesplatform.lang.contract.DApp import com.wavesplatform.lang.contract.DApp.{CallableAnnotation, CallableFunction, VerifierAnnotation, VerifierFunction} -import com.wavesplatform.lang.directives.values.{V2, V3, V5, V6} -import com.wavesplatform.lang.script.v1.ExprScript +import com.wavesplatform.lang.directives.values.{V2, V3, V6} import com.wavesplatform.lang.script.{ContractScript, Script} +import com.wavesplatform.lang.script.v1.ExprScript +import com.wavesplatform.lang.v1.{FunctionHeader, Serde} import com.wavesplatform.lang.v1.compiler.Terms.* import com.wavesplatform.lang.v1.compiler.TestCompiler import com.wavesplatform.lang.v1.estimator.v2.ScriptEstimatorV2 import com.wavesplatform.lang.v1.evaluator.ctx.impl.PureContext -import com.wavesplatform.lang.v1.{FunctionHeader, Serde} -import com.wavesplatform.lang.{Global, contract} import com.wavesplatform.protobuf.dapp.DAppMeta import com.wavesplatform.protobuf.dapp.DAppMeta.{CallableFuncSignature, CompactNameAndOriginalNamePair} import com.wavesplatform.settings.TestSettings -import com.wavesplatform.state.{AccountScriptInfo, Blockchain, IntegerDataEntry} +import com.wavesplatform.state.{Blockchain, IntegerDataEntry} import com.wavesplatform.state.diffs.FeeValidation -import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.TxHelpers import com.wavesplatform.transaction.smart.script.ScriptCompiler import com.wavesplatform.utils.{Schedulers, Time} @@ -38,9 +39,7 @@ import org.scalatest.Inside import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks as PropertyChecks import play.api.libs.json.* -import scala.concurrent.duration.* - -class UtilsRouteSpec extends RouteSpec("/utils") with RestAPISettingsHelper with PropertyChecks with PathMockFactory with Inside { +class UtilsRouteSpec extends RouteSpec("/utils") with RestAPISettingsHelper with PropertyChecks with PathMockFactory with Inside with WithDomain { implicit val routeTestTimeout = RouteTestTimeout(10.seconds) implicit val timeout = routeTestTimeout.duration @@ -805,55 +804,43 @@ class UtilsRouteSpec extends RouteSpec("/utils") with RestAPISettingsHelper with } } - routePath("/script/evaluate/{address}") in { - val blockchain = stub[Blockchain]("blockchain") + routePath("/script/evaluate/{address}") in withDomain(DomainPresets.RideV5) { d => + val blockchain = d.blockchain val api = utilsApi.copy(blockchain = blockchain) val route = seal(api.route) - (() => blockchain.activatedFeatures).when().returning(Map(BlockchainFeatures.SynchronousCalls.id -> 0)) - (() => blockchain.settings).when().returning(TestSettings.Default.blockchainSettings) val letFromContract = 1000 - val testScript = { - val str = s""" - |{-# STDLIB_VERSION 5 #-} - |{-# CONTENT_TYPE DAPP #-} - |{-# SCRIPT_TYPE ACCOUNT #-} - | - |let letFromContract = $letFromContract - | - |func test(i: Int) = i * 10 - |func testB() = true - |func testBS() = base58'MATCHER' - |func testS() = "Test" - |func testF() = throw("Test") - |func testCompl() = ${"sigVerify(base58'', base58'', base58'') ||" * 200} true - |func testThis() = this - |func testListArg(list: List[String|ByteVector|Int], str: String, bytes: ByteVector) = list.containsElement(str) - | - |@Callable(i) - |func testCallable() = [BinaryEntry("test", i.caller.bytes)] - | - |@Callable(i) - |func testSyncinvoke() = { - | strict r = invoke(this, "testCallable", [], [AttachedPayment(unit, 100)]) - | [BinaryEntry("testSyncInvoke", i.caller.bytes)] - |} - | - |@Callable(i) - |func testSyncCallComplexityExcess() = { - | strict r = invoke(this, "testSyncCallComplexityExcess", [], []) - | [] - |} - | - |@Callable(i) - |func testWriteEntryType(b: ByteVector) = [ BinaryEntry("bytes", b) ] - | - """.stripMargin - - val (script, _) = ScriptCompiler.compile(str, ScriptEstimatorV2).explicitGet() - AccountScriptInfo(TxHelpers.defaultSigner.publicKey, script, 0, Map(1 -> Map("testCallable" -> 200, "testSyncCallComplexityExcess" -> 100))) - } - + val testScript = TxHelpers.scriptV5(s""" + |let letFromContract = $letFromContract + | + |func test(i: Int) = i * 10 + |func testB() = true + |func testBS() = base58'MATCHER' + |func testS() = "Test" + |func testF() = throw("Test") + |func testCompl() = ${"sigVerify(base58'', base58'', base58'') ||" * 200} true + |func testThis() = this + |func testListArg(list: List[String|ByteVector|Int], str: String, bytes: ByteVector) = list.containsElement(str) + | + |@Callable(i) + |func testCallable() = [BinaryEntry("test", i.caller.bytes)] + | + |@Callable(i) + |func testSyncinvoke() = { + | strict r = invoke(this, "testCallable", [], []) + | [BinaryEntry("testSyncInvoke", i.caller.bytes)] + |} + | + |@Callable(i) + |func testSyncCallComplexityExcess() = { + | strict r = invoke(this, "testSyncCallComplexityExcess", [], []) + | [] + |} + | + |@Callable(i) + |func testWriteEntryType(b: ByteVector) = [ BinaryEntry("bytes", b) ] """.stripMargin) + + val dAppAccount = TxHelpers.defaultSigner val dAppAddress = TxHelpers.defaultSigner.toAddress def evalScript(text: String, address: Address = dAppAddress) = @@ -871,22 +858,20 @@ class UtilsRouteSpec extends RouteSpec("/utils") with RestAPISettingsHelper with (fullJson \ "result").asOpt[JsObject].getOrElse(fullJson - "address" - "expr") } - (blockchain.hasAccountScript _).when(dAppAddress).returning(false).once() - (() => utilsApi.blockchain.settings).when().returning(DefaultBlockchainSettings).anyNumberOfTimes() evalScript("testNone()") ~> route ~> check { responseAs[JsObject] shouldBe Json.obj("error" -> 199, "message" -> s"Address $dAppAddress is not dApp") } - (blockchain.hasAccountScript _).when(dAppAddress).returning(true).anyNumberOfTimes() - (blockchain.accountScript _).when(dAppAddress).returning(Some(testScript)).anyNumberOfTimes() + d.helpers.creditWavesToDefaultSigner() + d.helpers.setScript(dAppAccount, testScript) evalScript("testListArg([\"test\", 111, base64'dGVzdA==', false], \"test\", base58'aaa')") ~> route ~> check { responseJson shouldBe Json.obj("type" -> "Boolean", "value" -> true) } evalScript("testCallable()") ~> route ~> check { - responseAs[String] shouldBe """{"result":{"type":"Array","value":[{"type":"BinaryEntry","value":{"key":{"type":"String","value":"test"},"value":{"type":"ByteVector","value":"11111111111111111111111111"}}}]},"complexity":5,"expr":"testCallable()","address":"3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9"}""" + responseAs[JsValue] should matchJson("""{"result":{"type":"Array","value":[{"type":"BinaryEntry","value":{"key":{"type":"String","value":"test"},"value":{"type":"ByteVector","value":"11111111111111111111111111"}}}]},"complexity":5,"expr":"testCallable()","address":"3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9"}""") } evalScript("testThis()") ~> route ~> check { @@ -938,11 +923,7 @@ class UtilsRouteSpec extends RouteSpec("/utils") with RestAPISettingsHelper with val expectingKey = "some" val expectingValue = 1234 - (blockchain.accountData _) - .when(dAppAddress, expectingKey) - .returning(Some(IntegerDataEntry(expectingKey, expectingValue))) - .anyNumberOfTimes() - + d.helpers.setData(dAppAccount, IntegerDataEntry(expectingKey, expectingValue)) evalScript( s""" | this.getInteger("$expectingKey") == $expectingValue && @@ -956,57 +937,61 @@ class UtilsRouteSpec extends RouteSpec("/utils") with RestAPISettingsHelper with responseJson shouldBe Json.obj("type" -> "Int", "value" -> (letFromContract - 1)) } - (() => blockchain.settings) - .when() - .returning(DefaultBlockchainSettings) - .anyNumberOfTimes() - - (utilsApi.blockchain.balance _) - .when(*, *) - .returning(1000) - .anyNumberOfTimes() evalScript(""" testSyncinvoke() """) ~> route ~> check { - responseAs[String] shouldBe """{"result":{"type":"Array","value":[{"type":"BinaryEntry","value":{"key":{"type":"String","value":"testSyncInvoke"},"value":{"type":"ByteVector","value":"11111111111111111111111111"}}}]},"complexity":94,"expr":" testSyncinvoke() ","address":"3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9"}""" + responseAs[JsValue] should matchJson("""{ + | "result" : { + | "type" : "Array", + | "value" : [ { + | "type" : "BinaryEntry", + | "value" : { + | "key" : { + | "type" : "String", + | "value" : "testSyncInvoke" + | }, + | "value" : { + | "type" : "ByteVector", + | "value" : "11111111111111111111111111" + | } + | } + | } ] + | }, + | "complexity" : 92, + | "expr" : " testSyncinvoke() ", + | "address" : "3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9" + |}""".stripMargin) } val complexityLimit = 1234 val customApi = api.copy(settings = restAPISettings.copy(evaluateScriptComplexityLimit = complexityLimit)) evalScript(""" testSyncCallComplexityExcess() """) ~> customApi.route ~> check { - responseAs[String] shouldBe s"""{"error":306,"message":"FailedTransactionError(code = 1, error = Invoke complexity limit = $complexityLimit is exceeded, log =)","expr":" testSyncCallComplexityExcess() ","address":"3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9"}""" + responseAs[JsValue] should matchJson(s"""{"error":306,"message":"FailedTransactionError(code = 1, error = Invoke complexity limit = $complexityLimit is exceeded, log =)","expr":" testSyncCallComplexityExcess() ","address":"3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9"}""") } evalScript(""" testWriteEntryType("abc") """) ~> route ~> check { - responseAs[String] shouldBe """{"error":306,"message":"Passed args (bytes, abc) are unsuitable for constructor BinaryEntry(String, ByteVector)","expr":" testWriteEntryType(\"abc\") ","address":"3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9"}""" + responseAs[JsValue] should matchJson("""{"error":306,"message":"Passed args (bytes, abc) are unsuitable for constructor BinaryEntry(String, ByteVector)","expr":" testWriteEntryType(\"abc\") ","address":"3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9"}""") } evalScript(""" testWriteEntryType(base58'aaaa') """) ~> route ~> check { - responseAs[String] shouldBe """{"result":{"type":"Array","value":[{"type":"BinaryEntry","value":{"key":{"type":"String","value":"bytes"},"value":{"type":"ByteVector","value":"aaaa"}}}]},"complexity":3,"expr":" testWriteEntryType(base58'aaaa') ","address":"3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9"}""" + responseAs[JsValue] should matchJson("""{"result":{"type":"Array","value":[{"type":"BinaryEntry","value":{"key":{"type":"String","value":"bytes"},"value":{"type":"ByteVector","value":"aaaa"}}}]},"complexity":3,"expr":" testWriteEntryType(base58'aaaa') ","address":"3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9"}""") } evalScript(s"""parseBigIntValue("${PureContext.BigIntMax}")""") ~> route ~> check { - responseAs[String] shouldBe s"""{"result":{"type":"BigInt","value":${PureContext.BigIntMax}},"complexity":65,"expr":"parseBigIntValue(\\"${PureContext.BigIntMax}\\")","address":"3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9"}""" + responseAs[JsValue] should matchJson(s"""{"result":{"type":"BigInt","value":${PureContext.BigIntMax}},"complexity":65,"expr":"parseBigIntValue(\\"${PureContext.BigIntMax}\\")","address":"3MtGzgmNa5fMjGCcPi5nqMTdtZkfojyWHL9"}""") } + val dAppAccount2 = TxHelpers.secondSigner val dAppAddress2 = TxHelpers.secondAddress - val testScript2 = { - val script = TestCompiler(V5).compileContract( - s""" - | @Callable(i) - | func callable() = { - | strict a = sigVerify(base58'', base58'', base58'') - | strict r = Address(base58'$dAppAddress').invoke("testCallable", [], [AttachedPayment(unit, 100)]) - | [BinaryEntry("testSyncInvoke", i.caller.bytes)] - | } - """.stripMargin - ) - AccountScriptInfo(TxHelpers.secondSigner.publicKey, script, 0, Map(1 -> Map("callable" -> 999))) - } - (blockchain.hasAccountScript _).when(dAppAddress2).returning(true).anyNumberOfTimes() - (blockchain.accountScript _).when(dAppAddress2).returning(Some(testScript2)).anyNumberOfTimes() - (blockchain.balance _).when(dAppAddress2, Waves).returning(Int.MaxValue).anyNumberOfTimes() + d.helpers.creditWavesFromDefaultSigner(dAppAddress2) + val testScript2 = TxHelpers.scriptV5(s"""@Callable(i) + | func callable() = { + | strict a = sigVerify(base58'', base58'', base58'') + | strict r = Address(base58'$dAppAddress').invoke("testCallable", [], [AttachedPayment(unit, 100)]) + | [BinaryEntry("testSyncInvoke", i.caller.bytes)] + | }""".stripMargin) + d.helpers.setScript(dAppAccount2, testScript2) evalScript(""" callable() """, dAppAddress2) ~> route ~> check { - responseAs[String] shouldBe """{"result":{"type":"Array","value":[{"type":"BinaryEntry","value":{"key":{"type":"String","value":"testSyncInvoke"},"value":{"type":"ByteVector","value":"11111111111111111111111111"}}}]},"complexity":297,"expr":" callable() ","address":"3MuVqVJGmFsHeuFni5RbjRmALuGCkEwzZtC"}""" + responseAs[JsValue] should matchJson("""{"result":{"type":"Array","value":[{"type":"BinaryEntry","value":{"key":{"type":"String","value":"testSyncInvoke"},"value":{"type":"ByteVector","value":"11111111111111111111111111"}}}]},"complexity":297,"expr":" callable() ","address":"3MuVqVJGmFsHeuFni5RbjRmALuGCkEwzZtC"}""") } } diff --git a/node/src/test/scala/com/wavesplatform/mining/BlockV5Test.scala b/node/src/test/scala/com/wavesplatform/mining/BlockV5Test.scala index 37339f8602a..5ded6ffe51f 100644 --- a/node/src/test/scala/com/wavesplatform/mining/BlockV5Test.scala +++ b/node/src/test/scala/com/wavesplatform/mining/BlockV5Test.scala @@ -375,13 +375,11 @@ class BlockV5Test extends FlatSpec with WithDomain with OptionValues with Either forAll(preconditions) { case (acc, genesis) => - val fs = TestFunctionalitySettings.Stub.copy( - preActivatedFeatures = Map( + val fs = TestFunctionalitySettings.Stub.copy(preActivatedFeatures = Map( BlockchainFeatures.NG.id -> 0, BlockchainFeatures.BlockV5.id -> 2, BlockchainFeatures.SmartAccounts.id -> 0 - ) - ) + )) withDomain(WavesSettings.default().copy(blockchainSettings = WavesSettings.default().blockchainSettings.copy(functionalitySettings = fs))) { d => @@ -489,32 +487,23 @@ object BlockV5Test { private val defaultSettings = WavesSettings.fromRootConfig(ConfigFactory.load()) private val testSettings = defaultSettings.copy( blockchainSettings = defaultSettings.blockchainSettings.copy( - functionalitySettings = FunctionalitySettings( - blockVersion3AfterHeight = NGActivationHeight, - featureCheckBlocksPeriod = 10, - blocksForFeatureActivation = 1, - doubleFeaturesPeriodsAfterHeight = Int.MaxValue, - preActivatedFeatures = Map( + functionalitySettings = FunctionalitySettings(featureCheckBlocksPeriod = 10, blocksForFeatureActivation = 1, blockVersion3AfterHeight = NGActivationHeight, preActivatedFeatures = Map( BlockchainFeatures.BlockV5.id -> BlockV5ActivationHeight, BlockchainFeatures.BlockReward.id -> BlockRewardActivationHeight, BlockchainFeatures.NG.id -> NGActivationHeight, BlockchainFeatures.FairPoS.id -> FairPoSActivationHeight - ) - ) + ), doubleFeaturesPeriodsAfterHeight = Int.MaxValue) ), minerSettings = defaultSettings.minerSettings.copy(quorum = 0) ) private val preActivatedTestSettings = testSettings.copy( blockchainSettings = testSettings.blockchainSettings.copy( - functionalitySettings = testSettings.blockchainSettings.functionalitySettings.copy( - blockVersion3AfterHeight = 0, - preActivatedFeatures = Map( + functionalitySettings = testSettings.blockchainSettings.functionalitySettings.copy(blockVersion3AfterHeight = 0, preActivatedFeatures = Map( BlockchainFeatures.BlockV5.id -> 0, BlockchainFeatures.BlockReward.id -> 0, BlockchainFeatures.NG.id -> 0, BlockchainFeatures.FairPoS.id -> 0 - ) - ) + )) ) ) } diff --git a/node/src/test/scala/com/wavesplatform/mining/BlockWithMaxBaseTargetTest.scala b/node/src/test/scala/com/wavesplatform/mining/BlockWithMaxBaseTargetTest.scala index f4238f466b1..1c5e98af465 100644 --- a/node/src/test/scala/com/wavesplatform/mining/BlockWithMaxBaseTargetTest.scala +++ b/node/src/test/scala/com/wavesplatform/mining/BlockWithMaxBaseTargetTest.scala @@ -120,9 +120,7 @@ class BlockWithMaxBaseTargetTest extends FreeSpec with WithDB with DBCacheSettin val settings0 = WavesSettings.fromRootConfig(loadConfig(ConfigFactory.load())) val minerSettings = settings0.minerSettings.copy(quorum = 0) val blockchainSettings0 = settings0.blockchainSettings.copy( - functionalitySettings = settings0.blockchainSettings.functionalitySettings.copy( - preActivatedFeatures = Map(BlockchainFeatures.FairPoS.id -> 1) - ) + functionalitySettings = settings0.blockchainSettings.functionalitySettings.copy(preActivatedFeatures = Map(BlockchainFeatures.FairPoS.id -> 1)) ) val synchronizationSettings0 = settings0.synchronizationSettings.copy(maxBaseTarget = Some(1L)) val settings = settings0.copy( diff --git a/node/src/test/scala/com/wavesplatform/settings/TestFunctionalitySettings.scala b/node/src/test/scala/com/wavesplatform/settings/TestFunctionalitySettings.scala index 16220374034..68109dfd599 100644 --- a/node/src/test/scala/com/wavesplatform/settings/TestFunctionalitySettings.scala +++ b/node/src/test/scala/com/wavesplatform/settings/TestFunctionalitySettings.scala @@ -3,18 +3,12 @@ package com.wavesplatform.settings import com.wavesplatform.features.{BlockchainFeature, BlockchainFeatures} object TestFunctionalitySettings { - val Enabled = FunctionalitySettings( - featureCheckBlocksPeriod = 10000, - blocksForFeatureActivation = 9000, - preActivatedFeatures = Map( + val Enabled = FunctionalitySettings(featureCheckBlocksPeriod = 10000, blocksForFeatureActivation = 9000, preActivatedFeatures = Map( BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.SmartAssets.id -> 0, BlockchainFeatures.FairPoS.id -> 0, BlockchainFeatures.Ride4DApps.id -> 0 - ), - doubleFeaturesPeriodsAfterHeight = Int.MaxValue, - estimatorSumOverflowFixHeight = Int.MaxValue - ) + ), doubleFeaturesPeriodsAfterHeight = Int.MaxValue, estimatorSumOverflowFixHeight = Int.MaxValue) def withFeatures(features: BlockchainFeature*): FunctionalitySettings = Enabled.copy(preActivatedFeatures = Enabled.preActivatedFeatures ++ features.map(_.id -> 0)) diff --git a/node/src/test/scala/com/wavesplatform/settings/TestSettings.scala b/node/src/test/scala/com/wavesplatform/settings/TestSettings.scala index 6147b53edd4..217adb3ecbe 100644 --- a/node/src/test/scala/com/wavesplatform/settings/TestSettings.scala +++ b/node/src/test/scala/com/wavesplatform/settings/TestSettings.scala @@ -12,10 +12,7 @@ object TestSettings { def withNG: WavesSettings = ws.withFunctionalitySettings( - ws.blockchainSettings.functionalitySettings.copy( - blockVersion3AfterHeight = 0, - preActivatedFeatures = ws.blockchainSettings.functionalitySettings.preActivatedFeatures ++ Map(BlockchainFeatures.NG.id -> 0) - ) + ws.blockchainSettings.functionalitySettings.copy(blockVersion3AfterHeight = 0, preActivatedFeatures = ws.blockchainSettings.functionalitySettings.preActivatedFeatures ++ Map(BlockchainFeatures.NG.id -> 0)) ) } } diff --git a/node/src/test/scala/com/wavesplatform/state/RollbackSpec.scala b/node/src/test/scala/com/wavesplatform/state/RollbackSpec.scala index 0882fe885d7..fb726a62f32 100644 --- a/node/src/test/scala/com/wavesplatform/state/RollbackSpec.scala +++ b/node/src/test/scala/com/wavesplatform/state/RollbackSpec.scala @@ -930,11 +930,7 @@ class RollbackSpec extends FreeSpec with WithDomain { } def createSettings(preActivatedFeatures: (BlockchainFeature, Int)*): WavesSettings = { - val tfs = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = preActivatedFeatures.map { case (k, v) => k.id -> v }.toMap, - blocksForFeatureActivation = 1, - featureCheckBlocksPeriod = 1 - ) + val tfs = TestFunctionalitySettings.Enabled.copy(featureCheckBlocksPeriod = 1, blocksForFeatureActivation = 1, preActivatedFeatures = preActivatedFeatures.map { case (k, v) => k.id -> v }.toMap) history.DefaultWavesSettings.copy(blockchainSettings = history.DefaultWavesSettings.blockchainSettings.copy(functionalitySettings = tfs)) } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/AssetTransactionsDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/AssetTransactionsDiffTest.scala index f190eeff544..0263e33a60a 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/AssetTransactionsDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/AssetTransactionsDiffTest.scala @@ -117,9 +117,7 @@ class AssetTransactionsDiffTest extends PropSpec with BlocksTransactionsHelpers val fs = TestFunctionalitySettings.Enabled - .copy( - preActivatedFeatures = Map(BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.BurnAnyTokens.id -> 0) - ) + .copy(preActivatedFeatures = Map(BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.BurnAnyTokens.id -> 0)) forAll(setup) { case (genesis, issue, assetTransfer, wavesTransfer, burn) => @@ -147,9 +145,7 @@ class AssetTransactionsDiffTest extends PropSpec with BlocksTransactionsHelpers val fs = TestFunctionalitySettings.Enabled - .copy( - preActivatedFeatures = Map(BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.DataTransaction.id -> 0) - ) + .copy(preActivatedFeatures = Map(BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.DataTransaction.id -> 0)) forAll(setup) { case (_, _, genesis, issue, reissue) => @@ -209,9 +205,7 @@ class AssetTransactionsDiffTest extends PropSpec with BlocksTransactionsHelpers val fs = TestFunctionalitySettings.Enabled - .copy( - preActivatedFeatures = Map(BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.DataTransaction.id -> 0) - ) + .copy(preActivatedFeatures = Map(BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.DataTransaction.id -> 0)) forAll(setup) { case (_, _, genesis, issue, reissue, transfer) => @@ -348,10 +342,7 @@ class AssetTransactionsDiffTest extends PropSpec with BlocksTransactionsHelpers } val assetInfoUpdateEnabled: FunctionalitySettings = TestFunctionalitySettings.Enabled - .copy( - preActivatedFeatures = TestFunctionalitySettings.Enabled.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0) + (BlockchainFeatures.NG.id -> 0), - minAssetInfoUpdateInterval = 100 - ) + .copy(preActivatedFeatures = TestFunctionalitySettings.Enabled.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0) + (BlockchainFeatures.NG.id -> 0), minAssetInfoUpdateInterval = 100) property("Can't update before activation") { forAll(genesisIssueUpdate) { @@ -474,12 +465,10 @@ class AssetTransactionsDiffTest extends PropSpec with BlocksTransactionsHelpers | groth16Verify_15inputs(base64'ZGdnZHMK',base64'ZGdnZHMK',base64'ZGdnZHMK') """.stripMargin - val rideV4Activated = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + val rideV4Activated = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map( BlockchainFeatures.Ride4DApps.id -> 0, BlockchainFeatures.BlockV5.id -> 0 - ) - ) + )) forAll(genesisIssueTransferReissue(exprV4WithComplexityBetween3000And4000, V4)) { case (gen, issue, _, _, _) => @@ -582,10 +571,7 @@ class AssetTransactionsDiffTest extends PropSpec with BlocksTransactionsHelpers def settings(checkNegative: Boolean = false, checkSumOverflow: Boolean = false): FunctionalitySettings = { TestFunctionalitySettings .withFeatures(BlockV5) - .copy( - estimationOverflowFixHeight = if (checkNegative) 0 else 999, - estimatorSumOverflowFixHeight = if (checkSumOverflow) 0 else 999 - ) + .copy(estimationOverflowFixHeight = if (checkNegative) 0 else 999, estimatorSumOverflowFixHeight = if (checkSumOverflow) 0 else 999) } def assert(preparingTxs: Seq[Transaction], scriptedTx: () => Transaction) = { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/BlockDifferTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/BlockDifferTest.scala index 5ec6d3033bf..97113ec1836 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/BlockDifferTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/BlockDifferTest.scala @@ -102,12 +102,7 @@ class BlockDifferTest extends FreeSpec with BlockGen with WithState { } private def assertDiff(blocks: Seq[Block], ngAtHeight: Int)(assertion: (Diff, Blockchain) => Unit): Unit = { - val fs = FunctionalitySettings( - featureCheckBlocksPeriod = ngAtHeight / 2, - blocksForFeatureActivation = 1, - preActivatedFeatures = Map[Short, Int]((2, ngAtHeight)), - doubleFeaturesPeriodsAfterHeight = Int.MaxValue - ) + val fs = FunctionalitySettings(featureCheckBlocksPeriod = ngAtHeight / 2, blocksForFeatureActivation = 1, preActivatedFeatures = Map[Short, Int]((2, ngAtHeight)), doubleFeaturesPeriodsAfterHeight = Int.MaxValue) assertNgDiffState(blocks.init, blocks.last, fs)(assertion) } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/CommonValidationTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/CommonValidationTest.scala index 728248e3a13..ed667fdd84f 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/CommonValidationTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/CommonValidationTest.scala @@ -185,11 +185,7 @@ class CommonValidationTest extends PropSpec with WithState { private def createSettings(preActivatedFeatures: (BlockchainFeature, Int)*): FunctionalitySettings = TestFunctionalitySettings.Enabled - .copy( - preActivatedFeatures = preActivatedFeatures.map { case (k, v) => k.id -> v }.toMap, - blocksForFeatureActivation = 1, - featureCheckBlocksPeriod = 1 - ) + .copy(featureCheckBlocksPeriod = 1, blocksForFeatureActivation = 1, preActivatedFeatures = preActivatedFeatures.map { case (k, v) => k.id -> v }.toMap) private def smartTokensCheckFeeTest(feeInAssets: Boolean, feeAmount: Long)(f: Either[ValidationError, Unit] => Any): Unit = { val settings = createSettings(BlockchainFeatures.SmartAccounts -> 0, BlockchainFeatures.SmartAssets -> 0) diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/CreateAliasTransactionDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/CreateAliasTransactionDiffTest.scala index c9a36e0d71f..308928e0bb1 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/CreateAliasTransactionDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/CreateAliasTransactionDiffTest.scala @@ -18,9 +18,7 @@ import org.scalacheck.Gen class CreateAliasTransactionDiffTest extends PropSpec with WithState { val fs = - TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map(BlockchainFeatures.SmartAccounts.id -> 0) - ) + TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map(BlockchainFeatures.SmartAccounts.id -> 0)) val preconditionsAndAliasCreations : Gen[(GenesisTransaction, CreateAliasTransaction, CreateAliasTransaction, CreateAliasTransaction, CreateAliasTransaction)] = for { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ExchangeTransactionDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ExchangeTransactionDiffTest.scala index bcf97856ddb..cd824ff31e6 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ExchangeTransactionDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ExchangeTransactionDiffTest.scala @@ -44,14 +44,12 @@ class ExchangeTransactionDiffTest extends PropSpec with Inside with WithDomain w val MATCHER: KeyPair = TestValues.keyPair - val fs: FunctionalitySettings = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + val fs: FunctionalitySettings = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map( BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.SmartAssets.id -> 0, BlockchainFeatures.SmartAccountTrading.id -> 0, BlockchainFeatures.Ride4DApps.id -> 0 - ) - ) + )) val fsWithOrderFeature: FunctionalitySettings = fs.copy(preActivatedFeatures = fs.preActivatedFeatures ++ Map(BlockchainFeatures.OrderV3.id -> 0)) @@ -60,9 +58,7 @@ class ExchangeTransactionDiffTest extends PropSpec with Inside with WithDomain w fsWithOrderFeature.copy(preActivatedFeatures = fsWithOrderFeature.preActivatedFeatures + (BlockchainFeatures.MassTransfer.id -> 0)) val fsWithBlockV5: FunctionalitySettings = - fsWithOrderFeature.copy( - preActivatedFeatures = fsWithOrderFeature.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0) - ) + fsWithOrderFeature.copy(preActivatedFeatures = fsWithOrderFeature.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0)) private val estimator = ScriptEstimatorV2 @@ -774,11 +770,7 @@ class ExchangeTransactionDiffTest extends PropSpec with Inside with WithDomain w private def createSettings(preActivatedFeatures: (BlockchainFeature, Int)*): FunctionalitySettings = TestFunctionalitySettings.Enabled - .copy( - preActivatedFeatures = preActivatedFeatures.map { case (k, v) => k.id -> v }.toMap, - blocksForFeatureActivation = 1, - featureCheckBlocksPeriod = 1 - ) + .copy(featureCheckBlocksPeriod = 1, blocksForFeatureActivation = 1, preActivatedFeatures = preActivatedFeatures.map { case (k, v) => k.id -> v }.toMap) property(s"Exchange transaction with scripted matcher and orders needs extra fee ($ScriptExtraFee)") { val allValidP = smartTradePreconditions( diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/LeaseTransactionsDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/LeaseTransactionsDiffTest.scala index 7cec3a0f2a6..9fa1a51357d 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/LeaseTransactionsDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/LeaseTransactionsDiffTest.scala @@ -191,9 +191,7 @@ class LeaseTransactionsDiffTest extends PropSpec with WithDomain { forAll(scenario) { case (genesis, lease, leaseCancel, ts) => val beforeFailedTxs = TestFunctionalitySettings.Enabled - val afterFailedTxs = beforeFailedTxs.copy( - preActivatedFeatures = beforeFailedTxs.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0) - ) + val afterFailedTxs = beforeFailedTxs.copy(preActivatedFeatures = beforeFailedTxs.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0)) assertDiffEi(Seq(TestBlock.create(ts, Seq(genesis, lease))), TestBlock.create(ts + 1, Seq(leaseCancel)), beforeFailedTxs) { ei => ei.explicitGet() diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ReissueTransactionDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ReissueTransactionDiffTest.scala index e6d0f582431..32507d3a6a6 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ReissueTransactionDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ReissueTransactionDiffTest.scala @@ -122,14 +122,10 @@ object ReissueTransactionDiffTest { type ValidationResults = (Either[ValidationError, Unit], Either[ValidationError, Unit], Either[ValidationError, Unit]) val fs: FunctionalitySettings = - TestFunctionalitySettings.Enabled.copy( - featureCheckBlocksPeriod = 1, - blocksForFeatureActivation = 1, - preActivatedFeatures = TestFunctionalitySettings.Enabled.preActivatedFeatures ++ Seq( + TestFunctionalitySettings.Enabled.copy(featureCheckBlocksPeriod = 1, blocksForFeatureActivation = 1, preActivatedFeatures = TestFunctionalitySettings.Enabled.preActivatedFeatures ++ Seq( BlockchainFeatures.FeeSponsorship.id -> 0, BlockchainFeatures.BlockV5.id -> 3 - ) - ) + )) val BeforeActivationFee: Long = 1 * Constants.UnitsInWave val AfterActivationFee: Long = 100000 diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ScriptsCountTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ScriptsCountTest.scala index 0b94895858d..d5271660c4b 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ScriptsCountTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ScriptsCountTest.scala @@ -65,8 +65,7 @@ object ScriptsCountTest { //noinspection NameBooleanParameters class ScriptsCountTest extends PropSpec with WithState with Inside { - private val fs = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + private val fs = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map( BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.SmartAssets.id -> 0, BlockchainFeatures.SmartAccountTrading.id -> 0, @@ -75,11 +74,9 @@ class ScriptsCountTest extends PropSpec with WithState with Inside { BlockchainFeatures.MassTransfer.id -> 0, BlockchainFeatures.FeeSponsorship.id -> 0, BlockchainFeatures.Ride4DApps.id -> Int.MaxValue - ) - ) + )) - private val fs1 = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + private val fs1 = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map( BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.SmartAssets.id -> 0, BlockchainFeatures.SmartAccountTrading.id -> 0, @@ -88,8 +85,7 @@ class ScriptsCountTest extends PropSpec with WithState with Inside { BlockchainFeatures.MassTransfer.id -> 0, BlockchainFeatures.FeeSponsorship.id -> 0, BlockchainFeatures.Ride4DApps.id -> 0 - ) - ) + )) val allAllowed = ExprScript(TRUE).explicitGet() diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/SetScriptTransactionDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/SetScriptTransactionDiffTest.scala index 45785b0a089..46834cd7c3f 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/SetScriptTransactionDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/SetScriptTransactionDiffTest.scala @@ -27,9 +27,7 @@ import org.scalatest.Assertion class SetScriptTransactionDiffTest extends PropSpec with WithDomain { - private val fs = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map(BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.Ride4DApps.id -> 0) - ) + private val fs = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map(BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.Ride4DApps.id -> 0)) val preconditionsAndSetScript: Gen[(GenesisTransaction, SetScriptTransaction)] = for { master <- accountGen @@ -86,16 +84,12 @@ class SetScriptTransactionDiffTest extends PropSpec with WithDomain { property("Script with BlockV2 only works after Ride4DApps feature activation") { import com.wavesplatform.lagonaki.mocks.TestBlock.{create => block} - val settingsUnactivated = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + val settingsUnactivated = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map( BlockchainFeatures.Ride4DApps.id -> 3 - ) - ) - val settingsActivated = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + )) + val settingsActivated = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map( BlockchainFeatures.Ride4DApps.id -> 0 - ) - ) + )) val setup = for { master <- accountGen ts <- positiveLongGen @@ -201,18 +195,14 @@ class SetScriptTransactionDiffTest extends PropSpec with WithDomain { TestCompiler(V4).compileContract(script) } - val rideV3Activated = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + val rideV3Activated = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map( BlockchainFeatures.Ride4DApps.id -> 0 - ) - ) + )) - val rideV4Activated = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + val rideV4Activated = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map( BlockchainFeatures.Ride4DApps.id -> 0, BlockchainFeatures.BlockV5.id -> 0 - ) - ) + )) def assertSuccess(script: Script, settings: FunctionalitySettings): Unit = { forAll(preconditionsAndSetCustomContract(script)) { @@ -283,10 +273,7 @@ class SetScriptTransactionDiffTest extends PropSpec with WithDomain { def settings(checkNegative: Boolean = false, checkSumOverflow: Boolean = false): FunctionalitySettings = { TestFunctionalitySettings .withFeatures(BlockV5) - .copy( - estimationOverflowFixHeight = if (checkNegative) 0 else 999, - estimatorSumOverflowFixHeight = if (checkSumOverflow) 0 else 999 - ) + .copy(estimationOverflowFixHeight = if (checkNegative) 0 else 999, estimatorSumOverflowFixHeight = if (checkSumOverflow) 0 else 999) } def assert(script: Script, checkNegativeMessage: String): Assertion = { @@ -376,9 +363,7 @@ class SetScriptTransactionDiffTest extends PropSpec with WithDomain { val settings = DomainPresets.RideV5.copy(blockchainSettings = DomainPresets.RideV5.blockchainSettings.copy( - functionalitySettings = DomainPresets.RideV5.blockchainSettings.functionalitySettings.copy( - estimatorSumOverflowFixHeight = 3 - ) + functionalitySettings = DomainPresets.RideV5.blockchainSettings.functionalitySettings.copy(estimatorSumOverflowFixHeight = 3) )) withDomain(settings) { d => diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/SponsorshipDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/SponsorshipDiffTest.scala index c9b3e5b6bef..0bc298df61c 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/SponsorshipDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/SponsorshipDiffTest.scala @@ -19,14 +19,10 @@ import com.wavesplatform.utils._ class SponsorshipDiffTest extends PropSpec with WithState { def settings(sponsorshipActivationHeight: Int): FunctionalitySettings = - TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + TestFunctionalitySettings.Enabled.copy(featureCheckBlocksPeriod = 1, blocksForFeatureActivation = 1, preActivatedFeatures = Map( BlockchainFeatures.FeeSponsorship.id -> sponsorshipActivationHeight, BlockchainFeatures.BlockV5.id -> 0 - ), - featureCheckBlocksPeriod = 1, - blocksForFeatureActivation = 1 - ) + )) property("work") { val s = settings(0) diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/TransferDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/TransferDiffTest.scala index 63f954746e2..350e880255c 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/TransferDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/TransferDiffTest.scala @@ -83,13 +83,11 @@ class TransferDiffTest extends PropSpec with WithState { val rdEnabled = TestFunctionalitySettings.Stub - val rdDisabled = rdEnabled.copy( - preActivatedFeatures = Map( + val rdDisabled = rdEnabled.copy(preActivatedFeatures = Map( BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.SmartAssets.id -> 0, BlockchainFeatures.FairPoS.id -> 0 - ) - ) + )) forAll(precs) { case (genesis, issue, transfer) => diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/BigIntInvokeTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/BigIntInvokeTest.scala index a4d08d355af..eec7887476b 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/BigIntInvokeTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/BigIntInvokeTest.scala @@ -41,8 +41,7 @@ class BigIntInvokeTest private val time = new TestTime private def ts = time.getTimestamp() - private val fsWithV5 = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + private val fsWithV5 = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map( BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.SmartAssets.id -> 0, BlockchainFeatures.Ride4DApps.id -> 0, @@ -51,9 +50,7 @@ class BigIntInvokeTest BlockchainFeatures.BlockReward.id -> 0, BlockchainFeatures.BlockV5.id -> 0, BlockchainFeatures.SynchronousCalls.id -> 0 - ), - estimatorPreCheckHeight = Int.MaxValue - ) + ), estimatorPreCheckHeight = Int.MaxValue) private val bigIntValue = 12345 diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/CallableV4DiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/CallableV4DiffTest.scala index fbb1d35605a..22a53bdf98d 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/CallableV4DiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/CallableV4DiffTest.scala @@ -401,14 +401,12 @@ class CallableV4DiffTest extends PropSpec with WithDomain with EitherValues { | } """.stripMargin) - private val features = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Seq( + private val features = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Seq( BlockchainFeatures.SmartAccounts, BlockchainFeatures.SmartAssets, BlockchainFeatures.Ride4DApps, BlockchainFeatures.BlockV5 - ).map(_.id -> 0).toMap - ) + ).map(_.id -> 0).toMap) private def issuePreconditions( assetScript: Option[Script] = None, diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/DAppDataEntryTypeTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/DAppDataEntryTypeTest.scala index 3649a0b6b08..6f7ed0c9e44 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/DAppDataEntryTypeTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/DAppDataEntryTypeTest.scala @@ -37,8 +37,7 @@ class DAppDataEntryTypeTest private val time = new TestTime private def ts = time.getTimestamp() - private val fsWithV5 = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + private val fsWithV5 = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map( BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.SmartAssets.id -> 0, BlockchainFeatures.Ride4DApps.id -> 0, @@ -46,9 +45,7 @@ class DAppDataEntryTypeTest BlockchainFeatures.DataTransaction.id -> 0, BlockchainFeatures.BlockReward.id -> 0, BlockchainFeatures.BlockV5.id -> 0 - ), - estimatorPreCheckHeight = Int.MaxValue - ) + ), estimatorPreCheckHeight = Int.MaxValue) private def dApp(constructor: String): Script = { val value = if (constructor == "BooleanEntry") CONST_LONG(1) else CONST_BOOLEAN(true) diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/IllegalAddressChainIdTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/IllegalAddressChainIdTest.scala index 88523d66f60..24c2842d309 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/IllegalAddressChainIdTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/IllegalAddressChainIdTest.scala @@ -14,24 +14,28 @@ import com.wavesplatform.transaction.{GenesisTransaction, TxHelpers, TxVersion} class IllegalAddressChainIdTest extends PropSpec with WithDomain { import DomainPresets.* - private val contract = TestCompiler(V5).compileContract( + private[this] def sigVerify(c: Boolean): String = + s""" strict c = ${if (c) (1 to 5).map(_ => "sigVerify(base58'', base58'', base58'')").mkString(" || ") else "true"} """ + + private[this] def contract(bigComplexity: Boolean) = TestCompiler(V5).compileContract( s""" | @Callable(i) | func default() = { + | ${sigVerify(bigComplexity)} | let address = Address(base58'3PMj3yGPBEa1Sx9X4TSBFeJCMMaE3wvKR4N') | [ ScriptTransfer(address, 1, unit) ] | } """.stripMargin ) - private def scenario(fail: Boolean) = + private[this] def scenario(fail: Boolean, bigComplexity: Boolean = false) = for { master <- accountGen invoker <- accountGen fee <- ciFee() gTx1 = GenesisTransaction.create(master.toAddress, ENOUGH_AMT, TxHelpers.timestamp).explicitGet() gTx2 = GenesisTransaction.create(invoker.toAddress, ENOUGH_AMT, TxHelpers.timestamp).explicitGet() - ssTx = SetScriptTransaction.selfSigned(1.toByte, master, Some(contract), fee, TxHelpers.timestamp).explicitGet() + ssTx = SetScriptTransaction.selfSigned(1.toByte, master, Some(contract(bigComplexity)), fee, TxHelpers.timestamp).explicitGet() invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, None, Nil, fee, Waves, TxHelpers.timestamp) } yield (Seq(gTx1, gTx2, ssTx), invokeTx) @@ -45,12 +49,19 @@ class IllegalAddressChainIdTest extends PropSpec with WithDomain { } } - property("correct fail after fix") { + property("reject after fix") { withDomain(RideV6) { d => val (genesisTxs, invokeTx) = scenario(fail = true).sample.get d.appendBlock(genesisTxs*) - d.appendBlock(invokeTx) - d.liquidDiff.errorMessage(invokeTx.txId).get.text shouldBe error + d.appendAndCatchError(invokeTx).toString should include(error) + } + } + + property("fail after fix and big complexity") { + withDomain(RideV6) { d => + val (genesisTxs, invokeTx) = scenario(fail = true, bigComplexity = true).sample.get + d.appendBlock(genesisTxs: _*) + d.appendAndAssertFailed(invokeTx) } } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeActionsFeeTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeActionsFeeTest.scala index fd9032b7b85..18e2e7acad4 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeActionsFeeTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeActionsFeeTest.scala @@ -31,8 +31,7 @@ class InvokeActionsFeeTest extends PropSpec with Inside with WithState with DBCa private val activationHeight = 3 - private val fsWithV5 = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + private val fsWithV5 = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map( BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.SmartAssets.id -> 0, BlockchainFeatures.Ride4DApps.id -> 0, @@ -41,9 +40,7 @@ class InvokeActionsFeeTest extends PropSpec with Inside with WithState with DBCa BlockchainFeatures.BlockReward.id -> 0, BlockchainFeatures.BlockV5.id -> 0, BlockchainFeatures.SynchronousCalls.id -> activationHeight - ), - estimatorPreCheckHeight = Int.MaxValue - ) + ), estimatorPreCheckHeight = Int.MaxValue) val verifier: Script = { val script = s""" diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeAssetChecksTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeAssetChecksTest.scala index b557c0943e8..408e54b34ca 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeAssetChecksTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeAssetChecksTest.scala @@ -117,16 +117,12 @@ class InvokeAssetChecksTest extends PropSpec with Inside with WithState with DBC val fs = TestFunctionalitySettings.Enabled val features = if (activated) - TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = fs.preActivatedFeatures ++ Map( + TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = fs.preActivatedFeatures ++ Map( BlockchainFeatures.BlockV5.id -> 0, BlockchainFeatures.SynchronousCalls.id -> 0 - ) - ) + )) else - TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = fs.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0) - ) + TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = fs.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0)) assertDiffEi(Seq(TestBlock.create(genesisTxs)), TestBlock.create(Seq(invoke)), features)( _ shouldBe Right(expectedResult) @@ -168,8 +164,7 @@ class InvokeAssetChecksTest extends PropSpec with Inside with WithState with DBC """.stripMargin ) - val features = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + val features = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map( BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.SmartAssets.id -> 0, BlockchainFeatures.Ride4DApps.id -> 0, @@ -178,8 +173,7 @@ class InvokeAssetChecksTest extends PropSpec with Inside with WithState with DBC BlockchainFeatures.BlockReward.id -> 0, BlockchainFeatures.BlockV5.id -> 0, BlockchainFeatures.SynchronousCalls.id -> 0 - ) - ) + )) val preconditions = for { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeDataEntriesBytesTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeDataEntriesBytesTest.scala index 8a80c1ed22c..6a89418a7bd 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeDataEntriesBytesTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeDataEntriesBytesTest.scala @@ -5,18 +5,16 @@ import com.wavesplatform.account.Address import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.WithDomain -import com.wavesplatform.features.BlockchainFeatures.* import com.wavesplatform.lang.directives.values.V5 import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.v1.ContractLimits import com.wavesplatform.lang.v1.compiler.TestCompiler -import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.test.* +import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.utils.Signed -import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} class InvokeDataEntriesBytesTest extends PropSpec with WithDomain with TransactionGenBase { private val time = new TestTime @@ -90,13 +88,8 @@ class InvokeDataEntriesBytesTest extends PropSpec with WithDomain with Transacti invokeTx = () => Signed.invokeScript(TxVersion.V3, invoker, dApp1.toAddress, None, Nil, fee, Waves, ts) } yield (Seq(gTx1, gTx2, gTx3, gTx4, gTx5, ssTx1, ssTx2, ssTx3, ssTx4), invokeTx) - private val settings = - TestFunctionalitySettings - .withFeatures(BlockV5, SynchronousCalls) - .copy(checkTotalDataEntriesBytesHeight = 3, syncDAppCheckTransfersHeight = 4) - - property("exceeding 5 Kb before and after activation") { - withDomain(domainSettingsWithFS(settings)) { d => + property("exceeding 5 Kb after activation") { + withDomain(DomainPresets.RideV5) { d => val (preparingTxs, invoke) = scenario(exceed5Kb = true, sync = true).sample.get d.appendBlock(preparingTxs *) @@ -104,58 +97,44 @@ class InvokeDataEntriesBytesTest extends PropSpec with WithDomain with Transacti (the[RuntimeException] thrownBy d.appendBlock(invoke1)).getMessage should include( s"WriteSet size can't exceed 5120 bytes, actual: 5121 bytes" ) - - d.appendBlock() - d.appendBlock() - val invoke2 = invoke() - (the[RuntimeException] thrownBy d.appendBlock(invoke2)).getMessage should include( - s"WriteSet size can't exceed 5120 bytes, actual: 5121 bytes" - ) } } - property("exceeding 15 Kb before activation, after checkTotalDataEntriesBytesHeight and after syncDAppCheckTransfersHeight") { - withDomain(domainSettingsWithFS(settings)) { d => + property("exceeding 15 Kb after activation") { + withDomain(DomainPresets.RideV5) { d => val (preparingTxs, invoke) = scenario(exceed5Kb = false, sync = true).sample.get d.appendBlock(preparingTxs *) val invoke1 = invoke() - d.appendBlock(invoke1) - d.blockchain.transactionSucceeded(invoke1.id.value()) shouldBe true + d.appendAndAssertFailed(invoke1) + } + } - val invoke2 = invoke() - d.appendBlock(invoke2) - d.blockchain.bestLiquidDiff.get.errorMessage(invoke2.id.value()).get.text should include( - "Storing data size should not exceed 15360, actual: 20476 bytes" - ) + property("exceeding 15 Kb with RideV6") { + withDomain(DomainPresets.RideV6) { d => + val (preparingTxs, invoke) = scenario(exceed5Kb = false, sync = true).sample.get + d.appendBlock(preparingTxs *) - val invoke3 = invoke() - (the[Exception] thrownBy d.appendBlock(invoke3)).getMessage should include( - "Storing data size should not exceed 15360, actual: 20476 bytes" - ) + val invoke1 = invoke() + d.appendAndCatchError(invoke1).toString should include("Storing data size should not exceed 15360") } } - property("reaching 5 Kb before and after activation") { - withDomain(domainSettingsWithFS(settings)) { d => + property("reaching 5 Kb after activation") { + withDomain(DomainPresets.RideV5) { d => val (preparingTxs, invoke) = scenario(exceed5Kb = false, sync = false).sample.get d.appendBlock(preparingTxs *) val invoke1 = invoke() d.appendBlock(invoke1) d.blockchain.transactionSucceeded(invoke1.id.value()) shouldBe true - - val invoke2 = invoke() - d.appendBlock(invoke2) - d.blockchain.transactionSucceeded(invoke2.id.value()) shouldBe true } } property("reaching 15 Kb after activation") { - withDomain(domainSettingsWithFS(settings)) { d => + withDomain(DomainPresets.RideV5) { d => val (preparingTxs, invoke) = scenario(exceed5Kb = false, sync = true, reach15kb = true).sample.get d.appendBlock(preparingTxs *) - d.appendBlock() val invoke1 = invoke() d.appendBlock(invoke1) diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeFeeMultiplierTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeFeeMultiplierTest.scala index 4e3be3e15fe..29638723047 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeFeeMultiplierTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeFeeMultiplierTest.scala @@ -30,8 +30,7 @@ class InvokeFeeMultiplierTest extends PropSpec with WithState with DBCacheSettin private val estimatorV3ActivationHeight = 3 private val fixActivationHeight = 5 - private val fsWithV5 = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + private val fsWithV5 = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map( BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.SmartAssets.id -> 0, BlockchainFeatures.Ride4DApps.id -> 0, @@ -40,9 +39,7 @@ class InvokeFeeMultiplierTest extends PropSpec with WithState with DBCacheSettin BlockchainFeatures.BlockReward.id -> 0, BlockchainFeatures.BlockV5.id -> estimatorV3ActivationHeight, BlockchainFeatures.SynchronousCalls.id -> fixActivationHeight - ), - estimatorPreCheckHeight = Int.MaxValue - ) + ), estimatorPreCheckHeight = Int.MaxValue) private val lambordini: Script = { val base64 = diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeScriptTransactionDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeScriptTransactionDiffTest.scala index eb00d54348b..bef385ad246 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeScriptTransactionDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeScriptTransactionDiffTest.scala @@ -51,10 +51,11 @@ import org.scalacheck.{Arbitrary, Gen} import org.scalamock.scalatest.MockFactory import org.scalatest.{EitherValues, Inside} +//noinspection RedundantDefaultArgument class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCacheSettings with EitherValues with Inside with MockFactory { import DomainPresets._ - private val fs = settingsForRide(V3).blockchainSettings.functionalitySettings + private val fs = settingsForRide(V3).blockchainSettings.functionalitySettings private val fsWithV5 = settingsForRide(V5).blockchainSettings.functionalitySettings val assetAllowed: Script = ExprScript( @@ -279,7 +280,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa Monoid .combineAll( Seq( - PureContext.build(stdLibVersion, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(stdLibVersion, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(Global, stdLibVersion).withEnvironment[Environment], WavesContext.build( Global, @@ -318,22 +319,23 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa List.fill(invocationParamsCount)(FALSE) ) ci = Signed.invokeScript( - 1.toByte, - invoker, - master.toAddress, - Some(fc), - payment.toSeq, - if (sponsored) { - sponsorTx.minSponsoredAssetFee.get * 5 - } else { - fee - }, - if (sponsored) { - IssuedAsset(issueTx.id()) - } else { - Waves - }, - ts) + 1.toByte, + invoker, + master.toAddress, + Some(fc), + payment.toSeq, + if (sponsored) { + sponsorTx.minSponsoredAssetFee.get * 5 + } else { + fee + }, + if (sponsored) { + IssuedAsset(issueTx.id()) + } else { + Waves + }, + ts + ) } yield (List(genesis, genesis2), setContract, ci, master, issueTx, sponsorTx) } @@ -386,14 +388,15 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa else None ci = Signed.invokeScript( - txVersion, - invoker, - master.toAddress, - fc, - payment.toSeq, - if (sponsored) sponsoredFee else fee, - if (sponsored) sponsorTx.asset else Waves, - ts + 3) + txVersion, + invoker, + master.toAddress, + fc, + payment.toSeq, + if (sponsored) sponsoredFee else fee, + if (sponsored) sponsorTx.asset else Waves, + ts + 3 + ) } yield (if (selfSend) List(genesis) else List(genesis, genesis2), setContract, ci, master, issueTx, sponsorTx) def preconditionsAndSetContractWithVerifier( @@ -427,22 +430,23 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa else None ci = Signed.invokeScript( - 1.toByte, - invoker, - master.toAddress, - fc, - payment.toSeq, - if (sponsored) { - sponsorTx.minSponsoredAssetFee.get * 5 - } else { - fee - }, - if (sponsored) { - IssuedAsset(issueTx.id()) - } else { - Waves - }, - ts + 3) + 1.toByte, + invoker, + master.toAddress, + fc, + payment.toSeq, + if (sponsored) { + sponsorTx.minSponsoredAssetFee.get * 5 + } else { + fee + }, + if (sponsored) { + IssuedAsset(issueTx.id()) + } else { + Waves + }, + ts + 3 + ) } yield (List(genesis, genesis2), setVerifier, setContract, ci, master, issueTx, sponsorTx) def preconditionsAndSetContractWithAlias( @@ -475,41 +479,159 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa else None ciWithAlias = Signed.invokeScript( - 1.toByte, - invoker, - masterAlias, - fc, - payment.toSeq, - if (sponsored) { - sponsorTx.minSponsoredAssetFee.get * 5 - } else { - fee - }, - if (sponsored) { - IssuedAsset(issueTx.id()) - } else { - Waves - }, - ts + 3) + 1.toByte, + invoker, + masterAlias, + fc, + payment.toSeq, + if (sponsored) { + sponsorTx.minSponsoredAssetFee.get * 5 + } else { + fee + }, + if (sponsored) { + IssuedAsset(issueTx.id()) + } else { + Waves + }, + ts + 3 + ) ciWithFakeAlias = Signed.invokeScript( - 1.toByte, - invoker, - fakeAlias, - fc, - payment.toSeq, - if (sponsored) { - sponsorTx.minSponsoredAssetFee.get * 5 - } else { - fee - }, - if (sponsored) { - IssuedAsset(issueTx.id()) - } else { - Waves - }, - ts + 3) + 1.toByte, + invoker, + fakeAlias, + fc, + payment.toSeq, + if (sponsored) { + sponsorTx.minSponsoredAssetFee.get * 5 + } else { + fee + }, + if (sponsored) { + IssuedAsset(issueTx.id()) + } else { + Waves + }, + ts + 3 + ) } yield (List(genesis, genesis2), master, setContract, ciWithAlias, ciWithFakeAlias, aliasTx) + property("doesnt validate intermediate action balance before V6")(withDomain(DomainPresets.RideV5) { d => + val dApp = TxHelpers.defaultSigner + + d.helpers.creditWavesToDefaultSigner() + val asset = d.helpers.issueAsset() + d.helpers.transferAll(dApp, TxHelpers.voidAddress, asset) + d.helpers.setScript( + dApp, + TxHelpers.script(s""" + |{-# STDLIB_VERSION 4 #-} + |{-# CONTENT_TYPE DAPP #-} + | + |@Callable(i) + |func test(asset: ByteVector) = { + | [ + | ScriptTransfer(Address(base58'${TxHelpers.secondAddress}'), 100, asset), + | Reissue(asset, 100, true) + | ] + |} + |""".stripMargin) + ) + + val invoke = TxHelpers.invoke(dApp.toAddress, "test", Seq(CONST_BYTESTR(asset.id).explicitGet())) + d.appendAndAssertSucceed(invoke) + d.blockchain.balance(dApp.toAddress, asset) shouldBe 0L + d.blockchain.balance(TxHelpers.secondAddress, asset) shouldBe 100L + }) + + property("validates intermediate action balance after V6")(withDomain(DomainPresets.RideV6) { d => + val dApp = TxHelpers.defaultSigner + + d.helpers.creditWavesToDefaultSigner() + val asset = d.helpers.issueAsset() + d.helpers.transferAll(dApp, TxHelpers.voidAddress, asset) + + withClue("simple script") { + d.helpers.setScript( + dApp, + TxHelpers.scriptV5(s""" + |@Callable(i) + |func test(asset: ByteVector) = { + | [ + | ScriptTransfer(Address(base58'${TxHelpers.secondAddress}'), 100, asset), + | Reissue(asset, 100, true) + | ] + |} + |""".stripMargin) + ) + + val invoke = TxHelpers.invoke(dApp.toAddress, "test", Seq(CONST_BYTESTR(asset.id).explicitGet())) + d.appendAndCatchError(invoke).toString should include("negative asset balance") + d.blockchain.balance(dApp.toAddress, asset) shouldBe 0L + d.blockchain.balance(TxHelpers.secondAddress, asset) shouldBe 0L + } + + withClue("complex script") { + d.helpers.setScript( + dApp, + TxHelpers.scriptV5(s""" + |@Callable(i) + |func test(asset: ByteVector) = { + | strict test1 = ${"sigVerify(base58'', base58'', base58'') ||" * 16} true + | [ + | ScriptTransfer(Address(base58'${TxHelpers.secondAddress}'), 100, asset), + | Reissue(asset, 100, true) + | ] + |} + |""".stripMargin) + ) + + val invoke = TxHelpers.invoke(dApp.toAddress, "test", Seq(CONST_BYTESTR(asset.id).explicitGet())) + d.appendAndAssertFailed(invoke) + d.blockchain.balance(dApp.toAddress, asset) shouldBe 0L + d.blockchain.balance(TxHelpers.secondAddress, asset) shouldBe 0L + } + }) + + property("nested script failure") { + val firstDApp = TxHelpers.defaultSigner + val secondDApp = TxHelpers.secondSigner + + val firstScript = + s""" + |@Callable(i) + |func test() = { + | strict r = invoke(Address(base58'${secondDApp.toAddress}'), "test", [], []) + | ([], r) + |} + |""".stripMargin + val secondScript = + """ + |@Callable(i) + |func test() = throw("test error") + |""".stripMargin + + withClue("before V6")(withDomain(DomainPresets.RideV5) { d => + d.helpers.creditWavesToDefaultSigner() + d.helpers.creditWavesFromDefaultSigner(secondDApp.toAddress) + d.helpers.setScript(firstDApp, TxHelpers.scriptV5(firstScript)) + d.helpers.setScript(secondDApp, TxHelpers.scriptV5(secondScript)) + + val invoke = TxHelpers.invoke(firstDApp.toAddress, "test") + d.appendAndCatchError(invoke).toString should include("test error") + }) + + withClue("after V6")(withDomain(DomainPresets.RideV6) { d => + d.helpers.creditWavesToDefaultSigner() + d.helpers.creditWavesFromDefaultSigner(secondDApp.toAddress) + d.helpers.setScript(firstDApp, TxHelpers.scriptV5(firstScript)) + d.helpers.setScript(secondDApp, TxHelpers.scriptV5(secondScript)) + + val invoke = TxHelpers.invoke(firstDApp.toAddress, "test") + d.appendAndCatchError(invoke).toString should include("test error") + }) + } + property("invoking contract results contract's state") { forAll(for { r <- preconditionsAndSetContract(s => dataContractGen(s, bigData = false)) @@ -1108,7 +1230,18 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa funcBinding <- validAliasStringGen fee <- ciFee(1) fc = Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List(CONST_BYTESTR(ByteStr(arg)).explicitGet())) - ci = InvokeScriptTransaction.create(1.toByte, invoker.publicKey, master.toAddress, Some(fc), Seq(Payment(-1, Waves)), fee, Waves, ts, Proofs.empty, AddressScheme.current.chainId) + ci = InvokeScriptTransaction.create( + 1.toByte, + invoker.publicKey, + master.toAddress, + Some(fc), + Seq(Payment(-1, Waves)), + fee, + Waves, + ts, + Proofs.empty, + AddressScheme.current.chainId + ) } yield ci) { _ should produceRejectOrFailedDiff("NonPositiveAmount") } } @@ -1510,9 +1643,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa r <- preconditionsAndSetContract(contractGen, masterGen = Gen.oneOf(Seq(master)), feeGen = ciFee(1)) } yield (a, am, r._1, r._2, r._3, asset, master)) { case (acc, amount, genesis, setScript, ci, asset, master) => - val features = fs.copy( - preActivatedFeatures = fs.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0) - ) + val features = fs.copy(preActivatedFeatures = fs.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0)) assertDiffAndState(Seq(TestBlock.create(genesis ++ Seq(setScript))), TestBlock.create(Seq(asset, ci), Block.ProtoBlockVersion), features) { case (blockDiff, newState) => blockDiff.scriptsRun shouldBe 3 @@ -1573,7 +1704,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa contract = issueContract(funcBinding) script = ContractScript(V4, contract) - fc = Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List.empty) + fc = Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List.empty) invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 3) } yield (assetTx, invokeTx, master, script, funcBinding) @@ -1662,16 +1793,14 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa script = ContractScript(V4, contract) setScriptTx = SetScriptTransaction.selfSigned(1.toByte, master, script.toOption, fee, ts + 2).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List.empty) - invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 3) + invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 3) } yield (invokeTx, Seq(genesis1Tx, genesis2Tx, assetTx, setScriptTx)) property("Reissuing unreissued asset should produce error") { forAll(reissueAssetIdScenario) { case (invoke, genesisTxs) => tempDb { _ => - val features = fs.copy( - preActivatedFeatures = fs.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0) - ) + val features = fs.copy(preActivatedFeatures = fs.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0)) assertDiffEi(Seq(TestBlock.create(genesisTxs)), TestBlock.create(Seq(invoke), Block.ProtoBlockVersion), features) { ei => ei should produceRejectOrFailedDiff("Asset is not reissuable") @@ -1713,16 +1842,14 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa script = ContractScript(V4, contract) setScriptTx = SetScriptTransaction.selfSigned(1.toByte, master, script.toOption, fee, ts + 2).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List.empty) - invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 3) + invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 3) } yield (invokeTx, Seq(genesis1Tx, genesis2Tx, setScriptTx)) property("issued asset can be transfered") { forAll(transferAssetIdScenario) { case (invoke, genesisTxs) => tempDb { _ => - val features = fs.copy( - preActivatedFeatures = fs.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0) - ) + val features = fs.copy(preActivatedFeatures = fs.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0)) assertDiffEi(Seq(TestBlock.create(genesisTxs)), TestBlock.create(Seq(invoke), Block.ProtoBlockVersion), features) { ei => ei.explicitGet() @@ -1764,16 +1891,14 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa script = ContractScript(V4, contract) setScriptTx = SetScriptTransaction.selfSigned(1.toByte, master, script.toOption, fee, ts + 2).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List.empty) - invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 3) + invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 3) } yield (invokeTx, Seq(genesis1Tx, genesis2Tx, setScriptTx)) property("nonissued asset cann't be transfered") { forAll(transferNonAssetIdScenario) { case (invoke, genesisTxs) => tempDb { _ => - val features = fs.copy( - preActivatedFeatures = fs.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0) - ) + val features = fs.copy(preActivatedFeatures = fs.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0)) assertDiffEi(Seq(TestBlock.create(genesisTxs)), TestBlock.create(Seq(invoke), Block.ProtoBlockVersion), features) { ei => ei should produceRejectOrFailedDiff("negative asset balance") @@ -1815,17 +1940,14 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa script = ContractScript(V4, contract) setScriptTx = SetScriptTransaction.selfSigned(1.toByte, master, script.toOption, fee, ts + 2).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List.empty) - invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 3) + invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, Waves, ts + 3) } yield (invokeTx, Seq(genesis1Tx, genesis2Tx, setScriptTx)) property("duplicate issuing asset should produce diff error") { forAll(doubleAssetIdScenario) { case (invoke, genesisTxs) => tempDb { _ => - val features = fs.copy( - preActivatedFeatures = fs.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0), - syncDAppCheckTransfersHeight = 999 - ) + val features = fs.copy(preActivatedFeatures = fs.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0)) assertDiffEi(Seq(TestBlock.create(genesisTxs)), TestBlock.create(Seq(invoke), Block.ProtoBlockVersion), features) { ei => inside(ei) { case Right(diff) => diff.scriptResults(invoke.id()).error.get.text should include("is already issued") @@ -1888,9 +2010,9 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa .explicitGet() funcBinding <- funcNameGen (fee, feeAsset, contract, args) <- failInvariant(funcBinding, sTx, i2Tx) - script = ContractScript(V4, contract) - ssTx = SetScriptTransaction.selfSigned(1.toByte, master, script.toOption, fee, ts + 2).explicitGet() - fc = Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), args) + script = ContractScript(V4, contract) + ssTx = SetScriptTransaction.selfSigned(1.toByte, master, script.toOption, fee, ts + 2).explicitGet() + fc = Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), args) invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, feeAsset, ts + 3) } yield (invokeTx, (ENOUGH_AMT - enoughFee, i1Tx.quantity), Seq(g1Tx, g2Tx, g3Tx, i1Tx, i2Tx, sTx, tTx, ssTx)) @@ -1928,9 +2050,9 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa funcBinding <- funcNameGen arg <- genBoundedStringBytes(1, 32) contract <- paymentContractGen(invoker.toAddress, fee, List(feeAsset), V4)(funcBinding) - script = ContractScript(V4, contract) - ssTx = SetScriptTransaction.selfSigned(1.toByte, master, script.toOption, fee, ts + 2).explicitGet() - fc = Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List(CONST_BYTESTR(ByteStr(arg)).explicitGet())) + script = ContractScript(V4, contract) + ssTx = SetScriptTransaction.selfSigned(1.toByte, master, script.toOption, fee, ts + 2).explicitGet() + fc = Terms.FUNCTION_CALL(FunctionHeader.User(funcBinding), List(CONST_BYTESTR(ByteStr(arg)).explicitGet())) invokeTx = Signed.invokeScript(TxVersion.V2, invoker, master.toAddress, Some(fc), Seq(), fee, feeAsset, ts + 3) } yield (invokeTx, Seq(g1Tx, g2Tx, iTx, sTx, tTx, ssTx)) @@ -2094,7 +2216,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa ssTx = SetScriptTransaction.selfSigned(1.toByte, master, script.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = iTxs.takeRight(2).map(tx => Payment(10, IssuedAsset(tx.assetId))) - invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield (Seq(gTx1, gTx2) ++ invokerScriptTx ++ iTxs ++ tTxs ++ saTxs :+ ssTx, invokeTx, master.toAddress, complexity) forAll(scenario) { @@ -2502,7 +2624,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa diff.scriptResults(invokeTx.id()).error shouldBe None val l = diff.scriptResults(invokeTx.id()).leases(0) val l1 = diff.scriptResults(invokeTx.id()).leases(1) - val l2 = diff.scriptResults(invokeTx.id()).leaseCancels(0) + val l2 = diff.scriptResults(invokeTx.id()).leaseCancels(0) l.amount shouldBe 13 l.recipient shouldBe service l1.amount shouldBe 23 @@ -3636,7 +3758,7 @@ class InvokeScriptTransactionDiffTest extends PropSpec with WithDomain with DBCa setServiceDApp = SetScriptTransaction.selfSigned(1.toByte, serviceDAppAcc, serviceDAppScript.toOption, fee, ts + 5).explicitGet() fc = Terms.FUNCTION_CALL(FunctionHeader.User("foo"), List.empty) payments = List(Payment(paymentFromInvokerAmount, Waves)) - invokeTx = Signed.invokeScript(TxVersion.V3, invoker, clientDAppAcc.toAddress, Some(fc), payments, fee, Waves, ts + 6) + invokeTx = Signed.invokeScript(TxVersion.V3, invoker, clientDAppAcc.toAddress, Some(fc), payments, fee, Waves, ts + 6) } yield ( Seq(gTx1, gTx2, gTx3, setServiceDApp, setClientDApp, paymentIssue, transferIssue), invokeTx, diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeScriptV5LimitsTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeScriptV5LimitsTest.scala index 85f56187d7e..a84636da82e 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeScriptV5LimitsTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeScriptV5LimitsTest.scala @@ -44,8 +44,7 @@ import org.scalatest.EitherValues class InvokeScriptV5LimitsTest extends PropSpec with WithState with DBCacheSettings with MockFactory with EitherValues { - private val fsWithV5 = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + private val fsWithV5 = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map( BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.SmartAssets.id -> 0, BlockchainFeatures.Ride4DApps.id -> 0, @@ -53,8 +52,7 @@ class InvokeScriptV5LimitsTest extends PropSpec with WithState with DBCacheSetti BlockchainFeatures.DataTransaction.id -> 0, BlockchainFeatures.BlockV5.id -> 0, BlockchainFeatures.SynchronousCalls.id -> 0 - ) - ) + )) val assetAllowed: Script = ExprScript( FUNCTION_CALL(FunctionHeader.Native(FunctionIds.GT_LONG), List(GETTER(REF("tx"), "fee"), CONST_LONG(-1))) @@ -278,7 +276,7 @@ class InvokeScriptV5LimitsTest extends PropSpec with WithState with DBCacheSetti Monoid .combineAll( Seq( - PureContext.build(stdLibVersion, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(stdLibVersion, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(Global, stdLibVersion).withEnvironment[Environment], WavesContext.build( Global, diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/LeaseActionDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/LeaseActionDiffTest.scala index bc9f11861f1..5d2f49907cf 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/LeaseActionDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/LeaseActionDiffTest.scala @@ -40,7 +40,7 @@ class LeaseActionDiffTest extends PropSpec with WithDomain { BlockchainFeatures.Ride4DApps, BlockchainFeatures.BlockV5 ) ++ v5ForkO - TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = parameters.map(_.id -> 0).toMap, syncDAppCheckTransfersHeight = 999) + TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = parameters.map(_.id -> 0).toMap) } private val v4Features = features(activateV5 = false) @@ -588,7 +588,7 @@ class LeaseActionDiffTest extends PropSpec with WithDomain { v5Features ) { case (diff, _) => - diff.errorMessage(invoke.id()).get.text shouldBe "NonPositiveAmount(-100,waves)" + diff.errorMessage(invoke.id()).get.text should include("Negative lease amount") } } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/MultiPaymentInvokeDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/MultiPaymentInvokeDiffTest.scala index 28ab3117811..a73be84ca88 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/MultiPaymentInvokeDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/MultiPaymentInvokeDiffTest.scala @@ -334,12 +334,10 @@ class MultiPaymentInvokeDiffTest extends PropSpec with WithState { Gen.const(verifier(version, Account)) } yield verifier - private val features = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Seq( + private val features = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Seq( BlockchainFeatures.SmartAccounts, BlockchainFeatures.SmartAssets, BlockchainFeatures.Ride4DApps, BlockchainFeatures.BlockV5 - ).map(_.id -> 0).toMap - ) + ).map(_.id -> 0).toMap) } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeBurnTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeBurnTest.scala index b31b7cb97ee..9ceeac37f01 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeBurnTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeBurnTest.scala @@ -52,8 +52,7 @@ class NegativeBurnTest extends PropSpec with WithDomain with TransactionGenBase private val settings = TestFunctionalitySettings - .withFeatures(BlockV5, SynchronousCalls) - .copy(syncDAppCheckTransfersHeight = 3) + .withFeatures(BlockV5, SynchronousCalls, RideV6) property("negative burn quantity") { for (bigComplexity <- Seq(false, true)) { @@ -62,12 +61,11 @@ class NegativeBurnTest extends PropSpec with WithDomain with TransactionGenBase d.appendBlock(preparingTxs: _*) val invoke1 = invoke() - d.appendBlock(invoke1) - d.blockchain.transactionSucceeded(invoke1.txId) shouldBe true - d.blockchain.balance(dApp, asset) shouldBe 101 - - val invoke2 = invoke() - (the[Exception] thrownBy d.appendBlock(invoke2)).getMessage should include("Negative burn quantity = -1") + if (!bigComplexity) { + d.appendAndCatchError(invoke1).toString should include("Negative burn quantity") + } else { + d.appendAndAssertFailed(invoke1) + } } } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeLeaseTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeLeaseTest.scala index 343e22efd8d..a396e2fe114 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeLeaseTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeLeaseTest.scala @@ -52,8 +52,7 @@ class NegativeLeaseTest extends PropSpec with WithDomain with TransactionGenBase private val settings = TestFunctionalitySettings - .withFeatures(BlockV5, SynchronousCalls) - .copy(syncDAppCheckTransfersHeight = 3) + .withFeatures(BlockV5, SynchronousCalls, RideV6) property("negative lease amount") { for (bigComplexity <- Seq(false, true)) { @@ -62,11 +61,11 @@ class NegativeLeaseTest extends PropSpec with WithDomain with TransactionGenBase d.appendBlock(preparingTxs: _*) val invoke1 = invoke() - d.appendBlock(invoke1) - d.blockchain.bestLiquidDiff.get.errorMessage(invoke1.txId).get.text shouldBe "NonPositiveAmount(-1,waves)" - - val invoke2 = invoke() - (the[Exception] thrownBy d.appendBlock(invoke2)).getMessage should include("Negative lease amount = -1") + if (!bigComplexity) { + d.appendAndCatchError(invoke1).toString should include("Negative lease amount") + } else { + d.appendAndAssertFailed(invoke1) + } } } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeReissueTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeReissueTest.scala index e56f8ba7152..bcbe210304a 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeReissueTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeReissueTest.scala @@ -52,8 +52,7 @@ class NegativeReissueTest extends PropSpec with WithDomain with TransactionGenBa private val settings = TestFunctionalitySettings - .withFeatures(BlockV5, SynchronousCalls) - .copy(syncDAppCheckTransfersHeight = 3) + .withFeatures(BlockV5, SynchronousCalls, RideV6) property("negative reissue quantity") { for(bigComplexity <- Seq(false, true)) { @@ -62,12 +61,11 @@ class NegativeReissueTest extends PropSpec with WithDomain with TransactionGenBa d.appendBlock(preparingTxs: _*) val invoke1 = invoke() - d.appendBlock(invoke1) - d.blockchain.transactionSucceeded(invoke1.txId) shouldBe true - d.blockchain.balance(dApp, asset) shouldBe 99 - - val invoke2 = invoke() - (the[Exception] thrownBy d.appendBlock(invoke2)).getMessage should include ("Negative reissue quantity = -1") + if (!bigComplexity) { + d.appendAndCatchError(invoke1).toString should include("Negative reissue quantity") + } else { + d.appendAndAssertFailed(invoke1) + } } } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeSponsorFeeTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeSponsorFeeTest.scala index 20ef762e939..c575f4ad9d0 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeSponsorFeeTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeSponsorFeeTest.scala @@ -52,8 +52,7 @@ class NegativeSponsorFeeTest extends PropSpec with WithDomain with TransactionGe private val settings = TestFunctionalitySettings - .withFeatures(BlockV5, SynchronousCalls) - .copy(syncDAppCheckTransfersHeight = 3) + .withFeatures(BlockV5, SynchronousCalls, RideV6) property("negative sponsor amount") { for(bigComplexity <- Seq(false, true)) { @@ -62,11 +61,11 @@ class NegativeSponsorFeeTest extends PropSpec with WithDomain with TransactionGe d.appendBlock(preparingTxs: _*) val invoke1 = invoke() - d.appendBlock(invoke1) - d.blockchain.bestLiquidDiff.get.errorMessage(invoke1.txId).get.text shouldBe "NegativeMinFee(-1,asset)" - - val invoke2 = invoke() - (the[Exception] thrownBy d.appendBlock(invoke2)).getMessage should include ("Negative sponsor amount = -1") + if (!bigComplexity) { + d.appendAndCatchError(invoke1).toString should include("Negative sponsor amount") + } else { + d.appendAndAssertFailed(invoke1) + } } } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeTransferAmountTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeTransferAmountTest.scala index 2e7044fb417..f0d9dccf5ac 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeTransferAmountTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/NegativeTransferAmountTest.scala @@ -52,8 +52,7 @@ class NegativeTransferAmountTest extends PropSpec with WithDomain with Transacti private val settings = TestFunctionalitySettings - .withFeatures(BlockV5, SynchronousCalls) - .copy(syncDAppCheckTransfersHeight = 3) + .withFeatures(BlockV5, SynchronousCalls, RideV6) property("negative transfer amount") { for (bigComplexity <- Seq(false, true)) { @@ -62,11 +61,11 @@ class NegativeTransferAmountTest extends PropSpec with WithDomain with Transacti d.appendBlock(preparingTxs: _*) val invoke1 = invoke() - d.appendBlock(invoke1) - d.blockchain.bestLiquidDiff.get.errorMessage(invoke1.txId).get.text shouldBe "Negative amount" - - val invoke2 = invoke() - (the[Exception] thrownBy d.appendBlock(invoke2)).getMessage should include("Negative transfer amount = -1") + if (!bigComplexity) { + d.appendAndCatchError(invoke1).toString should include("Negative transfer amount") + } else { + d.appendAndAssertFailed(invoke1) + } } } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/ScriptTransferByAliasTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/ScriptTransferByAliasTest.scala index 912ab6fe86c..a3b0933c3f3 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/ScriptTransferByAliasTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/ScriptTransferByAliasTest.scala @@ -24,8 +24,7 @@ class ScriptTransferByAliasTest extends PropSpec with WithDomain { private val activationHeight = 3 - private val fsWithV5 = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + private val fsWithV5 = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map( BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.SmartAssets.id -> 0, BlockchainFeatures.Ride4DApps.id -> 0, @@ -34,9 +33,7 @@ class ScriptTransferByAliasTest extends PropSpec with WithDomain { BlockchainFeatures.BlockReward.id -> 0, BlockchainFeatures.BlockV5.id -> 0, BlockchainFeatures.SynchronousCalls.id -> activationHeight - ), - estimatorPreCheckHeight = Int.MaxValue - ) + ), estimatorPreCheckHeight = Int.MaxValue) private val verifier: Script = TestCompiler(V4).compileExpression( diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/InvokeScriptTransactionCrosscontractInvokeDiffTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/InvokeScriptTransactionCrosscontractInvokeDiffTest.scala index 68494dafe28..d24f3a3174a 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/InvokeScriptTransactionCrosscontractInvokeDiffTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/InvokeScriptTransactionCrosscontractInvokeDiffTest.scala @@ -32,8 +32,7 @@ class InvokeScriptTransactionCrosscontractInvokeDiffTest with DBCacheSettings with EitherValues { - private val fsWithV5 = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + private val fsWithV5 = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map( BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.SmartAssets.id -> 0, BlockchainFeatures.Ride4DApps.id -> 0, @@ -41,8 +40,7 @@ class InvokeScriptTransactionCrosscontractInvokeDiffTest BlockchainFeatures.DataTransaction.id -> 0, BlockchainFeatures.BlockV5.id -> 0, BlockchainFeatures.SynchronousCalls.id -> 0 - ) - ) + )) property("Crosscontract call - internal invoke state update") { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppBalanceCheckTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppBalanceCheckTest.scala index b2e8f2fcd8c..1b494ed8231 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppBalanceCheckTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppBalanceCheckTest.scala @@ -12,13 +12,11 @@ import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.ci.ciFee import com.wavesplatform.test._ +import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.utils.Signed -import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} -import org.scalatest.Ignore -@Ignore class SyncDAppBalanceCheckTest extends PropSpec with WithDomain with TransactionGenBase { private val time = new TestTime @@ -60,25 +58,17 @@ class SyncDAppBalanceCheckTest extends PropSpec with WithDomain with Transaction invokeTx = () => Signed.invokeScript(TxVersion.V3, invoker, dApp1.toAddress, None, Nil, fee, Waves, ts) } yield (Seq(gTx1, gTx2, gTx3, ssTx1, ssTx2), invokeTx) - property("temporary negative balance of sync call produce error only after set height") { + property("temporary negative balance of sync call produces error") { val (preparingTxs, invoke) = scenario.sample.get val settings = TestFunctionalitySettings .withFeatures(BlockV5, SynchronousCalls) - .copy(syncDAppCheckPaymentsHeight = 4) withDomain(domainSettingsWithFS(settings)) { d => d.appendBlock(preparingTxs*) val invoke1 = invoke() - d.appendBlock(invoke1) - d.blockchain.transactionSucceeded(invoke1.id.value()) shouldBe true - - val invoke2 = invoke() - d.appendBlock() - (the[RuntimeException] thrownBy d.appendBlock(invoke2)).getMessage should include( - s"Sync call leads to temporary negative balance = -100 for address ${invoke2.dApp}" - ) + d.appendAndCatchError(invoke1).toString should include("negative waves balance") } } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppBurnBalanceCheckTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppBurnBalanceCheckTest.scala index a63b08de413..653577e596a 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppBurnBalanceCheckTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppBurnBalanceCheckTest.scala @@ -13,15 +13,13 @@ import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.ci.ciFee import com.wavesplatform.test._ +import com.wavesplatform.transaction.{Asset, GenesisTransaction, TxVersion} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.IssueTransaction import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.transfer.TransferTransaction import com.wavesplatform.transaction.utils.Signed -import com.wavesplatform.transaction.{Asset, GenesisTransaction, TxVersion} -import org.scalatest.Ignore -@Ignore class SyncDAppBurnBalanceCheckTest extends PropSpec with WithDomain with TransactionGenBase { private val time = new TestTime @@ -77,27 +75,23 @@ class SyncDAppBurnBalanceCheckTest extends PropSpec with WithDomain with Transac private val settings = TestFunctionalitySettings .withFeatures(BlockV5, SynchronousCalls) - .copy(syncDAppCheckTransfersHeight = 4) - property("negative balance always rejects tx after syncDAppCheckTransfersHeight") { + property("negative balance rejects or fails tx") { for { bigComplexityDApp1 <- Seq(false, true) bigComplexityDApp2 <- Seq(false, true) } { - val (preparingTxs, invoke, dApp2Address, asset) = scenario(bigComplexityDApp1, bigComplexityDApp2).sample.get + val (preparingTxs, invoke, _, _) = scenario(bigComplexityDApp1, bigComplexityDApp2).sample.get withDomain(domainSettingsWithFS(settings)) { d => d.appendBlock(preparingTxs: _*) val invoke1 = invoke() - d.appendBlock(invoke1) - d.blockchain.transactionSucceeded(invoke1.id.value()) shouldBe true - - val invoke2 = invoke() - d.appendBlock() - (the[Exception] thrownBy d.appendBlock(invoke2)).getMessage should include( - s"Sync call leads to temporary negative asset $asset balance = -100 for address $dApp2Address" - ) + if (!bigComplexityDApp1 && !bigComplexityDApp2) { + d.appendAndCatchError(invoke1).toString should include("negative asset balance") + } else { + d.appendAndAssertFailed(invoke1) + } } } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppDoubleIssueTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppDoubleIssueTest.scala index 4278c2a5b29..6f9a39c9062 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppDoubleIssueTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppDoubleIssueTest.scala @@ -68,8 +68,7 @@ class SyncDAppDoubleIssueTest extends PropSpec with WithDomain with TransactionG private val settings = TestFunctionalitySettings - .withFeatures(BlockV5, SynchronousCalls) - .copy(syncDAppCheckTransfersHeight = 3) + .withFeatures(BlockV5, SynchronousCalls, RideV6) property("issue the same asset via 2 dApps") { for { @@ -82,11 +81,11 @@ class SyncDAppDoubleIssueTest extends PropSpec with WithDomain with TransactionG d.appendBlock(preparingTxs: _*) val invoke1 = invoke() - d.appendBlock(invoke1) - d.liquidDiff.errorMessage(invoke1.txId).get.text should include("already issued") - - val invoke2 = invoke() - (the[Exception] thrownBy d.appendBlock(invoke2)).getMessage should include("already issued") + if (!bigComplexityDApp1 && !bigComplexityDApp2) { + d.appendAndCatchError(invoke1).toString should include("already issued") + } else { + d.appendAndAssertFailed(invoke1) + } } } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppLeaseBalanceCheckTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppLeaseBalanceCheckTest.scala index d9b9eecffdd..20b1e83cb70 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppLeaseBalanceCheckTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppLeaseBalanceCheckTest.scala @@ -69,7 +69,6 @@ class SyncDAppLeaseBalanceCheckTest extends PropSpec with WithDomain with Transa private val settings = TestFunctionalitySettings .withFeatures(BlockV5, SynchronousCalls) - .copy(syncDAppCheckTransfersHeight = 100) property("negative balance always rejects tx after syncDAppCheckTransfersHeight") { for { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeBurnTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeBurnTest.scala index a1e0ff87ec5..4dcab23ee62 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeBurnTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeBurnTest.scala @@ -12,14 +12,12 @@ import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.ci.ciFee import com.wavesplatform.test._ +import com.wavesplatform.transaction.{Asset, GenesisTransaction, TxVersion} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.IssueTransaction import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.utils.Signed -import com.wavesplatform.transaction.{Asset, GenesisTransaction, TxVersion} -import org.scalatest.Ignore -@Ignore class SyncDAppNegativeBurnTest extends PropSpec with WithDomain with TransactionGenBase { private val time = new TestTime @@ -72,7 +70,6 @@ class SyncDAppNegativeBurnTest extends PropSpec with WithDomain with Transaction private val settings = TestFunctionalitySettings .withFeatures(BlockV5, SynchronousCalls) - .copy(syncDAppCheckTransfersHeight = 3) property("negative burn quantity") { for { @@ -85,12 +82,11 @@ class SyncDAppNegativeBurnTest extends PropSpec with WithDomain with Transaction d.appendBlock(preparingTxs: _*) val invoke1 = invoke() - d.appendBlock(invoke1) - d.blockchain.transactionSucceeded(invoke1.txId) shouldBe true - d.blockchain.balance(dApp, asset) shouldBe 101 - - val invoke2 = invoke() - (the[Exception] thrownBy d.appendBlock(invoke2)).getMessage should include("Negative burn quantity = -1") + if (!bigComplexityDApp1 && !bigComplexityDApp2) { + d.appendAndCatchError(invoke1).toString should include("Negative burn quantity") + } else { + d.appendAndAssertFailed(invoke1) + } } } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeIssueTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeIssueTest.scala index de3ae0e779e..46a0d6d5191 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeIssueTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeIssueTest.scala @@ -67,7 +67,6 @@ class SyncDAppNegativeIssueTest extends PropSpec with WithDomain with Transactio private val settings = TestFunctionalitySettings .withFeatures(BlockV5, SynchronousCalls) - .copy(syncDAppCheckTransfersHeight = 100) property("negative issue amount") { for { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeLeaseTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeLeaseTest.scala index 293548cfe0d..c06092b1eec 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeLeaseTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeLeaseTest.scala @@ -12,14 +12,12 @@ import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.ci.ciFee import com.wavesplatform.test._ +import com.wavesplatform.transaction.{Asset, GenesisTransaction, TxVersion} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.IssueTransaction import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.utils.Signed -import com.wavesplatform.transaction.{Asset, GenesisTransaction, TxVersion} -import org.scalatest.Ignore -@Ignore class SyncDAppNegativeLeaseTest extends PropSpec with WithDomain with TransactionGenBase { private val time = new TestTime @@ -72,7 +70,6 @@ class SyncDAppNegativeLeaseTest extends PropSpec with WithDomain with Transactio private val settings = TestFunctionalitySettings .withFeatures(BlockV5, SynchronousCalls) - .copy(syncDAppCheckTransfersHeight = 3) property("negative lease amount") { for { @@ -85,17 +82,11 @@ class SyncDAppNegativeLeaseTest extends PropSpec with WithDomain with Transactio d.appendBlock(preparingTxs: _*) val invoke1 = invoke() - if (bigComplexityDApp1 || bigComplexityDApp2) { - d.appendBlock(invoke1) - d.liquidDiff.errorMessage(invoke1.txId).get.text should include("NonPositiveAmount(-1,waves)") + if (!bigComplexityDApp1 && !bigComplexityDApp2) { + d.appendAndCatchError(invoke1).toString should include("Negative lease amount") } else { - (the[RuntimeException] thrownBy d.appendBlock(invoke1)).getMessage should include("NonPositiveAmount(-1,waves)") - d.appendBlock() + d.appendAndAssertFailed(invoke1) } - - val invoke2 = invoke() - d.appendBlock() - (the[Exception] thrownBy d.appendBlock(invoke2)).getMessage should include("Negative lease amount = -1") } } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeReissueTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeReissueTest.scala index 4209e2d2082..1767659749e 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeReissueTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeReissueTest.scala @@ -12,14 +12,12 @@ import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.ci.ciFee import com.wavesplatform.test._ +import com.wavesplatform.transaction.{Asset, GenesisTransaction, TxVersion} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.IssueTransaction import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.utils.Signed -import com.wavesplatform.transaction.{Asset, GenesisTransaction, TxVersion} -import org.scalatest.Ignore -@Ignore class SyncDAppNegativeReissueTest extends PropSpec with WithDomain with TransactionGenBase { private val time = new TestTime @@ -72,7 +70,6 @@ class SyncDAppNegativeReissueTest extends PropSpec with WithDomain with Transact private val settings = TestFunctionalitySettings .withFeatures(BlockV5, SynchronousCalls) - .copy(syncDAppCheckTransfersHeight = 3) property("negative reissue quantity") { for { @@ -85,12 +82,11 @@ class SyncDAppNegativeReissueTest extends PropSpec with WithDomain with Transact d.appendBlock(preparingTxs: _*) val invoke1 = invoke() - d.appendBlock(invoke1) - d.blockchain.transactionSucceeded(invoke1.txId) shouldBe true - d.blockchain.balance(dApp, asset) shouldBe 99 - - val invoke2 = invoke() - (the[Exception] thrownBy d.appendBlock(invoke2)).getMessage should include("Negative reissue quantity = -1") + if (!bigComplexityDApp1 && !bigComplexityDApp2) { + d.appendAndCatchError(invoke1).toString should include("Negative reissue quantity") + } else { + d.appendAndAssertFailed(invoke1) + } } } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeSponsorFeeTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeSponsorFeeTest.scala index 0b3537418b6..2b7790406fe 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeSponsorFeeTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeSponsorFeeTest.scala @@ -12,14 +12,12 @@ import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.ci.ciFee import com.wavesplatform.test._ +import com.wavesplatform.transaction.{Asset, GenesisTransaction, TxVersion} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.IssueTransaction import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.utils.Signed -import com.wavesplatform.transaction.{Asset, GenesisTransaction, TxVersion} -import org.scalatest.Ignore -@Ignore class SyncDAppNegativeSponsorFeeTest extends PropSpec with WithDomain with TransactionGenBase { private val time = new TestTime @@ -72,7 +70,6 @@ class SyncDAppNegativeSponsorFeeTest extends PropSpec with WithDomain with Trans private val settings = TestFunctionalitySettings .withFeatures(BlockV5, SynchronousCalls) - .copy(syncDAppCheckTransfersHeight = 3) property("negative sponsor amount") { for { @@ -85,17 +82,11 @@ class SyncDAppNegativeSponsorFeeTest extends PropSpec with WithDomain with Trans d.appendBlock(preparingTxs: _*) val invoke1 = invoke() - if (bigComplexityDApp1 || bigComplexityDApp2) { - d.appendBlock(invoke1) - d.liquidDiff.errorMessage(invoke1.txId).get.text should include("NegativeMinFee(-1,asset)") + if (!bigComplexityDApp1 && !bigComplexityDApp2) { + d.appendAndCatchError(invoke1).toString should include("Negative sponsor amount") } else { - (the[RuntimeException] thrownBy d.appendBlock(invoke1)).getMessage should include("NegativeMinFee(-1,asset)") - d.appendBlock() + d.appendAndAssertFailed(invoke1) } - - val invoke2 = invoke() - d.appendBlock() - (the[Exception] thrownBy d.appendBlock(invoke2)).getMessage should include ("Negative sponsor amount = -1") } } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeTransferTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeTransferTest.scala index c5fe8ea1885..c99554ad89e 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeTransferTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppNegativeTransferTest.scala @@ -12,14 +12,12 @@ import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.ci.ciFee import com.wavesplatform.test._ +import com.wavesplatform.transaction.{Asset, GenesisTransaction, TxVersion} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.IssueTransaction import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.utils.Signed -import com.wavesplatform.transaction.{Asset, GenesisTransaction, TxVersion} -import org.scalatest.Ignore -@Ignore class SyncDAppNegativeTransferTest extends PropSpec with WithDomain with TransactionGenBase { private val time = new TestTime @@ -72,30 +70,23 @@ class SyncDAppNegativeTransferTest extends PropSpec with WithDomain with Transac private val settings = TestFunctionalitySettings .withFeatures(BlockV5, SynchronousCalls) - .copy(syncDAppCheckTransfersHeight = 3) property("negative transfer amount") { for { bigComplexityDApp1 <- Seq(false, true) bigComplexityDApp2 <- Seq(false, true) } { - val (preparingTxs, invoke, dApp, asset) = scenario(bigComplexityDApp1, bigComplexityDApp2).sample.get + val (preparingTxs, invoke, _, _) = scenario(bigComplexityDApp1, bigComplexityDApp2).sample.get withDomain(domainSettingsWithFS(settings)) { d => d.appendBlock(preparingTxs: _*) val invoke1 = invoke() - if (bigComplexityDApp1 || bigComplexityDApp2) { - d.appendBlock(invoke1) - d.liquidDiff.errorMessage(invoke1.txId).get.text should include("Negative amount") + if (!bigComplexityDApp1 && !bigComplexityDApp2) { + d.appendAndCatchError(invoke1).toString should include("Negative transfer amount") } else { - (the[RuntimeException] thrownBy d.appendBlock(invoke1)).getMessage should include("Negative amount") - d.appendBlock() + d.appendAndAssertFailed(invoke1) } - - val invoke2 = invoke() - d.appendBlock() - (the[Exception] thrownBy d.appendBlock(invoke2)).getMessage should include("Negative transfer amount = -1") } } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppPaymentBalanceCheckTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppPaymentBalanceCheckTest.scala index 3adc2a27079..aa4bdf5b07e 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppPaymentBalanceCheckTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppPaymentBalanceCheckTest.scala @@ -12,13 +12,11 @@ import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.ci.ciFee import com.wavesplatform.test._ +import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.utils.Signed -import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} -import org.scalatest.Ignore -@Ignore class SyncDAppPaymentBalanceCheckTest extends PropSpec with WithDomain with TransactionGenBase { private val time = new TestTime @@ -68,10 +66,9 @@ class SyncDAppPaymentBalanceCheckTest extends PropSpec with WithDomain with Tran private val settings = TestFunctionalitySettings - .withFeatures(BlockV5, SynchronousCalls) - .copy(syncDAppCheckPaymentsHeight = 4, syncDAppCheckTransfersHeight = 5) + .withFeatures(BlockV5, SynchronousCalls, RideV6) - property("negative balance produces error after syncDAppCheckPaymentsHeight and always rejects tx after syncDAppCheckTransfersHeight") { + property("negative balance rejects or fails") { for { bigComplexityDApp1 <- Seq(false, true) bigComplexityDApp2 <- Seq(false, true) @@ -82,23 +79,11 @@ class SyncDAppPaymentBalanceCheckTest extends PropSpec with WithDomain with Tran d.appendBlock(preparingTxs: _*) val invoke1 = invoke() - val error = s"Sync call leads to temporary negative balance = -100 for address ${invoke1.dApp}" - d.appendBlock(invoke1) - d.blockchain.transactionSucceeded(invoke1.id.value()) shouldBe true - - d.appendBlock() - - val invoke2 = invoke() - if (bigComplexityDApp1) { - d.appendBlock(invoke2) - d.liquidDiff.errorMessage(invoke2.txId).get.text should include(error) + if (!bigComplexityDApp1 && !bigComplexityDApp2) { + d.appendAndCatchError(invoke1).toString should include("negative waves balance") } else { - (the[RuntimeException] thrownBy d.appendBlock(invoke2)).getMessage should include(error) - d.appendBlock() + d.appendAndAssertFailed(invoke1) } - - val invoke3 = invoke() - (the[RuntimeException] thrownBy d.appendBlock(invoke3)).getMessage should include(error) } } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppReissueForeignAssetTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppReissueForeignAssetTest.scala index 54102306bff..156993983e9 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppReissueForeignAssetTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppReissueForeignAssetTest.scala @@ -70,7 +70,6 @@ class SyncDAppReissueForeignAssetTest extends PropSpec with WithDomain with Tran private val settings = TestFunctionalitySettings .withFeatures(BlockV5, SynchronousCalls) - .copy(syncDAppCheckTransfersHeight = 100) property("reissue foreign asset") { for { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppTransferBalanceCheckTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppTransferBalanceCheckTest.scala index e64cae63e52..ef54e6af461 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppTransferBalanceCheckTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppTransferBalanceCheckTest.scala @@ -12,13 +12,11 @@ import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.ci.ciFee import com.wavesplatform.test._ +import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.utils.Signed -import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} -import org.scalatest.Ignore -@Ignore class SyncDAppTransferBalanceCheckTest extends PropSpec with WithDomain with TransactionGenBase { private val time = new TestTime @@ -71,7 +69,6 @@ class SyncDAppTransferBalanceCheckTest extends PropSpec with WithDomain with Tra private val settings = TestFunctionalitySettings .withFeatures(BlockV5, SynchronousCalls) - .copy(syncDAppCheckPaymentsHeight = 0, syncDAppCheckTransfersHeight = 4) property("negative balance always rejects tx after syncDAppCheckTransfersHeight") { for { @@ -82,16 +79,13 @@ class SyncDAppTransferBalanceCheckTest extends PropSpec with WithDomain with Tra withDomain(domainSettingsWithFS(settings)) { d => d.appendBlock(preparingTxs: _*) - + val invoke1 = invoke() - d.appendBlock(invoke1) - d.blockchain.transactionSucceeded(invoke1.id.value()) shouldBe true - - val invoke2 = invoke() - d.appendBlock() - (the[Exception] thrownBy d.appendBlock(invoke2)).getMessage should include( - s"Sync call leads to temporary negative balance = -100 for address $dApp2Address" - ) + if (!bigComplexityDApp1 && !bigComplexityDApp2) { + d.appendAndCatchError(invoke1).toString should include("negative waves balance") + } else { + d.appendAndAssertFailed(invoke1) + } } } } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/freecall/InvokeExpressionTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/freecall/InvokeExpressionTest.scala index b3bbe688f9d..7146bf9b55c 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/freecall/InvokeExpressionTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/freecall/InvokeExpressionTest.scala @@ -1,6 +1,5 @@ package com.wavesplatform.state.diffs.freecall -import com.wavesplatform.TransactionGen import com.wavesplatform.account.{Address, KeyPair} import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.WithDomain @@ -9,167 +8,74 @@ import com.wavesplatform.lang.directives.values.{StdLibVersion, V3, V6} import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.script.v1.ExprScript import com.wavesplatform.lang.v1.compiler.TestCompiler -import com.wavesplatform.state.diffs.ENOUGH_AMT +import com.wavesplatform.state.{BinaryDataEntry, BooleanDataEntry, NewAssetInfo} +import com.wavesplatform.state.diffs.{ENOUGH_AMT, FeeValidation} import com.wavesplatform.state.diffs.FeeValidation.{FeeConstants, FeeUnit} import com.wavesplatform.state.diffs.ci.ciFee -import com.wavesplatform.state.{BinaryDataEntry, BooleanDataEntry, NewAssetInfo} -import com.wavesplatform.test.{PropSpec, TestTime} +import com.wavesplatform.test.PropSpec +import com.wavesplatform.transaction.{GenesisTransaction, Transaction, TxHelpers, TxVersion} import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.{IssueTransaction, SponsorFeeTransaction} import com.wavesplatform.transaction.smart.{InvokeExpressionTransaction, SetScriptTransaction} -import com.wavesplatform.transaction.{GenesisTransaction, Transaction, TxVersion} +import com.wavesplatform.utils.JsonMatchers import org.scalatest.{Assertion, EitherValues} import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks +import play.api.libs.json.Json -class InvokeExpressionTest extends PropSpec with ScalaCheckPropertyChecks with TransactionGen with WithDomain with EitherValues { +class InvokeExpressionTest extends PropSpec with ScalaCheckPropertyChecks with WithDomain with EitherValues with JsonMatchers { + import DomainPresets.{RideV5, RideV6} + import InvokeExpressionTest.* - import DomainPresets.* + property("can call another contract") { + val dAppScript = TxHelpers.scriptV5(""" + |@Callable(i) + |func test() = ([], 123) + |""".stripMargin) + val dAppAccount = TxHelpers.secondSigner - private val time = new TestTime - private def ts = time.getTimestamp() + val freeCall = TestCompiler(V6).compileFreeCall(s"""strict test = invoke(Address(base58'${dAppAccount.toAddress}'), "test", [], []) + |if (test == 123) then [] else throw("err")""".stripMargin) - private val assetName = "name" - private val assetDescription = "description" - private val assetVolume = 1000 - private val assetDecimals = 4 - private val assetIsReissuable = true - - private def expr( - invoker: KeyPair, - fee: Long, - issue: Boolean, - transfersCount: Int, - receiver: Address, - sigVerifyCount: Int, - raiseError: Boolean - ): ExprScript = - TestCompiler(V6).compileFreeCall( - s""" - | ${(1 to sigVerifyCount).map(i => s"strict r$i = sigVerify(base58'', base58'', base58'')").mkString("\n")} - | ${if (raiseError) "strict f = throw()" else ""} - | let address = Address(base58'${invoker.toAddress}') - | let publicKey = base58'${invoker.publicKey}' - | let check = - | this == address && - | i.caller == address && - | i.originCaller == address && - | i.callerPublicKey == publicKey && - | i.originCallerPublicKey == publicKey && - | i.fee == $fee && - | i.payments == [] && - | i.feeAssetId == unit - | [ - | BooleanEntry("check", check), - | BinaryEntry("transactionId", i.transactionId) - | ${if (issue) s""", Issue("$assetName", "$assetDescription", $assetVolume, $assetDecimals, $assetIsReissuable, unit, 0) """ else ""} - | ${if (transfersCount > 0) "," else ""} - | ${(1 to transfersCount).map(_ => s"ScriptTransfer(Address(base58'$receiver'), 1, unit)").mkString(",")} - | ] - """.stripMargin - ) - - private def verifier(version: StdLibVersion): Script = - TestCompiler(version).compileExpression( - s""" - | match tx { - | case _ => true - | } - """.stripMargin - ) - - private def dAppVerifier(version: StdLibVersion): Script = - TestCompiler(version).compileContract( - s""" - | @Verifier(tx) - | func verify() = - | match tx { - | case _ => true - | } - """.stripMargin - ) - - private def dAppWithNoVerifier(version: StdLibVersion): Script = - TestCompiler(version).compileContract( - s""" - | @Callable(i) - | func default() = if (true) then throw() else throw() - """.stripMargin - ) - - private val forbidByTypeVerifier: Script = - TestCompiler(V6).compileExpression( - s""" - | match tx { - | case _: InvokeExpressionTransaction => false - | case _ => true - | } - """.stripMargin - ) - - private val forbidAllVerifier: Script = - TestCompiler(V6).compileExpression( - s""" - | match tx { - | case _ => false - | } - """.stripMargin - ) - - private val bigVerifier: Script = - TestCompiler(V6).compileExpression( - s""" - | strict r = ${(1 to 5).map(_ => "sigVerify(base58'', base58'', base58'')").mkString(" && ")} - | true - """.stripMargin - ) - - private def scenario( - enoughFee: Boolean = true, - issue: Boolean = true, - verifier: Option[Script] = None, - sponsor: Boolean = false, - version: Byte = 1, - transfersCount: Int = 0, - sigVerifyCount: Int = 0, - bigVerifier: Boolean = false, - raiseError: Boolean = false - ): (Seq[Transaction], InvokeExpressionTransaction) = { - val invoker = accountGen.sample.get - val receiver = accountGen.sample.get - val fee = ciFee(freeCall = enoughFee, nonNftIssue = if (issue) 1 else 0, sc = if (bigVerifier) 1 else 0).sample.get - - val genesis = GenesisTransaction.create(invoker.toAddress, ENOUGH_AMT, ts).explicitGet() - val setVerifier = SetScriptTransaction.selfSigned(TxVersion.V2, invoker, verifier, fee, ts).explicitGet() - - val sponsorIssueTx = IssueTransaction.selfSigned(TxVersion.V2, invoker, "name", "", 1000, 1, true, None, fee, ts).explicitGet() - val sponsorAsset = IssuedAsset(sponsorIssueTx.id.value()) - val sponsorTx = SponsorFeeTransaction.selfSigned(TxVersion.V2, invoker, sponsorAsset, Some(1000L), fee, ts).explicitGet() - val feeAsset = if (sponsor) sponsorAsset else Waves - - val call = expr(invoker, fee, issue, transfersCount, receiver.toAddress, sigVerifyCount, raiseError) - val invoke = InvokeExpressionTransaction.selfSigned(version, invoker, call, fee, feeAsset, ts).explicitGet() - - (Seq(genesis, sponsorIssueTx, sponsorTx, setVerifier), invoke) - } - - private def feeErrorMessage(invoke: InvokeExpressionTransaction, issue: Boolean = false, verifier: Boolean = false) = { - val expectingFee = FeeConstants(invoke.tpe) * FeeUnit + (if (issue) 1 else 0) * MinIssueFee + (if (verifier) 1 else 0) * ScriptExtraFee - val issueErr = if (issue) " with 1 assets issued" else "" - val verifierErr = if (verifier) " with 1 total scripts invoked" else "" - s"Fee in WAVES for InvokeExpressionTransaction (${invoke.fee} in WAVES)$issueErr$verifierErr does not exceed minimal value of $expectingFee WAVES." - } - - private def checkAsset( - invoke: InvokeExpressionTransaction, - asset: NewAssetInfo - ): Assertion = { - asset.dynamic.name.toStringUtf8 shouldBe assetName - asset.dynamic.description.toStringUtf8 shouldBe assetDescription - asset.volume.volume shouldBe assetVolume - asset.volume.isReissuable shouldBe assetIsReissuable - asset.static.decimals shouldBe assetDecimals - asset.static.nft shouldBe false - asset.static.issuer shouldBe invoke.sender + val invoke = InvokeExpressionTransaction + .selfSigned(TxVersion.V1, TxHelpers.defaultSigner, freeCall, 1000000L, Waves, System.currentTimeMillis()) + .explicitGet() + withDomain(RideV6) { d => + d.helpers.creditWavesToDefaultSigner() + d.helpers.creditWavesFromDefaultSigner(dAppAccount.toAddress) + d.helpers.setScript(dAppAccount, dAppScript) + d.appendAndAssertSucceed(invoke) + + val result = d.commonApi.invokeScriptResult(invoke.id()) + Json.toJson(result) should matchJson("""{ + | "data" : [ ], + | "transfers" : [ ], + | "issues" : [ ], + | "reissues" : [ ], + | "burns" : [ ], + | "sponsorFees" : [ ], + | "leases" : [ ], + | "leaseCancels" : [ ], + | "invokes" : [ { + | "dApp" : "3MuVqVJGmFsHeuFni5RbjRmALuGCkEwzZtC", + | "call" : { + | "function" : "test", + | "args" : [ ] + | }, + | "payment" : [ ], + | "stateChanges" : { + | "data" : [ ], + | "transfers" : [ ], + | "issues" : [ ], + | "reissues" : [ ], + | "burns" : [ ], + | "sponsorFees" : [ ], + | "leases" : [ ], + | "leaseCancels" : [ ], + | "invokes" : [ ] + | } + | } ] + |}""".stripMargin) + } } property("successful applying to the state") { @@ -192,21 +98,19 @@ class InvokeExpressionTest extends PropSpec with ScalaCheckPropertyChecks with T } } - property("insufficient fee for issue leading to fail") { + property("insufficient fee for issue leading to reject") { val (genesisTxs, invoke) = scenario(enoughFee = false) withDomain(RideV6) { d => d.appendBlock(genesisTxs *) - d.appendBlock(invoke) - d.liquidDiff.errorMessage(invoke.txId).get.text shouldBe feeErrorMessage(invoke, issue = true) + d.appendAndCatchError(invoke).toString should include(feeErrorMessage(invoke, issue = true)) } } - property("insufficient fee for big verifier leading to fail") { + property("insufficient fee for big verifier leading to reject") { val (genesisTxs, invoke) = scenario(issue = false, verifier = Some(bigVerifier)) withDomain(RideV6) { d => d.appendBlock(genesisTxs *) - d.appendBlock(invoke) - d.liquidDiff.errorMessage(invoke.txId).get.text shouldBe feeErrorMessage(invoke, verifier = true) + d.appendAndCatchError(invoke).toString should include(feeErrorMessage(invoke, verifier = true)) } } @@ -316,8 +220,7 @@ class InvokeExpressionTest extends PropSpec with ScalaCheckPropertyChecks with T val (genesisTxs, invoke) = scenario(transfersCount = 30) withDomain(RideV6) { d => d.appendBlock(genesisTxs *) - d.appendBlock(invoke) - d.liquidDiff.errorMessage(invoke.txId).get.text shouldBe "Actions count limit is exceeded" + d.appendAndCatchError(invoke).toString should include("Actions count limit is exceeded") } } @@ -345,4 +248,151 @@ class InvokeExpressionTest extends PropSpec with ScalaCheckPropertyChecks with T d.liquidDiff.errorMessage(invoke.id.value()).get.text should include("Explicit script termination") } } + + private[this] def checkAsset( + invoke: InvokeExpressionTransaction, + asset: NewAssetInfo + ): Assertion = { + asset.dynamic.name.toStringUtf8 shouldBe TestAssetName + asset.dynamic.description.toStringUtf8 shouldBe TestAssetDesc + asset.volume.volume shouldBe TestAssetVolume + asset.volume.isReissuable shouldBe TestAssetReissuable + asset.static.decimals shouldBe TestAssetDecimals + asset.static.nft shouldBe false + asset.static.issuer shouldBe invoke.sender + } +} + +private object InvokeExpressionTest { + val TestAssetName = "name" + val TestAssetDesc = "description" + val TestAssetVolume = 1000 + val TestAssetDecimals = 4 + val TestAssetReissuable = true + + def makeExpression( + invoker: KeyPair, + fee: Long, + issue: Boolean, + transfersCount: Int, + receiver: Address, + sigVerifyCount: Int, + raiseError: Boolean + ): ExprScript = + TestCompiler(V6).compileFreeCall( + s""" + | ${(1 to sigVerifyCount).map(i => s"strict r$i = sigVerify(base58'', base58'', base58'')").mkString("\n")} + | ${if (raiseError) "strict f = throw()" else ""} + | let address = Address(base58'${invoker.toAddress}') + | let publicKey = base58'${invoker.publicKey}' + | let check = + | this == address && + | i.caller == address && + | i.originCaller == address && + | i.callerPublicKey == publicKey && + | i.originCallerPublicKey == publicKey && + | i.fee == $fee && + | i.payments == [] && + | i.feeAssetId == unit + | [ + | BooleanEntry("check", check), + | BinaryEntry("transactionId", i.transactionId) + | ${if (issue) s""", Issue("$TestAssetName", "$TestAssetDesc", $TestAssetVolume, $TestAssetDecimals, $TestAssetReissuable, unit, 0) """ + else ""} + | ${if (transfersCount > 0) "," else ""} + | ${(1 to transfersCount).map(_ => s"ScriptTransfer(Address(base58'$receiver'), 1, unit)").mkString(",")} + | ] + """.stripMargin + ) + + def scenario( + enoughFee: Boolean = true, + issue: Boolean = true, + verifier: Option[Script] = None, + sponsor: Boolean = false, + version: Byte = 1, + transfersCount: Int = 0, + sigVerifyCount: Int = 0, + bigVerifier: Boolean = false, + raiseError: Boolean = false + ): (Seq[Transaction], InvokeExpressionTransaction) = { + val invoker = TxHelpers.signer(1) + val receiver = TxHelpers.signer(2) + val fee = ciFee(freeCall = enoughFee, nonNftIssue = if (issue) 1 else 0, sc = if (bigVerifier) 1 else 0).sample.get + + val genesis = GenesisTransaction.create(invoker.toAddress, ENOUGH_AMT, TxHelpers.timestamp).explicitGet() + val setVerifier = SetScriptTransaction.selfSigned(TxVersion.V2, invoker, verifier, fee, TxHelpers.timestamp).explicitGet() + + val sponsorIssueTx = IssueTransaction.selfSigned(TxVersion.V2, invoker, "name", "", 1000, 1, true, None, fee, TxHelpers.timestamp).explicitGet() + val sponsorAsset = IssuedAsset(sponsorIssueTx.id.value()) + val sponsorTx = SponsorFeeTransaction.selfSigned(TxVersion.V2, invoker, sponsorAsset, Some(1000L), fee, TxHelpers.timestamp).explicitGet() + val feeAsset = if (sponsor) sponsorAsset else Waves + + val call = makeExpression(invoker, fee, issue, transfersCount, receiver.toAddress, sigVerifyCount, raiseError) + val invoke = InvokeExpressionTransaction.selfSigned(version, invoker, call, fee, feeAsset, TxHelpers.timestamp).explicitGet() + + (Seq(genesis, sponsorIssueTx, sponsorTx, setVerifier), invoke) + } + + def feeErrorMessage(invoke: InvokeExpressionTransaction, issue: Boolean = false, verifier: Boolean = false): String = { + val expectingFee = FeeConstants(invoke.tpe) * FeeUnit + (if (issue) 1 else 0) * 1_0000_0000L + (if (verifier) 1 else 0) * FeeValidation.ScriptExtraFee + val issueErr = if (issue) " with 1 assets issued" else "" + val verifierErr = if (verifier) " with 1 total scripts invoked" else "" + s"Fee in WAVES for InvokeExpressionTransaction (${invoke.fee} in WAVES)$issueErr$verifierErr does not exceed minimal value of $expectingFee WAVES." + } + + def verifier(version: StdLibVersion): Script = + TestCompiler(version).compileExpression( + s""" + | match tx { + | case _ => true + | } + """.stripMargin + ) + + def dAppVerifier(version: StdLibVersion): Script = + TestCompiler(version).compileContract( + s""" + | @Verifier(tx) + | func verify() = + | match tx { + | case _ => true + | } + """.stripMargin + ) + + def dAppWithNoVerifier(version: StdLibVersion): Script = + TestCompiler(version).compileContract( + s""" + | @Callable(i) + | func default() = if (true) then throw() else throw() + """.stripMargin + ) + + def forbidByTypeVerifier: Script = + TestCompiler(V6).compileExpression( + s""" + | match tx { + | case _: InvokeExpressionTransaction => false + | case _ => true + | } + """.stripMargin + ) + + def forbidAllVerifier: Script = + TestCompiler(V6).compileExpression( + s""" + | match tx { + | case _ => false + | } + """.stripMargin + ) + + def bigVerifier: Script = + TestCompiler(V6).compileExpression( + s""" + | strict r = ${(1 to 5).map(_ => "sigVerify(base58'', base58'', base58'')").mkString(" && ")} + | true + """.stripMargin + ) } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/DiffComplexityCountTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/DiffComplexityCountTest.scala index 8fda5a567c4..c1a33eff109 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/DiffComplexityCountTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/DiffComplexityCountTest.scala @@ -37,8 +37,7 @@ class DiffComplexityCountTest private val activationHeight = 3 - private val fsWithV5 = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + private val fsWithV5 = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map( BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.SmartAssets.id -> 0, BlockchainFeatures.Ride4DApps.id -> 0, @@ -47,9 +46,7 @@ class DiffComplexityCountTest BlockchainFeatures.BlockReward.id -> 0, BlockchainFeatures.BlockV5.id -> 0, BlockchainFeatures.SynchronousCalls.id -> activationHeight - ), - estimatorPreCheckHeight = Int.MaxValue - ) + ), estimatorPreCheckHeight = Int.MaxValue) // ~1900 complexity val groth: String = diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/SmartAccountFeeTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/SmartAccountFeeTest.scala index a8a17c5f935..0d2db938239 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/SmartAccountFeeTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/SmartAccountFeeTest.scala @@ -62,8 +62,7 @@ class SmartAccountFeeTest extends PropSpec with WithDomain { | func default() = [] |""".stripMargin) - private val features = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + private val features = TestFunctionalitySettings.Enabled.copy(featureCheckBlocksPeriod = 1, blocksForFeatureActivation = 1, preActivatedFeatures = Map( BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.SmartAssets.id -> 0, BlockchainFeatures.Ride4DApps.id -> 0, @@ -72,10 +71,7 @@ class SmartAccountFeeTest extends PropSpec with WithDomain { BlockchainFeatures.BlockReward.id -> 0, BlockchainFeatures.BlockV5.id -> 0, BlockchainFeatures.SynchronousCalls.id -> activationHeight - ), - featureCheckBlocksPeriod = 1, - blocksForFeatureActivation = 1 - ) + )) private val preconditions = for { diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/package.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/package.scala index 6a1517de56f..e1be661caf6 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/package.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/package.scala @@ -5,12 +5,10 @@ import com.wavesplatform.settings.{FunctionalitySettings, TestFunctionalitySetti package object smart { val smartEnabledFS: FunctionalitySettings = - TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map( BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.SmartAssets.id -> 0, BlockchainFeatures.DataTransaction.id -> 0, BlockchainFeatures.Ride4DApps.id -> 0 - ) - ) + )) } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ContextFunctionsTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ContextFunctionsTest.scala index 4a6112c3ab7..72bf5af0f54 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ContextFunctionsTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/ContextFunctionsTest.scala @@ -754,7 +754,7 @@ class ContextFunctionsTest extends PropSpec with WithDomain with EthHelpers { val expr = Parser.parseContract(script).get.value val ctx = - PureContext.build(version, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(version, useNewPowPrecision = true).withEnvironment[Environment] |+| CryptoContext.build(Global, version).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet(version, Account, DApp).explicitGet()) diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/PowNewPrecisionTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/PowNewPrecisionTest.scala index 956328803f5..37b443d9f8e 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/PowNewPrecisionTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/PowNewPrecisionTest.scala @@ -2,22 +2,20 @@ package com.wavesplatform.state.diffs.smart.predef import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.db.WithDomain -import com.wavesplatform.features.BlockchainFeatures._ -import com.wavesplatform.lang.directives.values.V5 +import com.wavesplatform.lang.directives.values.V4 import com.wavesplatform.lang.v1.compiler.TestCompiler -import com.wavesplatform.settings.TestFunctionalitySettings import com.wavesplatform.state.diffs.ENOUGH_AMT import com.wavesplatform.state.diffs.ci.ciFee import com.wavesplatform.test.PropSpec +import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} import com.wavesplatform.transaction.Asset.Waves import com.wavesplatform.transaction.smart.SetScriptTransaction import com.wavesplatform.transaction.utils.Signed -import com.wavesplatform.transaction.{GenesisTransaction, TxVersion} class PowNewPrecisionTest extends PropSpec with WithDomain { private def ts = ntpTime.getTimestamp() - private val contract = TestCompiler(V5).compileContract( + private val contract = TestCompiler(V4).compileContract( """ | @Callable(i) | func default() = { @@ -51,19 +49,22 @@ class PowNewPrecisionTest extends PropSpec with WithDomain { invokeTx = () => Signed.invokeScript(TxVersion.V3, invoker, master.toAddress, None, Nil, fee, Waves, ts) } yield (Seq(gTx1, gTx2, ssTx), invokeTx, master.toAddress) - private val settings = - TestFunctionalitySettings - .withFeatures(BlockV5, SynchronousCalls) - .copy(syncDAppCheckPaymentsHeight = 3) - property("pow changes precision after syncDAppCheckPaymentsHeight") { + property("pow has bigger precision before SynchronousCalls") { val (genesisTxs, invoke, dApp) = scenario.sample.get - withDomain(domainSettingsWithFS(settings)) { d => + withDomain(DomainPresets.RideV4) { d => d.appendBlock(genesisTxs: _*) d.appendBlock(invoke()) d.blockchain.accountData(dApp, "result1").get.value shouldBe 9049204201489L d.blockchain.accountData(dApp, "result2").get.value shouldBe 1 + } + } + + property("pow changes precision after SynchronousCalls") { + val (genesisTxs, invoke, dApp) = scenario.sample.get + withDomain(DomainPresets.RideV5) { d => + d.appendBlock(genesisTxs: _*) d.appendBlock(invoke()) d.blockchain.accountData(dApp, "result1").get.value shouldBe 9049204201491L diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/TransactionBindingsTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/TransactionBindingsTest.scala index ce69de74432..764048be792 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/TransactionBindingsTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/predef/TransactionBindingsTest.scala @@ -714,7 +714,7 @@ class TransactionBindingsTest extends PropSpec with PathMockFactory with EitherV val expr = Parser.parseExpr(script).get.value val directives = DirectiveSet(V2, AssetType, Expression).explicitGet() val ctx = - PureContext.build(V2, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(V2, useNewPowPrecision = true).withEnvironment[Environment] |+| CryptoContext.build(Global, V2).withEnvironment[Environment] |+| WavesContext.build(Global, DirectiveSet(V2, AssetType, Expression).explicitGet()) @@ -745,7 +745,7 @@ class TransactionBindingsTest extends PropSpec with PathMockFactory with EitherV (() => blockchain.activatedFeatures).when().returning(Map(BlockchainFeatures.BlockV5.id -> 0)) val ctx = - PureContext.build(V2, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(V2, useNewPowPrecision = true).withEnvironment[Environment] |+| CryptoContext.build(Global, V2).withEnvironment[Environment] |+| WavesContext.build(Global, directives) diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/BalancesV4Test.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/BalancesV4Test.scala index 715905acc47..ec792eec178 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/BalancesV4Test.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/BalancesV4Test.scala @@ -40,13 +40,11 @@ class BalancesV4Test extends PropSpec with WithState { val SetScriptFee: Long = Constants.UnitsInWave / 1000L val SetAssetScriptFee: Long = Constants.UnitsInWave - val rideV4Activated: FunctionalitySettings = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map( + val rideV4Activated: FunctionalitySettings = TestFunctionalitySettings.Enabled.copy(preActivatedFeatures = Map( BlockchainFeatures.Ride4DApps.id -> 0, BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.BlockV5.id -> 0 - ) - ) + )) val functionCall: Option[FUNCTION_CALL] = Some( FUNCTION_CALL( @@ -133,7 +131,7 @@ class BalancesV4Test extends PropSpec with WithState { def assetScript(acc: ByteStr): Script = { val ctx = { val directives = DirectiveSet(V4, AssetType, Expression).explicitGet() - PureContext.build(V4, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(V4, useNewPowPrecision = true).withEnvironment[Environment] |+| CryptoContext.build(Global, V4).withEnvironment[Environment] |+| WavesContext.build(Global, directives) } @@ -218,7 +216,7 @@ class BalancesV4Test extends PropSpec with WithState { def assetScript(acc: ByteStr): Script = { val ctx = { val directives = DirectiveSet(V4, AssetType, Expression).explicitGet() - PureContext.build(V4, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(V4, useNewPowPrecision = true).withEnvironment[Environment] |+| CryptoContext.build(Global, V4).withEnvironment[Environment] |+| WavesContext.build(Global, directives) } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/ScriptedSponsorTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/ScriptedSponsorTest.scala index 5b83d346d4c..4fd8dc37ae2 100644 --- a/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/ScriptedSponsorTest.scala +++ b/node/src/test/scala/com/wavesplatform/state/diffs/smart/scenarios/ScriptedSponsorTest.scala @@ -24,8 +24,7 @@ class ScriptedSponsorTest extends PropSpec with WithState { val SPONSOR_FEE: Long = 100000 private val fs = TestFunctionalitySettings.Enabled - .copy( - preActivatedFeatures = Map( + .copy(featureCheckBlocksPeriod = 1, blocksForFeatureActivation = 1, preActivatedFeatures = Map( BlockchainFeatures.BlockV5.id -> 0, BlockchainFeatures.NG.id -> 0, BlockchainFeatures.MassTransfer.id -> 0, @@ -37,10 +36,7 @@ class ScriptedSponsorTest extends PropSpec with WithState { BlockchainFeatures.SmartAssets.id -> 0, BlockchainFeatures.SmartAccountTrading.id -> 0, BlockchainFeatures.SmallerMinimalGeneratingBalance.id -> 0 - ), - featureCheckBlocksPeriod = 1, - blocksForFeatureActivation = 1 - ) + )) private val estimator = ScriptEstimatorV2 diff --git a/node/src/test/scala/com/wavesplatform/state/patch/CancelLeasesToDisabledAliasesSpec.scala b/node/src/test/scala/com/wavesplatform/state/patch/CancelLeasesToDisabledAliasesSpec.scala index 729e885a340..1e6f3af3892 100644 --- a/node/src/test/scala/com/wavesplatform/state/patch/CancelLeasesToDisabledAliasesSpec.scala +++ b/node/src/test/scala/com/wavesplatform/state/patch/CancelLeasesToDisabledAliasesSpec.scala @@ -18,13 +18,11 @@ class CancelLeasesToDisabledAliasesSpec extends FlatSpec with PathMockFactory wi SettingsFromDefaultConfig.copy( blockchainSettings = SettingsFromDefaultConfig.blockchainSettings.copy( addressSchemeCharacter = 'W', - functionalitySettings = fs.copy( - preActivatedFeatures = fs.preActivatedFeatures ++ Map( + functionalitySettings = fs.copy(preActivatedFeatures = fs.preActivatedFeatures ++ Map( BlockchainFeatures.NG.id -> 0, BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.SynchronousCalls.id -> 2 - ) - ) + )) ) ) } diff --git a/node/src/test/scala/com/wavesplatform/state/rollback/EthereumTransactionRollbackSpec.scala b/node/src/test/scala/com/wavesplatform/state/rollback/EthereumTransactionRollbackSpec.scala index 013e7822262..372b33dfdf8 100644 --- a/node/src/test/scala/com/wavesplatform/state/rollback/EthereumTransactionRollbackSpec.scala +++ b/node/src/test/scala/com/wavesplatform/state/rollback/EthereumTransactionRollbackSpec.scala @@ -47,8 +47,8 @@ class EthereumTransactionRollbackSpec extends FlatSpec with WithDomain with EthH | StringEntry("key", "str"), | BinaryEntry("key", base58''), | DeleteEntry("key"), - | ScriptTransfer(i.caller, 1, unit), - | ScriptTransfer(i.caller, 1, base58'$asset'), + | ScriptTransfer(Address(base58'${TxHelpers.secondAddress}'), 1, unit), + | ScriptTransfer(Address(base58'${TxHelpers.secondAddress}'), 1, base58'$asset'), | Issue("name", "description", 1000, 4, true, unit, 0), | Reissue(base58'$asset', 1, false), | Burn(base58'$asset', 1), @@ -59,7 +59,7 @@ class EthereumTransactionRollbackSpec extends FlatSpec with WithDomain with EthH d.helpers.setScript(TxHelpers.defaultSigner, script) val (initHeight, initStateSnapshot) = d.makeStateSolid() - val invoke = TxHelpers.invoke(TxHelpers.defaultAddress, "foo", fee = 1_0000_0000) + val invoke = TxHelpers.invoke(TxHelpers.defaultAddress, "foo", fee = 1_0050_0000) d.appendBlock(invoke) d.rollbackTo(initHeight) diff --git a/node/src/test/scala/com/wavesplatform/transaction/BlockchainUpdaterTest.scala b/node/src/test/scala/com/wavesplatform/transaction/BlockchainUpdaterTest.scala index 15c173791e1..91ed316c1fa 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/BlockchainUpdaterTest.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/BlockchainUpdaterTest.scala @@ -20,21 +20,14 @@ class BlockchainUpdaterTest extends FreeSpec with HistoryTest with WithDomain { private val WavesSettings = history.DefaultWavesSettings.copy( blockchainSettings = history.DefaultWavesSettings.blockchainSettings.copy( - functionalitySettings = history.DefaultWavesSettings.blockchainSettings.functionalitySettings.copy( - featureCheckBlocksPeriod = ApprovalPeriod, - blocksForFeatureActivation = (ApprovalPeriod * 0.9).toInt, - preActivatedFeatures = Map.empty - ) + functionalitySettings = history.DefaultWavesSettings.blockchainSettings.functionalitySettings.copy(featureCheckBlocksPeriod = ApprovalPeriod, blocksForFeatureActivation = (ApprovalPeriod * 0.9).toInt, preActivatedFeatures = Map.empty) ), featuresSettings = history.DefaultWavesSettings.featuresSettings.copy(autoShutdownOnUnsupportedFeature = true) ) private val WavesSettingsWithDoubling = WavesSettings.copy( blockchainSettings = WavesSettings.blockchainSettings.copy( - functionalitySettings = WavesSettings.blockchainSettings.functionalitySettings.copy( - doubleFeaturesPeriodsAfterHeight = 300, - preActivatedFeatures = Map.empty - ) + functionalitySettings = WavesSettings.blockchainSettings.functionalitySettings.copy(preActivatedFeatures = Map.empty, doubleFeaturesPeriodsAfterHeight = 300) ) ) diff --git a/node/src/test/scala/com/wavesplatform/transaction/IssueTransactionV2Specification.scala b/node/src/test/scala/com/wavesplatform/transaction/IssueTransactionV2Specification.scala index 85517bd82dd..50836999bf5 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/IssueTransactionV2Specification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/IssueTransactionV2Specification.scala @@ -139,7 +139,7 @@ class IssueTransactionV2Specification Monoid .combineAll( Seq( - PureContext.build(V3, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(V3, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(Global, V3).withEnvironment[Environment], WavesContext.build( Global, diff --git a/node/src/test/scala/com/wavesplatform/transaction/SponsorFeeTransactionSpecification.scala b/node/src/test/scala/com/wavesplatform/transaction/SponsorFeeTransactionSpecification.scala index d5cd628e1f7..decb0f63800 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/SponsorFeeTransactionSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/SponsorFeeTransactionSpecification.scala @@ -21,14 +21,8 @@ import play.api.libs.json.Json class SponsorFeeTransactionSpecification extends PropSpec with WithState { val One = 100000000L - val NgAndSponsorshipSettings: FunctionalitySettings = TestFunctionalitySettings.Enabled.copy( - preActivatedFeatures = Map(NG.id -> 0, FeeSponsorship.id -> 0, SmartAccounts.id -> 0), - blocksForFeatureActivation = 1, - featureCheckBlocksPeriod = 1 - ) - val BlockV5Settings: FunctionalitySettings = NgAndSponsorshipSettings.copy( - preActivatedFeatures = NgAndSponsorshipSettings.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0) - ) + val NgAndSponsorshipSettings: FunctionalitySettings = TestFunctionalitySettings.Enabled.copy(featureCheckBlocksPeriod = 1, blocksForFeatureActivation = 1, preActivatedFeatures = Map(NG.id -> 0, FeeSponsorship.id -> 0, SmartAccounts.id -> 0)) + val BlockV5Settings: FunctionalitySettings = NgAndSponsorshipSettings.copy(preActivatedFeatures = NgAndSponsorshipSettings.preActivatedFeatures + (BlockchainFeatures.BlockV5.id -> 0)) property("SponsorFee serialization roundtrip") { forAll(sponsorFeeGen) { tx: SponsorFeeTransaction => diff --git a/node/src/test/scala/com/wavesplatform/transaction/TxHelpers.scala b/node/src/test/scala/com/wavesplatform/transaction/TxHelpers.scala index 0d955d111ad..77a81f017b1 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/TxHelpers.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/TxHelpers.scala @@ -4,14 +4,14 @@ import com.google.common.primitives.Ints import com.wavesplatform.TestValues import com.wavesplatform.account.{Address, AddressOrAlias, KeyPair} import com.wavesplatform.common.state.ByteStr -import com.wavesplatform.common.utils._ +import com.wavesplatform.common.utils.* import com.wavesplatform.lang.script.Script import com.wavesplatform.lang.script.v1.ExprScript import com.wavesplatform.lang.v1.FunctionHeader import com.wavesplatform.lang.v1.compiler.Terms.{EXPR, FUNCTION_CALL} import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3 import com.wavesplatform.state.{DataEntry, StringDataEntry} -import com.wavesplatform.test._ +import com.wavesplatform.test.* import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves} import com.wavesplatform.transaction.assets.{IssueTransaction, ReissueTransaction} import com.wavesplatform.transaction.assets.exchange.{AssetPair, ExchangeTransaction, Order, OrderType} @@ -20,8 +20,8 @@ import com.wavesplatform.transaction.smart.{InvokeExpressionTransaction, InvokeS import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment import com.wavesplatform.transaction.smart.script.ScriptCompiler import com.wavesplatform.transaction.transfer.TransferTransaction +import com.wavesplatform.transaction.utils.EthConverters.* import com.wavesplatform.transaction.utils.Signed -import com.wavesplatform.transaction.utils.EthConverters._ import org.web3j.crypto.ECKeyPair object TxHelpers { @@ -32,6 +32,7 @@ object TxHelpers { def defaultAddress: Address = defaultSigner.toAddress def secondSigner: KeyPair = signer(1) def secondAddress: Address = secondSigner.toAddress + def voidAddress: Address = Address(new Array[Byte](20)) def defaultEthSigner: ECKeyPair = defaultSigner.toEthKeyPair @@ -66,10 +67,13 @@ object TxHelpers { .selfSigned(TxVersion.V2, defaultSigner, asset, amount, reissuable = true, TestValues.fee, timestamp) .explicitGet() + def dataEntry(account: KeyPair, value: DataEntry[?]): DataTransaction = + DataTransaction.selfSigned(TxVersion.V1, account, Seq(value), TestValues.fee * 3, timestamp).explicitGet() + def data(account: KeyPair = defaultSigner, key: String = "test", value: String = "test"): DataTransaction = dataWithMultipleEntries(account, Seq(StringDataEntry(key, value))) - def dataWithMultipleEntries(account: KeyPair, entries: Seq[DataEntry[_]]): DataTransaction = + def dataWithMultipleEntries(account: KeyPair, entries: Seq[DataEntry[?]]): DataTransaction = DataTransaction.selfSigned(TxVersion.V1, account, entries, TestValues.fee * 3, timestamp).explicitGet() def orderV3(orderType: OrderType, asset: Asset, feeAsset: Asset): Order = { @@ -105,7 +109,13 @@ object TxHelpers { ) } - def exchange(order1: Order, order2: Order, version: TxVersion = TxVersion.V2, timestamp: TxTimestamp = this.timestamp, matcher: KeyPair = defaultSigner): ExchangeTransaction = { + def exchange( + order1: Order, + order2: Order, + version: TxVersion = TxVersion.V2, + timestamp: TxTimestamp = this.timestamp, + matcher: KeyPair = defaultSigner + ): ExchangeTransaction = { ExchangeTransaction .signed( version, @@ -146,7 +156,7 @@ object TxHelpers { fee: Long = TestValues.fee, feeAssetId: Asset = Waves ): InvokeScriptTransaction = { - val fc = functionCall(func, args: _*) + val fc = functionCall(func, args*) Signed.invokeScript(TxVersion.V1, defaultSigner, dApp, Some(fc), payments, fee, feeAssetId, timestamp) } diff --git a/node/src/test/scala/com/wavesplatform/transaction/smart/script/estimator/FunctionComplexityTest.scala b/node/src/test/scala/com/wavesplatform/transaction/smart/script/estimator/FunctionComplexityTest.scala index 429cc0c7cc3..d2266813610 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/smart/script/estimator/FunctionComplexityTest.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/smart/script/estimator/FunctionComplexityTest.scala @@ -41,7 +41,7 @@ class FunctionComplexityTest(estimator: ScriptEstimator) extends PropSpec with T Monoid .combineAll( Seq( - PureContext.build(version, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(version, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(Global, version).withEnvironment[Environment], WavesContext.build( Global, diff --git a/node/src/test/scala/com/wavesplatform/transaction/smart/script/estimator/UserFunctionComplexityTest.scala b/node/src/test/scala/com/wavesplatform/transaction/smart/script/estimator/UserFunctionComplexityTest.scala index ea1827e8487..00cdf308a6f 100644 --- a/node/src/test/scala/com/wavesplatform/transaction/smart/script/estimator/UserFunctionComplexityTest.scala +++ b/node/src/test/scala/com/wavesplatform/transaction/smart/script/estimator/UserFunctionComplexityTest.scala @@ -32,7 +32,7 @@ class UserFunctionComplexityTest(estimator: ScriptEstimator) extends PropSpec wi Monoid .combineAll( Seq( - PureContext.build(V1, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(V1, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(Global, V1).withEnvironment[Environment], WavesContext.build( Global, @@ -97,7 +97,7 @@ class UserFunctionComplexityTest(estimator: ScriptEstimator) extends PropSpec wi Monoid .combineAll( Seq( - PureContext.build(V2, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(V2, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(Global, V2).withEnvironment[Environment], WavesContext.build( Global, @@ -162,7 +162,7 @@ class UserFunctionComplexityTest(estimator: ScriptEstimator) extends PropSpec wi Monoid .combineAll( Seq( - PureContext.build(V3, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment], + PureContext.build(V3, useNewPowPrecision = true).withEnvironment[Environment], CryptoContext.build(Global, V3).withEnvironment[Environment], WavesContext.build( Global, diff --git a/node/src/test/scala/com/wavesplatform/utx/UtxPoolSpecification.scala b/node/src/test/scala/com/wavesplatform/utx/UtxPoolSpecification.scala index 85933a25e1c..15c8a325673 100644 --- a/node/src/test/scala/com/wavesplatform/utx/UtxPoolSpecification.scala +++ b/node/src/test/scala/com/wavesplatform/utx/UtxPoolSpecification.scala @@ -86,13 +86,11 @@ class UtxPoolSpecification val settings = origSettings.copy( blockchainSettings = BlockchainSettings( 'T', - FunctionalitySettings.TESTNET.copy( - preActivatedFeatures = Map( + FunctionalitySettings.TESTNET.copy(preActivatedFeatures = Map( BlockchainFeatures.MassTransfer.id -> 0, BlockchainFeatures.SmartAccounts.id -> 0, BlockchainFeatures.Ride4DApps.id -> 0 - ) - ), + )), genesisSettings, RewardsSettings.TESTNET ), diff --git a/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/package.scala b/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/package.scala index 8f9d36647c9..7afdc5bd43e 100644 --- a/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/package.scala +++ b/repl/shared/src/main/scala/com/wavesplatform/lang/v1/repl/package.scala @@ -22,7 +22,7 @@ package object repl { val initialCtx: CTX[Environment] = CryptoContext.build(global, version).withEnvironment[Environment] |+| - PureContext.build(version, fixUnicodeFunctions = true, useNewPowPrecision = true).withEnvironment[Environment] |+| + PureContext.build(version, useNewPowPrecision = true).withEnvironment[Environment] |+| WavesContext.build(global, directives) def buildEnvironment(settings: Option[NodeConnectionSettings]): Environment[Future] =