Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE2] prepare for Scala 3 migration #1113

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions be2-scala/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ assembly/ assemblyMergeStrategy := {

// ------------------------ DEPENDENCIES ------------------------ 77

val AkkaVersion = "2.6.8"
val AkkaHttpVersion = "10.2.0"
val AkkaVersion = "2.6.19"
val AkkaHttpVersion = "10.2.9"

libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-stream-typed" % AkkaVersion, // Akka streams (Graph)
Expand All @@ -144,7 +144,7 @@ libraryDependencies += "org.iq80.leveldb" % "leveldb" % "0.12"
libraryDependencies += "org.xerial.snappy" % "snappy-java" % "1.1.7.3"

// Json Parser (https://github.com/spray/spray-json)
libraryDependencies += "io.spray" %% "spray-json" % "1.3.5"
libraryDependencies += "io.spray" %% "spray-json" % "1.3.6"

// Cryptography
libraryDependencies += "com.google.crypto.tink" % "tink" % "1.5.0"
Expand All @@ -158,6 +158,5 @@ libraryDependencies += "com.networknt" % "json-schema-validator" % "1.0.60"
libraryDependencies += "com.fasterxml.jackson.core" % "jackson-databind" % "2.0.0-RC3"

// Scala file system handling
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value

conflictManager := ConflictManager.latestCompatible
1 change: 1 addition & 0 deletions be2-scala/project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ addSbtPlugin("com.sonar-scala" % "sbt-sonar" % "2.3.0")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0")
addSbtPlugin("com.rallyhealth.sbt" % "sbt-git-versioning" % "1.6.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
addSbtPlugin("ch.epfl.scala" % "sbt-scala3-migrate" % "0.5.1")
2 changes: 1 addition & 1 deletion be2-scala/src/main/scala/ch/epfl/pop/Server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import akka.actor.{ActorRef, Props}
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.{RequestContext, RouteResult}
import akka.pattern.AskableActorRef
import akka.pattern.{AskableActorRef, ask}
import akka.util.Timeout
import ch.epfl.pop.config.{RuntimeEnvironment, ServerConf}
import ch.epfl.pop.pubsub.{MessageRegistry, PubSubMediator, PublishSubscribe}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import java.io.File

import com.typesafe.config.{Config, ConfigFactory}

import scala.reflect.io.Directory
import scala.sys.SystemProperties

/** RuntimeConfiguration object provider This object provides application config for setting up akka http/actor environment
Expand All @@ -16,6 +15,14 @@ import scala.sys.SystemProperties
*/
object RuntimeEnvironment {

def deleteRecursively(f: File): Boolean = {
f.listFiles match {
case null =>
case entries => entries.foreach(deleteRecursively)
}
f.delete()
}

private lazy val sp = new SystemProperties()

private def getConfDir: String = {
Expand All @@ -24,9 +31,9 @@ object RuntimeEnvironment {
// starting the program with fresh database
println("Starting the server without any previous persistent state")

// removing database folder
val directory = new Directory(new File("database"))
if (directory.deleteRecursively()) {
// removing database directory
val database = new File("database/")
if (deleteRecursively(database)) {
println("Removed old database folder")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ object HighLevelProtocol extends DefaultJsonProtocol {
Broadcast(params.channel, params.message)
}

override def write(obj: Broadcast): JsValue = obj.toJson(ParamsFormat.write)
override def write(obj: Broadcast): JsValue = obj.toJson(ParamsFormat.write _)
}

implicit object CatchupFormat extends RootJsonFormat[Catchup] {
override def read(json: JsValue): Catchup = Catchup(json.convertTo[Params].channel)

override def write(obj: Catchup): JsValue = obj.toJson(ParamsFormat.write)
override def write(obj: Catchup): JsValue = obj.toJson(ParamsFormat.write _)
}

implicit object PublishFormat extends RootJsonFormat[Publish] {
Expand All @@ -98,19 +98,19 @@ object HighLevelProtocol extends DefaultJsonProtocol {
Publish(params.channel, params.message)
}

override def write(obj: Publish): JsValue = obj.toJson(ParamsFormat.write)
override def write(obj: Publish): JsValue = obj.toJson(ParamsFormat.write _)
}

implicit object SubscribeFormat extends RootJsonFormat[Subscribe] {
override def read(json: JsValue): Subscribe = Subscribe(json.convertTo[Params].channel)

override def write(obj: Subscribe): JsValue = obj.toJson(ParamsFormat.write)
override def write(obj: Subscribe): JsValue = obj.toJson(ParamsFormat.write _)
}

implicit object UnsubscribeFormat extends RootJsonFormat[Unsubscribe] {
override def read(json: JsValue): Unsubscribe = Unsubscribe(json.convertTo[Params].channel)

override def write(obj: Unsubscribe): JsValue = obj.toJson(ParamsFormat.write)
override def write(obj: Unsubscribe): JsValue = obj.toJson(ParamsFormat.write _)
}

implicit val errorObjectFormat: JsonFormat[ErrorObject] = jsonFormat2(ErrorObject.apply)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final case class Address(base64Data: Base64Data) {
object Address {

private val bytesCount = 20
val sha2_256 = MessageDigest.getInstance("SHA-256")
val sha2_256: MessageDigest = MessageDigest.getInstance("SHA-256")

/** Compute the address of the given public key
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object ElectionChannel {
* @return
* Future of a list of tuple containing the message and the data extracted
*/
def extractMessages[T: Manifest](dbActor: AskableActorRef = DbActor.getInstance): Future[List[(Message, T)]] = {
def extractMessages[T: reflect.ClassTag](dbActor: AskableActorRef = DbActor.getInstance): Future[List[(Message, T)]] = {
for {
DbActor.DbActorCatchupAck(messages) <- dbActor ? DbActor.Catchup(channel)
result <- Future.traverse(messages.flatMap(message =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final case class Transaction(
outputs: List[Transaction.Output],
lockTime: Int
) {
lazy val transactionId = {
lazy val transactionId: Hash = {
val strings = collection.mutable.ListBuffer.empty[String]
strings ++= inputs.foldRight(List.empty[String]) { (txin, acc) =>
txin.script.pubkey.base64Data.toString ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ch.epfl.pop.pubsub

import akka.actor.{Actor, ActorLogging, ActorRef, Props}
import akka.event.LoggingReceive
import akka.pattern.AskableActorRef
import akka.pattern.{AskableActorRef, ask}
import ch.epfl.pop.model.objects.Channel
import ch.epfl.pop.pubsub.ClientActor._
import ch.epfl.pop.pubsub.PubSubMediator._
Expand Down Expand Up @@ -92,7 +92,7 @@ object ClientActor {
final case class ConnectWsHandle(wsClient: ActorRef) extends Event

// unsubscribe from all channels
final case object DisconnectWsHandle extends Event
case object DisconnectWsHandle extends Event

// subscribe to a particular channel
final case class SubscribeTo(channel: Channel) extends Event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object Answerer {
.to(Sink.actorRef(
clientActorRef,
DisconnectWsHandle,
{ t: Throwable =>
{ (t: Throwable) =>
println(t); DisconnectWsHandle
}
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ case object LaoHandler extends MessageHandler {
_ <- dbActor ? DbActor.WriteLaoData(laoChannel, message, address)
// after creating the lao, we need to send a lao#greet message to the frontend
greet: GreetLao = GreetLao(data.id, params.get.sender, address.get, List.empty)
broadcastGreet: Base64Data = Base64Data.encode(GreetLaoFormat.write(greet).toString())
broadcastGreet: Base64Data = Base64Data.encode(GreetLaoFormat.write(greet).toString)
_ <- dbBroadcast(rpcMessage, laoChannel, broadcastGreet, laoChannel)
} yield ()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ch.epfl.pop.pubsub.graph.handlers

import akka.NotUsed
import akka.actor.ActorRef
import akka.pattern.AskableActorRef
import akka.pattern.{AskableActorRef, ask}
import akka.stream.FlowShape
import akka.stream.scaladsl.{Flow, GraphDSL, Merge, Partition}
import ch.epfl.pop.model.network.method.{Catchup, Subscribe, Unsubscribe}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class RollCallHandler(dbRef: => AskableActorRef) extends MessageHandler {
))
}
case error @ Right(_) => error
case _ => Right(PipelineError(ErrorCodes.SERVER_ERROR.id, unknownAnswer, rpcRequest.id))
case null => Right(PipelineError(ErrorCodes.SERVER_ERROR.id, unknownAnswer, rpcRequest.id))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SocialMediaHandler(dbRef: => AskableActorRef) extends MessageHandler {
case None => Right(PipelineError(ErrorCodes.SERVER_ERROR.id, "Server failed to extract LAO id for the broadcast", rpcMessage.id))
}
case error @ Right(_) => error
case _ => Right(PipelineError(ErrorCodes.SERVER_ERROR.id, unknownAnswerDatabase, rpcMessage.id))
case null => Right(PipelineError(ErrorCodes.SERVER_ERROR.id, unknownAnswerDatabase, rpcMessage.id))
}
}

Expand All @@ -79,7 +79,7 @@ class SocialMediaHandler(dbRef: => AskableActorRef) extends MessageHandler {
case None => Right(PipelineError(ErrorCodes.SERVER_ERROR.id, "Server failed to extract LAO id for the broadcast", rpcMessage.id))
}
case error @ Right(_) => error
case _ => Right(PipelineError(ErrorCodes.SERVER_ERROR.id, unknownAnswerDatabase, rpcMessage.id))
case null => Right(PipelineError(ErrorCodes.SERVER_ERROR.id, unknownAnswerDatabase, rpcMessage.id))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AddChirpSuite extends FunSuite with Matchers {
object AddChirpExample {
final val TEXT: String = "text"
final val PARENT_ID: Option[String] = None
final val TIMESTAMP = Timestamp(0)
final val TIMESTAMP: Timestamp = Timestamp(0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think at some places it was unnecessary to add the typing

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally don't mind but the "migrate" plugin made that change.


final val ADDCHIRP_MESSAGE: AddChirp = AddChirp(TEXT, PARENT_ID, TIMESTAMP)
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class ChannelSuite extends FunSuite with Matchers {
def channel = Channel("/root/full/pop")

val expected = Hash(Base64Data("pop"))
an[IllegalArgumentException] shouldNot be(thrownBy(channel))
channel.extractChildChannel should equal(expected)
}
test("Encoded LaoId extraction channel test") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class SignatureSuite extends FunSuite with Matchers with BeforeAndAfterAll {
TestObj(ed_signer, kpair)
}
// Data used for testing signature
final val dataTest = Seq("PoP-scala", "HelloWorld", "Not true is false", "😀", "OMEGA \u03A9", "\u03A8", "Non empty can be fully non empty", "Not false is true")
final val dataTest: Seq[String] = Seq("PoP-scala", "HelloWorld", "Not true is false", "😀", "OMEGA \u03A9", "\u03A8", "Non empty can be fully non empty", "Not false is true")

final val verify_pk = PublicKey(Base64Data.encode(tester.keyPair.getPublicKey))
final val verify_pk: PublicKey = PublicKey(Base64Data.encode(tester.keyPair.getPublicKey))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same


/*Provides correct signature for a msg*/
private def getTrueSignatureTest(msg: String): Signature = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ch.epfl.pop.pubsub.graph

import akka.actor.{Actor, ActorSystem, Props, Status}
import akka.pattern.AskableActorRef
import akka.pattern.{AskableActorRef, ask}
import akka.testkit.{ImplicitSender, TestKit}
import akka.util.Timeout
import ch.epfl.pop.model.network.method.message.Message
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ch.epfl.pop.pubsub.graph.handlers

import akka.actor.{Actor, ActorSystem, Props, Status}
import akka.pattern.AskableActorRef
import akka.pattern.{AskableActorRef, ask}
import akka.testkit.{ImplicitSender, TestKit}
import akka.util.Timeout
import ch.epfl.pop.model.network.method.message.Message
Expand Down Expand Up @@ -35,12 +35,12 @@ class ElectionHandlerTest extends TestKit(ActorSystem("Election-DB-System")) wit
private val keyPair: KeyPair = KeyPair()
private val electionData: ElectionData = ElectionData(Hash(Base64Data.encode("election")), keyPair)

private final val sender: PublicKey = SetupElectionExamples.SENDER_SETUPELECTION
private final val SENDER: PublicKey = SetupElectionExamples.SENDER_SETUPELECTION

private final val PUBLIC_KEY: PublicKey = PublicKey(Base64Data("jsNj23IHALvppqV1xQfP71_3IyAHzivxiCz236_zzQc="))
private final val PRIVATE_KEY: PrivateKey = PrivateKey(Base64Data("qRfms3wzSLkxAeBz6UtwA-L1qP0h8D9XI1FSvY68t7Y="))
private final val PK_OWNER: PublicKey = PublicKey(Base64Data.encode("wrongOwner"))
private final val laoDataRight: LaoData = LaoData(sender, List(sender), PRIVATE_KEY, PUBLIC_KEY, List.empty)
private final val laoDataRight: LaoData = LaoData(SENDER, List(SENDER), PRIVATE_KEY, PUBLIC_KEY, List.empty)

private final val channelDataWithSetupAndOpenAndCastMessage: ChannelData = ChannelData(ObjectType.ELECTION, List(DATA_CAST_VOTE_MESSAGE, DATA_SET_UP_OPEN_BALLOT, DATA_OPEN_MESSAGE))
private final val messages: List[Message] = List(MESSAGE_CAST_VOTE_ELECTION_WORKING, MESSAGE_SETUPELECTION_OPEN_BALLOT_WORKING, MESSAGE_OPEN_ELECTION_WORKING, MESSAGE_END_ELECTION_WORKING)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ch.epfl.pop.pubsub.graph.handlers

import akka.actor.{Actor, ActorSystem, Props, Status}
import akka.pattern.AskableActorRef
import akka.pattern.{AskableActorRef, ask}
import akka.testkit.{ImplicitSender, TestKit}
import akka.util.Timeout
import ch.epfl.pop.model.objects.DbActorNAckException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ch.epfl.pop.pubsub.graph.handlers

import akka.actor.{Actor, ActorSystem, Props, Status}
import akka.pattern.AskableActorRef
import akka.pattern.{AskableActorRef, ask}
import akka.testkit.{ImplicitSender, TestKit}
import akka.util.Timeout
import ch.epfl.pop.model.objects.DbActorNAckException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ch.epfl.pop.pubsub.graph.handlers

import akka.actor.{Actor, ActorSystem, Props, Status}
import akka.pattern.AskableActorRef
import akka.pattern.{AskableActorRef, ask}
import akka.testkit.{ImplicitSender, TestKit}
import akka.util.Timeout
import ch.epfl.pop.model.network.method.message.Message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import akka.actor.{Actor, ActorRef, ActorSystem, Props}
import akka.pattern.AskableActorRef
import akka.testkit.{ImplicitSender, TestKit}
import akka.util.Timeout
import ch.epfl.pop.config.RuntimeEnvironment.deleteRecursively
import ch.epfl.pop.model.network.method.message.data.ObjectType
import ch.epfl.pop.model.objects._
import ch.epfl.pop.pubsub.graph.{GraphMessage, PipelineError}
Expand All @@ -17,8 +18,6 @@ import org.scalatest.funsuite.{AnyFunSuiteLike => FunSuiteLike}
import org.scalatest.matchers.should.Matchers
import util.examples.data.PostTransactionMessages._

import scala.reflect.io.Directory

class CoinValidatorSuite extends TestKit(ActorSystem("coinValidatorTestActorSystem"))
with FunSuiteLike
with ImplicitSender
Expand All @@ -34,8 +33,8 @@ class CoinValidatorSuite extends TestKit(ActorSystem("coinValidatorTestActorSyst
TestKit.shutdownActorSystem(system)

// Deletes the test database
val directory = new Directory(new File(DB_TEST_FOLDER))
directory.deleteRecursively()
val directory = new File(DB_TEST_FOLDER)
deleteRecursively(directory)
}

test("Posting a transaction works as intended") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package ch.epfl.pop.pubsub.graph.validators

import akka.actor.{Actor, ActorRef, ActorSystem, Props}
import akka.pattern.AskableActorRef
import akka.pattern.{AskableActorRef, ask}
import akka.testkit.{ImplicitSender, TestKit}
import akka.util.Timeout
import ch.epfl.pop.config.RuntimeEnvironment.deleteRecursively
import ch.epfl.pop.model.network.method.message.Message
import ch.epfl.pop.model.network.method.message.data.ObjectType
import ch.epfl.pop.model.objects._
Expand All @@ -22,7 +23,6 @@ import util.examples.JsonRpcRequestExample._

import java.io.File
import java.util.concurrent.TimeUnit
import scala.reflect.io.Directory

class ElectionValidatorSuite extends TestKit(ActorSystem("electionValidatorTestActorSystem"))
with FunSuiteLike
Expand All @@ -42,16 +42,16 @@ class ElectionValidatorSuite extends TestKit(ActorSystem("electionValidatorTestA
TestKit.shutdownActorSystem(system)

// Deletes the test database
val directory = new Directory(new File(DB_TEST_FOLDER))
directory.deleteRecursively()
val directory = new File(DB_TEST_FOLDER)
deleteRecursively(directory)
}

private final val sender: PublicKey = SetupElectionExamples.SENDER_SETUPELECTION
private final val SENDER: PublicKey = SetupElectionExamples.SENDER_SETUPELECTION

private final val PUBLIC_KEY: PublicKey = PublicKey(Base64Data("jsNj23IHALvppqV1xQfP71_3IyAHzivxiCz236_zzQc="))
private final val PRIVATE_KEY: PrivateKey = PrivateKey(Base64Data("qRfms3wzSLkxAeBz6UtwA-L1qP0h8D9XI1FSvY68t7Y="))
private final val PK_WRONG: PublicKey = PublicKey(Base64Data.encode("wrongOwner"))
private final val laoDataRight: LaoData = LaoData(sender, List(sender), PRIVATE_KEY, PUBLIC_KEY, List.empty)
private final val laoDataRight: LaoData = LaoData(SENDER, List(SENDER), PRIVATE_KEY, PUBLIC_KEY, List.empty)
private final val laoDataWrong: LaoData = LaoData(PK_WRONG, List(PK_WRONG), PRIVATE_KEY, PUBLIC_KEY, List.empty)
private final val channelDataRightSetup: ChannelData = ChannelData(ObjectType.LAO, List.empty)
private final val channelDataWrongSetup: ChannelData = ChannelData(ObjectType.ELECTION, List.empty)
Expand Down
Loading