Skip to content

Commit

Permalink
add TransactionsActorTest
Browse files Browse the repository at this point in the history
  • Loading branch information
fluency03 committed Apr 25, 2018
1 parent ec14245 commit 19db3ef
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.fluency03.blockchain.api.actors

import akka.actor.{ActorRef, ActorSystem, Props}
import akka.testkit.{DefaultTimeout, ImplicitSender, TestKit}
import com.fluency03.blockchain.api.actors.BlockchainActor._
import com.fluency03.blockchain.api.{FailureMsg, SuccessMsg}
import com.fluency03.blockchain.api.actors.BlockchainActor.{CreateBlockchain, DeleteBlockchain, GetBlockchain}
import com.fluency03.blockchain.core.Blockchain
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ 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.{FailureMsg, SuccessMsg}
import com.fluency03.blockchain.api.actors.BlocksActor.{CreateBlock, DeleteBlock, GetBlock, GetBlocks}
import com.fluency03.blockchain.core.Block
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
package com.fluency03.blockchain.api.actors

class TransactionsActorTest {
import akka.actor.{ActorRef, ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestKit}
import com.fluency03.blockchain.api.actors.TransactionsActor._
import com.fluency03.blockchain.api.{FailureMsg, SuccessMsg}
import com.fluency03.blockchain.core.Transaction
import com.fluency03.blockchain.core.Transaction.createCoinbaseTx
import com.fluency03.blockchain.{genesisMiner, genesisTimestamp}
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

class TransactionsActorTest extends TestKit(ActorSystem("TransactionsActorTest")) with ImplicitSender
with WordSpecLike with Matchers with BeforeAndAfterAll {

override def afterAll: Unit = {
shutdown()
}

val transActor: ActorRef = system.actorOf(Props[TransactionsActor])

"A TransactionsActor" should {
"Respond with a Seq of Transactions." in {
transActor ! GetTransactions
expectMsg(Seq.empty[Transaction])

val genesisTx: Transaction = createCoinbaseTx(0, genesisMiner, genesisTimestamp)
transActor ! CreateTransaction(genesisTx)
expectMsg(SuccessMsg(s"Transaction ${genesisTx.id} created."))

transActor ! CreateTransaction(genesisTx)
expectMsg(FailureMsg(s"Transaction ${genesisTx.id} already exists."))

transActor ! GetTransactions
expectMsg(Seq(genesisTx))

transActor ! GetTransaction(genesisTx.id)
expectMsg(Some(genesisTx))

transActor ! DeleteTransaction(genesisTx.id)
expectMsg(SuccessMsg(s"Transaction ${genesisTx.id} deleted."))

transActor ! DeleteTransaction(genesisTx.id)
expectMsg(FailureMsg(s"Transaction ${genesisTx.id} does not exist."))

transActor ! GetTransaction(genesisTx.id)
expectMsg(None)

transActor ! "other"
expectNoMessage
}
}

}

0 comments on commit 19db3ef

Please sign in to comment.