From 720ef1b4169e439eab0705b6d10f629b9a1dab53 Mon Sep 17 00:00:00 2001 From: fluency03 Date: Sat, 5 May 2018 18:02:14 +0200 Subject: [PATCH] fix block pool routes --- .../blockchain/api/routes/BlockPoolRoutes.scala | 12 ++++++------ .../blockchain/api/routes/TxPoolRoutes.scala | 2 +- .../blockchain/api/actors/BlockPoolActorTest.scala | 6 ++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/scala/com/github/fluency03/blockchain/api/routes/BlockPoolRoutes.scala b/src/main/scala/com/github/fluency03/blockchain/api/routes/BlockPoolRoutes.scala index 999a5b2..28ca5ec 100644 --- a/src/main/scala/com/github/fluency03/blockchain/api/routes/BlockPoolRoutes.scala +++ b/src/main/scala/com/github/fluency03/blockchain/api/routes/BlockPoolRoutes.scala @@ -11,7 +11,7 @@ import akka.http.scaladsl.unmarshalling.PredefinedFromStringUnmarshallers.CsvSeq import akka.pattern.ask import com.github.fluency03.blockchain.api.{Blocks, Input, Message} import com.github.fluency03.blockchain.api.actors.BlockPoolActor._ -import com.github.fluency03.blockchain.api.actors.BlockchainActor.MineNextBlock +import com.github.fluency03.blockchain.api.actors.BlockchainActor import com.github.fluency03.blockchain.core.{Block, Transaction} import scala.concurrent.Future @@ -28,7 +28,7 @@ trait BlockPoolRoutes extends RoutesSupport { */ lazy val blockPoolRoutes: Route = - path(BLOCK_POOL) { + pathPrefix(BLOCK_POOL) { path(BLOCKS) { parameters('hashes.as(CsvSeq[String]).?) { hashesOpt: Option[Seq[String]] => val blocks: Future[Blocks] = hashesOpt match { @@ -64,10 +64,10 @@ trait BlockPoolRoutes extends RoutesSupport { val maybeBlock: Future[Option[Block]] = (blockPoolActor ? GetBlock(hash)).mapTo[Option[Block]] rejectEmptyResponse { complete(maybeBlock) } } ~ - delete { - val blockDeleted: Future[Message] = (blockPoolActor ? DeleteBlock(hash)).mapTo[Message] - onSuccess(blockDeleted) { respondOnDeletion } - } + delete { + val blockDeleted: Future[Message] = (blockPoolActor ? DeleteBlock(hash)).mapTo[Message] + onSuccess(blockDeleted) { respondOnDeletion } + } } ~ path(TRANSACTION / Segment) { id => get { diff --git a/src/main/scala/com/github/fluency03/blockchain/api/routes/TxPoolRoutes.scala b/src/main/scala/com/github/fluency03/blockchain/api/routes/TxPoolRoutes.scala index 968ad8b..8f7d001 100644 --- a/src/main/scala/com/github/fluency03/blockchain/api/routes/TxPoolRoutes.scala +++ b/src/main/scala/com/github/fluency03/blockchain/api/routes/TxPoolRoutes.scala @@ -28,7 +28,7 @@ trait TxPoolRoutes extends RoutesSupport { */ lazy val txPoolRoutes: Route = - path(TX_POOL) { + pathPrefix(TX_POOL) { path(TRANSACTIONS) { parameters('ids.as(CsvSeq[String]).?) { idsOpt => val transactions: Future[Transactions] = idsOpt match { diff --git a/src/test/scala/com/github/fluency03/blockchain/api/actors/BlockPoolActorTest.scala b/src/test/scala/com/github/fluency03/blockchain/api/actors/BlockPoolActorTest.scala index 6df0ddd..e04291c 100644 --- a/src/test/scala/com/github/fluency03/blockchain/api/actors/BlockPoolActorTest.scala +++ b/src/test/scala/com/github/fluency03/blockchain/api/actors/BlockPoolActorTest.scala @@ -3,7 +3,7 @@ package com.github.fluency03.blockchain.api.actors import akka.actor.{ActorRef, ActorSystem, Props} import akka.testkit.{ImplicitSender, TestKit} import com.github.fluency03.blockchain.api.actors.BlockPoolActor._ -import com.github.fluency03.blockchain.api.{FailureMsg, SuccessMsg} +import com.github.fluency03.blockchain.api._ import com.github.fluency03.blockchain.core.Block import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike} @@ -14,7 +14,9 @@ class BlockPoolActorTest extends TestKit(ActorSystem("BlocksActorTest")) with Im shutdown() } - val blockPoolActor: ActorRef = system.actorOf(Props[BlockPoolActor]) + val blockchainActor: ActorRef = system.actorOf(Props[BlockchainActor], BLOCKCHAIN_ACTOR_NAME) + val blockPoolActor: ActorRef = system.actorOf(Props[BlockPoolActor], BLOCK_POOL_ACTOR_NAME) + val txPoolActor: ActorRef = system.actorOf(Props[TxPoolActor], TX_POOL_ACTOR_NAME) "A BlocksActor" should { "Respond with a Seq of Blocks." in {