Skip to content

Commit

Permalink
add PeerActorTest
Browse files Browse the repository at this point in the history
  • Loading branch information
fluency03 committed Apr 25, 2018
1 parent 19db3ef commit f9c0a54
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class PeerActor extends ActorSupport {
override def preStart(): Unit = log.info("{} started!", this.getClass.getSimpleName)
override def postStop(): Unit = log.info("{} stopped!", this.getClass.getSimpleName)


// TODO (Chang): need persistence
val wallets = mutable.Map.empty[String, KeyPair]
wallets += {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}
import scala.concurrent.duration._

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

override def afterAll: Unit = {
shutdown()
Expand All @@ -20,6 +20,8 @@ class BlockchainActorTest extends TestKit(ActorSystem("BlockchainActorTest")) wi

"A BlockchainActor" should {
"Respond with a Blockchain." in {
BlockchainActor.props shouldEqual Props[BlockchainActor]

blockchainActor ! GetBlockchain
expectMsg(None)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class BlocksActorTest extends TestKit(ActorSystem("BlocksActorTest")) with Impli

"A BlocksActor" should {
"Respond with a Seq of Blocks." in {
BlocksActor.props shouldEqual Props[BlocksActor]

blocksActor ! GetBlocks
expectMsg(Seq.empty[Block])

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

class NetworkActorTest {
import akka.actor.{ActorRef, ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestKit}
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

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

override def afterAll: Unit = {
shutdown()
}

val networkActor: ActorRef = system.actorOf(Props[NetworkActor])






}
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
package com.fluency03.blockchain.api.actors

class PeerActorTest {
import akka.actor.{ActorRef, ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestKit}
import com.fluency03.blockchain.api.actors.PeerActor.GetPublicKeys
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

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

override def afterAll: Unit = {
shutdown()
}

val peerActor: ActorRef = system.actorOf(Props[PeerActor])

"A BlocksActor" should {
"Respond with a Seq of Blocks." in {
PeerActor.props shouldEqual Props[PeerActor]

peerActor ! GetPublicKeys
val publicKeys = expectMsgType[Set[String]]
publicKeys.size shouldEqual 1

peerActor ! "other"
expectNoMessage
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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 {
with WordSpecLike with Matchers with BeforeAndAfterAll {

override def afterAll: Unit = {
shutdown()
Expand All @@ -20,6 +20,8 @@ class TransactionsActorTest extends TestKit(ActorSystem("TransactionsActorTest")

"A TransactionsActor" should {
"Respond with a Seq of Transactions." in {
TransactionsActor.props shouldEqual Props[TransactionsActor]

transActor ! GetTransactions
expectMsg(Seq.empty[Transaction])

Expand Down

0 comments on commit f9c0a54

Please sign in to comment.