diff --git a/src/main/scala/com/github/fluency03/blockchain/api/routes/BlockchainRoutes.scala b/src/main/scala/com/github/fluency03/blockchain/api/routes/BlockchainRoutes.scala index 83e16ee..b85e05c 100644 --- a/src/main/scala/com/github/fluency03/blockchain/api/routes/BlockchainRoutes.scala +++ b/src/main/scala/com/github/fluency03/blockchain/api/routes/BlockchainRoutes.scala @@ -8,7 +8,7 @@ import akka.http.scaladsl.server.directives.MethodDirectives.{delete, get, post} import akka.http.scaladsl.server.directives.RouteDirectives.complete import akka.http.scaladsl.unmarshalling.PredefinedFromStringUnmarshallers.CsvSeq import akka.pattern.ask -import com.github.fluency03.blockchain.api.{FailureMsg, Input, Message} +import com.github.fluency03.blockchain.api.{Input, Message} import com.github.fluency03.blockchain.api.actors.BlockchainActor._ import com.github.fluency03.blockchain.core.{Block, Blockchain, Transaction} 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 e04291c..835a5a1 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 @@ -1,13 +1,16 @@ 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 akka.testkit.{DefaultTimeout, ImplicitSender, TestKit} import com.github.fluency03.blockchain.api._ -import com.github.fluency03.blockchain.core.Block +import com.github.fluency03.blockchain.api.actors.BlockPoolActor._ +import com.github.fluency03.blockchain.api.actors.BlockchainActor.CreateBlockchain +import com.github.fluency03.blockchain.core.{Block, Transaction} import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike} -class BlockPoolActorTest extends TestKit(ActorSystem("BlocksActorTest")) with ImplicitSender +import scala.concurrent.duration._ + +class BlockPoolActorTest extends TestKit(ActorSystem("BlocksActorTest")) with DefaultTimeout with ImplicitSender with WordSpecLike with Matchers with BeforeAndAfterAll { override def afterAll: Unit = { @@ -55,6 +58,28 @@ class BlockPoolActorTest extends TestKit(ActorSystem("BlocksActorTest")) with Im blockPoolActor ! GetBlock(Block.genesisBlock.hash) expectMsg(Some(Block.genesisBlock)) + + within(15 seconds) { + blockchainActor ! CreateBlockchain + expectMsgType[SuccessMsg] + } + + var actualBlock: Block = Block.genesisBlock + within(15 seconds) { + blockPoolActor ! MineAndAddNextBlock("next", Seq.empty[String]) + actualBlock = expectMsgType[Some[Block]].get + actualBlock.data shouldEqual "next" + actualBlock.transactions shouldEqual Seq.empty[Transaction] + actualBlock.index shouldEqual 1 + actualBlock.hasValidHash shouldEqual true + } + + blockPoolActor ! GetBlocks + val blocks = expectMsgType[Seq[Block]] + + blocks.length shouldEqual 2 + blocks should contain allOf (Block.genesisBlock, actualBlock) + blockPoolActor ! DeleteBlock(Block.genesisBlock.hash) expectMsg(SuccessMsg(s"Block ${Block.genesisBlock.hash} deleted from the Pool.")) diff --git a/src/test/scala/com/github/fluency03/blockchain/api/actors/BlockchainActorTest.scala b/src/test/scala/com/github/fluency03/blockchain/api/actors/BlockchainActorTest.scala index 6562f74..57d83ad 100644 --- a/src/test/scala/com/github/fluency03/blockchain/api/actors/BlockchainActorTest.scala +++ b/src/test/scala/com/github/fluency03/blockchain/api/actors/BlockchainActorTest.scala @@ -2,9 +2,9 @@ package com.github.fluency03.blockchain.api.actors import akka.actor.{ActorRef, ActorSystem, Props} import akka.testkit.{DefaultTimeout, ImplicitSender, TestKit} +import com.github.fluency03.blockchain.api._ import com.github.fluency03.blockchain.api.actors.BlockPoolActor.AddBlock import com.github.fluency03.blockchain.api.actors.BlockchainActor._ -import com.github.fluency03.blockchain.api._ import com.github.fluency03.blockchain.api.actors.TxPoolActor.AddTransaction import com.github.fluency03.blockchain.core.Transaction.createCoinbaseTx import com.github.fluency03.blockchain.core.{Block, Blockchain, Transaction}