Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add some simple specs for EthFilterService
- Loading branch information
Jaap van der Plas
committed
Jan 18, 2021
1 parent
741b109
commit 9a5b874
Showing
2 changed files
with
110 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 98 additions & 1 deletion
99
src/test/scala/io/iohk/ethereum/jsonrpc/EthFilterServiceSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,100 @@ | ||
package io.iohk.ethereum.jsonrpc | ||
|
||
class EthFilterServiceSpec {} | ||
import akka.actor.ActorSystem | ||
import akka.testkit.TestKit | ||
import akka.testkit.TestProbe | ||
import io.iohk.ethereum.NormalPatience | ||
import io.iohk.ethereum.Timeouts | ||
import io.iohk.ethereum.utils.FilterConfig | ||
import io.iohk.ethereum.WithActorSystemShutDown | ||
import io.iohk.ethereum.jsonrpc.EthFilterService._ | ||
import io.iohk.ethereum.jsonrpc.{FilterManager => FM} | ||
import org.scalactic.TypeCheckedTripleEquals | ||
import org.scalamock.scalatest.MockFactory | ||
import org.scalatest.concurrent.ScalaFutures | ||
import org.scalatest.flatspec.AnyFlatSpecLike | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.OptionValues | ||
import scala.concurrent.duration.FiniteDuration | ||
import monix.execution.Scheduler.Implicits.global | ||
import io.iohk.ethereum.jsonrpc.FilterManager.UninstallFilter | ||
import io.iohk.ethereum.jsonrpc.FilterManager.FilterChanges | ||
|
||
class EthFilterServiceSpec | ||
extends TestKit(ActorSystem("EthFilterServiceSpec_ActorSystem")) | ||
with AnyFlatSpecLike | ||
with WithActorSystemShutDown | ||
with Matchers | ||
with ScalaFutures | ||
with OptionValues | ||
with MockFactory | ||
with NormalPatience | ||
with TypeCheckedTripleEquals { | ||
|
||
it should "handle newFilter request" in new TestSetup { | ||
val filter = Filter(None, None, None, Seq.empty) | ||
val res = ethFilterService.newFilter(NewFilterRequest(filter)).runToFuture | ||
filterManager.expectMsg(FM.NewLogFilter(None, None, None, Seq.empty)) | ||
filterManager.reply(FM.NewFilterResponse(123)) | ||
res.futureValue shouldEqual Right(NewFilterResponse(123)) | ||
} | ||
|
||
it should "handle newBlockFilter request" in new TestSetup { | ||
val res = ethFilterService.newBlockFilter(NewBlockFilterRequest()).runToFuture | ||
filterManager.expectMsg(FM.NewBlockFilter) | ||
filterManager.reply(FM.NewFilterResponse(123)) | ||
res.futureValue shouldEqual Right(NewFilterResponse(123)) | ||
} | ||
|
||
it should "handle newPendingTransactionFilter request" in new TestSetup { | ||
val res = ethFilterService.newPendingTransactionFilter(NewPendingTransactionFilterRequest()).runToFuture | ||
filterManager.expectMsg(FM.NewPendingTransactionFilter) | ||
filterManager.reply(FM.NewFilterResponse(123)) | ||
res.futureValue shouldEqual Right(NewFilterResponse((123))) | ||
} | ||
|
||
it should "handle uninstallFilter request" in new TestSetup { | ||
val res = ethFilterService.uninstallFilter(UninstallFilterRequest(123)).runToFuture | ||
filterManager.expectMsg(FM.UninstallFilter(123)) | ||
filterManager.reply(FM.UninstallFilterResponse) | ||
res.futureValue shouldEqual Right(UninstallFilterResponse(true)) | ||
} | ||
|
||
it should "handle getFilterChanges request" in new TestSetup { | ||
val res = ethFilterService.getFilterChanges(GetFilterChangesRequest(123)).runToFuture | ||
filterManager.expectMsg(FM.GetFilterChanges(123)) | ||
val changes = FM.LogFilterChanges(Seq.empty) | ||
filterManager.reply(changes) | ||
res.futureValue shouldEqual Right(GetFilterChangesResponse(changes)) | ||
} | ||
|
||
it should "handle getFilterLogs request" in new TestSetup { | ||
val res = ethFilterService.getFilterLogs(GetFilterLogsRequest(123)).runToFuture | ||
filterManager.expectMsg(FM.GetFilterLogs(123)) | ||
val logs = FM.LogFilterLogs(Seq.empty) | ||
filterManager.reply(logs) | ||
res.futureValue shouldEqual Right(GetFilterLogsResponse(logs)) | ||
} | ||
|
||
it should "handle getLogs request" in new TestSetup { | ||
val filter = Filter(None, None, None, Seq.empty) | ||
val res = ethFilterService.getLogs(GetLogsRequest(filter)).runToFuture | ||
filterManager.expectMsg(FM.GetLogs(None, None, None, Seq.empty)) | ||
val logs = FM.LogFilterLogs(Seq.empty) | ||
filterManager.reply(logs) | ||
res.futureValue shouldEqual Right(GetLogsResponse(logs)) | ||
} | ||
|
||
class TestSetup(implicit system: ActorSystem) { | ||
val filterManager = TestProbe() | ||
val filterConfig = new FilterConfig { | ||
override val filterTimeout: FiniteDuration = Timeouts.normalTimeout | ||
override val filterManagerQueryTimeout: FiniteDuration = Timeouts.normalTimeout | ||
} | ||
|
||
lazy val ethFilterService = new EthFilterService( | ||
filterManager.ref, | ||
filterConfig | ||
) | ||
} | ||
} |