From 7ae47de730ee250847abfbefd24c43eb049a8ca9 Mon Sep 17 00:00:00 2001 From: fluency03 Date: Fri, 4 May 2018 11:32:06 +0200 Subject: [PATCH] rename Blocks -> BlockPool & Transactions -> TxPool --- .../com/fluency03/blockchain/api/Server.scala | 8 ++-- ...BlocksActor.scala => BlockPoolActor.scala} | 10 ++--- .../api/actors/BlockchainActor.scala | 10 ++--- .../blockchain/api/actors/NetworkActor.scala | 4 +- ...nsactionsActor.scala => TxPoolActor.scala} | 10 ++--- .../fluency03/blockchain/api/package.scala | 4 +- ...lockRoutes.scala => BlockPoolRoutes.scala} | 20 +++++----- ...sactionRoutes.scala => TxPoolRoutes.scala} | 22 +++++------ ...torTest.scala => BlockPoolActorTest.scala} | 32 ++++++++-------- ...sActorTest.scala => TxPoolActorTest.scala} | 38 +++++++++---------- ...esTest.scala => BlockPoolRoutesTest.scala} | 2 +- ...outesTest.scala => TxPoolRoutesTest.scala} | 2 +- 12 files changed, 81 insertions(+), 81 deletions(-) rename src/main/scala/com/fluency03/blockchain/api/actors/{BlocksActor.scala => BlockPoolActor.scala} (89%) rename src/main/scala/com/fluency03/blockchain/api/actors/{TransactionsActor.scala => TxPoolActor.scala} (91%) rename src/main/scala/com/fluency03/blockchain/api/routes/{BlockRoutes.scala => BlockPoolRoutes.scala} (67%) rename src/main/scala/com/fluency03/blockchain/api/routes/{TransactionRoutes.scala => TxPoolRoutes.scala} (68%) rename src/test/scala/com/fluency03/blockchain/api/actors/{BlocksActorTest.scala => BlockPoolActorTest.scala} (55%) rename src/test/scala/com/fluency03/blockchain/api/actors/{TransactionsActorTest.scala => TxPoolActorTest.scala} (65%) rename src/test/scala/com/fluency03/blockchain/api/routes/{TransactionRoutesTest.scala => BlockPoolRoutesTest.scala} (65%) rename src/test/scala/com/fluency03/blockchain/api/routes/{BlockRoutesTest.scala => TxPoolRoutesTest.scala} (66%) diff --git a/src/main/scala/com/fluency03/blockchain/api/Server.scala b/src/main/scala/com/fluency03/blockchain/api/Server.scala index 415949e..1fb7a5b 100644 --- a/src/main/scala/com/fluency03/blockchain/api/Server.scala +++ b/src/main/scala/com/fluency03/blockchain/api/Server.scala @@ -15,7 +15,7 @@ import scala.concurrent.{Await, ExecutionContextExecutor, Future} import scala.concurrent.duration.Duration object Server extends App - with BlockchainRoutes with BlockRoutes with TransactionRoutes with NetworkRoutes with GenericRoutes { + with BlockchainRoutes with BlockPoolRoutes with TxPoolRoutes with NetworkRoutes with GenericRoutes { // we leave these abstract, since they will be provided by the App implicit val system: ActorSystem = ActorSystem("blockchain-http-service") implicit val materializer: ActorMaterializer = ActorMaterializer() @@ -28,11 +28,11 @@ object Server extends App val (host, port) = (httpConfig.getString("host"), httpConfig.getInt("port")) val blockchainActor: ActorRef = system.actorOf(BlockchainActor.props, BLOCKCHAIN_ACTOR_NAME) - val blocksActor: ActorRef = system.actorOf(BlocksActor.props, BLOCKS_ACTOR_NAME) - val transActor: ActorRef = system.actorOf(TransactionsActor.props, TRANS_ACTOR_NAME) + val blockPoolActor: ActorRef = system.actorOf(BlockPoolActor.props, BLOCK_POOL_ACTOR_NAME) + val txPoolActor: ActorRef = system.actorOf(TxPoolActor.props, TX_POOL_ACTOR_NAME) val networkActor: ActorRef = system.actorOf(NetworkActor.props, NETWORK_ACTOR_NAME) - lazy val routes: Route = blockchainRoutes ~ blockRoutes ~ transRoutes ~ networkRoutes ~ genericRoutes + lazy val routes: Route = blockchainRoutes ~ blockPoolRoutes ~ txPoolRoutes ~ networkRoutes ~ genericRoutes val bindingFuture: Future[ServerBinding] = Http().bindAndHandle(routes, host, port) diff --git a/src/main/scala/com/fluency03/blockchain/api/actors/BlocksActor.scala b/src/main/scala/com/fluency03/blockchain/api/actors/BlockPoolActor.scala similarity index 89% rename from src/main/scala/com/fluency03/blockchain/api/actors/BlocksActor.scala rename to src/main/scala/com/fluency03/blockchain/api/actors/BlockPoolActor.scala index 445acb4..559675a 100644 --- a/src/main/scala/com/fluency03/blockchain/api/actors/BlocksActor.scala +++ b/src/main/scala/com/fluency03/blockchain/api/actors/BlockPoolActor.scala @@ -1,29 +1,29 @@ package com.fluency03.blockchain.api.actors import akka.actor.{ActorSelection, Props} -import com.fluency03.blockchain.api.actors.BlocksActor._ +import com.fluency03.blockchain.api.actors.BlockPoolActor._ import com.fluency03.blockchain.api._ import com.fluency03.blockchain.core.Block import scala.collection.mutable -object BlocksActor { +object BlockPoolActor { final case object GetBlocks final case class GetBlocks(hashes: Set[String]) final case class CreateBlock(block: Block) final case class GetBlock(hash: String) final case class DeleteBlock(hash: String) - def props: Props = Props[BlocksActor] + def props: Props = Props[BlockPoolActor] } -class BlocksActor extends ActorSupport { +class BlockPoolActor extends ActorSupport { override def preStart(): Unit = log.info("{} started!", this.getClass.getSimpleName) override def postStop(): Unit = log.info("{} stopped!", this.getClass.getSimpleName) val blockchainActor: ActorSelection = context.actorSelection(PARENT_UP + BLOCKCHAIN_ACTOR_NAME) val networkActor: ActorSelection = context.actorSelection(PARENT_UP + NETWORK_ACTOR_NAME) - val transActor: ActorSelection = context.actorSelection(PARENT_UP + TRANS_ACTOR_NAME) + val txPoolActor: ActorSelection = context.actorSelection(PARENT_UP + TX_POOL_ACTOR_NAME) // TODO (Chang): need persistence var blocksPool = mutable.Map.empty[String, Block] diff --git a/src/main/scala/com/fluency03/blockchain/api/actors/BlockchainActor.scala b/src/main/scala/com/fluency03/blockchain/api/actors/BlockchainActor.scala index be15392..f21a05b 100644 --- a/src/main/scala/com/fluency03/blockchain/api/actors/BlockchainActor.scala +++ b/src/main/scala/com/fluency03/blockchain/api/actors/BlockchainActor.scala @@ -32,8 +32,8 @@ class BlockchainActor extends ActorSupport { import context.dispatcher - val blocksActor: ActorSelection = context.actorSelection(PARENT_UP + BLOCKS_ACTOR_NAME) - val transActor: ActorSelection = context.actorSelection(PARENT_UP + TRANS_ACTOR_NAME) + val blockPoolActor: ActorSelection = context.actorSelection(PARENT_UP + BLOCK_POOL_ACTOR_NAME) + val txPoolActor: ActorSelection = context.actorSelection(PARENT_UP + TX_POOL_ACTOR_NAME) val networkActor: ActorSelection = context.actorSelection(PARENT_UP + NETWORK_ACTOR_NAME) // TODO (Chang): need persistence @@ -101,7 +101,7 @@ class BlockchainActor extends ActorSupport { private def onAddBlockFromPool(hash: String): Unit = blockchainOpt match { case Some(blockchain) => - val maybeBlock: Future[Option[Block]] = (blocksActor ? BlocksActor.GetBlock(hash)).mapTo[Option[Block]] + val maybeBlock: Future[Option[Block]] = (blockPoolActor ? BlockPoolActor.GetBlock(hash)).mapTo[Option[Block]] maybeBlock onComplete { case Success(blockOpt) => blockOpt match { case Some(block) => @@ -135,7 +135,7 @@ class BlockchainActor extends ActorSupport { if (ids.isEmpty) sender() ! Some(blockchain.mineNextBlock(data, Seq.empty[Transaction])) else { val maybeTrans: Future[Seq[Transaction]] = - (transActor ? TransactionsActor.GetTransactions(ids.toSet)).mapTo[Seq[Transaction]] + (txPoolActor ? TxPoolActor.GetTransactions(ids.toSet)).mapTo[Seq[Transaction]] maybeTrans onComplete { case Success(trans) => sender() ! Some(blockchain.mineNextBlock(data, trans)) case Failure(_) => sender() ! None @@ -157,7 +157,7 @@ class BlockchainActor extends ActorSupport { sender() ! FailureMsg("Blockchain does not exist.") } - private def onGetBlockFromPool(hash: String): Unit = blocksActor forward BlocksActor.GetBlock(hash) + private def onGetBlockFromPool(hash: String): Unit = blockPoolActor forward BlockPoolActor.GetBlock(hash) private def getBlockFromChain(hash: String): Option[Block] = hashIndexMapping.get(hash) match { diff --git a/src/main/scala/com/fluency03/blockchain/api/actors/NetworkActor.scala b/src/main/scala/com/fluency03/blockchain/api/actors/NetworkActor.scala index c953beb..8ecd406 100644 --- a/src/main/scala/com/fluency03/blockchain/api/actors/NetworkActor.scala +++ b/src/main/scala/com/fluency03/blockchain/api/actors/NetworkActor.scala @@ -26,9 +26,9 @@ class NetworkActor extends ActorSupport { import context.dispatcher - val blockActor: ActorSelection = context.actorSelection(PARENT_UP + BLOCKS_ACTOR_NAME) + val blockPoolActor: ActorSelection = context.actorSelection(PARENT_UP + BLOCK_POOL_ACTOR_NAME) val blockchainActor: ActorSelection = context.actorSelection(PARENT_UP + BLOCKCHAIN_ACTOR_NAME) - val transActor: ActorSelection = context.actorSelection(PARENT_UP + TRANS_ACTOR_NAME) + val txPoolActor: ActorSelection = context.actorSelection(PARENT_UP + TX_POOL_ACTOR_NAME) // TODO (Chang): need persistence diff --git a/src/main/scala/com/fluency03/blockchain/api/actors/TransactionsActor.scala b/src/main/scala/com/fluency03/blockchain/api/actors/TxPoolActor.scala similarity index 91% rename from src/main/scala/com/fluency03/blockchain/api/actors/TransactionsActor.scala rename to src/main/scala/com/fluency03/blockchain/api/actors/TxPoolActor.scala index e85e139..523f9fb 100644 --- a/src/main/scala/com/fluency03/blockchain/api/actors/TransactionsActor.scala +++ b/src/main/scala/com/fluency03/blockchain/api/actors/TxPoolActor.scala @@ -1,24 +1,24 @@ package com.fluency03.blockchain.api.actors import akka.actor.{ActorSelection, Props} -import com.fluency03.blockchain.api.actors.TransactionsActor._ +import com.fluency03.blockchain.api.actors.TxPoolActor._ import com.fluency03.blockchain.api._ import com.fluency03.blockchain.core.{Outpoint, Transaction, TxOut} import com.fluency03.blockchain.core.Transaction.hashOfTransaction import scala.collection.mutable -object TransactionsActor { +object TxPoolActor { final case object GetTransactions final case class GetTransactions(ids: Set[String]) final case class CreateTransaction(tx: Transaction) final case class GetTransaction(id: String) final case class DeleteTransaction(id: String) final case class UpdateTransaction(tx: Transaction) - def props: Props = Props[TransactionsActor] + def props: Props = Props[TxPoolActor] } -class TransactionsActor extends ActorSupport { +class TxPoolActor extends ActorSupport { override def preStart(): Unit = log.info("{} started!", this.getClass.getSimpleName) override def postStop(): Unit = log.info("{} stopped!", this.getClass.getSimpleName) @@ -27,7 +27,7 @@ class TransactionsActor extends ActorSupport { val uTxOs: mutable.Map[Outpoint, TxOut] = mutable.Map.empty[Outpoint, TxOut] val blockchainActor: ActorSelection = context.actorSelection(PARENT_UP + BLOCKCHAIN_ACTOR_NAME) - val blockActor: ActorSelection = context.actorSelection(PARENT_UP + BLOCKS_ACTOR_NAME) + val blockPoolActor: ActorSelection = context.actorSelection(PARENT_UP + BLOCK_POOL_ACTOR_NAME) val networkActor: ActorSelection = context.actorSelection(PARENT_UP + NETWORK_ACTOR_NAME) /** diff --git a/src/main/scala/com/fluency03/blockchain/api/package.scala b/src/main/scala/com/fluency03/blockchain/api/package.scala index ffadc5c..a0544d1 100644 --- a/src/main/scala/com/fluency03/blockchain/api/package.scala +++ b/src/main/scala/com/fluency03/blockchain/api/package.scala @@ -8,11 +8,11 @@ package object api { type Transactions = Seq[Transaction] type Peers = Seq[Peer] - val BLOCKS_ACTOR_NAME = "blocksActor" + val BLOCK_POOL_ACTOR_NAME = "blocksPoolActor" val BLOCKCHAIN_ACTOR_NAME = "blockchainActor" val NETWORK_ACTOR_NAME = "networkActor" val PEER_ACTOR_NAME = "peerActor" - val TRANS_ACTOR_NAME = "transActor" + val TX_POOL_ACTOR_NAME = "txPoolActor" val PARENT_UP = "../" diff --git a/src/main/scala/com/fluency03/blockchain/api/routes/BlockRoutes.scala b/src/main/scala/com/fluency03/blockchain/api/routes/BlockPoolRoutes.scala similarity index 67% rename from src/main/scala/com/fluency03/blockchain/api/routes/BlockRoutes.scala rename to src/main/scala/com/fluency03/blockchain/api/routes/BlockPoolRoutes.scala index 3ac0bd0..c5e9d4b 100644 --- a/src/main/scala/com/fluency03/blockchain/api/routes/BlockRoutes.scala +++ b/src/main/scala/com/fluency03/blockchain/api/routes/BlockPoolRoutes.scala @@ -10,15 +10,15 @@ import akka.http.scaladsl.server.directives.RouteDirectives.complete import akka.http.scaladsl.unmarshalling.PredefinedFromStringUnmarshallers.CsvSeq import akka.pattern.ask import com.fluency03.blockchain.api.{Blocks, Message} -import com.fluency03.blockchain.api.actors.BlocksActor._ +import com.fluency03.blockchain.api.actors.BlockPoolActor._ import com.fluency03.blockchain.core.Block import scala.concurrent.Future -trait BlockRoutes extends RoutesSupport { - lazy val log = Logging(system, classOf[BlockRoutes]) +trait BlockPoolRoutes extends RoutesSupport { + lazy val log = Logging(system, classOf[BlockPoolRoutes]) - def blocksActor: ActorRef + def blockPoolActor: ActorRef /** * TODO (Chang): new APIS: @@ -30,12 +30,12 @@ trait BlockRoutes extends RoutesSupport { * */ - lazy val blockRoutes: Route = + lazy val blockPoolRoutes: Route = path(BLOCKS) { parameters( 'hashes.as(CsvSeq[String]).? ) { hashesOpt => val blocks: Future[Blocks] = hashesOpt match { - case Some(hashes) => (blocksActor ? GetBlocks(hashes.toSet)).mapTo[Blocks] - case None => (blocksActor ? GetBlocks).mapTo[Blocks] + case Some(hashes) => (blockPoolActor ? GetBlocks(hashes.toSet)).mapTo[Blocks] + case None => (blockPoolActor ? GetBlocks).mapTo[Blocks] } complete(blocks) } @@ -44,18 +44,18 @@ trait BlockRoutes extends RoutesSupport { pathEnd { post { entity(as[Block]) { block => - val blockCreated: Future[Message] = (blocksActor ? CreateBlock(block)).mapTo[Message] + val blockCreated: Future[Message] = (blockPoolActor ? CreateBlock(block)).mapTo[Message] onSuccess(blockCreated) { respondOnCreation } } } } ~ path(Segment) { hash => get { - val maybeBlock: Future[Option[Block]] = (blocksActor ? GetBlock(hash)).mapTo[Option[Block]] + val maybeBlock: Future[Option[Block]] = (blockPoolActor ? GetBlock(hash)).mapTo[Option[Block]] rejectEmptyResponse { complete(maybeBlock) } } ~ delete { - val blockDeleted: Future[Message] = (blocksActor ? DeleteBlock(hash)).mapTo[Message] + val blockDeleted: Future[Message] = (blockPoolActor ? DeleteBlock(hash)).mapTo[Message] onSuccess(blockDeleted) { respondOnDeletion } } } diff --git a/src/main/scala/com/fluency03/blockchain/api/routes/TransactionRoutes.scala b/src/main/scala/com/fluency03/blockchain/api/routes/TxPoolRoutes.scala similarity index 68% rename from src/main/scala/com/fluency03/blockchain/api/routes/TransactionRoutes.scala rename to src/main/scala/com/fluency03/blockchain/api/routes/TxPoolRoutes.scala index c29fc56..6479013 100644 --- a/src/main/scala/com/fluency03/blockchain/api/routes/TransactionRoutes.scala +++ b/src/main/scala/com/fluency03/blockchain/api/routes/TxPoolRoutes.scala @@ -10,16 +10,16 @@ import akka.http.scaladsl.server.directives.PathDirectives.path import akka.http.scaladsl.server.directives.RouteDirectives.complete import akka.http.scaladsl.unmarshalling.PredefinedFromStringUnmarshallers.CsvSeq import akka.pattern.ask -import com.fluency03.blockchain.api.actors.TransactionsActor._ +import com.fluency03.blockchain.api.actors.TxPoolActor._ import com.fluency03.blockchain.api.{FailureMsg, Message, Transactions} import com.fluency03.blockchain.core.Transaction import scala.concurrent.Future -trait TransactionRoutes extends RoutesSupport { - lazy val log = Logging(system, classOf[TransactionRoutes]) +trait TxPoolRoutes extends RoutesSupport { + lazy val log = Logging(system, classOf[TxPoolRoutes]) - def transActor: ActorRef + def txPoolActor: ActorRef /** * TODO (Chang): @@ -28,12 +28,12 @@ trait TransactionRoutes extends RoutesSupport { * */ - lazy val transRoutes: Route = + lazy val txPoolRoutes: Route = path(TRANSACTIONS) { parameters( 'ids.as(CsvSeq[String]).? ) { idsOpt => val transactions: Future[Transactions] = idsOpt match { - case Some(ids) => (transActor ? GetTransactions(ids.toSet)).mapTo[Transactions] - case None => (transActor ? GetTransactions).mapTo[Transactions] + case Some(ids) => (txPoolActor ? GetTransactions(ids.toSet)).mapTo[Transactions] + case None => (txPoolActor ? GetTransactions).mapTo[Transactions] } complete(transactions) } @@ -42,18 +42,18 @@ trait TransactionRoutes extends RoutesSupport { pathEnd { post { entity(as[Transaction]) { tx => - val msgOnCreate: Future[Message] = (transActor ? CreateTransaction(tx)).mapTo[Message] + val msgOnCreate: Future[Message] = (txPoolActor ? CreateTransaction(tx)).mapTo[Message] onSuccess(msgOnCreate) { respondOnCreation } } } } ~ path(Segment) { id => get { - val maybeTx: Future[Option[Transaction]] = (transActor ? GetTransaction(id)).mapTo[Option[Transaction]] + val maybeTx: Future[Option[Transaction]] = (txPoolActor ? GetTransaction(id)).mapTo[Option[Transaction]] rejectEmptyResponse { complete(maybeTx) } } ~ delete { - val txDeleted: Future[Message] = (transActor ? DeleteTransaction(id)).mapTo[Message] + val txDeleted: Future[Message] = (txPoolActor ? DeleteTransaction(id)).mapTo[Message] onSuccess(txDeleted) { respondOnDeletion } } ~ put { @@ -61,7 +61,7 @@ trait TransactionRoutes extends RoutesSupport { if (tx.id != id) complete((StatusCodes.InternalServerError, FailureMsg("Transaction ID in the data does not match ID on the path."))) else { - val msgOnUpdate: Future[Message] = (transActor ? UpdateTransaction(tx)).mapTo[Message] + val msgOnUpdate: Future[Message] = (txPoolActor ? UpdateTransaction(tx)).mapTo[Message] onSuccess(msgOnUpdate) { respondOnUpdate } } } diff --git a/src/test/scala/com/fluency03/blockchain/api/actors/BlocksActorTest.scala b/src/test/scala/com/fluency03/blockchain/api/actors/BlockPoolActorTest.scala similarity index 55% rename from src/test/scala/com/fluency03/blockchain/api/actors/BlocksActorTest.scala rename to src/test/scala/com/fluency03/blockchain/api/actors/BlockPoolActorTest.scala index ee51ed5..98d2899 100644 --- a/src/test/scala/com/fluency03/blockchain/api/actors/BlocksActorTest.scala +++ b/src/test/scala/com/fluency03/blockchain/api/actors/BlockPoolActorTest.scala @@ -2,58 +2,58 @@ package com.fluency03.blockchain.api.actors import akka.actor.{ActorRef, ActorSystem, Props} import akka.testkit.{ImplicitSender, TestKit} -import com.fluency03.blockchain.api.actors.BlocksActor._ +import com.fluency03.blockchain.api.actors.BlockPoolActor._ import com.fluency03.blockchain.api.{FailureMsg, SuccessMsg} import com.fluency03.blockchain.core.Block import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike} -class BlocksActorTest extends TestKit(ActorSystem("BlocksActorTest")) with ImplicitSender +class BlockPoolActorTest extends TestKit(ActorSystem("BlocksActorTest")) with ImplicitSender with WordSpecLike with Matchers with BeforeAndAfterAll { override def afterAll: Unit = { shutdown() } - val blocksActor: ActorRef = system.actorOf(Props[BlocksActor]) + val blockPoolActor: ActorRef = system.actorOf(Props[BlockPoolActor]) "A BlocksActor" should { "Respond with a Seq of Blocks." in { - BlocksActor.props shouldEqual Props[BlocksActor] + BlockPoolActor.props shouldEqual Props[BlockPoolActor] - blocksActor ! GetBlocks + blockPoolActor ! GetBlocks expectMsg(Seq.empty[Block]) - blocksActor ! GetBlocks(Set("somehash")) + blockPoolActor ! GetBlocks(Set("somehash")) expectMsg(Seq.empty[Block]) - blocksActor ! CreateBlock(Block.genesisBlock) + blockPoolActor ! CreateBlock(Block.genesisBlock) expectMsg(SuccessMsg(s"Block ${Block.genesisBlock.hash} created.")) - blocksActor ! CreateBlock(Block.genesisBlock) + blockPoolActor ! CreateBlock(Block.genesisBlock) expectMsg(FailureMsg(s"Block ${Block.genesisBlock.hash} already exists.")) - blocksActor ! GetBlocks + blockPoolActor ! GetBlocks expectMsg(Seq(Block.genesisBlock)) - blocksActor ! GetBlocks(Set("somehash")) + blockPoolActor ! GetBlocks(Set("somehash")) expectMsg(Seq.empty[Block]) - blocksActor ! GetBlocks(Set(Block.genesisBlock.hash)) + blockPoolActor ! GetBlocks(Set(Block.genesisBlock.hash)) expectMsg(Seq(Block.genesisBlock)) - blocksActor ! GetBlock(Block.genesisBlock.hash) + blockPoolActor ! GetBlock(Block.genesisBlock.hash) expectMsg(Some(Block.genesisBlock)) - blocksActor ! DeleteBlock(Block.genesisBlock.hash) + blockPoolActor ! DeleteBlock(Block.genesisBlock.hash) expectMsg(SuccessMsg(s"Block ${Block.genesisBlock.hash} deleted.")) - blocksActor ! DeleteBlock(Block.genesisBlock.hash) + blockPoolActor ! DeleteBlock(Block.genesisBlock.hash) expectMsg(FailureMsg(s"Block ${Block.genesisBlock.hash} does not exist.")) - blocksActor ! GetBlock(Block.genesisBlock.hash) + blockPoolActor ! GetBlock(Block.genesisBlock.hash) expectMsg(None) - blocksActor ! "other" + blockPoolActor ! "other" expectNoMessage } } diff --git a/src/test/scala/com/fluency03/blockchain/api/actors/TransactionsActorTest.scala b/src/test/scala/com/fluency03/blockchain/api/actors/TxPoolActorTest.scala similarity index 65% rename from src/test/scala/com/fluency03/blockchain/api/actors/TransactionsActorTest.scala rename to src/test/scala/com/fluency03/blockchain/api/actors/TxPoolActorTest.scala index 1be093b..f530c4b 100644 --- a/src/test/scala/com/fluency03/blockchain/api/actors/TransactionsActorTest.scala +++ b/src/test/scala/com/fluency03/blockchain/api/actors/TxPoolActorTest.scala @@ -2,73 +2,73 @@ package com.fluency03.blockchain.api.actors import akka.actor.{ActorRef, ActorSystem, Props} import akka.testkit.{ImplicitSender, TestKit} -import com.fluency03.blockchain.api.actors.TransactionsActor._ +import com.fluency03.blockchain.api.actors.TxPoolActor._ import com.fluency03.blockchain.api.{FailureMsg, SuccessMsg} import com.fluency03.blockchain.core.{Transaction, TxIn, TxOut} import com.fluency03.blockchain.core.Transaction.{createCoinbaseTx, hashOfTransaction} import com.fluency03.blockchain.{genesisMiner, genesisTimestamp} import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike} -class TransactionsActorTest extends TestKit(ActorSystem("TransactionsActorTest")) with ImplicitSender +class TxPoolActorTest extends TestKit(ActorSystem("TransactionsActorTest")) with ImplicitSender with WordSpecLike with Matchers with BeforeAndAfterAll { override def afterAll: Unit = { shutdown() } - val transActor: ActorRef = system.actorOf(Props[TransactionsActor]) + val txPoolActor: ActorRef = system.actorOf(Props[TxPoolActor]) "A TransactionsActor" should { "Respond with a Seq of Transactions." in { - TransactionsActor.props shouldEqual Props[TransactionsActor] + TxPoolActor.props shouldEqual Props[TxPoolActor] - transActor ! GetTransactions + txPoolActor ! GetTransactions expectMsg(Seq.empty[Transaction]) - transActor ! GetTransactions(Set("someid")) + txPoolActor ! GetTransactions(Set("someid")) expectMsg(Seq.empty[Transaction]) val genesisTx: Transaction = createCoinbaseTx(0, genesisMiner, genesisTimestamp) - transActor ! CreateTransaction(genesisTx) + txPoolActor ! CreateTransaction(genesisTx) expectMsg(SuccessMsg(s"Transaction ${genesisTx.id} created.")) - transActor ! CreateTransaction(genesisTx) + txPoolActor ! CreateTransaction(genesisTx) expectMsg(FailureMsg(s"Transaction ${genesisTx.id} already exists.")) - transActor ! GetTransactions + txPoolActor ! GetTransactions expectMsg(Seq(genesisTx)) - transActor ! GetTransactions(Set("someid")) + txPoolActor ! GetTransactions(Set("someid")) expectMsg(Seq.empty[Transaction]) - transActor ! GetTransactions(Set(genesisTx.id)) + txPoolActor ! GetTransactions(Set(genesisTx.id)) expectMsg(Seq(genesisTx)) - transActor ! GetTransaction(genesisTx.id) + txPoolActor ! GetTransaction(genesisTx.id) expectMsg(Some(genesisTx)) - transActor ! UpdateTransaction(genesisTx) + txPoolActor ! UpdateTransaction(genesisTx) expectMsg(SuccessMsg(s"Transaction ${genesisTx.id} updated.")) val tx1: Transaction = createCoinbaseTx(1, genesisMiner, genesisTimestamp + 10) - transActor ! UpdateTransaction(tx1) + txPoolActor ! UpdateTransaction(tx1) expectMsg(SuccessMsg(s"Transaction ${tx1.id} does not exist. New transaction created.")) val tx0: Transaction = Transaction(Seq.empty[TxIn], Seq.empty[TxOut], genesisTimestamp, "0000") val idOfTx0 = hashOfTransaction(tx0) - transActor ! UpdateTransaction(tx0) + txPoolActor ! UpdateTransaction(tx0) expectMsg(FailureMsg(s"Transaction does not have valid ID. Should be: $idOfTx0; actually is: ${tx0.id}")) - transActor ! DeleteTransaction(genesisTx.id) + txPoolActor ! DeleteTransaction(genesisTx.id) expectMsg(SuccessMsg(s"Transaction ${genesisTx.id} deleted.")) - transActor ! DeleteTransaction(genesisTx.id) + txPoolActor ! DeleteTransaction(genesisTx.id) expectMsg(FailureMsg(s"Transaction ${genesisTx.id} does not exist.")) - transActor ! GetTransaction(genesisTx.id) + txPoolActor ! GetTransaction(genesisTx.id) expectMsg(None) - transActor ! "other" + txPoolActor ! "other" expectNoMessage } } diff --git a/src/test/scala/com/fluency03/blockchain/api/routes/TransactionRoutesTest.scala b/src/test/scala/com/fluency03/blockchain/api/routes/BlockPoolRoutesTest.scala similarity index 65% rename from src/test/scala/com/fluency03/blockchain/api/routes/TransactionRoutesTest.scala rename to src/test/scala/com/fluency03/blockchain/api/routes/BlockPoolRoutesTest.scala index 6dbe8cc..84d6dda 100644 --- a/src/test/scala/com/fluency03/blockchain/api/routes/TransactionRoutesTest.scala +++ b/src/test/scala/com/fluency03/blockchain/api/routes/BlockPoolRoutesTest.scala @@ -4,6 +4,6 @@ import akka.http.scaladsl.testkit.ScalatestRouteTest import com.fluency03.blockchain.api.JsonSupport import org.scalatest.{Matchers, WordSpec} -class TransactionRoutesTest extends WordSpec with Matchers with ScalatestRouteTest with JsonSupport { +class BlockPoolRoutesTest extends WordSpec with Matchers with ScalatestRouteTest with JsonSupport { } diff --git a/src/test/scala/com/fluency03/blockchain/api/routes/BlockRoutesTest.scala b/src/test/scala/com/fluency03/blockchain/api/routes/TxPoolRoutesTest.scala similarity index 66% rename from src/test/scala/com/fluency03/blockchain/api/routes/BlockRoutesTest.scala rename to src/test/scala/com/fluency03/blockchain/api/routes/TxPoolRoutesTest.scala index aff84b5..336a9bf 100644 --- a/src/test/scala/com/fluency03/blockchain/api/routes/BlockRoutesTest.scala +++ b/src/test/scala/com/fluency03/blockchain/api/routes/TxPoolRoutesTest.scala @@ -4,6 +4,6 @@ import akka.http.scaladsl.testkit.ScalatestRouteTest import com.fluency03.blockchain.api.JsonSupport import org.scalatest.{Matchers, WordSpec} -class BlockRoutesTest extends WordSpec with Matchers with ScalatestRouteTest with JsonSupport { +class TxPoolRoutesTest extends WordSpec with Matchers with ScalatestRouteTest with JsonSupport { }