Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
phearnot committed Oct 18, 2023
1 parent 3183ae6 commit 0d12e8f
Show file tree
Hide file tree
Showing 28 changed files with 205 additions and 187 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
path: ~/.cache/coursier
key: coursier-cache
- name: Check PR
run: sbt --mem 6144 --batch checkPR
run: sbt --mem 6144 --batch ;checkPR;completeQaseRun
env:
QASE_ENABLE: true
QASE_RUN_NAME: checkPR
Expand Down
22 changes: 8 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ buildTarballsForDocker := {
}

lazy val checkPRRaw = taskKey[Unit]("Build a project and run unit tests")
checkPRRaw := Def.taskDyn {
val res = Def
checkPRRaw := Def
.sequential(
`waves-node` / clean,
Def.task {
Expand All @@ -209,19 +208,9 @@ checkPRRaw := Def.taskDyn {
(`node-it` / Test / compile).value
(benchmark / Test / compile).value
(`node-generator` / Compile / compile).value
(`ride-runner` / Test / compile).value
}
)
.result
.value

Def.task {
(`lang-testkit` / Test / runMain).toTask(" com.wavesplatform.report.QaseRunCompleter").value
res match {
case Inc(inc: Incomplete) => throw inc
case Value(v) => v
}
}
}.value
).value

def checkPR: Command = Command.command("checkPR") { state =>
val newState = Project
Expand All @@ -234,6 +223,11 @@ def checkPR: Command = Command.command("checkPR") { state =>
state
}

lazy val completeQaseRun = taskKey[Unit]("Complete Qase run")
completeQaseRun := Def.task {
(`lang-testkit` / Test / runMain).toTask(" com.wavesplatform.report.QaseRunCompleter").value
}.value

lazy val buildDebPackages = taskKey[Unit]("Build debian packages")
buildDebPackages := {
(`grpc-server` / Debian / packageBin).value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.wavesplatform.lang.contract.meta
import com.wavesplatform.lang.v1.compiler.Types.FINAL
import com.wavesplatform.protobuf.dapp.DAppMeta

private[meta] trait MetaMapperStrategy[V <: MetaVersion] {
private[meta] trait MetaMapperStrategy {
def toProto(data: List[List[FINAL]], nameMap: Map[String, String] = Map.empty): Either[String, DAppMeta]
def fromProto(meta: DAppMeta): Either[String, List[List[FINAL]]]
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package com.wavesplatform.lang.contract.meta

sealed trait MetaVersion {
type Self <: MetaVersion
val strategy: MetaMapperStrategy[Self]
val strategy: MetaMapperStrategy
val number: Int
}

object V1 extends MetaVersion {
override type Self = V1.type
override val strategy = MetaMapperStrategyV1
override val strategy: MetaMapperStrategy = MetaMapperStrategyV1
override val number: Int = 1
}

object V2 extends MetaVersion {
override type Self = V2.type
override val strategy = MetaMapperStrategyV2
override val strategy: MetaMapperStrategy = MetaMapperStrategyV2
override val number: Int = 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ package object meta {

object MetaMapperStrategyV1
extends DataMetaMapper(unionTypeMapper, V1)
with MetaMapperStrategy[V1.Self]
with MetaMapperStrategy

object MetaMapperStrategyV2
extends DataMetaMapper(listTypeMapper, V2)
with MetaMapperStrategy[V2.Self]
with MetaMapperStrategy
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.wavesplatform.lang.v1.compiler

import java.nio.charset.StandardCharsets

import cats.Eval
import cats.instances.list.*
import cats.syntax.traverse.*
import com.wavesplatform.common.state.ByteStr
import com.wavesplatform.lang.{ExecutionError, CommonError}
import com.wavesplatform.lang.{CommonError, ExecutionError}
import com.wavesplatform.lang.v1.ContractLimits.*
import com.wavesplatform.lang.v1.FunctionHeader
import com.wavesplatform.lang.v1.compiler.Types.*
import com.wavesplatform.lang.v1.evaluator.ctx.impl.PureContext.MaxListLengthV4
import monix.eval.Coeval

import scala.annotation.nowarn

object Terms {
val DataTxMaxBytes: Int = 150 * 1024 // should be the same as DataTransaction.MaxBytes
val DataTxMaxProtoBytes: Int = 165947 // depends from DataTransaction.MaxProtoBytes
Expand Down Expand Up @@ -242,6 +243,7 @@ object Terms {
lazy val TRUE: CONST_BOOLEAN = CONST_BOOLEAN(true)
lazy val FALSE: CONST_BOOLEAN = CONST_BOOLEAN(false)

@nowarn // do not warn about private constructor
case class CaseObj private (caseType: CASETYPEREF, fields: Map[String, EVALUATED]) extends EVALUATED {
// must be with fixArrIndentation = false, because of makeString behavior before RideV6 (NODE-2370)
override def toString: String = TermPrinter().string(this)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wavesplatform.lang.v1.compiler

import cats.syntax.traverse.*
import cats.instances.list.*
import cats.syntax.traverse.*

import scala.annotation.tailrec

Expand All @@ -14,36 +14,36 @@ object Types {
def fields: List[(String, FINAL)] = List()
def typeList: List[REAL]
def unfold: FINAL = this
def union: UNION = UNION(typeList)
def union: UNION = UNION(typeList)
def name: String
override def toString: String = name
}
sealed trait PARAMETERIZED extends TYPE

case class TYPEPARAM(char: Byte) extends PARAMETERIZED with SINGLE { override def toString: String = char.toChar.toString }
case class PARAMETERIZEDLIST(t: TYPE) extends PARAMETERIZED with SINGLE { override def toString: String = s"List[$t]" }
case class TYPEPARAM(char: Byte) extends PARAMETERIZED with SINGLE { override def toString: String = char.toChar.toString }
case class PARAMETERIZEDLIST(t: TYPE) extends PARAMETERIZED with SINGLE { override def toString: String = s"List[$t]" }
case class PARAMETERIZEDTUPLE(t: List[TYPE]) extends PARAMETERIZED with SINGLE { override def toString: String = t.mkString("(", ", ", ")") }
case class PARAMETERIZEDUNION(l: List[SINGLE]) extends PARAMETERIZED { override def toString: String = l.mkString("|")}
case object NOTHING extends REAL { override val name = "Nothing"; override val typeList = List() }
case object LONG extends REAL { override val name = "Int"; override val typeList = List(this) }
case object BIGINT extends REAL { override val name = "BigInt"; override val typeList = List(this) }
case object BYTESTR extends REAL { override val name = "ByteVector"; override val typeList = List(this) }
case object BOOLEAN extends REAL { override val name = "Boolean"; override val typeList = List(this) }
case object STRING extends REAL { override val name = "String"; override val typeList = List(this) }
case class PARAMETERIZEDUNION(l: List[SINGLE]) extends PARAMETERIZED { override def toString: String = l.mkString("|") }
case object NOTHING extends REAL { override val name = "Nothing"; override val typeList: List[REAL] = List() }
case object LONG extends REAL { override val name = "Int"; override val typeList: List[REAL] = List(this) }
case object BIGINT extends REAL { override val name = "BigInt"; override val typeList: List[REAL] = List(this) }
case object BYTESTR extends REAL { override val name = "ByteVector"; override val typeList: List[REAL] = List(this) }
case object BOOLEAN extends REAL { override val name = "Boolean"; override val typeList: List[REAL] = List(this) }
case object STRING extends REAL { override val name = "String"; override val typeList: List[REAL] = List(this) }
case class LIST(innerType: FINAL) extends REAL {
override lazy val name: String = "List[" ++ innerType.toString ++ "]"
override def typeList: List[REAL] = List(this)
}
sealed trait UNIONLIKE extends FINAL
case object ANY extends UNIONLIKE { override val name = "Any"; override val typeList = List() }
case object ANY extends UNIONLIKE { override val name = "Any"; override val typeList: List[REAL] = List() }
case class UNION(override val typeList: List[REAL], n: Option[String] = None) extends UNIONLIKE {
override lazy val fields = typeList.map(_.fields.toSet).reduce(_ intersect _).toList
override val name = if (n.nonEmpty) n.get else typeList.sortBy(_.toString).mkString("|")
override lazy val fields: List[(String, FINAL)] = typeList.map(_.fields.toSet).reduce(_ intersect _).toList
override val name: String = if (n.nonEmpty) n.get else typeList.sortBy(_.toString).mkString("|")

override def equals(obj: Any): Boolean =
obj match {
case UNION(typeList, _) if typeList.sortBy(_.toString) == this.typeList.sortBy(_.toString) => true
case _ => false
case _ => false
}

override def unfold: UNIONLIKE = {
Expand All @@ -60,7 +60,7 @@ object Types {
}

case class TUPLE(types: List[FINAL]) extends REAL {
override def name: String = types.mkString("(", ", ", ")")
override def name: String = types.mkString("(", ", ", ")")
override def typeList: List[REAL] = List(this)

override def fields: List[(String, FINAL)] =
Expand All @@ -71,7 +71,7 @@ object Types {
||
\/
(A1, ..., Z1) | ... | (A1, ..., Zk) | ... | (An, ..., Zk)
*/
*/
override def unfold: FINAL = {
val regrouped = regroup(types.map(_.typeList)).map(t => TUPLE(t.toList))
UNION.reduce(UNION.create(regrouped))
Expand Down Expand Up @@ -100,57 +100,58 @@ object Types {

object UNION {
def create(l: Seq[FINAL], n: Option[String] = None): UNIONLIKE = {
if(l.contains(ANY)) {
if (l.contains(ANY)) {
ANY
} else {
new UNION(l.flatMap {
case NOTHING => List.empty
case UNION(inner, _) => inner
case s: REAL => List(s)
case ANY => ???
}
.toList
.distinct ,
n)
new UNION(
l.flatMap {
case NOTHING => List.empty
case UNION(inner, _) => inner
case s: REAL => List(s)
case ANY => ???
}.toList
.distinct,
n
)
}
}

def apply(l: FINAL*): UNIONLIKE = create(l.toList)

def reduce(u: UNIONLIKE): FINAL = u match {
case UNION(Nil, _) => throw new Exception("Empty union")
case UNION(Nil, _) => throw new Exception("Empty union")
case UNION(x :: Nil, _) => x
case _ => u
case _ => u
}
}

implicit class TypeExt(l1: FINAL) {
def equivalent(l2: FINAL): Boolean = (l1, l2) match {
case (l1: TUPLE, l2: TUPLE) =>
(l1.types.length == l2.types.length) && {
val unfolded = l1.unfold
if (l1 == unfolded)
(l1.types zip l2.types).forall { case (t1, t2) => t1 equivalent t2 }
else
unfolded equivalent l2.unfold
}
case (l1: LIST, l2: LIST) => l1.innerType equivalent l2.innerType
case (l1: REAL, l2: REAL) => l1 == l2
val unfolded = l1.unfold
if (l1 == unfolded)
(l1.types zip l2.types).forall { case (t1, t2) => t1 equivalent t2 }
else
unfolded equivalent l2.unfold
}
case (l1: LIST, l2: LIST) => l1.innerType equivalent l2.innerType
case (l1: REAL, l2: REAL) => l1 == l2
case (l1: UNION, l2: UNION) =>
l1.typeList.length == l2.typeList.length &&
l1.typeList.length == l2.typeList.length &&
(l1.unfold.typeList.sortBy(_.name) zip l2.unfold.typeList.sortBy(_.name))
.forall { case (t1, t2) => t1 equivalent t2 }
case (l1: FINAL, l2: FINAL) => l1.union equivalent l2.union
}

def >=(l2: FINAL): Boolean = (l1, l2) match {
case (ANY, _) => true
case (l1, UNION(l2, _)) => l2.forall(l1 >= _)
case (UNION(l1, _), l2) => l1.exists(_ >= l2)
case (_, ANY) => false
case (_, NOTHING) => true
case (NOTHING, _) => false
case (LIST(t1), LIST(t2)) => t1 >= t2
case (ANY, _) => true
case (l1, UNION(l2, _)) => l2.forall(l1 >= _)
case (UNION(l1, _), l2) => l1.exists(_ >= l2)
case (_, ANY) => false
case (_, NOTHING) => true
case (NOTHING, _) => false
case (LIST(t1), LIST(t2)) => t1 >= t2
case (TUPLE(types1), TUPLE(types2)) =>
types1.length == types2.length && (types1 zip types2).forall { case (t1, t2) => t1 >= t2 }
case (l1: REAL, l2: REAL) => l1 equivalent l2
Expand All @@ -162,10 +163,10 @@ object Types {
@tailrec
def check(tpe: FINAL): Boolean = {
tpe match {
case Types.UNION(types, _) if types.size > 1 => true
case Types.UNION(types, _) if types.size > 1 => true
case Types.LIST(Types.UNION(types, _)) if types.size > 1 => true
case Types.LIST(inner@Types.LIST(_)) => check(inner)
case _ => false
case Types.LIST(inner @ Types.LIST(_)) => check(inner)
case _ => false
}
}
check(l1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object BinaryOperation {
}
case object GT_OP extends BinaryOperation {
val func = ">"
override def parser[A: P] = P(">" ~ !P("=")).map(_ => this)
override def parser[A: P]: P[BinaryOperation] = P(">" ~ !P("=")).map(_ => this)
}
case object SUM_OP extends BinaryOperation {
val func = "+"
Expand All @@ -64,15 +64,15 @@ object BinaryOperation {
override val func: String = "%"
}
case object LE_OP extends BinaryOperation {
val func = ">="
override def parser[A: P] = P("<=").map(_ => this)
val func = ">="
override def parser[A: P]: P[BinaryOperation] = P("<=").map(_ => this)
override def expr(shiftedStart: Int, shiftedEnd: Int, op1: EXPR, op2: EXPR): EXPR = {
BINARY_OP(Pos.fromShifted(shiftedStart, shiftedEnd), op2, LE_OP, op1)
}
}
case object LT_OP extends BinaryOperation {
val func = ">"
override def parser[A: P] = P("<" ~ !P("=")).map(_ => this)
val func = ">"
override def parser[A: P]: P[BinaryOperation] = P("<" ~ !P("=")).map(_ => this)
override def expr(shiftedStart: Int, shiftedEnd: Int, op1: EXPR, op2: EXPR): EXPR = {
BINARY_OP(Pos.fromShifted(shiftedStart, shiftedEnd), op2, LT_OP, op1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,15 @@ object JsAPITest extends JsTestBase {
}

test("ill-formed characters") {
val invalidChar = '\ud87e'
val script =
"""
s"""
|{-# STDLIB_VERSION 6 #-}
|{-# CONTENT_TYPE DAPP #-}
|{-# SCRIPT_TYPE ACCOUNT #-}
|
|func call(a: String, b: Int) = {
| let zzz = "aaa\ud87ebbb"
| let zzz = "aaa${invalidChar}bbb"
| ([], zzz)
|}
""".stripMargin
Expand Down
14 changes: 14 additions & 0 deletions lang/tests/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date %-5level [%.15thread] %logger{26} - %msg%n</pattern>
</encoder>
</appender>

<logger name="scorex.crypto.signatures.Curve25519$" level="INFO"/>

<root level="${logback.test.level:-OFF}">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class ScriptParserTest extends PropSpec with ScriptGenParser {
}

property("invalid base16 definition") {
parse("base16'mid-size'") shouldBe CONST_BYTESTR(Pos(0, 16), PART.INVALID(Pos(8, 15), "Unrecognized character: m"), None)
parse("base16'mid-size'") shouldBe CONST_BYTESTR(Pos(0, 16), PART.INVALID(Pos(8, 15), "invalid characters encountered in Hex string"), None)
parse("base16'123'") shouldBe CONST_BYTESTR(Pos(0, 11), PART.INVALID(Pos(8, 10), "Invalid input length 3"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ object AttachedPayment {
case class Invocation(dApp: String, call: Call, payments: Seq[AttachedPayment], stateChanges: StateChangesDetails)
object Invocation {
implicit val invokationFormat: Reads[Invocation] = new Reads[Invocation] {
override def reads(json: JsValue) =
override def reads(json: JsValue): JsResult[Invocation] =
JsSuccess(
Invocation(
(json \ "dApp").as[String],
Expand Down
Loading

0 comments on commit 0d12e8f

Please sign in to comment.