Skip to content

Commit

Permalink
Update scala to 2.13.2
Browse files Browse the repository at this point in the history
- `RightProjection` is deprecated, `toOption.get` is now recommended: scala/scala#6682
- varargs now works only for immutable Seq, so in `Network` we can't pass
  directly our `Array`: https://docs.scala-lang.org/overviews/core/collections-migration-213.html
- Regarding the `import Ordering.Double.IeeeOrdering` in `AVectorSpec`,
  have a look at: https://www.scala-lang.org/api/2.13.2/scala/math/Ordering$$Double$.html
  • Loading branch information
tdroxler authored and aloiscochard committed Apr 29, 2020
1 parent 661e291 commit daebdb1
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 69 deletions.
11 changes: 2 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ lazy val macros = subProject("macros")
val commonSettings = Seq(
organization := "org.alephium",
version := "0.3.0-SNAPSHOT",
scalaVersion := "2.12.10",
scalaVersion := "2.13.2",
parallelExecution in Test := false,
scalacOptions ++= Seq(
// "-Xdisable-assertions", // TODO: use this properly
Expand All @@ -89,7 +89,6 @@ val commonSettings = Seq(
"-unchecked",
"-Xfatal-warnings",
"-Xlint:adapted-args",
"-Xlint:by-name-right-associative",
"-Xlint:constant",
"-Xlint:delayedinit-select",
"-Xlint:doc-detached",
Expand All @@ -104,15 +103,8 @@ val commonSettings = Seq(
"-Xlint:private-shadow",
"-Xlint:stars-align",
"-Xlint:type-parameter-shadow",
"-Xlint:unsound-match",
"-Yno-adapted-args",
"-Ypartial-unification",
"-Ywarn-dead-code",
"-Ywarn-extra-implicit",
"-Ywarn-inaccessible",
"-Ywarn-infer-any",
"-Ywarn-nullary-override",
"-Ywarn-nullary-unit",
"-Ywarn-numeric-widen",
"-Ywarn-unused:implicits",
"-Ywarn-unused:imports",
Expand Down Expand Up @@ -145,6 +137,7 @@ val wartsCompileExcludes = Seq(
Wart.Nothing,
Wart.Return, // Covered by scalastyle
Wart.Any,
Wart.StringPlusAny,
Wart.Equals
)

Expand Down
5 changes: 2 additions & 3 deletions crypto/src/test/scala/org/alephium/crypto/HashSpec.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.alephium.crypto

import akka.util.ByteString
import org.scalatest.EitherValues._

import org.alephium.serde._
import org.alephium.util.AlephiumSpec
Expand All @@ -18,7 +17,7 @@ class HashSpec extends AlephiumSpec {

it should "serde correctly" in {
val input = provider.hash(message)
val output = deserialize[T](serialize(input)).right.value
val output = deserialize[T](serialize(input)).toOption.get
output is input
}
}
Expand All @@ -35,7 +34,7 @@ class HashSpec extends AlephiumSpec {
it should "serde correctly" in {
for ((message, _) <- tests) {
val input = provider.hash(message)
val output = deserialize[T](serialize(input)).right.value
val output = deserialize[T](serialize(input)).toOption.get
output is input
}
}
Expand Down
5 changes: 2 additions & 3 deletions project/Boilerplate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ object Boilerplate {
|package org.alephium.serde
|
|import org.alephium.util.AlephiumSpec
|import org.scalatest.EitherValues._
|
|class ProductSerdeSpec extends AlephiumSpec {
|
Expand All @@ -202,7 +201,7 @@ object Boilerplate {
+ it should "serde $arity fields" in {
+ forAll { ($fields) =>
+ val input = Test$arity(${`a..n`})
+ val output = deserialize[Test$arity](serialize(input)).right.value
+ val output = deserialize[Test$arity](serialize(input)).toOption.get
+ output is input
+ }
+ }
Expand All @@ -211,7 +210,7 @@ object Boilerplate {
+ forAll { ($fields) =>
+ val input = (${`a..n`})
+ val serde = Serde.tuple$arity[$types]
+ val output = serde.deserialize(serde.serialize(input)).right.value
+ val output = serde.deserialize(serde.serialize(input)).toOption.get
+ output is input
+ }
+ }
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sbt._

object Version {
lazy val akka = "2.6.3"
lazy val akka = "2.6.4"
lazy val circe = "0.13.0"
lazy val `akka-http` = "10.1.11"
}
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.4.0")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.4.5")
9 changes: 4 additions & 5 deletions rpc/src/test/scala/org/alephium/rpc/CirceUtilsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import io.circe.generic.semiauto._
import io.circe.parser._
import io.circe.syntax._
import org.scalatest.Assertion
import org.scalatest.EitherValues._

import org.alephium.util.{AlephiumSpec, AVector}

Expand All @@ -25,7 +24,7 @@ class CirceUtilsSpec extends AlephiumSpec {
def check[T: Codec](input: T, rawJson: String): Assertion = {
val json = input.asJson
print(json) is rawJson
json.as[T].right.get is input
json.as[T] isE input
}

it should "encode/decode vectors" in {
Expand All @@ -48,13 +47,13 @@ class CirceUtilsSpec extends AlephiumSpec {

it should "fail for address based on host name" in {
val rawJson = addressJson("foobar")
parse(rawJson).right.value.as[InetSocketAddress].isLeft is true
parse(rawJson).toOption.get.as[InetSocketAddress].isLeft is true
}

it should "encode/decode hexstring" in {
val jsonRaw = """{"bar": "48656c6c6f20776f726c642021"}"""
val json = parse(jsonRaw).right.value
val foo = json.as[Foo].right.value
val json = parse(jsonRaw).toOption.get
val foo = json.as[Foo].toOption.get
foo.bar.utf8String is "Hello world !"
}
}
14 changes: 7 additions & 7 deletions rpc/src/test/scala/org/alephium/rpc/model/JsonRPCSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class JsonRPCSpec extends AlephiumSpec with EitherValues with Inside {
def handler(method: String): JsonRPC.Handler = Map((method, (_: JsonRPC.Request) => dummy))

def parseAs[A: Decoder](jsonRaw: String): A = {
val json = parse(jsonRaw).right.value
json.as[A].right.value
val json = parse(jsonRaw).toOption.get
json.as[A].toOption.get
}

def parseNotification(jsonRaw: String): JsonRPC.Notification =
parseNotificationUnsafe(jsonRaw).asNotification.right.value
parseNotificationUnsafe(jsonRaw).asNotification.toOption.get

def parseNotificationUnsafe(jsonRaw: String): JsonRPC.NotificationUnsafe =
parseAs[JsonRPC.NotificationUnsafe](jsonRaw)
Expand Down Expand Up @@ -166,7 +166,7 @@ class JsonRPCSpec extends AlephiumSpec with EitherValues with Inside {

it should "parse response - success" in {
val jsonRaw = """{"jsonrpc": "2.0", "result": 42, "id": 1}"""
val response = parse(jsonRaw).right.value.as[JsonRPC.Response].right.value
val response = parse(jsonRaw).toOption.get.as[JsonRPC.Response].toOption.get

inside(response) {
case JsonRPC.Response.Success(result, id) =>
Expand All @@ -177,7 +177,7 @@ class JsonRPCSpec extends AlephiumSpec with EitherValues with Inside {

it should "parse response - failure" in {
val jsonRaw = """{"jsonrpc":"2.0","error":{"code":42,"message":"foo"},"id":1}"""
val response = parse(jsonRaw).right.value.as[JsonRPC.Response].right.value
val response = parse(jsonRaw).toOption.get.as[JsonRPC.Response].toOption.get

inside(response) {
case JsonRPC.Response.Failure(error, id) =>
Expand All @@ -188,15 +188,15 @@ class JsonRPCSpec extends AlephiumSpec with EitherValues with Inside {

it should "parse success" in {
val jsonRaw = """{"jsonrpc": "2.0", "result": 42, "id": 1}"""
val success = parse(jsonRaw).right.value.as[JsonRPC.Response.Success].right.value
val success = parse(jsonRaw).toOption.get.as[JsonRPC.Response.Success].toOption.get

success.result is Json.fromInt(42)
success.id is 1
}

it should "parse success - fail on wrong rpc version" in {
val jsonRaw = """{"jsonrpc": "1.0", "result": 42, "id": 1}"""
val error = parse(jsonRaw).right.value.as[JsonRPC.Response].left.value
val error = parse(jsonRaw).toOption.get.as[JsonRPC.Response].left.value
error.message is "Invalid JSON-RPC version '1.0'"
}
}
38 changes: 19 additions & 19 deletions serde/src/test/scala/org/alephium/serde/SerdeSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class SerdeSpec extends AlephiumSpec {
it should "serde correctly" in {
forAll { b: Byte =>
val bb = deserialize[Byte](serialize(b))
bb.right.value is b
bb isE b
}

forAll { b: Byte =>
val input = ByteString(b)
val output = serialize(deserialize[Byte](input).right.value)
val output = serialize(deserialize[Byte](input).toOption.get)
output is input
}
}
Expand All @@ -50,12 +50,12 @@ class SerdeSpec extends AlephiumSpec {
it should "serde correctly" in {
forAll { n: Int =>
val nn = deserialize[Int](serialize(n))
nn.right.value is n
nn isE n
}

forAll { (a: Byte, b: Byte, c: Byte, d: Byte) =>
val input = ByteString(a, b, c, d)
val output = serialize(deserialize[Int](input).right.value)
val output = serialize(deserialize[Int](input).toOption.get)
output is input
}
}
Expand All @@ -69,30 +69,30 @@ class SerdeSpec extends AlephiumSpec {
it should "serde correctly" in {
forAll { n: Long =>
val nn = deserialize[Long](serialize(n))
nn.right.value is n
nn isE n
}
}

checkException(LongSerde)

"Serde for ByteString" should "serialize correctly" in {
deserialize[ByteString](serialize(ByteString.empty)).right.value is ByteString.empty
deserialize[ByteString](serialize(ByteString.empty)) isE ByteString.empty
forAll { n: Int =>
val bs = ByteString.fromInts(n)
deserialize[ByteString](serialize(bs)).right.value is bs
deserialize[ByteString](serialize(bs)) isE bs
}
}

"Serde for String" should "serialize correctly" in {
forAll { s: String =>
deserialize[String](serialize(s)).right.value is s
deserialize[String](serialize(s)) isE s
}
}

"Serde for BigInt" should "serde correctly" in {
forAll { n: Long =>
val bn = BigInt(n)
val bnn = deserialize[BigInt](serialize(bn)).right.value
val bnn = deserialize[BigInt](serialize(bn)).toOption.get
bnn is bn
}
}
Expand All @@ -101,7 +101,7 @@ class SerdeSpec extends AlephiumSpec {
forAll(bytesGen) { input: AVector[Byte] =>
{
val serde = Serde.fixedSizeSerde(input.length, byteSerde)
val output = serde.deserialize(serde.serialize(input)).right.value
val output = serde.deserialize(serde.serialize(input)).toOption.get
output is input
}
{
Expand All @@ -121,23 +121,23 @@ class SerdeSpec extends AlephiumSpec {
"Serde for sequence" should "serde correctly" in {
forAll(bytesGen) { input: AVector[Byte] =>
val serde = Serde.dynamicSizeSerde(byteSerde)
val output = serde.deserialize(serde.serialize(input)).right.value
val output = serde.deserialize(serde.serialize(input)).toOption.get
output is input
}
}

"Serde for option" should "work" in {
forAll(Gen.option(Gen.choose(0, Int.MaxValue))) { input =>
deserialize[Option[Int]](serialize(input)).right.value is input
deserialize[Option[Int]](serialize(input)) isE input
}
}

"Serde for either" should "work" in {
forAll { (left: Int, right: Long) =>
val input1: Either[Int, Long] = Left(left)
deserialize[Either[Int, Long]](serialize(input1)).right.value is input1
deserialize[Either[Int, Long]](serialize(input1)) isE input1
val input2: Either[Int, Long] = Right(right)
deserialize[Either[Int, Long]](serialize(input2)).right.value is input2
deserialize[Either[Int, Long]](serialize(input2)) isE input2
}
}

Expand All @@ -160,34 +160,34 @@ class SerdeSpec extends AlephiumSpec {
forAll { x: Int =>
val input = Test1(x)
val output = deserialize[Test1](serialize(input))
output.right.value is input
output isE input
}
}

it should "serde two fields correctly" in {
forAll { (x: Int, y: Int) =>
val input = Test2(x, y)
val output = deserialize[Test2](serialize(input))
output.right.value is input
output isE input
}
}

it should "serde three fields correctly" in {
forAll { (x: Int, y: Int, z: Int) =>
val input = Test3(x, y, z)
val output = deserialize[Test3](serialize(input))
output.right.value is input
output isE input
}
}

"Serde for address" should "serde correctly" in {
val address0 = new InetSocketAddress("127.0.0.1", 9000)
val output0 = deserialize[InetSocketAddress](serialize(address0))
output0.right.value is address0
output0 isE address0

val address1 = new InetSocketAddress("2001:0db8:85a3:0000:0000:8a2e:0370:7334", 9000)
val output1 = deserialize[InetSocketAddress](serialize(address1))
output1.right.value is address1
output1 isE address1
}

it should "fail for address based on host name" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.alephium.util
import java.util.Map.Entry
import java.util.concurrent.{ConcurrentHashMap => JCHashMap}

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

object ConcurrentHashMap {
def empty[K, V]: ConcurrentHashMap[K, V] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.alephium.util

import java.util.concurrent.{ConcurrentHashMap => JCHashMap}

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

object ConcurrentHashSet {
def empty[K]: ConcurrentHashSet[K] = {
Expand Down
2 changes: 1 addition & 1 deletion util/src/main/scala/org/alephium/util/LruCache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.alephium.util
import java.util.{LinkedHashMap, Map}
import java.util.Map.Entry

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

object LruCache {
def apply[K, V, E](maxCapacity: Int): LruCache[K, V, E] = {
Expand Down
2 changes: 1 addition & 1 deletion util/src/main/scala/org/alephium/util/Network.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object Network {
val (left, right) = address.splitAt(splitIndex)
new InetSocketAddress(left, right.tail.toInt)
}
AVector(addresses: _*)
AVector.unsafe(addresses)
}
}
}
Loading

0 comments on commit daebdb1

Please sign in to comment.